use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldReturnKeyConstraintString.
@Test
public void shouldReturnKeyConstraintString() {
// Given:
when(plannerOptions.getTableScansEnabled()).thenReturn(true);
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.STRING).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
when(source.getSchema()).thenReturn(schema);
final Expression keyExp1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v1"));
final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v2"));
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp1, keyExp2);
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(KeyConstraint.class));
final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
assertThat(keyConstraint.getKey(), is(GenericKey.genericKey("v2")));
assertThat(keyConstraint.getOperator(), is(KeyConstraint.ConstraintOperator.EQUAL));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnMultiColKeySchema.
@Test
public void shouldThrowOnMultiColKeySchema() {
// Given:
final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1)));
when(source.getSchema()).thenReturn(multiSchema);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("Multi-column sources must specify every key in the WHERE clause. Specified: [`K`] Expected: [`K` INTEGER KEY, `K2` INTEGER KEY]."));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class KsqlResourceTest method addTestTopicAndSources.
private void addTestTopicAndSources() {
final LogicalSchema schema1 = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("S1_F1"), SqlTypes.BOOLEAN).build();
givenSource(DataSourceType.KTABLE, "TEST_TABLE", "KAFKA_TOPIC_1", schema1);
final LogicalSchema schema2 = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("S2_F1"), SqlTypes.STRING).build();
givenSource(DataSourceType.KSTREAM, "TEST_STREAM", "KAFKA_TOPIC_2", schema2);
givenKafkaTopicExists("orders-topic");
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class KsqlResourceTest method shouldDescribeStreamsExtended.
@Test
public void shouldDescribeStreamsExtended() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BOOLEAN).valueColumn(ColumnName.of("FIELD2"), SqlTypes.STRING).build();
givenSource(DataSourceType.KSTREAM, "new_stream", "new_topic", schema);
// When:
final SourceDescriptionList descriptionList = makeSingleRequest("DESCRIBE STREAMS EXTENDED;", SourceDescriptionList.class);
// Then:
assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("TEST_STREAM")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("KAFKA_TOPIC_2")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors()), SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("new_stream")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("new_topic")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors())));
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class KsqlResourceTest method shouldDescribeTablesExtended.
@Test
public void shouldDescribeTablesExtended() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BOOLEAN).valueColumn(ColumnName.of("FIELD2"), SqlTypes.STRING).build();
givenSource(DataSourceType.KTABLE, "new_table", "new_topic", schema, ImmutableSet.of(SourceName.of("TEST_TABLE")));
// When:
final SourceDescriptionList descriptionList = makeSingleRequest("DESCRIBE TABLES EXTENDED;", SourceDescriptionList.class);
// Then:
assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("TEST_TABLE")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("KAFKA_TOPIC_1")), Collections.emptyList(), ImmutableList.of("new_table"), new MetricCollectors()), SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("new_table")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("new_topic")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors())));
}
Aggregations