|
17 | 17 |
|
18 | 18 | package org.apache.doris.datasource.iceberg; |
19 | 19 |
|
| 20 | +import org.apache.doris.catalog.Column; |
| 21 | +import org.apache.doris.catalog.Type; |
20 | 22 | import org.apache.doris.common.security.authentication.ExecutionAuthenticator; |
21 | 23 | import org.apache.doris.datasource.CatalogProperty; |
22 | 24 | import org.apache.doris.datasource.ExternalDatabase; |
|
28 | 30 | import org.apache.doris.filesystem.FileSystem; |
29 | 31 | import org.apache.doris.filesystem.Location; |
30 | 32 | import org.apache.doris.fs.MemoryFileSystem; |
| 33 | +import org.apache.doris.nereids.trees.plans.commands.info.CreateTableInfo; |
31 | 34 |
|
| 35 | +import org.apache.iceberg.CatalogProperties; |
| 36 | +import org.apache.iceberg.PartitionSpec; |
| 37 | +import org.apache.iceberg.Schema; |
| 38 | +import org.apache.iceberg.TableProperties; |
32 | 39 | import org.apache.iceberg.catalog.Catalog; |
33 | 40 | import org.apache.iceberg.catalog.Namespace; |
34 | 41 | import org.apache.iceberg.catalog.SupportsNamespaces; |
35 | 42 | import org.apache.iceberg.catalog.TableIdentifier; |
36 | 43 | import org.apache.iceberg.catalog.ViewCatalog; |
37 | 44 | import org.junit.Assert; |
38 | 45 | import org.junit.jupiter.api.Test; |
| 46 | +import org.mockito.ArgumentCaptor; |
39 | 47 | import org.mockito.Mockito; |
40 | 48 |
|
41 | 49 | import java.io.IOException; |
@@ -129,6 +137,42 @@ public void testListTableNamesFiltersViewsWhenRestViewEnabled() { |
129 | 137 | Assert.assertEquals(Collections.singletonList("DORIS_HORIZON_T"), tableNames); |
130 | 138 | } |
131 | 139 |
|
| 140 | + @Test |
| 141 | + public void testPerformCreateTableRespectsCatalogDefaultFormatVersion() throws Exception { |
| 142 | + Map<String, String> catalogProps = new HashMap<>(); |
| 143 | + catalogProps.put(CatalogProperties.TABLE_DEFAULT_PREFIX + TableProperties.FORMAT_VERSION, "3"); |
| 144 | + IcebergExternalCatalog dorisCatalog = mockHmsCatalog(catalogProps); |
| 145 | + Catalog icebergCatalog = Mockito.mock(Catalog.class, |
| 146 | + Mockito.withSettings().extraInterfaces(SupportsNamespaces.class)); |
| 147 | + IcebergMetadataOps ops = new IcebergMetadataOps(dorisCatalog, icebergCatalog); |
| 148 | + |
| 149 | + ExternalDatabase<?> dorisDb = Mockito.mock(ExternalDatabase.class); |
| 150 | + Mockito.when(dorisDb.getRemoteName()).thenReturn("db"); |
| 151 | + Mockito.when(dorisDb.getTableNullable("tbl")).thenReturn(null); |
| 152 | + Mockito.doReturn(dorisDb).when(dorisCatalog).getDbNullable("db"); |
| 153 | + Mockito.when(dorisCatalog.getName()).thenReturn("iceberg_catalog"); |
| 154 | + Mockito.when(icebergCatalog.tableExists(TableIdentifier.of("db", "tbl"))).thenReturn(false); |
| 155 | + |
| 156 | + CreateTableInfo createTableInfo = Mockito.mock(CreateTableInfo.class); |
| 157 | + Map<String, String> tableProps = new HashMap<>(); |
| 158 | + Mockito.when(createTableInfo.getDbName()).thenReturn("db"); |
| 159 | + Mockito.when(createTableInfo.getTableName()).thenReturn("tbl"); |
| 160 | + Mockito.when(createTableInfo.isIfNotExists()).thenReturn(false); |
| 161 | + Mockito.when(createTableInfo.getColumns()).thenReturn(Collections.singletonList( |
| 162 | + new Column("id", Type.INT, true))); |
| 163 | + Mockito.when(createTableInfo.getProperties()).thenReturn(tableProps); |
| 164 | + |
| 165 | + ops.performCreateTable(createTableInfo); |
| 166 | + |
| 167 | + Mockito.verify(createTableInfo).validateIcebergRowLineageColumns(3); |
| 168 | + ArgumentCaptor<Map<String, String>> propsCaptor = ArgumentCaptor.forClass(Map.class); |
| 169 | + Mockito.verify(icebergCatalog).createTable(Mockito.eq(TableIdentifier.of("db", "tbl")), |
| 170 | + Mockito.any(Schema.class), Mockito.any(PartitionSpec.class), propsCaptor.capture()); |
| 171 | + Assert.assertFalse(propsCaptor.getValue().containsKey(TableProperties.FORMAT_VERSION)); |
| 172 | + Assert.assertEquals(3, IcebergUtils.getEffectiveIcebergFormatVersion( |
| 173 | + propsCaptor.getValue(), catalogProps)); |
| 174 | + } |
| 175 | + |
132 | 176 | @Test |
133 | 177 | public void testDropTableCleansEmptyTableLocation() throws Exception { |
134 | 178 | MemoryFileSystem fs = new MemoryFileSystem(); |
@@ -214,10 +258,14 @@ public void testDeleteEmptyTableLocationCleansFlatObjectStoreMarkers() throws Ex |
214 | 258 | } |
215 | 259 |
|
216 | 260 | private IcebergExternalCatalog mockHmsCatalog() { |
| 261 | + return mockHmsCatalog(Collections.emptyMap()); |
| 262 | + } |
| 263 | + |
| 264 | + private IcebergExternalCatalog mockHmsCatalog(Map<String, String> catalogProperties) { |
217 | 265 | IcebergExternalCatalog dorisCatalog = Mockito.mock(IcebergExternalCatalog.class); |
218 | 266 | Mockito.when(dorisCatalog.getExecutionAuthenticator()).thenReturn(new ExecutionAuthenticator() { |
219 | 267 | }); |
220 | | - Mockito.when(dorisCatalog.getProperties()).thenReturn(Collections.emptyMap()); |
| 268 | + Mockito.when(dorisCatalog.getProperties()).thenReturn(catalogProperties); |
221 | 269 | Mockito.when(dorisCatalog.getIcebergCatalogType()).thenReturn(IcebergExternalCatalog.ICEBERG_HMS); |
222 | 270 | Mockito.when(dorisCatalog.getCatalogProperty()).thenReturn(new CatalogProperty(null, Collections.emptyMap())); |
223 | 271 | return dorisCatalog; |
|
0 commit comments