Search in sources :

Example 1 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo in project drill by apache.

the class TestIcebergBasicTablesRequests method testMetastoreTableInfoExistingTable.

@Test
public void testMetastoreTableInfoExistingTable() {
    MetastoreTableInfo metastoreTableInfo = basicRequests.metastoreTableInfo(nationTableInfo);
    assertTrue(metastoreTableInfo.isExists());
    assertEquals(nationTableInfo, metastoreTableInfo.tableInfo());
    assertEquals(nationTable.lastModifiedTime(), metastoreTableInfo.lastModifiedTime());
    assertTrue(metastoreTableInfo.metastoreVersion() > 0);
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) IcebergBaseTest(org.apache.drill.metastore.iceberg.IcebergBaseTest) Test(org.junit.Test) AbstractBasicTablesRequestsTest(org.apache.drill.metastore.components.tables.AbstractBasicTablesRequestsTest)

Example 2 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo 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();
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) MetadataInfo(org.apache.drill.metastore.metadata.MetadataInfo) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) MetadataControllerContext(org.apache.drill.exec.metastore.analyze.MetadataControllerContext) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression)

Example 3 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo in project drill by apache.

the class TestRdbmsBasicTablesRequests method testMetastoreTableInfoExistingTable.

@Test
public void testMetastoreTableInfoExistingTable() {
    MetastoreTableInfo metastoreTableInfo = basicRequests.metastoreTableInfo(nationTableInfo);
    assertTrue(metastoreTableInfo.isExists());
    assertEquals(nationTableInfo, metastoreTableInfo.tableInfo());
    assertEquals(nationTable.lastModifiedTime(), metastoreTableInfo.lastModifiedTime());
    assertEquals(Metadata.UNDEFINED, metastoreTableInfo.metastoreVersion());
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) Test(org.junit.Test) AbstractBasicTablesRequestsTest(org.apache.drill.metastore.components.tables.AbstractBasicTablesRequestsTest)

Example 4 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo in project drill by apache.

the class TestMetastoreCommands method testDropMetadata.

@Test
public void testDropMetadata() throws Exception {
    String tableName = "tableDropMetadata";
    TableInfo tableInfo = getTableInfo(tableName, "tmp");
    try {
        run("create table dfs.tmp.`%s` as\n" + "select * from cp.`tpch/region.parquet`", tableName);
        testBuilder().sqlQuery("analyze table dfs.tmp.`%s` REFRESH METADATA", tableName).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Collected / refreshed metadata for table [dfs.tmp.%s]", tableName)).go();
        MetastoreTableInfo metastoreTableInfo = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().metastoreTableInfo(tableInfo);
        assertTrue(metastoreTableInfo.isExists());
        BaseTableMetadata baseTableMetadata = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().tableMetadata(tableInfo);
        assertNotNull(baseTableMetadata);
        List<RowGroupMetadata> rowGroupMetadata = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().rowGroupsMetadata(tableInfo, (String) null, null);
        assertEquals(1, rowGroupMetadata.size());
        testBuilder().sqlQuery("analyze table dfs.tmp.`%s` drop metadata", tableName).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Metadata for table [%s] dropped.", tableName)).go();
        metastoreTableInfo = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().metastoreTableInfo(tableInfo);
        assertFalse(metastoreTableInfo.isExists());
        baseTableMetadata = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().tableMetadata(tableInfo);
        assertNull(baseTableMetadata);
        rowGroupMetadata = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().rowGroupsMetadata(tableInfo, (String) null, null);
        assertEquals(0, rowGroupMetadata.size());
    } finally {
        run("analyze table dfs.tmp.`%s` drop metadata if exists", tableName);
        run("drop table if exists dfs.tmp.`%s`", tableName);
        client.resetSession(ExecConstants.METASTORE_ENABLED);
    }
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) BaseTableMetadata(org.apache.drill.metastore.metadata.BaseTableMetadata) TableInfo(org.apache.drill.metastore.metadata.TableInfo) MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RowGroupMetadata(org.apache.drill.metastore.metadata.RowGroupMetadata) ClusterTest(org.apache.drill.test.ClusterTest) SlowTest(org.apache.drill.categories.SlowTest) MetastoreTest(org.apache.drill.categories.MetastoreTest) Test(org.junit.Test)

Example 5 with MetastoreTableInfo

use of org.apache.drill.metastore.components.tables.MetastoreTableInfo in project drill by apache.

the class TestMetastoreCommands method testAnalyzeWithLeadingSlash.

@Test
public void testAnalyzeWithLeadingSlash() throws Exception {
    String tableName = "tableWithLeadingSlash";
    TableInfo tableInfo = getTableInfo("/" + tableName, "tmp");
    try {
        run("create table dfs.tmp.`%s` as\n" + "select * from cp.`tpch/region.parquet`", tableName);
        testBuilder().sqlQuery("analyze table dfs.tmp.`%s` REFRESH METADATA", tableName).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Collected / refreshed metadata for table [dfs.tmp.%s]", tableName)).go();
        MetastoreTableInfo metastoreTableInfo = cluster.drillbit().getContext().getMetastoreRegistry().get().tables().basicRequests().metastoreTableInfo(tableInfo);
        assertTrue("table metadata wasn't found", metastoreTableInfo.isExists());
    } finally {
        run("analyze table dfs.tmp.`%s` drop metadata", tableName);
        run("drop table if exists dfs.tmp.`%s`", tableName);
    }
}
Also used : MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) TableInfo(org.apache.drill.metastore.metadata.TableInfo) MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ClusterTest(org.apache.drill.test.ClusterTest) SlowTest(org.apache.drill.categories.SlowTest) MetastoreTest(org.apache.drill.categories.MetastoreTest) Test(org.junit.Test)

Aggregations

MetastoreTableInfo (org.apache.drill.metastore.components.tables.MetastoreTableInfo)16 Test (org.junit.Test)13 TableInfo (org.apache.drill.metastore.metadata.TableInfo)11 MetastoreTest (org.apache.drill.categories.MetastoreTest)9 SlowTest (org.apache.drill.categories.SlowTest)9 ClusterTest (org.apache.drill.test.ClusterTest)9 File (java.io.File)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 BaseTableMetadata (org.apache.drill.metastore.metadata.BaseTableMetadata)5 FileMetadata (org.apache.drill.metastore.metadata.FileMetadata)5 ColumnStatistics (org.apache.drill.metastore.statistics.ColumnStatistics)5 Path (org.apache.hadoop.fs.Path)5 RowGroupMetadata (org.apache.drill.metastore.metadata.RowGroupMetadata)3 MetadataControllerContext (org.apache.drill.exec.metastore.analyze.MetadataControllerContext)2 TestMetastoreCommands.getBaseTableMetadata (org.apache.drill.exec.sql.TestMetastoreCommands.getBaseTableMetadata)2 TestMetastoreCommands.getColumnStatistics (org.apache.drill.exec.sql.TestMetastoreCommands.getColumnStatistics)2 AbstractBasicTablesRequestsTest (org.apache.drill.metastore.components.tables.AbstractBasicTablesRequestsTest)2