import sys
import boto3
import json
import argparse
import logging

lfclient = boto3.client('lakeformation')
glueclient = boto3.client('glue')
print('boto3 version = ', boto3.__version__)
stsclient = boto3.client("sts")


catalogid= stsclient.get_caller_identity()["Account"]
databasename= 'bankdata_icebergdb'
tablename='transactiontable3'
table_location= 's3://sampledatabucket/bankdataiceberg/transactiontable3/'


response_updatetable = glueclient.update_table(
    CatalogId=catalogid,
    DatabaseName=databasename,
    Name=tablename,
    UpdateOpenTableFormatInput={
        'UpdateIcebergInput': {
            'UpdateIcebergTableInput': {
                'Updates': [
                    {
                        'Location': table_location,
                        'Schema': {
                            'SchemaId': 1,
                            'Type': 'struct',
                            'Fields': [
                                { 
                                   'Id': 1,
                                   'Name': 'transaction_id',
                                   'Required': True,
                                   'Type': 'string'
                                },
                                { 
                                   'Id': 2,
                                   'Name': 'transaction_name',
                                   'Required': True,
                                   'Type': 'string'
                                },
                                { 
                                   'Id': 3,
                                   'Name': 'transaction_amount',
                                   'Required': True,
                                   'Type': 'float'
                                },
                                { 
                                   'Id': 4,
                                   'Name': 'transaction_date',
                                   'Required': True,
                                   'Type': 'date'
                                },
                            ]
                        },
                        'PartitionSpec': {
                            'Fields': [
                                {
                                    'SourceId': 1,
                                    'Transform': 'identity',
                                    'Name': 'transaction_id'
                                },
                                {
                                    'SourceId': 4,
                                    'Transform': 'year',
                                    'Name': 'transaction_date'
                                }
                            ],
                            'SpecId': 1
                        },
                        'SortOrder': {
                            'OrderId': 1,
                            'Fields': [
                                {
                                    'SourceId': 1,
                                    'Transform': 'none',
                                    'Direction': 'asc',
                                    'NullOrder': 'nulls-last'
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
)
print('response_updatetable = ',response_updatetable)
