use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class ForeignKeyTableTableJoinBuilder method build.
public static <KLeftT, KRightT> KTableHolder<KLeftT> build(final KTableHolder<KLeftT> left, final KTableHolder<KRightT> right, final ForeignKeyTableTableJoin<KLeftT, KRightT> join, final RuntimeBuildContext buildContext) {
final LogicalSchema leftSchema = left.getSchema();
final LogicalSchema rightSchema = right.getSchema();
final ProcessingLogger logger = buildContext.getProcessingLogger(join.getProperties().getQueryContext());
final ExpressionEvaluator expressionEvaluator;
final CodeGenRunner codeGenRunner = new CodeGenRunner(leftSchema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
final Optional<ColumnName> leftColumnName = join.getLeftJoinColumnName();
final Optional<Expression> leftJoinExpression = join.getLeftJoinExpression();
if (leftColumnName.isPresent()) {
expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(new UnqualifiedColumnReferenceExp(leftColumnName.get()), "Left Join Expression");
} else if (leftJoinExpression.isPresent()) {
expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(leftJoinExpression.get(), "Left Join Expression");
} else {
throw new IllegalStateException("Both leftColumnName and leftJoinExpression are empty.");
}
final ForeignKeyJoinParams<KRightT> joinParams = ForeignKeyJoinParamsFactory.create(expressionEvaluator, leftSchema, rightSchema, logger);
final Formats formats = join.getFormats();
final PhysicalSchema physicalSchema = PhysicalSchema.from(joinParams.getSchema(), formats.getKeyFeatures(), formats.getValueFeatures());
final Serde<KLeftT> keySerde = left.getExecutionKeyFactory().buildKeySerde(formats.getKeyFormat(), physicalSchema, join.getProperties().getQueryContext());
final Serde<GenericRow> valSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, join.getProperties().getQueryContext());
final KTable<KLeftT, GenericRow> result;
switch(join.getJoinType()) {
case INNER:
result = left.getTable().join(right.getTable(), joinParams.getKeyExtractor(), joinParams.getJoiner(), Materialized.with(keySerde, valSerde));
break;
case LEFT:
result = left.getTable().leftJoin(right.getTable(), joinParams.getKeyExtractor(), joinParams.getJoiner(), Materialized.with(keySerde, valSerde));
break;
default:
throw new IllegalStateException("invalid join type: " + join.getJoinType());
}
return KTableHolder.unmaterialized(result, joinParams.getSchema(), left.getExecutionKeyFactory());
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class SchemaKStreamTest method shouldFailIfForceRepartitionWindowedStream.
@Test
public void shouldFailIfForceRepartitionWindowedStream() {
// Given:
givenInitialKStreamOf("SELECT col0, col2, col3 FROM test1 PARTITION BY col0 EMIT CHANGES;", windowedKeyFormat);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> initialSchemaKStream.selectKey(valueFormat.getFormatInfo(), ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("COL1"))), Optional.empty(), childContextStacker, true));
// Then:
assertThat(e.getMessage(), containsString("Implicit repartitioning of windowed sources is not supported. See https://github.com/confluentinc/ksql/issues/4385."));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class SchemaKStreamTest method shouldFailRepartitionTable.
@Test(expected = UnsupportedOperationException.class)
public void shouldFailRepartitionTable() {
// Given:
givenInitialKStreamOf("SELECT * FROM test2 EMIT CHANGES;");
final UnqualifiedColumnReferenceExp col2 = new UnqualifiedColumnReferenceExp(ColumnName.of("COL2"));
// When:
schemaKTable.selectKey(valueFormat.getFormatInfo(), ImmutableList.of(col2), Optional.empty(), childContextStacker, false);
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class SchemaKStreamTest method shouldBuildSchemaForGroupBy.
@Test
public void shouldBuildSchemaForGroupBy() {
// Given:
givenInitialKStreamOf("SELECT col0, col1 FROM test1 WHERE col0 > 100 EMIT CHANGES;");
final List<Expression> groupBy = Collections.singletonList(new UnqualifiedColumnReferenceExp(ColumnName.of("COL1")));
// When:
final SchemaKGroupedStream groupedSchemaKStream = initialSchemaKStream.groupBy(valueFormat.getFormatInfo(), groupBy, childContextStacker);
// Then:
assertThat(groupedSchemaKStream.schema, is(schemaResolver.resolve(groupedSchemaKStream.getSourceStep(), initialSchemaKStream.getSchema())));
}
use of io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp in project ksql by confluentinc.
the class SchemaKTableTest method shouldFailSelectKeyIfNotForced.
@Test
public void shouldFailSelectKeyIfNotForced() {
// Given:
final String selectQuery = "SELECT col0 AS K, col2, col3 FROM test2 WHERE col0 > 100 EMIT CHANGES;";
final PlanNode logicalPlan = buildLogicalPlan(selectQuery);
initialSchemaKTable = buildSchemaKTableFromPlan(logicalPlan);
// When:
final Exception e = assertThrows(UnsupportedOperationException.class, () -> initialSchemaKTable.selectKey(valueFormat.getFormatInfo(), ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("COL1"))), Optional.empty(), childContextStacker, false));
// Then:
assertThat(e.getMessage(), containsString("Cannot repartition a TABLE source."));
}
Aggregations