use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesInputDataTransformer method testValidDataSeveralRecords.
@Test
public void testValidDataSeveralRecords() {
List<TableMetadataUnit> units = Arrays.asList(TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataType(MetadataType.TABLE.name()).metadataIdentifier(MetadataInfo.GENERAL_INFO_KEY).column("a").build(), TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataType(MetadataType.TABLE.name()).metadataIdentifier(MetadataInfo.GENERAL_INFO_KEY).column("b").build(), TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataType(MetadataType.TABLE.name()).metadataIdentifier(MetadataInfo.GENERAL_INFO_KEY).column("c").build());
InputDataTransformer<TableMetadataUnit> inputDataTransformer = new InputDataTransformer<>(TableMetadataUnit.SCHEMA.unitGetters());
List<Document> documents = inputDataTransformer.units(units).execute();
Document tableRecord1 = new Document();
tableRecord1.append("storagePlugin", "dfs");
tableRecord1.append("workspace", "tmp");
tableRecord1.append("tableName", "nation");
tableRecord1.append("metadataType", "TABLE");
tableRecord1.append("metadataIdentifier", MetadataInfo.GENERAL_INFO_KEY);
Document tableRecord2 = new Document();
tableRecord2.append("storagePlugin", "dfs");
tableRecord2.append("workspace", "tmp");
tableRecord2.append("tableName", "nation");
tableRecord2.append("metadataType", "TABLE");
tableRecord2.append("metadataIdentifier", MetadataInfo.GENERAL_INFO_KEY);
Document tableRecord3 = new Document();
tableRecord3.append("storagePlugin", "dfs");
tableRecord3.append("workspace", "tmp");
tableRecord3.append("tableName", "nation");
tableRecord3.append("metadataType", "TABLE");
tableRecord3.append("metadataIdentifier", MetadataInfo.GENERAL_INFO_KEY);
assertEquals(tableRecord1, documents.get(0).get(MongoConfigConstants.ID));
assertEquals(tableRecord2, documents.get(1).get(MongoConfigConstants.ID));
assertEquals(tableRecord3, documents.get(2).get(MongoConfigConstants.ID));
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestMongoBasicTablesRequests method testTableMetastoreSchemaParse.
@Test
public void testTableMetastoreSchemaParse() {
TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("test").owner("user").tableType("json").metadataType(MetadataType.TABLE.name()).metadataKey(MetadataInfo.GENERAL_INFO_KEY).location("/tmp/donuts.json").schema("{\"type\":\"tuple_schema\",\"columns\":[" + "{\"name\":\"id\",\"type\":\"VARCHAR\",\"mode\":\"OPTIONAL\"}," + "{\"name\":\"type\",\"type\":\"VARCHAR\",\"mode\":\"OPTIONAL\"}," + "{\"name\":\"name\",\"type\":\"VARCHAR\",\"mode\":\"OPTIONAL\"}," + "{\"name\":\"ppu\",\"type\":\"DOUBLE\",\"mode\":\"OPTIONAL\"}," + "{\"name\":\"sales\",\"type\":\"BIGINT\",\"mode\":\"OPTIONAL\"}," + "{\"name\":\"batters\",\"type\":\"STRUCT<`batter` ARRAY<STRUCT<`id` VARCHAR, `type` VARCHAR>>>\",\"mode\":\"REQUIRED\"}," + "{\"name\":\"topping\",\"type\":\"ARRAY<STRUCT<`id` VARCHAR, `type` VARCHAR>>\",\"mode\":\"REPEATED\"}," + "{\"name\":\"filling\",\"type\":\"ARRAY<STRUCT<`id` VARCHAR, `type` VARCHAR>>\",\"mode\":\"REPEATED\"}]}").lastModifiedTime(System.currentTimeMillis()).columnsStatistics(Maps.newHashMap()).metadataStatistics(Lists.newArrayList()).partitionKeys(Maps.newHashMap()).build();
List<SchemaPath> schemaPaths = SchemaUtil.getSchemaPaths(BasicTablesTransformer.tables(Collections.singletonList(unit)).get(0).getSchema());
Set<String> schemaSet = schemaPaths.stream().map(SchemaPath::toString).collect(Collectors.toSet());
assertEquals(String.format("Schema path is not parsed correctly:%s", Joiner.on(",").join(schemaPaths)), schemaPaths.size(), schemaSet.size());
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestMongoBasicTablesRequests method testDelete.
@Test
public void testDelete() {
MetastoreTableInfo metastoreTableInfo = basicRequests.metastoreTableInfo(nationTableInfo);
assertTrue(metastoreTableInfo.isExists());
tables.modify().delete(Delete.builder().metadataType(MetadataType.TABLE).filter(nationTableInfo.toFilter()).build()).execute();
metastoreTableInfo = basicRequests.metastoreTableInfo(nationTableInfo);
assertFalse(metastoreTableInfo.isExists());
List<TableMetadataUnit> res = tables.read().metadataType(MetadataType.ALL).execute();
assertFalse(res.isEmpty());
tables.modify().purge();
res = tables.read().metadataType(MetadataType.ALL).execute();
assertTrue(res.isEmpty());
prepareData(tables);
}
use of org.apache.drill.metastore.components.tables.TableMetadataUnit in project drill by apache.
the class TestTablesOutputDataTransformer method testValidDataSeveralRecords.
@Test
public void testValidDataSeveralRecords() {
Document record1 = new Document();
record1.append("tableName", "a");
Document record2 = new Document();
record2.append("tableName", "b");
Document record3 = new Document();
record3.append("tableName", "c");
List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).columns(Collections.singletonList("tableName")).documents(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 TestTablesOutputDataTransformer method testInvalidColumns.
@Test
public void testInvalidColumns() {
Document record = new Document();
record.append("tableName", "a");
List<TableMetadataUnit> actualResult = new TablesOutputDataTransformer(unitSetters).documents(Collections.singletonList(record)).columns(Arrays.asList("a", "b")).execute();
assertEquals(Collections.emptyList(), actualResult);
}
Aggregations