Search in sources :

Example 11 with BooleanLiteral

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

the class CreateSourceAsPropertiesTest method shouldNotQuoteNonStringPropValues.

@Test
public void shouldNotQuoteNonStringPropValues() {
    // Given:
    final CreateSourceAsProperties props = CreateSourceAsProperties.from(ImmutableMap.of("Wrap_Single_value", new BooleanLiteral("true")));
    // When:
    final String sql = props.toString();
    // Then:
    assertThat(sql, containsString("WRAP_SINGLE_VALUE=true"));
}
Also used : BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 12 with BooleanLiteral

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

the class InsertValuesExecutorTest method shouldHandleNullKeyForSourceWithKeyField.

@Test
public void shouldHandleNullKeyForSourceWithKeyField() {
    // Given:
    givenSourceStreamWithSchema(BIG_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(BIG_SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new IntegerLiteral(0), new LongLiteral(2), new DoubleLiteral(3.0), new BooleanLiteral("TRUE"), new StringLiteral("str"), new DecimalLiteral(new BigDecimal("1.2"))));
    // When:
    executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
    // Then:
    verify(keySerializer).serialize(TOPIC_NAME, genericKey("str"));
    verify(valueSerializer).serialize(TOPIC_NAME, genericRow("str", 0, 2L, 3.0, true, "str", new BigDecimal("1.2", new MathContext(2))));
    verify(producer).send(new ProducerRecord<>(TOPIC_NAME, null, 1L, KEY, VALUE));
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) InsertValues(io.confluent.ksql.parser.tree.InsertValues) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext) Test(org.junit.Test)

Example 13 with BooleanLiteral

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

the class CoercionUtilTest method shouldNotCoerceStructOfIncompatibleLiterals.

@Test
public void shouldNotCoerceStructOfIncompatibleLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", new BooleanLiteral(false)))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: STRUCT<`a` INTEGER> = STRUCT<`a` BOOLEAN> (STRUCT(a:=false))"));
}
Also used : Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 14 with BooleanLiteral

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

the class CoercionUtilTest method shouldDriveCoercionFromFirstNonNullExpression.

@Test
public void shouldDriveCoercionFromFirstNonNullExpression() {
    // Given:
    final ImmutableList<Expression> stringFirst = ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new BooleanLiteral(true));
    final ImmutableList<Expression> boolFirst = ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new StringLiteral("false"));
    // When:
    final Result stringResult = CoercionUtil.coerceUserList(stringFirst, typeManager);
    final Result boolResult = CoercionUtil.coerceUserList(boolFirst, typeManager);
    // Then:
    assertThat(stringResult.commonType(), is(Optional.of(SqlTypes.STRING)));
    assertThat(stringResult.expressions(), is(ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new StringLiteral("true"))));
    assertThat(boolResult.commonType(), is(Optional.of(SqlTypes.BOOLEAN)));
    assertThat(boolResult.expressions(), is(ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new BooleanLiteral(false))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 15 with BooleanLiteral

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

the class CoercionUtilTest method shouldNotCoerceArrayOfIncompatibleLiterals.

@Test
public void shouldNotCoerceArrayOfIncompatibleLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10))), new CreateArrayExpression(ImmutableList.of(new BooleanLiteral(false))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: ARRAY<INTEGER> = ARRAY<BOOLEAN> (ARRAY[false])"));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)22 Test (org.junit.Test)22 Expression (io.confluent.ksql.execution.expression.tree.Expression)14 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)11 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)11 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)11 KsqlException (io.confluent.ksql.util.KsqlException)11 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)9 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)6 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)3 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)3 Literal (io.confluent.ksql.execution.expression.tree.Literal)3 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)3 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)3 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)2