use of io.prestosql.cube.CubeManager in project hetu-core by openlookeng.
the class TestStarTreeAggregationRule method testDoNotFireWhenWithoutCube.
@Test
public void testDoNotFireWhenWithoutCube() {
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())));
Mockito.when(cubeMetaStore.getMetadataList(eq("local.sf1.0.orders"))).then(new Returns(ImmutableList.of()));
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.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"));
}
use of io.prestosql.cube.CubeManager 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));
}
use of io.prestosql.cube.CubeManager in project hetu-core by openlookeng.
the class TestStarTreeAggregationRule method testDoNotFireWhenFeatureIsDisabled.
@Test
public void testDoNotFireWhenFeatureIsDisabled() {
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())));
StarTreeAggregationRule starTreeAggregationRule = new StarTreeAggregationRule(cubeManager, tester().getMetadata());
tester().assertThat(starTreeAggregationRule).setSystemProperty(ENABLE_STAR_TREE_INDEX, "false").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"), p.variable("custkey", custkeyHandle.getType())).build(), p.tableScan(tmpOrdersTableHandle, ImmutableList.of(p.symbol("orderkey", BIGINT)), ImmutableMap.of(p.symbol("orderkey", BIGINT), new TpchColumnHandle("orderkey", BIGINT))))))).doesNotFire();
Mockito.verify(cubeMetaStore, Mockito.never()).getMetadataList(eq("local.sf1.0.orders"));
}
use of io.prestosql.cube.CubeManager in project hetu-core by openlookeng.
the class TaskTestUtils method createTestingPlanner.
public static LocalExecutionPlanner createTestingPlanner() {
Metadata metadata = createTestMetadataManager();
PageSourceManager pageSourceManager = new PageSourceManager();
HetuMetaStoreManager hetuMetaStoreManager = new HetuMetaStoreManager();
FeaturesConfig featuresConfig = new FeaturesConfig();
CubeManager cubeManager = new CubeManager(featuresConfig, hetuMetaStoreManager);
pageSourceManager.addConnectorPageSourceProvider(CONNECTOR_ID, new TestingPageSourceProvider());
// we don't start the finalizer so nothing will be collected, which is ok for a test
FinalizerService finalizerService = new FinalizerService();
NodeScheduler nodeScheduler = new NodeScheduler(new LegacyNetworkTopology(), new InMemoryNodeManager(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(finalizerService));
NodePartitioningManager nodePartitioningManager = new NodePartitioningManager(nodeScheduler);
PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(metadata, 0);
NodeInfo nodeInfo = new NodeInfo("test");
FileSystemClientManager fileSystemClientManager = new FileSystemClientManager();
SeedStoreManager seedStoreManager = new SeedStoreManager(fileSystemClientManager);
StateStoreProvider stateStoreProvider = new LocalStateStoreProvider(seedStoreManager);
HeuristicIndexerManager heuristicIndexerManager = new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager());
return new LocalExecutionPlanner(metadata, new TypeAnalyzer(new SqlParser(), metadata), Optional.empty(), pageSourceManager, new IndexManager(), nodePartitioningManager, new PageSinkManager(), new MockExchangeClientSupplier(), new ExpressionCompiler(metadata, pageFunctionCompiler), pageFunctionCompiler, new JoinFilterFunctionCompiler(metadata), new IndexJoinLookupStats(), new TaskManagerConfig(), new GenericSpillerFactory((types, spillContext, memoryContext) -> {
throw new UnsupportedOperationException();
}), (types, spillContext, memoryContext) -> {
throw new UnsupportedOperationException();
}, (types, partitionFunction, spillContext, memoryContext) -> {
throw new UnsupportedOperationException();
}, new PagesIndex.TestingFactory(false), new JoinCompiler(metadata), new LookupJoinOperators(), new OrderingCompiler(), nodeInfo, stateStoreProvider, new StateStoreListenerManager(stateStoreProvider), new DynamicFilterCacheManager(), heuristicIndexerManager, cubeManager);
}
use of io.prestosql.cube.CubeManager in project hetu-core by openlookeng.
the class TestStarTreeAggregationRule method setupBeforeClass.
@BeforeClass
public void setupBeforeClass() {
PlanSymbolAllocator symbolAllocator = new PlanSymbolAllocator();
columnOrderkey = symbolAllocator.newSymbol("orderkey", BIGINT);
columnOrderDate = symbolAllocator.newSymbol("orderdate", DATE);
columnCustkey = symbolAllocator.newSymbol("custkey", BIGINT);
columnTotalprice = symbolAllocator.newSymbol("totalprice", DOUBLE);
orderkeyHandle = new TpchColumnHandle("orderkey", BIGINT);
orderdateHandle = new TpchColumnHandle("orderdate", DATE);
custkeyHandle = new TpchColumnHandle("custkey", BIGINT);
totalpriceHandle = new TpchColumnHandle("totalprice", DOUBLE);
ColumnMetadata orderKeyColumnMetadata = new ColumnMetadata(orderkeyHandle.getColumnName(), orderkeyHandle.getType());
ColumnMetadata orderDateColumnMetadata = new ColumnMetadata(orderdateHandle.getColumnName(), orderdateHandle.getType());
ColumnMetadata custKeyColumnMetadata = new ColumnMetadata(custkeyHandle.getColumnName(), custkeyHandle.getType());
ColumnMetadata totalPriceColumnMetadata = new ColumnMetadata(totalpriceHandle.getColumnName(), totalpriceHandle.getType());
output = symbolAllocator.newSymbol("output", DOUBLE);
assignments = ImmutableMap.<Symbol, ColumnHandle>builder().put(columnOrderkey, orderkeyHandle).put(columnOrderDate, orderdateHandle).put(columnCustkey, custkeyHandle).put(columnTotalprice, totalpriceHandle).build();
TpchTableHandle orders = new TpchTableHandle("orders", 1.0);
ordersTableHandle = new TableHandle(tester().getCurrentConnectorId(), orders, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(orders, TupleDomain.all())));
baseTableScan = new TableScanNode(newId(), ordersTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
QualifiedObjectName baseTableName = QualifiedObjectName.valueOf(baseTableScan.getTable().getFullyQualifiedName());
baseTableMetadata = new TableMetadata(ordersTableHandle.getCatalogName(), new ConnectorTableMetadata(new SchemaTableName(baseTableName.getSchemaName(), baseTableName.getObjectName()), Arrays.asList(orderKeyColumnMetadata, orderDateColumnMetadata, custKeyColumnMetadata, totalPriceColumnMetadata)));
columnCountAll = symbolAllocator.newSymbol("count_all", BIGINT);
columnSumTotalPrice = symbolAllocator.newSymbol("sum_totalprice", DOUBLE);
columnCountOrderKey = symbolAllocator.newSymbol("count_orderkey", BIGINT);
columnGroupingBitSet = symbolAllocator.newSymbol("grouping_bit_set", BIGINT);
cubeColumnCustKey = symbolAllocator.newSymbol("custkey", BIGINT);
cubeColumnOrderDate = symbolAllocator.newSymbol("orderdate", DATE);
countAllHandle = new TpchColumnHandle("count_all", BIGINT);
sumTotalPriceHandle = new TpchColumnHandle("sum_totalprice", DOUBLE);
countOrderKeyHandle = new TpchColumnHandle("count_orderkey", BIGINT);
groupingBitSetHandle = new TpchColumnHandle("grouping_bit_set", BIGINT);
custKeyCubeColumnHandle = new TpchColumnHandle("custkey", BIGINT);
orderDateCubeColumnHandle = new TpchColumnHandle("orderdate", DATE);
ordersCubeColumnHandles.put(countAllHandle.getColumnName(), countAllHandle);
ordersCubeColumnHandles.put(sumTotalPriceHandle.getColumnName(), sumTotalPriceHandle);
ordersCubeColumnHandles.put(countOrderKeyHandle.getColumnName(), countOrderKeyHandle);
ordersCubeColumnHandles.put(groupingBitSetHandle.getColumnName(), groupingBitSetHandle);
ordersCubeColumnHandles.put(custKeyCubeColumnHandle.getColumnName(), custKeyCubeColumnHandle);
ordersCubeColumnHandles.put(orderDateCubeColumnHandle.getColumnName(), orderDateCubeColumnHandle);
TpchTableHandle ordersCube = new TpchTableHandle("orders_cube", 1.0);
ordersCubeHandle = new TableHandle(tester().getCurrentConnectorId(), ordersCube, TpchTransactionHandle.INSTANCE, Optional.of(new TpchTableLayoutHandle(ordersCube, TupleDomain.all())));
countAllColumnMetadata = new ColumnMetadata(countAllHandle.getColumnName(), countAllHandle.getType());
sumTotalPriceColumnMetadata = new ColumnMetadata(sumTotalPriceHandle.getColumnName(), sumTotalPriceHandle.getType());
countOrderKeyColumnMetadata = new ColumnMetadata(countOrderKeyHandle.getColumnName(), countOrderKeyHandle.getType());
groupingBitSetColumnMetadata = new ColumnMetadata(groupingBitSetHandle.getColumnName(), groupingBitSetHandle.getType());
custKeyCubeColumnMetadata = new ColumnMetadata(custKeyCubeColumnHandle.getColumnName(), custKeyCubeColumnHandle.getType());
orderDateCubeColumnMetadata = new ColumnMetadata(orderDateCubeColumnHandle.getColumnName(), orderDateCubeColumnHandle.getType());
config = new FeaturesConfig();
config.setEnableStarTreeIndex(true);
cubeManager = Mockito.mock(CubeManager.class);
provider = Mockito.mock(CubeProvider.class);
cubeMetaStore = Mockito.mock(CubeMetaStore.class);
cubeMetadata = Mockito.mock(CubeMetadata.class);
ordersTableHandleMatcher = new BaseMatcher<TableHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof TableHandle)) {
return false;
}
TableHandle th = (TableHandle) o;
return th.getFullyQualifiedName().equals(ordersTableHandle.getFullyQualifiedName());
}
@Override
public void describeTo(Description description) {
}
};
ordersCubeHandleMatcher = new BaseMatcher<TableHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof TableHandle)) {
return false;
}
TableHandle th = (TableHandle) o;
return th.getFullyQualifiedName().equals(ordersCubeHandle.getFullyQualifiedName());
}
@Override
public void describeTo(Description description) {
}
};
countAllColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public void describeTo(Description description) {
}
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(countAllHandle.getColumnName());
}
};
sumTotalPriceColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public void describeTo(Description description) {
}
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(sumTotalPriceHandle.getColumnName());
}
};
countOrderKeyColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(countOrderKeyHandle.getColumnName());
}
@Override
public void describeTo(Description description) {
}
};
groupingBitSetColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(groupingBitSetHandle.getColumnName());
}
@Override
public void describeTo(Description description) {
}
};
orderDateCubeColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(orderDateCubeColumnHandle.getColumnName());
}
@Override
public void describeTo(Description description) {
}
};
custKeyCubeColumnHandleMatcher = new BaseMatcher<ColumnHandle>() {
@Override
public boolean matches(Object o) {
if (!(o instanceof ColumnHandle)) {
return false;
}
ColumnHandle ch = (ColumnHandle) o;
return ch.getColumnName().equalsIgnoreCase(custKeyCubeColumnHandle.getColumnName());
}
@Override
public void describeTo(Description description) {
}
};
}
Aggregations