use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds.
@Test
public void shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds() {
// Given:
when(keyFormat.isWindowed()).thenReturn(true);
when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(K_REF, Optional.of(K)))).build();
when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, K));
// When:
final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
// Then:
final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).keyColumn(K, SqlTypes.STRING).build();
assertThat(expected, is(projectNode.getSchema()));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectStar.
@Test
public void shouldBuildPullQueryOutputSchemaSelectStar() {
// Given:
selects = ImmutableList.of(new AllColumns(Optional.of(SOURCE_NAME)));
when(keyFormat.isWindowed()).thenReturn(false);
when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of());
// When:
final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, false, plannerOptions, false);
// Then:
final LogicalSchema expectedSchema = INPUT_SCHEMA;
final LogicalSchema expectedIntermediateSchema = QueryLogicalPlanUtil.buildIntermediateSchema(INPUT_SCHEMA, true, false, true);
assertThat(expectedIntermediateSchema, is(projectNode.getIntermediateSchema()));
assertThat(expectedSchema.withoutPseudoAndKeyColsInValue(), is(projectNode.getSchema()));
assertThrows(IllegalStateException.class, projectNode::getCompiledSelectExpressions);
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds.
@Test
public void shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds() {
// Given:
when(keyFormat.isWindowed()).thenReturn(true);
when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(COL0_REF, Optional.of(COL0)))).build();
when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, COL0));
// When:
final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
// Then:
final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).build();
assertThat(expected, is(projectNode.getSchema()));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldNotExtractMultiColKeySchema.
@Test
public void shouldNotExtractMultiColKeySchema() {
// Given:
final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
final Expression keyExp1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new IntegerLiteral(1));
final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K2")), new IntegerLiteral(3));
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp1, keyExp2);
when(source.getSchema()).thenReturn(multiSchema);
QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
// When:
final List<LookupConstraint> keys = filterNode.getLookupConstraints();
// Then:
assertThat(keys.size(), is(1));
assertThat(keys.get(0), instanceOf(NonKeyConstraint.class));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class DefaultSchemaInjectorFunctionalTest method constructCSASSource.
private void constructCSASSource(Schema valueSchema) {
if (testType != TestType.CSAS_WITH_SCHEMA_ID) {
return;
}
LogicalSchema.Builder builder = LogicalSchema.builder();
valueSchema.fields().forEach(field -> {
if (!field.name().equals("field1")) {
builder.valueColumn(ColumnName.of(field.name()), SchemaConverters.connectToSqlConverter().toSqlType(field.schema()));
}
});
builder.keyColumn(ColumnName.of("key"), SqlTypes.INTEGER);
LogicalSchema schema = builder.build();
when(metaStore.getSource(any())).thenReturn(ksqlStream);
when(ksqlStream.getSchema()).thenReturn(schema);
when(serviceContext.getSchemaRegistryClient()).thenReturn(srClient);
when(serviceContext.getTopicClient()).thenReturn(topicClient);
when(serviceContext.getConsumerGroupClient()).thenReturn(consumerGroupClient);
when(executionContext.createSandbox(any())).thenReturn(executionSandbox);
when(executionSandbox.plan(any(), any())).thenReturn(ksqlPlan);
when(ksqlPlan.getDdlCommand()).thenReturn(Optional.of(ddlCommand));
when(ddlCommand.getSchema()).thenReturn(schema);
when(ddlCommand.getFormats()).thenReturn(Formats.of(FormatInfo.of(KafkaFormat.NAME), FormatInfo.of(AvroFormat.NAME), SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), SerdeFeatures.of(SerdeFeature.WRAP_SINGLES)));
}
Aggregations