use of org.apache.drill.metastore.expressions.FilterExpression in project drill by apache.
the class TableInfo method toFilter.
public FilterExpression toFilter() {
FilterExpression storagePluginFilter = FilterExpression.equal(MetastoreColumn.STORAGE_PLUGIN, storagePlugin);
FilterExpression workspaceFilter = FilterExpression.equal(MetastoreColumn.WORKSPACE, workspace);
FilterExpression tableNameFilter = FilterExpression.equal(MetastoreColumn.TABLE_NAME, name);
return FilterExpression.and(storagePluginFilter, workspaceFilter, tableNameFilter);
}
use of org.apache.drill.metastore.expressions.FilterExpression in project drill by apache.
the class MetadataControllerBatch method writeToMetastore.
private void writeToMetastore() {
MetadataControllerContext mdContext = popConfig.getContext();
FilterExpression deleteFilter = mdContext.tableInfo().toFilter();
for (MetadataInfo metadataInfo : mdContext.metadataToRemove()) {
deleteFilter = FilterExpression.and(deleteFilter, FilterExpression.equal(MetastoreColumn.METADATA_KEY, metadataInfo.key()));
}
Modify<TableMetadataUnit> modify = tables.modify();
if (!popConfig.getContext().metadataToRemove().isEmpty()) {
modify.delete(Delete.builder().metadataType(MetadataType.SEGMENT, MetadataType.FILE, MetadataType.ROW_GROUP, MetadataType.PARTITION).filter(deleteFilter).build());
}
MetastoreTableInfo metastoreTableInfo = mdContext.metastoreTableInfo();
if (tables.basicRequests().hasMetastoreTableInfoChanged(metastoreTableInfo)) {
throw UserException.executionError(null).message("Metadata for table [%s] was changed before analyze is finished", tableInfo.name()).build(logger);
}
modify.overwrite(metadataUnits).execute();
}
use of org.apache.drill.metastore.expressions.FilterExpression 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.expressions.FilterExpression 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));
}
use of org.apache.drill.metastore.expressions.FilterExpression in project drill by apache.
the class TestBasicTablesRequestsRequestMetadata method testRequestMetadataWithCustomFilter.
@Test
public void testRequestMetadataWithCustomFilter() {
String column = "col";
List<String> metadataKeys = Arrays.asList("a", "b", "c");
FilterExpression customFilter = FilterExpression.equal(MetastoreColumn.STORAGE_PLUGIN, "dfs");
BasicTablesRequests.RequestMetadata requestMetadata = BasicTablesRequests.RequestMetadata.builder().column(column).metadataKeys(metadataKeys).customFilter(customFilter).build();
FilterExpression expected = FilterExpression.and(FilterExpression.equal(MetastoreColumn.COLUMN, column), FilterExpression.in(MetastoreColumn.METADATA_KEY, metadataKeys), customFilter);
assertEquals(expected.toString(), requestMetadata.filter().toString());
}
Aggregations