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_createtable = glueclient.create_table(
    CatalogId=catalogid,
    DatabaseName=databasename,
    Name=tablename,
    OpenTableFormatInput={
        'IcebergInput': {
            'MetadataOperation': 'CREATE',
            'Version': '2',
            'CreateIcebergTableInput': {
                'Location': table_location,
                'Schema': {
                    'SchemaId': 0,
                    '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'
                        }
                    ]
                },
                'PartitionSpec': {
                    'Fields': [
                        {
                            'SourceId': 1,
                            'Transform': 'identity',
                            'Name': 'transaction_id'
                        }
                    ],
                    'SpecId': 0
                },
                'WriteOrder': {
                    'OrderId': 1,
                    'Fields': [
                        {
                            'SourceId': 1,
                            'Transform': 'none',
                            'Direction': 'asc',
                            'NullOrder': 'nulls-last'
                        }
                    ]
                }
            }
        }
    }
)
print('response_createtable = ',response_createtable)
