Search in sources :

Example 1 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TableScanMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    TableScanNode tableScanNode = (TableScanNode) node;
    TableMetadata tableMetadata = metadata.getTableMetadata(session, tableScanNode.getTable());
    String actualTableName = tableMetadata.getTable().getTableName();
    return new MatchResult(expectedTableName.equalsIgnoreCase(actualTableName) && ((!expectedConstraint.isPresent()) || domainsMatch(expectedConstraint, tableScanNode.getEnforcedConstraint(), tableScanNode.getTable(), session, metadata)));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) TableScanNode(io.prestosql.spi.plan.TableScanNode)

Example 2 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TestStarTreeAggregationRule method testDoNotUseCubeIfSourceTableUpdatedAfterCubeCreated.

@Test
public void testDoNotUseCubeIfSourceTableUpdatedAfterCubeCreated() {
    Mockito.when(cubeManager.getCubeProvider(anyString())).then(new Returns(Optional.of(provider)));
    Mockito.when(cubeManager.getMetaStore(anyString())).then(new Returns(Optional.of(cubeMetaStore)));
    Metadata metadata = Mockito.mock(Metadata.class);
    TableMetadata ordersTableMetadata = Mockito.mock(TableMetadata.class);
    QualifiedObjectName objectName = new QualifiedObjectName("local", "sf1.0", "orders");
    Mockito.when(metadata.getTableHandle(any(Session.class), eq(objectName))).thenReturn(Optional.of(ordersTableHandle));
    Mockito.when(metadata.getTableLastModifiedTimeSupplier(any(Session.class), any(TableHandle.class))).thenReturn(() -> DateTimeUtils.parseTimestampWithoutTimeZone("2020-01-02 12:00:00"));
    Mockito.when(metadata.getTableMetadata(any(Session.class), eq(ordersTableHandle))).thenReturn(ordersTableMetadata);
    Mockito.when(ordersTableMetadata.getQualifiedName()).thenReturn(objectName);
    List<CubeMetadata> metadataList = ImmutableList.of(cubeMetadata);
    Mockito.when(cubeMetaStore.getMetadataList(eq("local.sf1.0.orders"))).then(new Returns(metadataList));
    Mockito.when(cubeMetadata.matches(any(CubeStatement.class))).thenReturn(true);
    Mockito.when(cubeMetadata.getLastUpdatedTime()).thenReturn(DateTimeUtils.parseTimestampWithoutTimeZone("2020-01-01 12:00:00"));
    StarTreeAggregationRule starTreeAggregationRule = new StarTreeAggregationRule(cubeManager, metadata);
    tester().assertThat(starTreeAggregationRule).setSystemProperty(ENABLE_STAR_TREE_INDEX, "true").on(p -> p.aggregation(builder -> builder.step(SINGLE).addAggregation(new Symbol("count_orderkey"), PlanBuilder.expression("count(orderkey)"), ImmutableList.of(BIGINT)).singleGroupingSet(new Symbol("orderdate")).source(p.project(Assignments.builder().put(p.symbol("orderdate", DATE), p.variable("orderdate", DATE)).put(p.symbol("orderkey", BIGINT), p.variable("orderkey", BIGINT)).build(), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderdate", DATE), p.symbol("orderkey", BIGINT)), ImmutableMap.of(p.symbol("orderkey", BIGINT), new TpchColumnHandle("orderkey", BIGINT), p.symbol("orderdate", DATE), new TpchColumnHandle("orderdate", DATE))))))).doesNotFire();
    Mockito.verify(cubeMetaStore, Mockito.atLeastOnce()).getMetadataList(eq("local.sf1.0.orders"));
    Mockito.verify(cubeMetadata, Mockito.atLeastOnce()).matches(any(CubeStatement.class));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Arrays(java.util.Arrays) ListMultimap(com.google.common.collect.ListMultimap) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) QualifiedName(io.prestosql.sql.tree.QualifiedName) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) Test(org.testng.annotations.Test) AggregationNode(io.prestosql.spi.plan.AggregationNode) Cast(io.prestosql.sql.tree.Cast) FilterNode(io.prestosql.spi.plan.FilterNode) ENABLE_STAR_TREE_INDEX(io.prestosql.SystemSessionProperties.ENABLE_STAR_TREE_INDEX) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanBuilder.expression(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.expression) Assert.assertFalse(org.testng.Assert.assertFalse) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) SymbolUtils(io.prestosql.sql.planner.SymbolUtils) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) BeforeClass(org.testng.annotations.BeforeClass) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) UUID(java.util.UUID) CubeStatement(io.hetu.core.spi.cube.CubeStatement) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) FunctionHandle(io.prestosql.spi.function.FunctionHandle) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) Matchers.any(org.mockito.Matchers.any) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Returns(org.mockito.internal.stubbing.answers.Returns) UnionNode(io.prestosql.spi.plan.UnionNode) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) TpchTableLayoutHandle(io.prestosql.plugin.tpch.TpchTableLayoutHandle) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TableMetadata(io.prestosql.metadata.TableMetadata) StandardTypes(io.prestosql.spi.type.StandardTypes) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) AbstractMockMetadata.dummyMetadata(io.prestosql.metadata.AbstractMockMetadata.dummyMetadata) TableHandle(io.prestosql.spi.metadata.TableHandle) Matchers.anyString(org.mockito.Matchers.anyString) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) BaseMatcher(org.hamcrest.BaseMatcher) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) SINGLE(io.prestosql.spi.plan.AggregationNode.Step.SINGLE) DateTimeUtils(io.prestosql.spi.util.DateTimeUtils) Session(io.prestosql.Session) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) TpchTransactionHandle(io.prestosql.plugin.tpch.TpchTransactionHandle) DATE(io.prestosql.spi.type.DateType.DATE) CubeProvider(io.prestosql.spi.cube.CubeProvider) Symbol(io.prestosql.spi.plan.Symbol) Description(org.hamcrest.Description) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) Assignments(io.prestosql.spi.plan.Assignments) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) Expressions(io.prestosql.sql.relational.Expressions) CubeManager(io.prestosql.cube.CubeManager) Mockito(org.mockito.Mockito) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Matcher(org.hamcrest.Matcher) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Assert.assertTrue(org.testng.Assert.assertTrue) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) Metadata(io.prestosql.metadata.Metadata) TableMetadata(io.prestosql.metadata.TableMetadata) AbstractMockMetadata.dummyMetadata(io.prestosql.metadata.AbstractMockMetadata.dummyMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) CubeStatement(io.hetu.core.spi.cube.CubeStatement) Returns(org.mockito.internal.stubbing.answers.Returns) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) Session(io.prestosql.Session) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 3 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TableInfoSupplier method apply.

