use of io.hetu.core.spi.cube.io.CubeMetaStore 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) {
}
};
}
use of io.hetu.core.spi.cube.io.CubeMetaStore 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.io.CubeMetaStore in project hetu-core by openlookeng.
the class CubeManager method getMetaStore.
public synchronized Optional<CubeMetaStore> getMetaStore(String name) {
CubeMetaStore cubeMetaStore = this.cubeMetaStores.get(name);
if (cubeMetaStore != null) {
return Optional.of(cubeMetaStore);
}
CubeProvider cubeProvider = this.cubeProviders.get(name);
if (cubeProvider != null) {
HetuMetastore hetuMetastore = metaStoreManager.getHetuMetastore();
if (hetuMetastore == null) {
return Optional.empty();
}
cubeMetaStore = cubeProvider.getCubeMetaStore(metaStoreManager.getHetuMetastore(), properties);
this.cubeMetaStores.put(name, cubeMetaStore);
return Optional.of(cubeMetaStore);
}
return Optional.empty();
}
Aggregations