use of io.prestosql.spi.connector.TestingColumnHandle in project hetu-core by openlookeng.
the class TestDynamicFiltersCollector method TestCollectingGlobalDynamicFilters.
@Test
public void TestCollectingGlobalDynamicFilters() throws InterruptedException {
final QueryId queryId = new QueryId("test_query");
final String filterId = "1";
final String columnName = "column";
final TestingColumnHandle columnHandle = new TestingColumnHandle(columnName);
final Set<String> valueSet = ImmutableSet.of("1", "2", "3");
TaskContext taskContext = mock(TaskContext.class);
Session session = testSessionBuilder().setQueryId(queryId).setSystemProperty(ENABLE_DYNAMIC_FILTERING, "true").setSystemProperty(DYNAMIC_FILTERING_DATA_TYPE, "HASHSET").build();
when(taskContext.getSession()).thenReturn(session);
// set up state store and merged dynamic filters map
Map mockMap = new HashMap<>();
StateStoreProvider stateStoreProvider = mock(StateStoreProvider.class);
StateStore stateStore = mock(StateStore.class);
StateMap stateMap = new MockStateMap<>("test-map", mockMap);
when(stateStoreProvider.getStateStore()).thenReturn(stateStore);
when(stateStore.getStateCollection(any())).thenReturn(stateMap);
when(stateStore.createStateMap(any())).thenReturn(stateMap);
when(stateStore.getOrCreateStateCollection(any(), any())).thenReturn(stateMap);
// set up state store listener and dynamic filter cache
StateStoreListenerManager stateStoreListenerManager = new StateStoreListenerManager(stateStoreProvider);
DynamicFilterCacheManager dynamicFilterCacheManager = new DynamicFilterCacheManager();
stateStoreListenerManager.addStateStoreListener(new DynamicFilterListener(dynamicFilterCacheManager), MERGED_DYNAMIC_FILTERS);
LocalDynamicFiltersCollector collector = new LocalDynamicFiltersCollector(taskContext, Optional.empty(), dynamicFilterCacheManager);
TableScanNode tableScan = mock(TableScanNode.class);
when(tableScan.getAssignments()).thenReturn(ImmutableMap.of(new Symbol(columnName), columnHandle));
List<DynamicFilters.Descriptor> dynamicFilterDescriptors = ImmutableList.of(new DynamicFilters.Descriptor(filterId, new VariableReferenceExpression(columnName, BIGINT)));
collector.initContext(ImmutableList.of(dynamicFilterDescriptors), SymbolUtils.toLayOut(tableScan.getOutputSymbols()));
assertTrue(collector.getDynamicFilters(tableScan).isEmpty(), "there should be no dynamic filter available");
// put some values in state store as a new dynamic filter
// and wait for the listener to process the event
stateMap.put(createKey(DynamicFilterUtils.FILTERPREFIX, filterId, queryId.getId()), valueSet);
TimeUnit.MILLISECONDS.sleep(100);
// get available dynamic filter and verify it
List<Map<ColumnHandle, DynamicFilter>> dynamicFilters = collector.getDynamicFilters(tableScan);
assertEquals(dynamicFilters.size(), 1, "there should be a new dynamic filter");
assertEquals(dynamicFilters.size(), 1);
DynamicFilter dynamicFilter = dynamicFilters.get(0).get(columnHandle);
assertTrue(dynamicFilter instanceof HashSetDynamicFilter, "new dynamic filter should be hashset");
assertEquals(dynamicFilter.getSize(), valueSet.size(), "new dynamic filter should have correct size");
for (String value : valueSet) {
assertTrue(dynamicFilter.contains(value), "new dynamic filter should contain correct values");
}
// clean up when task finishes
collector.removeDynamicFilter(true);
DynamicFilter cachedFilter = dynamicFilterCacheManager.getDynamicFilter(DynamicFilterCacheManager.createCacheKey(filterId, queryId.getId()));
assertNull(cachedFilter, "cached dynamic filter should have been removed");
}
use of io.prestosql.spi.connector.TestingColumnHandle in project hetu-core by openlookeng.
the class TestCardinalityExtractorPlanVisitor method testAggregation.
@Test
public void testAggregation() {
PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
Symbol symbol = planBuilder.symbol("symbol");
ColumnHandle columnHandle = new TestingColumnHandle("column");
// single default aggregation
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet().source(planBuilder.values(10)))), Range.singleton(1L));
// multiple grouping sets with default aggregation with source that produces arbitrary number of rows
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.tableScan(ImmutableList.of(symbol), ImmutableMap.of(symbol, columnHandle))))), Range.atLeast(1L));
// multiple grouping sets with default aggregation with source that produces exact number of rows
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.values(10, symbol)))), Range.closed(1L, 10L));
// multiple grouping sets with default aggregation with source that produces no rows
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.groupingSets(AggregationNode.groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(planBuilder.values(0, symbol)))), Range.singleton(1L));
// single non-default aggregation with source that produces arbitrary number of rows
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.tableScan(ImmutableList.of(symbol), ImmutableMap.of(symbol, columnHandle))))), Range.atLeast(0L));
// single non-default aggregation with source that produces at least single row
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.values(10, symbol)))), Range.closed(1L, 10L));
// single non-default aggregation with source that produces no rows
assertEquals(extractCardinality(planBuilder.aggregation(builder -> builder.singleGroupingSet(symbol).source(planBuilder.values(0, symbol)))), Range.singleton(0L));
}
use of io.prestosql.spi.connector.TestingColumnHandle in project hetu-core by openlookeng.
the class TestSchedulingOrderVisitor method testSemiJoinOrder.
@Test
public void testSemiJoinOrder() {
PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
Symbol sourceJoin = planBuilder.symbol("sourceJoin");
TableScanNode a = planBuilder.tableScan(ImmutableList.of(sourceJoin), ImmutableMap.of(sourceJoin, new TestingColumnHandle("sourceJoin")));
Symbol filteringSource = planBuilder.symbol("filteringSource");
TableScanNode b = planBuilder.tableScan(ImmutableList.of(filteringSource), ImmutableMap.of(filteringSource, new TestingColumnHandle("filteringSource")));
List<PlanNodeId> order = scheduleOrder(planBuilder.semiJoin(sourceJoin, filteringSource, planBuilder.symbol("semiJoinOutput"), Optional.empty(), Optional.empty(), a, b));
assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
use of io.prestosql.spi.connector.TestingColumnHandle in project hetu-core by openlookeng.
the class TestTableLayoutResult method testComputeEnforced.
@Test
public void testComputeEnforced() {
assertComputeEnforced(TupleDomain.all(), TupleDomain.all(), TupleDomain.all());
assertComputeEnforcedFails(TupleDomain.all(), TupleDomain.none());
assertComputeEnforced(TupleDomain.none(), TupleDomain.all(), TupleDomain.none());
assertComputeEnforced(TupleDomain.none(), TupleDomain.none(), TupleDomain.all());
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.all(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))));
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.all());
assertComputeEnforcedFails(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.none());
assertComputeEnforcedFails(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 9999L))));
assertComputeEnforcedFails(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c9999"), Domain.singleValue(BIGINT, 1L))));
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.all(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))));
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))));
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L))));
assertComputeEnforced(TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("c1"), Domain.singleValue(BIGINT, 1L), new TestingColumnHandle("c2"), Domain.singleValue(BIGINT, 2L))), TupleDomain.all());
}
use of io.prestosql.spi.connector.TestingColumnHandle in project hetu-core by openlookeng.
the class TestDynamicFilterSupplier method testNotNullDynamicFilter.
@Test(description = "get dynamic-filter when supplier is not null")
void testNotNullDynamicFilter() throws IOException {
// construct a supplier
List<Long> filterValues = ImmutableList.of(1L, 50L, 100L);
ColumnHandle testColumnHandle = new TestingColumnHandle("test");
BloomFilter filter = new BloomFilter(filterValues.size(), 0.01);
for (Long value : filterValues) {
filter.add(value);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
filter.writeTo(out);
DynamicFilter dynamicFilter = DynamicFilterFactory.create("testFilter", testColumnHandle, out.toByteArray(), DynamicFilter.Type.GLOBAL);
Supplier<List<Map<ColumnHandle, DynamicFilter>>> supplier = () -> ImmutableList.of(ImmutableMap.of(testColumnHandle, dynamicFilter));
DynamicFilterSupplier theSupplier = new DynamicFilterSupplier(supplier, System.currentTimeMillis(), 10000);
assertEquals(theSupplier.getDynamicFilters(), supplier.get());
}
Aggregations