use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class DynamicFilterSourceOperator method finish.
@Override
public void finish() {
if (finished) {
// NOTE: finish() may be called multiple times (see comment at Driver::processInternal).
return;
}
finished = true;
ImmutableMap.Builder<DynamicFilterId, Domain> domainsBuilder = ImmutableMap.builder();
if (valueSets == null) {
if (minValues == null) {
// else it was notified with 'all' in handleMinMaxCollectionLimitExceeded
return;
}
// valueSets became too large, create TupleDomain from min/max values
for (Integer channelIndex : minMaxChannels) {
Type type = channels.get(channelIndex).type;
if (minValues[channelIndex] == null) {
// all values were null
domainsBuilder.put(channels.get(channelIndex).filterId, Domain.none(type));
continue;
}
Object min = readNativeValue(type, minValues[channelIndex], 0);
Object max = readNativeValue(type, maxValues[channelIndex], 0);
Domain domain = Domain.create(ValueSet.ofRanges(range(type, min, true, max, true)), false);
domainsBuilder.put(channels.get(channelIndex).filterId, domain);
}
minValues = null;
maxValues = null;
dynamicPredicateConsumer.accept(TupleDomain.withColumnDomains(domainsBuilder.buildOrThrow()));
return;
}
for (int channelIndex = 0; channelIndex < channels.size(); ++channelIndex) {
Block block = blockBuilders[channelIndex].build();
Type type = channels.get(channelIndex).type;
domainsBuilder.put(channels.get(channelIndex).filterId, convertToDomain(type, block));
}
valueSets = null;
blockBuilders = null;
dynamicPredicateConsumer.accept(TupleDomain.withColumnDomains(domainsBuilder.buildOrThrow()));
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class DynamicFilters method getDescriptor.
public static Optional<Descriptor> getDescriptor(Expression expression) {
if (!(expression instanceof FunctionCall)) {
return Optional.empty();
}
FunctionCall functionCall = (FunctionCall) expression;
if (!isDynamicFilterFunction(functionCall)) {
return Optional.empty();
}
List<Expression> arguments = functionCall.getArguments();
checkArgument(arguments.size() == 4, "invalid arguments count: %s", arguments.size());
Expression probeSymbol = arguments.get(0);
Expression operatorExpression = arguments.get(1);
checkArgument(operatorExpression instanceof StringLiteral, "operatorExpression is expected to be an instance of StringLiteral: %s", operatorExpression.getClass().getSimpleName());
String operatorExpressionString = ((StringLiteral) operatorExpression).getValue();
ComparisonExpression.Operator operator = ComparisonExpression.Operator.valueOf(operatorExpressionString);
Expression idExpression = arguments.get(2);
checkArgument(idExpression instanceof StringLiteral, "id is expected to be an instance of StringLiteral: %s", idExpression.getClass().getSimpleName());
String id = ((StringLiteral) idExpression).getValue();
Expression nullAllowedExpression = arguments.get(3);
checkArgument(nullAllowedExpression instanceof BooleanLiteral, "nullAllowedExpression is expected to be an instance of BooleanLiteral: %s", nullAllowedExpression.getClass().getSimpleName());
boolean nullAllowed = ((BooleanLiteral) nullAllowedExpression).getValue();
return Optional.of(new Descriptor(new DynamicFilterId(id), probeSymbol, operator, nullAllowed));
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class DynamicFilterService method getDynamicFilteringStats.
public DynamicFiltersStats getDynamicFilteringStats(QueryId queryId, Session session) {
DynamicFilterContext context = dynamicFilterContexts.get(queryId);
if (context == null) {
// query has been removed or dynamic filtering is not enabled
return DynamicFiltersStats.EMPTY;
}
int lazyFilters = context.getLazyDynamicFilters().size();
int replicatedFilters = context.getReplicatedDynamicFilters().size();
int totalDynamicFilters = context.getTotalDynamicFilters();
ConnectorSession connectorSession = session.toConnectorSession();
List<DynamicFilterDomainStats> dynamicFilterDomainStats = context.getDynamicFilterSummaries().entrySet().stream().map(entry -> {
DynamicFilterId dynamicFilterId = entry.getKey();
return new DynamicFilterDomainStats(dynamicFilterId, // use small limit for readability
entry.getValue().toString(connectorSession, 2), context.getDynamicFilterCollectionDuration(dynamicFilterId));
}).collect(toImmutableList());
return new DynamicFiltersStats(dynamicFilterDomainStats, lazyFilters, replicatedFilters, totalDynamicFilters, dynamicFilterDomainStats.size());
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestSqlTask method testDynamicFilters.
@Test(timeOut = 30_000)
public void testDynamicFilters() throws Exception {
SqlTask sqlTask = createInitialTask();
sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(new SplitAssignment(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), false)), createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds(), ImmutableMap.of());
assertEquals(sqlTask.getTaskStatus().getDynamicFiltersVersion(), INITIAL_DYNAMIC_FILTERS_VERSION);
TaskContext taskContext = sqlTask.getQueryContext().getTaskContextByTaskId(sqlTask.getTaskId());
ListenableFuture<?> future = sqlTask.getTaskStatus(STARTING_VERSION);
assertFalse(future.isDone());
// make sure future gets unblocked when dynamic filters version is updated
taskContext.updateDomains(ImmutableMap.of(new DynamicFilterId("filter"), Domain.none(BIGINT)));
assertEquals(sqlTask.getTaskStatus().getVersion(), STARTING_VERSION + 1);
assertEquals(sqlTask.getTaskStatus().getDynamicFiltersVersion(), INITIAL_DYNAMIC_FILTERS_VERSION + 1);
future.get();
}
use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.
the class TestDynamicFilterSourceOperator method testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues.
@Test
public void testMultipleColumnsCollectMinMaxRangeWhenTooManyDistinctValues() {
int maxDistinctValues = 100;
Page largePage = new Page(createLongSequenceBlock(0, 101), createColorRepeatBlock(100, 101), createLongRepeatBlock(200, 101));
List<TupleDomain<DynamicFilterId>> expectedTupleDomains = ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.ofRanges(range(BIGINT, 0L, true, 100L, true)), false), new DynamicFilterId("2"), Domain.create(ValueSet.ofRanges(equal(BIGINT, 200L)), false))));
assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT, COLOR, BIGINT), ImmutableList.of(largePage), expectedTupleDomains);
}
Aggregations