Search in sources :

Example 1 with DynamicFilterListener

use of io.prestosql.dynamicfilter.DynamicFilterListener 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 DynamicFilterListener

use of io.prestosql.dynamicfilter.DynamicFilterListener in project hetu-core by openlookeng.

the class PrestoServer method registerStateStoreListeners.

private static void registerStateStoreListeners(StateStoreListenerManager stateStoreListenerManager, DynamicFilterCacheManager dynamicFilterCacheManager, ServerConfig serverConfig, NodeSchedulerConfig nodeSchedulerConfig) {
    if (serverConfig.isCoordinator() && !nodeSchedulerConfig.isIncludeCoordinator()) {
        return;
    }
    stateStoreListenerManager.addStateStoreListener(new DynamicFilterListener(dynamicFilterCacheManager), MERGED_DYNAMIC_FILTERS);
    stateStoreListenerManager.addStateStoreListener(new CrossRegionDynamicFilterListener(dynamicFilterCacheManager), CROSS_REGION_DYNAMIC_FILTERS);
}
Also used : DynamicFilterListener(io.prestosql.dynamicfilter.DynamicFilterListener) CrossRegionDynamicFilterListener(io.prestosql.dynamicfilter.CrossRegionDynamicFilterListener) CrossRegionDynamicFilterListener(io.prestosql.dynamicfilter.CrossRegionDynamicFilterListener)

Aggregations

DynamicFilterListener (io.prestosql.dynamicfilter.DynamicFilterListener)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Session (io.prestosql.Session)1 CrossRegionDynamicFilterListener (io.prestosql.dynamicfilter.CrossRegionDynamicFilterListener)1 DynamicFilterCacheManager (io.prestosql.dynamicfilter.DynamicFilterCacheManager)1 TaskContext (io.prestosql.operator.TaskContext)1 QueryId (io.prestosql.spi.QueryId)1 TestingColumnHandle (io.prestosql.spi.connector.TestingColumnHandle)1 DynamicFilter (io.prestosql.spi.dynamicfilter.DynamicFilter)1 HashSetDynamicFilter (io.prestosql.spi.dynamicfilter.HashSetDynamicFilter)1 Symbol (io.prestosql.spi.plan.Symbol)1 TableScanNode (io.prestosql.spi.plan.TableScanNode)1 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)1 StateMap (io.prestosql.spi.statestore.StateMap)1 StateStore (io.prestosql.spi.statestore.StateStore)1 DynamicFilters (io.prestosql.sql.DynamicFilters)1 MockStateMap (io.prestosql.statestore.MockStateMap)1 StateStoreProvider (io.prestosql.statestore.StateStoreProvider)1 StateStoreListenerManager (io.prestosql.statestore.listener.StateStoreListenerManager)1 HashMap (java.util.HashMap)1