use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesInputDataTransformer method testInvalidPartition.
@Test
public void testInvalidPartition() {
TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").build();
thrown.expect(IcebergMetastoreException.class);
new InputDataTransformer<TableMetadataUnit>(metastoreSchema, partitionSchema, unitGetters).units(Collections.singletonList(unit)).execute();
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesOutputDataTransformer method testValidDataOneRecord.
@Test
public void testValidDataOneRecord() {
Map<String, String> partitionKeys = new HashMap<>();
partitionKeys.put("dir0", "2018");
partitionKeys.put("dir1", "2019");
List<String> partitionValues = Arrays.asList("a", "b", "c");
Long lastModifiedTime = System.currentTimeMillis();
Record record = GenericRecord.create(schema);
record.setField("storagePlugin", "dfs");
record.setField("workspace", "tmp");
record.setField("tableName", "nation");
record.setField("partitionKeys", partitionKeys);
record.setField("partitionValues", partitionValues);
record.setField("lastModifiedTime", lastModifiedTime);
List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).columns(Arrays.asList("storagePlugin", "workspace", "tableName", "partitionKeys", "partitionValues", "lastModifiedTime")).records(Collections.singletonList(record)).execute();
List<TableMetadataUnit> expectedResult = Collections.singletonList(TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").partitionKeys(partitionKeys).partitionValues(partitionValues).lastModifiedTime(lastModifiedTime).build());
assertEquals(expectedResult, actualResult);
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesOutputDataTransformer method testValidDataSeveralRecords.
@Test
public void testValidDataSeveralRecords() {
Record record1 = GenericRecord.create(schema);
record1.setField("tableName", "a");
Record record2 = GenericRecord.create(schema);
record2.setField("tableName", "b");
Record record3 = GenericRecord.create(schema);
record3.setField("tableName", "c");
List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).columns(Collections.singletonList("tableName")).records(Arrays.asList(record1, record2, record3)).execute();
List<TableMetadataUnit> expectedResult = Arrays.asList(TableMetadataUnit.builder().tableName("a").build(), TableMetadataUnit.builder().tableName("b").build(), TableMetadataUnit.builder().tableName("c").build());
assertEquals(expectedResult, actualResult);
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TablesOutputDataTransformer method execute.
@Override
public List<TableMetadataUnit> execute() {
List<TableMetadataUnit> results = new ArrayList<>();
for (Map<MethodHandle, Object> valueToSet : valuesToSet()) {
TableMetadataUnit.Builder builder = TableMetadataUnit.builder();
for (Map.Entry<MethodHandle, Object> entry : valueToSet.entrySet()) {
try {
entry.getKey().invokeWithArguments(builder, entry.getValue());
} catch (Throwable e) {
throw new IcebergMetastoreException(String.format("Unable to invoke setter for [%s] using [%s]", TableMetadataUnit.Builder.class.getSimpleName(), entry.getKey()), e);
}
}
results.add(builder.build());
}
return results;
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesInputDataTransformer method testValidDataOneRecord.
@Test
public void testValidDataOneRecord() {
Map<String, String> partitionKeys = new HashMap<>();
partitionKeys.put("dir0", "2018");
partitionKeys.put("dir1", "2019");
List<String> partitionValues = Arrays.asList("a", "b", "c");
Long lastModifiedTime = System.currentTimeMillis();
TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataType(MetadataType.TABLE.name()).metadataIdentifier(MetadataInfo.GENERAL_INFO_KEY).partitionKeys(partitionKeys).partitionValues(partitionValues).lastModifiedTime(lastModifiedTime).build();
InputDataTransformer<TableMetadataUnit> inputDataTransformer = new InputDataTransformer<>(TableMetadataUnit.SCHEMA.unitGetters());
List<Document> documents = inputDataTransformer.units(Collections.singletonList(unit)).execute();
Document tableRecord = new Document();
tableRecord.append("storagePlugin", "dfs");
tableRecord.append("workspace", "tmp");
tableRecord.append("tableName", "nation");
tableRecord.append("metadataType", "TABLE");
tableRecord.append("metadataIdentifier", MetadataInfo.GENERAL_INFO_KEY);
assertEquals(tableRecord, documents.get(0).get(MongoConfigConstants.ID));
assertEquals(partitionKeys, documents.get(0).get("partitionKeys"));
assertEquals(partitionValues, documents.get(0).get("partitionValues"));
assertEquals(lastModifiedTime, documents.get(0).get("lastModifiedTime"));
}
Aggregations