Search in sources :

Example 6 with TableInfo

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));
}
Also used : TableInfo(org.apache.drill.metastore.metadata.TableInfo) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test) MetastoreTest(org.apache.drill.categories.MetastoreTest)

Example 7 with TableInfo

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));
}
Also used : TableInfo(org.apache.drill.metastore.metadata.TableInfo) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test) MetastoreTest(org.apache.drill.categories.MetastoreTest)

Example 8 with TableInfo

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));
}
Also used : TableInfo(org.apache.drill.metastore.metadata.TableInfo) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test) MetastoreTest(org.apache.drill.categories.MetastoreTest)

Example 9 with TableInfo

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));
}
Also used : TableInfo(org.apache.drill.metastore.metadata.TableInfo) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test) MetastoreTest(org.apache.drill.categories.MetastoreTest)

Example 10 with TableInfo

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));
}
Also used : TableInfo(org.apache.drill.metastore.metadata.TableInfo) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test) MetastoreTest(org.apache.drill.categories.MetastoreTest)

Aggregations

TableInfo (org.apache.drill.metastore.metadata.TableInfo)58 MetastoreTest (org.apache.drill.categories.MetastoreTest)50 Test (org.junit.Test)50 MetastoreTableInfo (org.apache.drill.metastore.components.tables.MetastoreTableInfo)39 SchemaPath (org.apache.drill.common.expression.SchemaPath)37 BaseTableMetadata (org.apache.drill.metastore.metadata.BaseTableMetadata)37 Path (org.apache.hadoop.fs.Path)36 ClusterTest (org.apache.drill.test.ClusterTest)33 SlowTest (org.apache.drill.categories.SlowTest)32 File (java.io.File)29 ColumnStatistics (org.apache.drill.metastore.statistics.ColumnStatistics)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)25 HashMap (java.util.HashMap)24 FileMetadata (org.apache.drill.metastore.metadata.FileMetadata)23 SegmentMetadata (org.apache.drill.metastore.metadata.SegmentMetadata)23 StatisticsHolder (org.apache.drill.metastore.statistics.StatisticsHolder)23 RowGroupMetadata (org.apache.drill.metastore.metadata.RowGroupMetadata)20 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)18 BaseTest (org.apache.drill.test.BaseTest)17 MetadataInfo (org.apache.drill.metastore.metadata.MetadataInfo)16