Search in sources :

Example 81 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression 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 82 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression 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 83 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression 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 84 with Expression

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

the class GenericExpressionResolverTest method shouldThrowIfCannotCoerce.

@Test
public void shouldThrowIfCannotCoerce() {
    // Given:
    final SqlType type = SqlTypes.array(SqlTypes.INTEGER);
    final Expression exp = new IntegerLiteral(1);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp));
    // Then:
    assertThat(e.getMessage(), containsString("Expected type ARRAY<INTEGER> for field `FOO` but got INTEGER(1)"));
}
Also used : CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) KsqlException(io.confluent.ksql.util.KsqlException) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 85 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression 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

Expression (io.confluent.ksql.execution.expression.tree.Expression)343 Test (org.junit.Test)297 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)213 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)195 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)179 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)170 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)170 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)159 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)150 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)143 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)142 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)138 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)125 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)114 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)112 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)99 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)94 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)89 KsqlException (io.confluent.ksql.util.KsqlException)72 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)53