Search in sources :

Example 1 with TestingColumnHandle

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");
}
Also used : HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) MockStateMap(io.prestosql.statestore.MockStateMap) StateMap(io.prestosql.spi.statestore.StateMap) StateStoreListenerManager(io.prestosql.statestore.listener.StateStoreListenerManager) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) MockStateMap(io.prestosql.statestore.MockStateMap) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) DynamicFilters(io.prestosql.sql.DynamicFilters) DynamicFilterListener(io.prestosql.dynamicfilter.DynamicFilterListener) DynamicFilterCacheManager(io.prestosql.dynamicfilter.DynamicFilterCacheManager) TaskContext(io.prestosql.operator.TaskContext) DynamicFilter(io.prestosql.spi.dynamicfilter.DynamicFilter) HashSetDynamicFilter(io.prestosql.spi.dynamicfilter.HashSetDynamicFilter) QueryId(io.prestosql.spi.QueryId) StateStore(io.prestosql.spi.statestore.StateStore) HashSetDynamicFilter(io.prestosql.spi.dynamicfilter.HashSetDynamicFilter) TableScanNode(io.prestosql.spi.plan.TableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) MockStateMap(io.prestosql.statestore.MockStateMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) StateMap(io.prestosql.spi.statestore.StateMap) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 2 with TestingColumnHandle

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));
}
Also used : TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 3 with TestingColumnHandle

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()));
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 4 with TestingColumnHandle

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());
}
Also used : TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) Test(org.testng.annotations.Test)

Example 5 with TestingColumnHandle

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());
}
Also used : TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TestingColumnHandle(io.prestosql.spi.connector.TestingColumnHandle) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BloomFilter(io.prestosql.spi.util.BloomFilter) Test(org.testng.annotations.Test)

Aggregations

TestingColumnHandle (io.prestosql.spi.connector.TestingColumnHandle)5 Test (org.testng.annotations.Test)5 Symbol (io.prestosql.spi.plan.Symbol)3 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)2 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)2 TableScanNode (io.prestosql.spi.plan.TableScanNode)2 PlanBuilder (io.prestosql.sql.planner.iterative.rule.test.PlanBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Session (io.prestosql.Session)1 DynamicFilterCacheManager (io.prestosql.dynamicfilter.DynamicFilterCacheManager)1 DynamicFilterListener (io.prestosql.dynamicfilter.DynamicFilterListener)1 TaskContext (io.prestosql.operator.TaskContext)1 QueryId (io.prestosql.spi.QueryId)1 DynamicFilter (io.prestosql.spi.dynamicfilter.DynamicFilter)1 HashSetDynamicFilter (io.prestosql.spi.dynamicfilter.HashSetDynamicFilter)1 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)1 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)1 StateMap (io.prestosql.spi.statestore.StateMap)1 StateStore (io.prestosql.spi.statestore.StateStore)1