Search in sources :

Example 71 with IntegerLiteral

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

the class CoercionUtilTest method shouldCoerceMapOfCompatibleLiterals.

@Test
public void shouldCoerceMapOfCompatibleLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))));
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER))));
    assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)), cast(new CreateMapExpression(ImmutableMap.of(new StringLiteral("123456789000"), new StringLiteral("\t -100 \t"))), SqlTypes.map(SqlTypes.BIGINT, SqlTypes.INTEGER)))));
}
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) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 72 with IntegerLiteral

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

Example 73 with IntegerLiteral

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

the class CoercionUtilTest method shouldNotCoerceMapOfIncompatibleValueLiterals.

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

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

the class ExpressionTypeManagerTest method shouldFailIfDefaultHasDifferentTypeToWhen.

@Test
public void shouldFailIfDefaultHasDifferentTypeToWhen() {
    // Given:
    final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), new StringLiteral("good"))), Optional.of(new BooleanLiteral("true")));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), containsString("Invalid Case expression. Type for the default clause should be the same as for 'THEN' clauses." + System.lineSeparator() + "THEN type: STRING." + System.lineSeparator() + "DEFAULT type: BOOLEAN."));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) 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 75 with IntegerLiteral

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

the class CreateSourcePropertiesTest method shouldSetPartitions.

@Test
public void shouldSetPartitions() {
    // When:
    final CreateSourceProperties properties = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(2)).build());
    // Then:
    assertThat(properties.getPartitions(), is(Optional.of(2)));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Literal(io.confluent.ksql.execution.expression.tree.Literal) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Matchers.containsString(org.hamcrest.Matchers.containsString) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Aggregations

IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)150 Test (org.junit.Test)146 Expression (io.confluent.ksql.execution.expression.tree.Expression)111 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)85 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)81 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)66 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)62 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)61 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)61 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)60 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)46 KsqlException (io.confluent.ksql.util.KsqlException)46 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)45 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)42 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)38 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)38 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)30 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)24 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)23 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)23