Search in sources :

Example 26 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.

the class GenericRecordFactoryTest method shouldBuildPartialColumns.

@Test
public void shouldBuildPartialColumns() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
    final List<ColumnName> names = ImmutableList.of(KEY, COL0);
    final Expression exp = new StringLiteral("a");
    // When:
    final KsqlGenericRecord record = recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KSTREAM);
    // Then:
    assertThat(record, is(KsqlGenericRecord.of(GenericKey.genericKey("a"), GenericRow.genericRow("a", null), 0)));
}
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) Test(org.junit.Test)

Example 27 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.

the class GenericRecordFactoryTest method shouldThrowOnTableMissingKey.

@Test
public void shouldThrowOnTableMissingKey() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
    final List<ColumnName> names = ImmutableList.of(COL0, COL1);
    final Expression exp = new StringLiteral("a");
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(names, ImmutableList.of(exp, exp), schema, DataSourceType.KTABLE));
    // Then:
    assertThat(e.getMessage(), containsString("Value for primary key column"));
}
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)

Example 28 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.

the class GenericRecordFactoryTest method shouldThrowOnColumnMismatch.

@Test
public void shouldThrowOnColumnMismatch() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).valueColumn(COL1, SqlTypes.STRING).build();
    final List<ColumnName> names = ImmutableList.of(KEY, COL0, COL1);
    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 a value for each column"));
}
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)

Example 29 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.

the class GenericRecordFactoryTest method shouldThrowOnInsertRowoffset.

@Test
public void shouldThrowOnInsertRowoffset() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
    final Expression exp = new StringLiteral("a");
    when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, SystemColumns.ROWOFFSET_NAME), ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM));
    // Then:
    assertThat(e.getMessage(), containsString("Inserting into column `ROWOFFSET` is not allowed."));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 30 with StringLiteral

use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.

the class GenericExpressionResolverTest method shouldParseDate.

@Test
public void shouldParseDate() {
    // Given:
    final SqlType type = SqlTypes.DATE;
    final Expression exp = new StringLiteral("2021-01-09");
    // When:
    Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
    // Then:
    assertTrue(o instanceof Date);
    assertThat(((Date) o).getTime(), is(1610150400000L));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Date(java.sql.Date) 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