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));
}
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);
}
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);
}
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;
}
Aggregations