use of org.apache.drill.metastore.metadata.TableInfo in project drill by apache.
the class AbstractTablesMetastoreTest method testDelete.
@Test
public void testDelete() {
TableInfo tableInfo = TableInfo.builder().storagePlugin("dfs").workspace("tmp").name("nation").build();
TableMetadataUnit firstUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey("1994").metadataIdentifier("1994").metadataType(MetadataType.SEGMENT.name()).location("/tmp/nation/1994").lastModifiedTime(System.currentTimeMillis()).build();
TableMetadataUnit secondUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey("1995").metadataIdentifier("1995").metadataType(MetadataType.SEGMENT.name()).location("/tmp/nation/1995").lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(firstUnit, secondUnit).execute();
List<TableMetadataUnit> units = tables.read().metadataType(MetadataType.SEGMENT).filter(tableInfo.toFilter()).execute();
assertEquals(2, units.size());
FilterExpression deleteFilter = FilterExpression.and(tableInfo.toFilter(), FilterExpression.equal(MetastoreColumn.METADATA_KEY, "1994"));
tables.modify().delete(Delete.builder().metadataType(MetadataType.SEGMENT).filter(deleteFilter).build()).execute();
List<TableMetadataUnit> updatedUnits = tables.read().metadataType(MetadataType.SEGMENT).filter(tableInfo.toFilter()).execute();
assertEquals(1, updatedUnits.size());
assertEquals(secondUnit, updatedUnits.get(0));
}
use of org.apache.drill.metastore.metadata.TableInfo in project drill by apache.
the class AbstractTablesMetastoreTest method testReadAbsentColumns.
@Test
public void testReadAbsentColumns() {
TableInfo tableInfo = TableInfo.builder().storagePlugin("dfs").workspace("tmp").name("nation").build();
TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey(MetadataInfo.GENERAL_INFO_KEY).metadataType(MetadataType.TABLE.name()).lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(unit).execute();
List<TableMetadataUnit> units = tables.read().metadataType(MetadataType.TABLE).filter(tableInfo.toFilter()).columns(MetastoreColumn.TABLE_NAME, MetastoreColumn.HOST_AFFINITY).execute();
assertEquals(1, units.size());
assertEquals(TableMetadataUnit.builder().tableName("nation").build(), units.get(0));
units = tables.read().metadataType(MetadataType.TABLE).filter(tableInfo.toFilter()).columns(MetastoreColumn.HOST_AFFINITY).execute();
assertEquals(1, units.size());
assertEquals(TableMetadataUnit.EMPTY_UNIT, units.get(0));
}
use of org.apache.drill.metastore.metadata.TableInfo in project drill by apache.
the class AbstractTablesMetastoreTest method testReadSelectedColumns.
@Test
public void testReadSelectedColumns() {
TableInfo tableInfo = TableInfo.builder().storagePlugin("dfs").workspace("tmp").name("nation").build();
TableMetadataUnit unit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey(MetadataInfo.GENERAL_INFO_KEY).metadataType(MetadataType.TABLE.name()).lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(unit).execute();
List<TableMetadataUnit> units = tables.read().metadataType(MetadataType.ALL).filter(tableInfo.toFilter()).columns(MetastoreColumn.TABLE_NAME, MetastoreColumn.METADATA_KEY).execute();
assertEquals(1, units.size());
assertEquals(TableMetadataUnit.builder().tableName("nation").metadataKey(MetadataInfo.GENERAL_INFO_KEY).build(), units.get(0));
}
use of org.apache.drill.metastore.metadata.TableInfo in project drill by apache.
the class AbstractTablesMetastoreTest method testOverwrite.
@Test
public void testOverwrite() {
TableInfo tableInfo = TableInfo.builder().storagePlugin("dfs").workspace("tmp").name("nation").build();
TableMetadataUnit initialUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey(MetadataInfo.GENERAL_INFO_KEY).metadataType(MetadataType.TABLE.name()).tableType("parquet").lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(initialUnit).execute();
List<TableMetadataUnit> units = tables.read().metadataType(MetadataType.TABLE).filter(tableInfo.toFilter()).execute();
assertEquals(1, units.size());
assertEquals(initialUnit, units.get(0));
TableMetadataUnit updatedUnit = TableMetadataUnit.builder().storagePlugin("dfs").workspace("tmp").tableName("nation").metadataKey(MetadataInfo.GENERAL_INFO_KEY).metadataType(MetadataType.TABLE.name()).tableType("text").lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(updatedUnit).execute();
List<TableMetadataUnit> updatedUnits = tables.read().metadataType(MetadataType.TABLE).filter(tableInfo.toFilter()).execute();
assertEquals(1, updatedUnits.size());
assertEquals(updatedUnit, updatedUnits.get(0));
}
use of org.apache.drill.metastore.metadata.TableInfo in project drill by apache.
the class AbstractTablesMetastoreTest method testOverwriteAndDeleteInOneTransaction.
@Test
public void testOverwriteAndDeleteInOneTransaction() {
TableInfo tableInfo = TableInfo.builder().storagePlugin("dfs").workspace("tmp").name("nation").build();
TableMetadataUnit firstUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey("1994").metadataIdentifier("1994").metadataType(MetadataType.SEGMENT.name()).location("/tmp/nation/1994").lastModifiedTime(System.currentTimeMillis()).build();
TableMetadataUnit secondUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey("1995").metadataIdentifier("1995").metadataType(MetadataType.SEGMENT.name()).location("/tmp/nation/1995").lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().overwrite(firstUnit, secondUnit).execute();
List<TableMetadataUnit> units = tables.read().metadataType(MetadataType.SEGMENT).filter(tableInfo.toFilter()).execute();
assertEquals(2, units.size());
FilterExpression deleteFilter = FilterExpression.and(tableInfo.toFilter(), FilterExpression.equal(MetastoreColumn.METADATA_KEY, "1994"));
TableMetadataUnit updatedUnit = TableMetadataUnit.builder().storagePlugin(tableInfo.storagePlugin()).workspace(tableInfo.workspace()).tableName(tableInfo.name()).metadataKey("1995").metadataIdentifier("1995").metadataType(MetadataType.SEGMENT.name()).location("/user/nation/1995").lastModifiedTime(System.currentTimeMillis()).build();
tables.modify().delete(Delete.builder().metadataType(MetadataType.SEGMENT).filter(deleteFilter).build()).overwrite(updatedUnit).execute();
List<TableMetadataUnit> updatedUnits = tables.read().metadataType(MetadataType.SEGMENT).filter(tableInfo.toFilter()).execute();
assertEquals(1, updatedUnits.size());
assertEquals(updatedUnit, updatedUnits.get(0));
}
Aggregations