@@ -223,11 +223,15 @@ def get_glue_table(self, relation: AthenaRelation) -> Optional[GetTableResponseT
223
223
"""
224
224
conn = self .connections .get_thread_connection ()
225
225
client = conn .handle
226
+
227
+ data_catalog = self ._get_data_catalog (relation .database )
228
+ catalog_id = get_catalog_id (data_catalog )
229
+
226
230
with boto3_client_lock :
227
231
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
228
232
229
233
try :
230
- table = glue_client .get_table (DatabaseName = relation .schema , Name = relation .identifier )
234
+ table = glue_client .get_table (CatalogId = catalog_id , DatabaseName = relation .schema , Name = relation .identifier )
231
235
except ClientError as e :
232
236
if e .response ["Error" ]["Code" ] == "EntityNotFoundException" :
233
237
LOGGER .debug (f"Table { relation .render ()} does not exists - Ignoring" )
@@ -596,16 +600,25 @@ def swap_table(self, src_relation: AthenaRelation, target_relation: AthenaRelati
596
600
conn = self .connections .get_thread_connection ()
597
601
client = conn .handle
598
602
603
+ data_catalog = self ._get_data_catalog (src_relation .database )
604
+ src_catalog_id = get_catalog_id (data_catalog )
605
+
599
606
with boto3_client_lock :
600
607
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
601
608
602
- src_table = glue_client .get_table (DatabaseName = src_relation .schema , Name = src_relation .identifier ).get ("Table" )
609
+ src_table = glue_client .get_table (
610
+ CatalogId = src_catalog_id , DatabaseName = src_relation .schema , Name = src_relation .identifier
611
+ ).get ("Table" )
612
+
603
613
src_table_partitions = glue_client .get_partitions (
604
- DatabaseName = src_relation .schema , TableName = src_relation .identifier
614
+ CatalogId = src_catalog_id , DatabaseName = src_relation .schema , TableName = src_relation .identifier
605
615
).get ("Partitions" )
606
616
617
+ data_catalog = self ._get_data_catalog (src_relation .database )
618
+ target_catalog_id = get_catalog_id (data_catalog )
619
+
607
620
target_table_partitions = glue_client .get_partitions (
608
- DatabaseName = target_relation .schema , TableName = target_relation .identifier
621
+ CatalogId = target_catalog_id , DatabaseName = target_relation .schema , TableName = target_relation .identifier
609
622
).get ("Partitions" )
610
623
611
624
target_table_version = {
@@ -618,7 +631,9 @@ def swap_table(self, src_relation: AthenaRelation, target_relation: AthenaRelati
618
631
}
619
632
620
633
# perform a table swap
621
- glue_client .update_table (DatabaseName = target_relation .schema , TableInput = target_table_version )
634
+ glue_client .update_table (
635
+ CatalogId = target_catalog_id , DatabaseName = target_relation .schema , TableInput = target_table_version
636
+ )
622
637
LOGGER .debug (f"Table { target_relation .render ()} swapped with the content of { src_relation .render ()} " )
623
638
624
639
# we delete the target table partitions in any case
@@ -627,6 +642,7 @@ def swap_table(self, src_relation: AthenaRelation, target_relation: AthenaRelati
627
642
if target_table_partitions :
628
643
for partition_batch in get_chunks (target_table_partitions , AthenaAdapter .BATCH_DELETE_PARTITION_API_LIMIT ):
629
644
glue_client .batch_delete_partition (
645
+ CatalogId = target_catalog_id ,
630
646
DatabaseName = target_relation .schema ,
631
647
TableName = target_relation .identifier ,
632
648
PartitionsToDelete = [{"Values" : partition ["Values" ]} for partition in partition_batch ],
@@ -635,6 +651,7 @@ def swap_table(self, src_relation: AthenaRelation, target_relation: AthenaRelati
635
651
if src_table_partitions :
636
652
for partition_batch in get_chunks (src_table_partitions , AthenaAdapter .BATCH_CREATE_PARTITION_API_LIMIT ):
637
653
glue_client .batch_create_partition (
654
+ CatalogId = target_catalog_id ,
638
655
DatabaseName = target_relation .schema ,
639
656
TableName = target_relation .identifier ,
640
657
PartitionInputList = [
@@ -676,6 +693,9 @@ def expire_glue_table_versions(
676
693
conn = self .connections .get_thread_connection ()
677
694
client = conn .handle
678
695
696
+ data_catalog = self ._get_data_catalog (relation .database )
697
+ catalog_id = get_catalog_id (data_catalog )
698
+
679
699
with boto3_client_lock :
680
700
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
681
701
@@ -688,7 +708,10 @@ def expire_glue_table_versions(
688
708
location = v ["Table" ]["StorageDescriptor" ]["Location" ]
689
709
try :
690
710
glue_client .delete_table_version (
691
- DatabaseName = relation .schema , TableName = relation .identifier , VersionId = str (version )
711
+ CatalogId = catalog_id ,
712
+ DatabaseName = relation .schema ,
713
+ TableName = relation .identifier ,
714
+ VersionId = str (version ),
692
715
)
693
716
deleted_versions .append (version )
694
717
LOGGER .debug (f"Deleted version { version } of table { relation .render ()} " )
@@ -720,13 +743,16 @@ def persist_docs_to_glue(
720
743
conn = self .connections .get_thread_connection ()
721
744
client = conn .handle
722
745
746
+ data_catalog = self ._get_data_catalog (relation .database )
747
+ catalog_id = get_catalog_id (data_catalog )
748
+
723
749
with boto3_client_lock :
724
750
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
725
751
726
752
# By default, there is no need to update Glue Table
727
753
need_udpate_table = False
728
754
# Get Table from Glue
729
- table = glue_client .get_table (DatabaseName = relation .schema , Name = relation .name )["Table" ]
755
+ table = glue_client .get_table (CatalogId = catalog_id , DatabaseName = relation .schema , Name = relation .name )["Table" ]
730
756
# Prepare new version of Glue Table picking up significant fields
731
757
updated_table = self ._get_table_input (table )
732
758
# Update table description
@@ -766,7 +792,10 @@ def persist_docs_to_glue(
766
792
# It prevents redundant schema version creating after incremental runs.
767
793
if need_udpate_table :
768
794
glue_client .update_table (
769
- DatabaseName = relation .schema , TableInput = updated_table , SkipArchive = skip_archive_table_version
795
+ CatalogId = catalog_id ,
796
+ DatabaseName = relation .schema ,
797
+ TableInput = updated_table ,
798
+ SkipArchive = skip_archive_table_version ,
770
799
)
771
800
772
801
@available
@@ -797,11 +826,16 @@ def get_columns_in_relation(self, relation: AthenaRelation) -> List[AthenaColumn
797
826
conn = self .connections .get_thread_connection ()
798
827
client = conn .handle
799
828
829
+ data_catalog = self ._get_data_catalog (relation .database )
830
+ catalog_id = get_catalog_id (data_catalog )
831
+
800
832
with boto3_client_lock :
801
833
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
802
834
803
835
try :
804
- table = glue_client .get_table (DatabaseName = relation .schema , Name = relation .identifier )["Table" ]
836
+ table = glue_client .get_table (CatalogId = catalog_id , DatabaseName = relation .schema , Name = relation .identifier )[
837
+ "Table"
838
+ ]
805
839
except ClientError as e :
806
840
if e .response ["Error" ]["Code" ] == "EntityNotFoundException" :
807
841
LOGGER .debug ("table not exist, catching the error" )
@@ -829,11 +863,14 @@ def delete_from_glue_catalog(self, relation: AthenaRelation) -> None:
829
863
conn = self .connections .get_thread_connection ()
830
864
client = conn .handle
831
865
866
+ data_catalog = self ._get_data_catalog (relation .database )
867
+ catalog_id = get_catalog_id (data_catalog )
868
+
832
869
with boto3_client_lock :
833
870
glue_client = client .session .client ("glue" , region_name = client .region_name , config = get_boto3_config ())
834
871
835
872
try :
836
- glue_client .delete_table (DatabaseName = schema_name , Name = table_name )
873
+ glue_client .delete_table (CatalogId = catalog_id , DatabaseName = schema_name , Name = table_name )
837
874
LOGGER .debug (f"Deleted table from glue catalog: { relation .render ()} " )
838
875
except ClientError as e :
839
876
if e .response ["Error" ]["Code" ] == "EntityNotFoundException" :
0 commit comments