Search in sources :

Example 21 with StringLiteral

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)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 22 with StringLiteral

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)"));
}
Also used : BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 23 with StringLiteral

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);
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) CreateTable(io.confluent.ksql.parser.tree.CreateTable) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) DropTable(io.confluent.ksql.parser.tree.DropTable) Table(io.confluent.ksql.parser.tree.Table) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) StringContains.containsString(org.hamcrest.core.StringContains.containsString) JoinOn(io.confluent.ksql.parser.tree.JoinOn) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Before(org.junit.Before)

Example 24 with StringLiteral

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);
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal)

Example 25 with StringLiteral

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"));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)204 Test (org.junit.Test)199 Expression (io.confluent.ksql.execution.expression.tree.Expression)95 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)70 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)66 KsqlException (io.confluent.ksql.util.KsqlException)64 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)63 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)63 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)63 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)61 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)53 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)51 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)49 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)43 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)36 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)35 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)34 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)31 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)28 Matchers.containsString (org.hamcrest.Matchers.containsString)27