Search in sources :

Example 1 with TableFilter

use of io.confluent.ksql.execution.plan.TableFilter in project ksql by confluentinc.

the class TableFilterBuilder method build.

static <K> KTableHolder<K> build(final KTableHolder<K> table, final TableFilter<K> step, final RuntimeBuildContext buildContext, final SqlPredicateFactory sqlPredicateFactory) {
    final SqlPredicate predicate = sqlPredicateFactory.create(step.getFilterExpression(), table.getSchema(), buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
    final ProcessingLogger processingLogger = buildContext.getProcessingLogger(step.getProperties().getQueryContext());
    final Stacker stacker = Stacker.of(step.getProperties().getQueryContext());
    final KTable<K, GenericRow> filtered = table.getTable().transformValues(() -> new KsTransformer<>(predicate.getTransformer(processingLogger)), Named.as(StreamsUtil.buildOpName(stacker.push(PRE_PROCESS_OP).getQueryContext()))).filter((k, v) -> v.isPresent(), Named.as(StreamsUtil.buildOpName(stacker.push(FILTER_OP).getQueryContext()))).mapValues(Optional::get, Named.as(StreamsUtil.buildOpName(stacker.push(POST_PROCESS_OP).getQueryContext())));
    return table.withTable(filtered, table.getSchema()).withMaterialization(table.getMaterializationBuilder().map(b -> b.filter(predicate::getTransformer, step.getProperties().getQueryContext())));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) SqlPredicate(io.confluent.ksql.execution.transform.sqlpredicate.SqlPredicate) KTableHolder(io.confluent.ksql.execution.plan.KTableHolder) TableFilter(io.confluent.ksql.execution.plan.TableFilter) KTable(org.apache.kafka.streams.kstream.KTable) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) KsTransformer(io.confluent.ksql.execution.streams.transform.KsTransformer) GenericRow(io.confluent.ksql.GenericRow) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) Named(org.apache.kafka.streams.kstream.Named) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) Optional(java.util.Optional) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) Optional(java.util.Optional) SqlPredicate(io.confluent.ksql.execution.transform.sqlpredicate.SqlPredicate) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker)

Example 2 with TableFilter

use of io.confluent.ksql.execution.plan.TableFilter in project ksql by confluentinc.

the class SchemaKTableTest method shouldRewriteTimeComparisonInFilter.

@Test
public void shouldRewriteTimeComparisonInFilter() {
    // Given:
    final String selectQuery = "SELECT col0, col2, col3 FROM test2 " + "WHERE ROWTIME = '1984-01-01T00:00:00+00:00' EMIT CHANGES;";
    final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
    final FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
    initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
    // When:
    final SchemaKTable<?> filteredSchemaKTable = initialSchemaKTable.filter(filterNode.getPredicate(), childContextStacker);
    // Then:
    final TableFilter<?> step = (TableFilter) filteredSchemaKTable.getSourceTableStep();
    assertThat(step.getFilterExpression(), Matchers.equalTo(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("ROWTIME")), new LongLiteral(441763200000L))));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) PlanNode(io.confluent.ksql.planner.plan.PlanNode) TableFilter(io.confluent.ksql.execution.plan.TableFilter) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) FilterNode(io.confluent.ksql.planner.plan.FilterNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 3 with TableFilter

use of io.confluent.ksql.execution.plan.TableFilter in project ksql by confluentinc.

the class StepSchemaResolverTest method shouldResolveSchemaForTableFilter.

@Test
public void shouldResolveSchemaForTableFilter() {
    // Given:
    final TableFilter<?> step = new TableFilter<>(PROPERTIES, tableSource, mock(Expression.class));
    // When:
    final LogicalSchema result = resolver.resolve(step, SCHEMA);
    // Then:
    assertThat(result, is(SCHEMA));
}
Also used : TableFilter(io.confluent.ksql.execution.plan.TableFilter) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Aggregations

TableFilter (io.confluent.ksql.execution.plan.TableFilter)3 Test (org.junit.Test)2 GenericRow (io.confluent.ksql.GenericRow)1 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)1 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)1 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)1 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)1 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)1 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)1 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)1 KsTransformer (io.confluent.ksql.execution.streams.transform.KsTransformer)1 SqlPredicate (io.confluent.ksql.execution.transform.sqlpredicate.SqlPredicate)1 TumblingWindowExpression (io.confluent.ksql.execution.windows.TumblingWindowExpression)1 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)1 FilterNode (io.confluent.ksql.planner.plan.FilterNode)1 PlanNode (io.confluent.ksql.planner.plan.PlanNode)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 Optional (java.util.Optional)1