|
25 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
26 | 26 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
27 | 27 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
| 28 | +import static org.mockito.Mockito.mock; |
| 29 | +import static org.mockito.Mockito.when; |
28 | 30 |
|
29 | 31 | import java.nio.file.Path;
|
30 | 32 | import java.time.Instant;
|
31 | 33 | import java.time.temporal.ChronoUnit;
|
32 | 34 | import java.util.ArrayList;
|
33 | 35 | import java.util.Arrays;
|
34 | 36 | import java.util.Collections;
|
| 37 | +import java.util.HashMap; |
35 | 38 | import java.util.List;
|
36 | 39 | import java.util.Map;
|
37 | 40 |
|
38 | 41 | import lombok.SneakyThrows;
|
39 | 42 |
|
40 | 43 | import org.apache.hadoop.conf.Configuration;
|
| 44 | +import org.apache.iceberg.Table; |
| 45 | +import org.apache.iceberg.catalog.Catalog; |
| 46 | +import org.apache.iceberg.catalog.TableIdentifier; |
41 | 47 | import org.junit.jupiter.api.BeforeEach;
|
42 | 48 | import org.junit.jupiter.api.Test;
|
43 | 49 | import org.junit.jupiter.api.io.TempDir;
|
|
61 | 67 | import org.apache.xtable.model.schema.PartitionTransformType;
|
62 | 68 | import org.apache.xtable.model.storage.DataLayoutStrategy;
|
63 | 69 | import org.apache.xtable.model.storage.TableFormat;
|
| 70 | +import org.mockito.Mockito; |
64 | 71 |
|
65 | 72 | public class ITIcebergConversionSource {
|
66 | 73 | private static final Configuration hadoopConf = new Configuration();
|
@@ -126,7 +133,95 @@ void getCurrentTableTest() {
|
126 | 133 | .build();
|
127 | 134 | validateTable(
|
128 | 135 | internalTable,
|
| 136 | + testIcebergTable.getTableName(), |
| 137 | + TableFormat.ICEBERG, |
| 138 | + internalSchema, |
| 139 | + DataLayoutStrategy.FLAT, |
129 | 140 | testIcebergTable.getBasePath(),
|
| 141 | + Collections.emptyList()); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + void getCurrentTableWithCatalogConfigTest() { |
| 147 | + String tableName = getTableName(); |
| 148 | + try (TestIcebergTable testIcebergTable = |
| 149 | + new TestIcebergTable( |
| 150 | + tableName, |
| 151 | + tempDir, |
| 152 | + hadoopConf, |
| 153 | + "field1", |
| 154 | + Collections.singletonList(null), |
| 155 | + TestIcebergDataHelper.SchemaType.BASIC)) { |
| 156 | + testIcebergTable.insertRows(50); |
| 157 | + |
| 158 | + // create resources |
| 159 | + Map<String, String> OPTIONS = Collections.singletonMap("key", "value"); |
| 160 | + Catalog mockCatalog = mock(Catalog.class); |
| 161 | + String catalogName = "catalog1"; |
| 162 | + StubCatalog.registerMock(catalogName, mockCatalog); |
| 163 | + IcebergCatalogConfig catalogConfig = |
| 164 | + IcebergCatalogConfig.builder() |
| 165 | + .catalogImpl(StubCatalog.class.getName()) |
| 166 | + .catalogName(catalogName) |
| 167 | + .catalogOptions(OPTIONS) |
| 168 | + .build(); |
| 169 | + Map<Integer, org.apache.iceberg.Schema> map = new HashMap<>(); |
| 170 | + map.put(0, testIcebergTable.getSchema()); |
| 171 | + Table mockTable = mock(Table.class, Mockito.RETURNS_DEEP_STUBS); |
| 172 | + when(mockTable.name()).thenReturn(tableName); |
| 173 | + when(mockTable.location()).thenReturn(testIcebergTable.getBasePath()); |
| 174 | + when(mockTable.schemas()).thenReturn(map); |
| 175 | + |
| 176 | + when(mockCatalog.loadTable(Mockito.any(TableIdentifier.class))) |
| 177 | + .thenReturn(mockTable); |
| 178 | + |
| 179 | + // begin test |
| 180 | + SourceTable tableConfig = |
| 181 | + SourceTable.builder() |
| 182 | + .name(testIcebergTable.getTableName()) |
| 183 | + .basePath(testIcebergTable.getBasePath()) |
| 184 | + .formatName(TableFormat.ICEBERG) |
| 185 | + .catalogConfig(catalogConfig) |
| 186 | + .build(); |
| 187 | + IcebergConversionSource conversionSource = |
| 188 | + sourceProvider.getConversionSourceInstance(tableConfig); |
| 189 | + InternalTable internalTable = conversionSource.getCurrentTable(); |
| 190 | + |
| 191 | + // expectations |
| 192 | + InternalSchema internalSchema = |
| 193 | + InternalSchema.builder() |
| 194 | + .name("record") |
| 195 | + .dataType(InternalType.RECORD) |
| 196 | + .fields( |
| 197 | + Arrays.asList( |
| 198 | + InternalField.builder() |
| 199 | + .name("field1") |
| 200 | + .fieldId(1) |
| 201 | + .schema( |
| 202 | + InternalSchema.builder() |
| 203 | + .name("string") |
| 204 | + .dataType(InternalType.STRING) |
| 205 | + .isNullable(true) |
| 206 | + .build()) |
| 207 | + .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE) |
| 208 | + .build(), |
| 209 | + InternalField.builder() |
| 210 | + .name("field2") |
| 211 | + .fieldId(2) |
| 212 | + .schema( |
| 213 | + InternalSchema.builder() |
| 214 | + .name("string") |
| 215 | + .dataType(InternalType.STRING) |
| 216 | + .isNullable(true) |
| 217 | + .build()) |
| 218 | + .defaultValue(InternalField.Constants.NULL_DEFAULT_VALUE) |
| 219 | + .build())) |
| 220 | + .build(); |
| 221 | + |
| 222 | + validateTable( |
| 223 | + internalTable, |
| 224 | + testIcebergTable.getTableName(), |
130 | 225 | TableFormat.ICEBERG,
|
131 | 226 | internalSchema,
|
132 | 227 | DataLayoutStrategy.FLAT,
|
|
0 commit comments