1818
1919package org .apache .xtable .hms ;
2020
21+ import java .util .Arrays ;
2122import java .util .Collections ;
2223import java .util .HashMap ;
24+ import java .util .List ;
2325import java .util .Map ;
2426
2527import org .apache .hadoop .conf .Configuration ;
2628import org .apache .hadoop .hive .metastore .IMetaStoreClient ;
2729import org .apache .hadoop .hive .metastore .api .Database ;
30+ import org .apache .hadoop .hive .metastore .api .FieldSchema ;
2831import org .apache .hadoop .hive .metastore .api .StorageDescriptor ;
2932import org .apache .hadoop .hive .metastore .api .Table ;
3033import org .mockito .Mock ;
3134
3235import org .apache .xtable .conversion .ExternalCatalogConfig ;
3336import org .apache .xtable .model .InternalTable ;
3437import org .apache .xtable .model .catalog .ThreePartHierarchicalTableIdentifier ;
38+ import org .apache .xtable .model .schema .InternalField ;
39+ import org .apache .xtable .model .schema .InternalPartitionField ;
3540import org .apache .xtable .model .schema .InternalSchema ;
41+ import org .apache .xtable .model .schema .InternalType ;
42+ import org .apache .xtable .model .schema .PartitionTransformType ;
3643import org .apache .xtable .model .storage .CatalogType ;
3744import org .apache .xtable .model .storage .TableFormat ;
3845
@@ -57,17 +64,80 @@ public class HMSCatalogSyncClientTestBase {
5764
5865 protected static final String ICEBERG_METADATA_FILE_LOCATION = "base-path/metadata" ;
5966 protected static final String ICEBERG_METADATA_FILE_LOCATION_V2 = "base-path/v2-metadata" ;
67+ protected static final InternalPartitionField PARTITION_FIELD =
68+ InternalPartitionField .builder ()
69+ .sourceField (
70+ InternalField .builder ()
71+ .name ("partitionField" )
72+ .schema (
73+ InternalSchema .builder ().name ("string" ).dataType (InternalType .STRING ).build ())
74+ .build ())
75+ .transformType (PartitionTransformType .VALUE )
76+ .build ();
77+ protected static final InternalSchema INTERNAL_SCHEMA =
78+ InternalSchema .builder ()
79+ .dataType (InternalType .RECORD )
80+ .fields (
81+ Arrays .asList (
82+ getInternalField ("intField" , "int" , InternalType .INT ),
83+ getInternalField ("stringField" , "string" , InternalType .STRING ),
84+ getInternalField ("partitionField" , "string" , InternalType .STRING )))
85+ .build ();
86+ protected static final InternalSchema UPDATED_INTERNAL_SCHEMA =
87+ InternalSchema .builder ()
88+ .dataType (InternalType .RECORD )
89+ .fields (
90+ Arrays .asList (
91+ getInternalField ("intField" , "int" , InternalType .INT ),
92+ getInternalField ("stringField" , "string" , InternalType .STRING ),
93+ getInternalField ("partitionField" , "string" , InternalType .STRING ),
94+ getInternalField ("booleanField" , "boolean" , InternalType .BOOLEAN )))
95+ .build ();
96+ protected static final List <FieldSchema > FIELD_SCHEMA =
97+ Arrays .asList (
98+ getFieldSchema ("intField" , "int" ),
99+ getFieldSchema ("stringField" , "string" ),
100+ getFieldSchema ("partitionField" , "string" ));
101+ protected static final List <FieldSchema > UPDATED_FIELD_SCHEMA =
102+ Arrays .asList (
103+ getFieldSchema ("intField" , "int" ),
104+ getFieldSchema ("stringField" , "string" ),
105+ getFieldSchema ("partitionField" , "string" ),
106+ getFieldSchema ("booleanField" , "boolean" ));
60107 protected static final InternalTable TEST_ICEBERG_INTERNAL_TABLE =
61108 InternalTable .builder ()
62109 .basePath (TEST_BASE_PATH )
63110 .tableFormat (TableFormat .ICEBERG )
64- .readSchema (InternalSchema .builder ().fields (Collections .emptyList ()).build ())
111+ .readSchema (INTERNAL_SCHEMA )
112+ .partitioningFields (Collections .singletonList (PARTITION_FIELD ))
113+ .build ();
114+ protected static final InternalTable TEST_UPDATED_ICEBERG_INTERNAL_TABLE =
115+ InternalTable .builder ()
116+ .basePath (TEST_BASE_PATH )
117+ .tableFormat (TableFormat .ICEBERG )
118+ .readSchema (UPDATED_INTERNAL_SCHEMA )
119+ .partitioningFields (Collections .singletonList (PARTITION_FIELD ))
120+ .build ();
121+ protected static final InternalTable TEST_DELTA_INTERNAL_TABLE =
122+ InternalTable .builder ()
123+ .basePath (TEST_BASE_PATH )
124+ .tableFormat (TableFormat .DELTA )
125+ .readSchema (INTERNAL_SCHEMA )
126+ .partitioningFields (Collections .singletonList (PARTITION_FIELD ))
127+ .build ();
128+ protected static final InternalTable TEST_UPDATED_DELTA_INTERNAL_TABLE =
129+ InternalTable .builder ()
130+ .basePath (TEST_BASE_PATH )
131+ .tableFormat (TableFormat .DELTA )
132+ .readSchema (UPDATED_INTERNAL_SCHEMA )
133+ .partitioningFields (Collections .singletonList (PARTITION_FIELD ))
65134 .build ();
66135 protected static final InternalTable TEST_HUDI_INTERNAL_TABLE =
67136 InternalTable .builder ()
68137 .basePath (TEST_BASE_PATH )
69138 .tableFormat (TableFormat .HUDI )
70- .readSchema (InternalSchema .builder ().fields (Collections .emptyList ()).build ())
139+ .readSchema (INTERNAL_SCHEMA )
140+ .partitioningFields (Collections .singletonList (PARTITION_FIELD ))
71141 .build ();
72142 protected static final ThreePartHierarchicalTableIdentifier TEST_CATALOG_TABLE_IDENTIFIER =
73143 new ThreePartHierarchicalTableIdentifier (TEST_HMS_DATABASE , TEST_HMS_TABLE );
@@ -95,4 +165,16 @@ protected Database newDatabase(String dbName) {
95165 return new Database (
96166 dbName , "Created by " + HMSCatalogSyncClient .class .getName (), null , Collections .emptyMap ());
97167 }
168+
169+ protected static FieldSchema getFieldSchema (String name , String type ) {
170+ return new FieldSchema (name , type , null );
171+ }
172+
173+ protected static InternalField getInternalField (
174+ String fieldName , String schemaName , InternalType dataType ) {
175+ return InternalField .builder ()
176+ .name (fieldName )
177+ .schema (InternalSchema .builder ().name (schemaName ).dataType (dataType ).build ())
178+ .build ();
179+ }
98180}
0 commit comments