Search in sources :

Example 1 with BooleanLiteral

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

the class DefaultSchemaInjectorTest method shouldThrowIfValueFormatDoesNotSupportSchemaIdInference.

@Test
public void shouldThrowIfValueFormatDoesNotSupportSchemaIdInference() {
    // Given
    givenKeyButNotValueInferenceSupported(ImmutableMap.of("value_schema_id", new IntegerLiteral(123), "WRAP_SINGLE_VALUE", new BooleanLiteral(true)));
    when(cs.getElements()).thenReturn(SOME_KEY_ELEMENTS_STREAM);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> injector.inject(csStatement));
    // Then:
    assertThat(e.getMessage(), containsString("VALUE_FORMAT should support schema inference when VALUE_SCHEMA_ID is provided. " + "Current format is DELIMITED."));
}
Also used : 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)

Example 2 with BooleanLiteral

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

the class ExpressionTypeManagerTest method shouldFailIfOperatorCannotBeAppiled.

@Test
public void shouldFailIfOperatorCannotBeAppiled() {
    // Given:
    final ComparisonExpression expr = new ComparisonExpression(Type.GREATER_THAN, new BooleanLiteral("true"), new BooleanLiteral("false"));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expr));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot compare true (BOOLEAN) to false (BOOLEAN) with " + "GREATER_THAN"));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 3 with BooleanLiteral

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

the class CoercionUtilTest method shouldCoerceToBooleans.

@Test
public void shouldCoerceToBooleans() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new BooleanLiteral(true), new StringLiteral("FaLsE"), BOOL_EXPRESSION);
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.BOOLEAN)));
    assertThat(result.expressions(), is(ImmutableList.of(new BooleanLiteral(true), new BooleanLiteral(false), BOOL_EXPRESSION)));
}
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) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 4 with BooleanLiteral

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

the class CoercionUtilTest method shouldNotCoerceMapOfIncompatibleKeyLiterals.

@Test
public void shouldNotCoerceMapOfIncompatibleKeyLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new BooleanLiteral(false), new StringLiteral("123456789000"))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<BOOLEAN, STRING> (MAP(false:='123456789000'))"));
}
Also used : CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) 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) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 5 with BooleanLiteral

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

the class CoercionUtilTest method shouldThrowOnIncompatible.

@Test
public void shouldThrowOnIncompatible() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new BooleanLiteral(true), // <-- can not be coerced to boolean.
    new IntegerLiteral(10));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), is("operator does not exist: BOOLEAN = INTEGER (10)" + System.lineSeparator() + "Hint: You might need to add explicit type casts."));
}
Also used : 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