Search in sources :

Example 11 with CubeMetadata

use of io.hetu.core.spi.cube.CubeMetadata in project hetu-core by openlookeng.

the class TestStarTreeAggregationRule method testDoNotFireWhenMatchingCubeNotFound.

@Test
public void testDoNotFireWhenMatchingCubeNotFound() {
    Mockito.when(cubeManager.getCubeProvider(anyString())).then(new Returns(Optional.of(provider)));
    Mockito.when(cubeManager.getMetaStore(anyString())).then(new Returns(Optional.of(cubeMetaStore)));
    TpchTableHandle orders = new TpchTableHandle("orders", 1.0);
    TableHandle tmpOrdersTableHandle = new TableHandle(tester().getCurrentConnectorId(), orders, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(orders, TupleDomain.all())));
    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(false);
    StarTreeAggregationRule starTreeAggregationRule = new StarTreeAggregationRule(cubeManager, tester().getMetadata());
    tester().assertThat(starTreeAggregationRule).setSystemProperty(ENABLE_STAR_TREE_INDEX, "true").on(p -> p.aggregation(builder -> builder.globalGrouping().addAggregation(p.symbol("count", BIGINT), new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).build(), ImmutableList.of(BIGINT)).step(SINGLE).source(p.project(Assignments.builder().put(p.symbol("custkey"), OriginalExpressionUtils.castToRowExpression(SymbolUtils.toSymbolReference(p.symbol("custkey")))).build(), p.filter(expression("orderkey=1"), p.tableScan(tmpOrdersTableHandle, ImmutableList.of(p.symbol("orderkey", BIGINT)), ImmutableMap.of(p.symbol("orderkey", BIGINT), new TpchColumnHandle("orderkey", BIGINT)))))))).doesNotFire();
    Mockito.verify(cubeMetaStore, Mockito.atLeastOnce()).getMetadataList(eq("local.sf1.0.orders"));
    Mockito.verify(cubeMetadata, Mockito.atLeastOnce()).matches(any(CubeStatement.class));
}
Also used : CubeStatement(io.hetu.core.spi.cube.CubeStatement) 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) Returns(org.mockito.internal.stubbing.answers.Returns) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) TpchTableLayoutHandle(io.prestosql.plugin.tpch.TpchTableLayoutHandle) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 12 with CubeMetadata

use of io.hetu.core.spi.cube.CubeMetadata in project hetu-core by openlookeng.

the class TestStarTreeMetaStore method testGetMetaDataByCubeName.

@Test
public void testGetMetaDataByCubeName() {
    cubeMetadataService.persist(cubeMetadata1);
    cubeMetadataService.persist(cubeMetadata2);
    CubeMetadata found = cubeMetadataService.getMetadataFromCubeName("star1").get();
    assertEquals(found, cubeMetadata1);
    assertNotEquals(found, cubeMetadata2);
}
Also used : CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Test(org.testng.annotations.Test)

Example 13 with CubeMetadata

use of io.hetu.core.spi.cube.CubeMetadata in project hetu-core by openlookeng.

the class TestStarTreeMetaStore method testUpdateMetadata.

@Test
public void testUpdateMetadata() {
    cubeMetadataService.persist(cubeMetadata1);
    StarTreeMetadata starTreeMetadata = (StarTreeMetadata) cubeMetadata1;
    StarTreeMetadataBuilder builder = new StarTreeMetadataBuilder(starTreeMetadata);
    builder.setCubeLastUpdatedTime(System.currentTimeMillis());
    CubeMetadata updated = builder.build();
    assertNotEquals(cubeMetadata1, updated);
}
Also used : StarTreeMetadataBuilder(io.hetu.core.cube.startree.tree.StarTreeMetadataBuilder) StarTreeMetadata(io.hetu.core.cube.startree.tree.StarTreeMetadata) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Test(org.testng.annotations.Test)

Example 14 with CubeMetadata

use of io.hetu.core.spi.cube.CubeMetadata in project hetu-core by openlookeng.

the class StarTreeAggregationRule method rewriteByRemovingSourceFilter.