@Override
public TableInfo apply(TableScanNode node) {
    TableMetadata tableMetadata = metadata.getTableMetadata(session, node.getTable());
    TableProperties tableProperties = metadata.getTableProperties(session, node.getTable());
    return new TableInfo(tableMetadata.getQualifiedName(), tableProperties.getPredicate());
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) TableInfo(io.prestosql.execution.TableInfo) TableProperties(io.prestosql.metadata.TableProperties)

Example 4 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method testCreatePartitionedTableAs.

private void testCreatePartitionedTableAs(Session session, HiveStorageFormat storageFormat) {
    @Language("SQL") String createTable = "" + "CREATE TABLE test_create_partitioned_table_as " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'SHIP_PRIORITY', 'ORDER_STATUS' ]" + ") " + "AS " + "SELECT orderkey AS order_key, shippriority AS ship_priority, orderstatus AS order_status " + "FROM tpch.tiny.orders";
    assertUpdate(session, createTable, "SELECT count(*) from orders");
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_create_partitioned_table_as");
    assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
    assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("ship_priority", "order_status"));
    List<?> partitions = getPartitions("test_create_partitioned_table_as");
    assertEquals(partitions.size(), 3);
    assertQuery(session, "SELECT * from test_create_partitioned_table_as", "SELECT orderkey, shippriority, orderstatus FROM orders");
    assertUpdate(session, "DROP TABLE test_create_partitioned_table_as");
    assertFalse(getQueryRunner().tableExists(session, "test_create_partitioned_table_as"));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language)

Example 5 with TableMetadata

use of io.prestosql.metadata.TableMetadata in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method testFullVacuum2.

@Test
public void testFullVacuum2() {
    String table = "tab3";
    String schema = "default";
    assertUpdate(String.format("CREATE SCHEMA IF NOT EXISTS %s", schema));
    assertUpdate(String.format("CREATE TABLE %s.%s (a int, b int) with (transactional=true, format='orc')", schema, table));
    assertUpdate(String.format("INSERT INTO %s.%s VALUES (1, 2)", schema, table), 1);
    assertUpdate(String.format("INSERT INTO %s.%s VALUES (3, 4)", schema, table), 1);
    assertUpdate(String.format("INSERT INTO %s.%s VALUES (5, 6)", schema, table), 1);
    assertUpdate(String.format("VACUUM TABLE %s.%s AND WAIT", schema, table), 3);
    assertUpdate(String.format("VACUUM TABLE %s.%s FULL AND WAIT", schema, table), 3);
    TableMetadata tableMetadata = getTableMetadata("hive", schema, table);
    String tablePath = ((String) tableMetadata.getMetadata().getProperties().get("location"));
    assertFilesAfterCleanup(tablePath, 1);
    assertUpdate(String.format("DROP TABLE %s.%s", schema, table));
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Aggregations

TableMetadata (io.prestosql.metadata.TableMetadata)59 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)19 TableHandle (io.prestosql.spi.metadata.TableHandle)19 Language (org.intellij.lang.annotations.Language)17 Test (org.testng.annotations.Test)17 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)16 Session (io.prestosql.Session)15 TableScanNode (io.prestosql.spi.plan.TableScanNode)15 Expression (io.prestosql.sql.tree.Expression)15 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)14 PlanNode (io.prestosql.spi.plan.PlanNode)14 Symbol (io.prestosql.spi.plan.Symbol)14 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ImmutableList (com.google.common.collect.ImmutableList)13 ProjectNode (io.prestosql.spi.plan.ProjectNode)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Metadata (io.prestosql.metadata.Metadata)11 AggregationNode (io.prestosql.spi.plan.AggregationNode)11 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)11