use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatSimpleCaseExpression.
@Test
public void shouldFormatSimpleCaseExpression() {
final SimpleCaseExpression expression = new SimpleCaseExpression(new StringLiteral("operand"), Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral(1))), Optional.empty());
assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE 'operand' WHEN 'foo' THEN 1 END)"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatBetweenPredicate.
@Test
public void shouldFormatBetweenPredicate() {
final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral(5), new LongLiteral(10));
assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class SqlFormatterTest method setUp.
@Before
public void setUp() {
final Table left = new Table(SourceName.of("left"));
final Table right = new Table(SourceName.of("right"));
final Table right2 = new Table(SourceName.of("right2"));
leftAlias = new AliasedRelation(left, SourceName.of("L"));
rightAlias = new AliasedRelation(right, SourceName.of("R"));
right2Alias = new AliasedRelation(right2, SourceName.of("R2"));
criteria = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right.col0")));
criteria2 = new JoinOn(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new StringLiteral("left.col0"), new StringLiteral("right2.col0")));
metaStore = MetaStoreFixture.getNewMetaStore(mock(FunctionRegistry.class));
final KsqlTopic ksqlTopicOrders = new KsqlTopic("orders_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
final KsqlStream<?> ksqlStreamOrders = new KsqlStream<>("sqlexpression", SourceName.of("ADDRESS"), ORDERS_SCHEMA, Optional.empty(), false, ksqlTopicOrders, false);
metaStore.putSource(ksqlStreamOrders, false);
final KsqlTopic ksqlTopicItems = new KsqlTopic("item_topic", KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.JSON.name()), SerdeFeatures.of()));
final KsqlTable<String> ksqlTableOrders = new KsqlTable<>("sqlexpression", SourceName.of("ITEMID"), ITEM_INFO_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
metaStore.putSource(ksqlTableOrders, false);
final KsqlTable<String> ksqlTableTable = new KsqlTable<>("sqlexpression", SourceName.of("TABLE"), TABLE_SCHEMA, Optional.empty(), false, ksqlTopicItems, false);
metaStore.putSource(ksqlTableTable, false);
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class CreateSourceProperties method withFormats.
public CreateSourceProperties withFormats(final String keyFormat, final String valueFormat) {
final Map<String, Literal> originals = props.copyOfOriginalLiterals();
originals.put(CommonCreateConfigs.KEY_FORMAT_PROPERTY, new StringLiteral(keyFormat));
originals.put(CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral(valueFormat));
return new CreateSourceProperties(originals, durationParser);
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnTypeMismatchCannotCoerce.
@Test
public void shouldThrowOnTypeMismatchCannotCoerce() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.INTEGER).build();
final List<ColumnName> names = ImmutableList.of(KEY, COL0);
final Expression exp = new StringLiteral("a");
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Expected type"));
}
Aggregations