private FilterNode rewriteByRemovingSourceFilter(PlanNode filterNode, CubeMetadata matchedCubeMetadata) {
    FilterNode rewritten = (FilterNode) filterNode;
    if (filterNode != null && matchedCubeMetadata.getCubeFilter() != null && matchedCubeMetadata.getCubeFilter().getSourceTablePredicate() != null) {
        // rewrite the expression by removing source filter predicate as cube would not have those columns necessarily
        Expression predicate = castToExpression(((FilterNode) filterNode).getPredicate());
        SqlParser sqlParser = new SqlParser();
        Set<Identifier> sourceFilterPredicateColumns = ExpressionUtils.getIdentifiers(sqlParser.createExpression(matchedCubeMetadata.getCubeFilter().getSourceTablePredicate(), new ParsingOptions()));
        predicate = ExpressionUtils.filterConjuncts(predicate, conjunct -> !sourceFilterPredicateColumns.containsAll(SymbolsExtractor.extractUnique(conjunct).stream().map(Symbol::getName).map(Identifier::new).collect(Collectors.toList())));
        rewritten = new FilterNode(filterNode.getId(), ((FilterNode) filterNode).getSource(), castToRowExpression(predicate));
    }
    return rewritten;
}
Also used : LongSupplier(java.util.function.LongSupplier) PrestoWarning(io.prestosql.spi.PrestoWarning) Patterns.aggregation(io.prestosql.sql.planner.plan.Patterns.aggregation) SystemSessionProperties(io.prestosql.SystemSessionProperties) TypeProvider(io.prestosql.sql.planner.TypeProvider) SqlParser(io.prestosql.sql.parser.SqlParser) AggregationNode(io.prestosql.spi.plan.AggregationNode) WarningCollector(io.prestosql.execution.warnings.WarningCollector) Capture.newCapture(io.prestosql.matching.Capture.newCapture) FilterNode(io.prestosql.spi.plan.FilterNode) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) CubeFilter(io.hetu.core.spi.cube.CubeFilter) Identifier(io.prestosql.sql.tree.Identifier) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) SymbolsExtractor(io.prestosql.sql.planner.SymbolsExtractor) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) CubeStatement(io.hetu.core.spi.cube.CubeStatement) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) Metadata(io.prestosql.metadata.Metadata) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) Captures(io.prestosql.matching.Captures) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) Capture(io.prestosql.matching.Capture) AggregationSignature(io.hetu.core.spi.cube.aggregator.AggregationSignature) Optional(java.util.Optional) STAR_TREE(io.prestosql.cube.CubeManager.STAR_TREE) Patterns.optionalSource(io.prestosql.sql.planner.plan.Patterns.optionalSource) Patterns.source(io.prestosql.sql.planner.plan.Patterns.source) TableMetadata(io.prestosql.metadata.TableMetadata) Logger(io.airlift.log.Logger) Pattern(io.prestosql.matching.Pattern) TableHandle(io.prestosql.spi.metadata.TableHandle) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionDomainTranslator(io.prestosql.sql.planner.ExpressionDomainTranslator) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) LinkedList(java.util.LinkedList) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) EXPIRED_CUBE(io.prestosql.spi.connector.StandardWarningCode.EXPIRED_CUBE) Rule(io.prestosql.sql.planner.iterative.Rule) TupleDomain(io.prestosql.spi.predicate.TupleDomain) CubeStatementGenerator(io.prestosql.cube.CubeStatementGenerator) SystemSessionProperties.isEnableStarTreeIndex(io.prestosql.SystemSessionProperties.isEnableStarTreeIndex) Patterns.anyPlan(io.prestosql.sql.planner.plan.Patterns.anyPlan) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) CubeManager(io.prestosql.cube.CubeManager) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Patterns.tableScan(io.prestosql.sql.planner.plan.Patterns.tableScan) Comparator(java.util.Comparator) Expression(io.prestosql.sql.tree.Expression) Identifier(io.prestosql.sql.tree.Identifier) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) Expression(io.prestosql.sql.tree.Expression) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) SqlParser(io.prestosql.sql.parser.SqlParser)

Aggregations

CubeMetadata (io.hetu.core.spi.cube.CubeMetadata)14 TableHandle (io.prestosql.spi.metadata.TableHandle)9 CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)8 Session (io.prestosql.Session)8 TableMetadata (io.prestosql.metadata.TableMetadata)7 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)7 Symbol (io.prestosql.spi.plan.Symbol)7 TableScanNode (io.prestosql.spi.plan.TableScanNode)7 ArrayList (java.util.ArrayList)7 Metadata (io.prestosql.metadata.Metadata)6 AggregationNode (io.prestosql.spi.plan.AggregationNode)6 PlanNode (io.prestosql.spi.plan.PlanNode)6 ProjectNode (io.prestosql.spi.plan.ProjectNode)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)5 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)5 FilterNode (io.prestosql.spi.plan.FilterNode)5 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)5