import boto3

class helper:
    def get_table_location(self,database, table_name):
        """
        get table data location from glue catalogue
        :param database: database name
        :param table_name: table name
        :return: full path to data
        """
        boto_glue = boto3.client("glue", region_name='us-east-1', 
                      aws_access_key_id='AKIATBUD4GB6F6DFJQ53',
                  aws_secret_access_key='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')
        table_def = boto_glue.get_table(DatabaseName=database, Name=table_name)
        return table_def["Table"]["StorageDescriptor"]["Location"]



    def create_index(self,database, table, column, index_name):
        # Create a client for the Glue service
        client = boto3.client("glue", region_name='us-east-1', 
                        aws_access_key_id='AKIATBUD4GB6F6DFJQ53',
                    aws_secret_access_key='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')
        
        # Create an index on the specified column of the table
        client.create_partition_index(
            TableName={
                "DatabaseName": database,
                "Name": table
            },
            PartitionIndex={
                "Name": index_name,
                "Columns": [
                    {
                        "Name": column,
                        "Type": "varchar",
                        "SortOrder": 1
                    }
                ],
                "IsUnique": True
            }
        )


    def create_partition_index(self, catalog_id, database_name, table_name, index_name, keys):
        glue_client = boto3.client("glue", region_name='us-east-1', 
                            aws_access_key_id='AKIATBUD4GB6F6DFJQ53',
                        aws_secret_access_key='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')

        response = glue_client.create_partition_index(
            CatalogId=catalog_id,
            DatabaseName=database_name,
            TableName=table_name,
            PartitionIndex={
                'IndexName': index_name,
                'Keys': ['uuid_z']
            }
        )

    

"""# Example usage"""


#print(helper.get_table_location('assortment_dev','assortment_dev'))
h= helper()
h.create_partition_index(
    
    database_name='bungeedatawarehouse',
    table_name='bungee_global_prod_d_back_up_20221229',
    index_name='idx_uuid_z',
    keys=[
        {
            'Name': 'uuid_z',
            'Type': 'string'
        }
    ]
)