@@ -116,6 +116,37 @@ void getTableTest(@TempDir Path workingDir) throws IOException {
116116 internalTable .getPartitioningFields ().get (0 ).getTransformType ());
117117 }
118118
119+ @ Test
120+ void testGetTableWithoutSnapshot (@ TempDir Path workingDir ) throws IOException {
121+ Table emptyTable = createTestCatalogTable (workingDir .toString ());
122+ assertNull (emptyTable .currentSnapshot ());
123+
124+ SourceTable sourceTableConfig = getPerTableConfig (emptyTable );
125+
126+ IcebergConversionSource conversionSource =
127+ sourceProvider .getConversionSourceInstance (sourceTableConfig );
128+
129+ InternalTable internalTable = conversionSource .getTable (null );
130+ assertNotNull (internalTable );
131+ assertEquals (TableFormat .ICEBERG , internalTable .getTableFormat ());
132+ assertEquals (emptyTable .location (), internalTable .getBasePath ());
133+ assertEquals (
134+ ((BaseTable ) emptyTable ).operations ().current ().lastUpdatedMillis (),
135+ internalTable .getLatestCommitTime ().toEpochMilli ());
136+
137+ assertEquals (
138+ emptyTable .schema ().columns ().size (), internalTable .getReadSchema ().getFields ().size ());
139+ validateSchema (internalTable .getReadSchema (), emptyTable .schema ());
140+
141+ assertEquals (1 , internalTable .getPartitioningFields ().size ());
142+ InternalField partitionField = internalTable .getPartitioningFields ().get (0 ).getSourceField ();
143+ assertEquals ("cs_sold_date_sk" , partitionField .getName ());
144+ assertEquals (7 , partitionField .getFieldId ());
145+ assertEquals (
146+ PartitionTransformType .VALUE ,
147+ internalTable .getPartitioningFields ().get (0 ).getTransformType ());
148+ }
149+
119150 @ Test
120151 public void testGetCurrentSnapshot (@ TempDir Path workingDir ) throws IOException {
121152 Table catalogSales = createTestTableWithData (workingDir .toString ());
@@ -164,6 +195,45 @@ public void testGetCurrentSnapshot(@TempDir Path workingDir) throws IOException
164195 }
165196 }
166197
198+ @ Test
199+ void testGetCurrentSnapshotForEmptyTable (@ TempDir Path workingDir ) throws IOException {
200+ Table emptyTable = createTestCatalogTable (workingDir .toString ());
201+ assertNull (emptyTable .currentSnapshot ());
202+
203+ SourceTable sourceTableConfig = getPerTableConfig (emptyTable );
204+
205+ IcebergDataFileExtractor spyDataFileExtractor = spy (IcebergDataFileExtractor .builder ().build ());
206+ IcebergPartitionValueConverter spyPartitionConverter =
207+ spy (IcebergPartitionValueConverter .getInstance ());
208+
209+ IcebergConversionSource conversionSource =
210+ IcebergConversionSource .builder ()
211+ .hadoopConf (hadoopConf )
212+ .sourceTableConfig (sourceTableConfig )
213+ .dataFileExtractor (spyDataFileExtractor )
214+ .partitionConverter (spyPartitionConverter )
215+ .build ();
216+
217+ InternalSnapshot internalSnapshot = conversionSource .getCurrentSnapshot ();
218+ assertNotNull (internalSnapshot );
219+ assertEquals ("0" , internalSnapshot .getVersion ());
220+ assertEquals ("0" , internalSnapshot .getSourceIdentifier ());
221+ assertTrue (internalSnapshot .getPartitionedDataFiles ().isEmpty ());
222+
223+ InternalTable internalTable = internalSnapshot .getTable ();
224+ assertNotNull (internalTable );
225+ assertEquals (emptyTable .location (), internalTable .getBasePath ());
226+ assertEquals (
227+ ((BaseTable ) emptyTable ).operations ().current ().lastUpdatedMillis (),
228+ internalTable .getLatestCommitTime ().toEpochMilli ());
229+
230+ assertEquals (
231+ emptyTable .schema ().columns ().size (), internalTable .getReadSchema ().getFields ().size ());
232+
233+ verify (spyPartitionConverter , never ()).toXTable (any (), any (), any ());
234+ verify (spyDataFileExtractor , never ()).fromIceberg (any (), any (), any ());
235+ }
236+
167237 @ Test
168238 public void testGetTableChangeForCommit (@ TempDir Path workingDir ) throws IOException {
169239 Table catalogSales = createTestTableWithData (workingDir .toString ());
0 commit comments