Search in sources :

Example 6 with CreateArrayExpression

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

the class CoercionUtilTest method shouldNotCoerceArrayWithDifferentExpression.

@Test
public void shouldNotCoerceArrayWithDifferentExpression() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10))), new CreateArrayExpression(ImmutableList.of(STRING_EXPRESSION)));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: ARRAY<INTEGER> = ARRAY<STRING> (ARRAY[STR])"));
}
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) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 7 with CreateArrayExpression

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

the class ExpressionTypeManagerTest method shouldThrowOnArrayAllNulls.

@Test
public void shouldThrowOnArrayAllNulls() {
    // Given:
    Expression expression = new CreateArrayExpression(ImmutableList.of(new NullLiteral()));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot construct an array with all NULL elements"));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 8 with CreateArrayExpression

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

the class ExpressionTypeManagerTest method shouldEvaluateTypeForCreateArrayExpression.

@Test
public void shouldEvaluateTypeForCreateArrayExpression() {
    // Given:
    Expression expression = new CreateArrayExpression(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0)));
    // When:
    final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(type, is(SqlTypes.array(SqlTypes.BIGINT)));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 9 with CreateArrayExpression

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

the class ExpressionTypeManagerTest method shouldThrowOnArrayMultipleTypes.

@Test
public void shouldThrowOnArrayMultipleTypes() {
    // Given:
    Expression expression = new CreateArrayExpression(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("foo")));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), containsString("invalid input syntax for type BIGINT: \"foo\"."));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 10 with CreateArrayExpression

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

the class ExpressionTypeManagerTest method shouldEvaluateTypeForCreateArrayExpressionWithNull.

@Test
public void shouldEvaluateTypeForCreateArrayExpressionWithNull() {
    // Given:
    Expression expression = new CreateArrayExpression(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0), new NullLiteral()));
    // When:
    final SqlType type = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(type, is(SqlTypes.array(SqlTypes.BIGINT)));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Test(org.junit.Test)

Aggregations

CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)13 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)12 Test (org.junit.Test)12 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)10 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)9 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)9 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)9 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)9 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)8 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)7 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)6 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)6 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)6 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)5 KsqlException (io.confluent.ksql.util.KsqlException)5 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)4 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)3