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())));
}
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))));
}
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));
}
Aggregations