Search in sources :

Example 11 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class DefaultSqlValueCoercerTest method assertUnsupported.

private static void assertUnsupported(final DefaultSqlValueCoercer coercer, final SqlType from, final SqlType to) {
    // Given:
    final Object value = InstanceInstances.instanceFor(from, to);
    // When:
    final Optional<SqlType> coercedType = coercer.canCoerce(from, to);
    final Result result = coercer.coerce(value, to);
    // Then:
    assertThat("canCoerce(" + from + "," + to + ")", coercedType, is(Optional.empty()));
    assertThat("coerce(" + value + "," + to + ")", result, is(Result.failure()));
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Result(io.confluent.ksql.schema.ksql.SqlValueCoercer.Result)

Example 12 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class GenericsUtilTest method shouldResolveSchemaWithMapping.

@Test
public void shouldResolveSchemaWithMapping() {
    // Given:
    final GenericType a = GenericType.of("A");
    final ImmutableMap<GenericType, SqlType> mapping = ImmutableMap.of(a, SqlTypes.STRING);
    // When:
    final SqlType resolved = GenericsUtil.applyResolved(a, mapping);
    // Then:
    assertThat(resolved, is(SqlTypes.STRING));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 13 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class SchemaConvertersTest method shouldGetSqlTypeForAllParamTypes.

@Test
public void shouldGetSqlTypeForAllParamTypes() {
    for (Entry<ParamType, SqlType> entry : SQL_TO_FUNCTION.inverse().entrySet()) {
        ParamType param = entry.getKey();
        if (REQUIRES_SCHEMA_SPEC.contains(param)) {
            continue;
        }
        SqlType sqlType = entry.getValue();
        assertThat(SchemaConverters.functionToSqlConverter().toSqlType(param), is(sqlType));
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 14 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class SchemaConvertersTest method shouldGetParamTypesForAllSqlTypes.

@Test
public void shouldGetParamTypesForAllSqlTypes() {
    for (final Entry<SqlType, ParamType> entry : SQL_TO_FUNCTION.entrySet()) {
        final SqlType sqlType = entry.getKey();
        final ParamType javaType = entry.getValue();
        final ParamType result = SchemaConverters.sqlToFunctionConverter().toFunctionType(sqlType);
        assertThat(result, equalTo(javaType));
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 15 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class LogicalPlanner method verifyForeignKeyJoin.

private Optional<Expression> verifyForeignKeyJoin(final JoinInfo joinInfo, final PlanNode leftNode, final PlanNode rightNode) {
    final JoinType joinType = joinInfo.getType();
    final Expression leftExpression = joinInfo.getLeftJoinExpression();
    final Expression rightExpression = joinInfo.getRightJoinExpression();
    if (joinInfo.getType().equals(JoinType.OUTER)) {
        throw new KsqlException(String.format("Invalid join type:" + " full-outer join not supported for foreign-key table-table join." + " Got %s %s %s.", joinInfo.getLeftSource().getDataSource().getName().text(), joinType, joinInfo.getRightSource().getDataSource().getName().text()));
    }
    // because a FK-join output table has the same PK as its left input table
    if (!(leftNode instanceof DataSourceNode) || !(rightNode instanceof DataSourceNode)) {
        throw new KsqlException(String.format("Invalid join condition:" + " foreign-key table-table joins are not supported as part of n-way joins." + " Got %s = %s.", joinInfo.getFlippedLeftJoinExpression(), joinInfo.getFlippedRightJoinExpression()));
    }
    final CodeGenRunner codeGenRunner = new CodeGenRunner(leftNode.getSchema(), ksqlConfig, metaStore);
    final VisitParentExpressionVisitor<Optional<Expression>, Context<Void>> unqualifiedRewritter = new VisitParentExpressionVisitor<Optional<Expression>, Context<Void>>(Optional.empty()) {

        @Override
        public Optional<Expression> visitQualifiedColumnReference(final QualifiedColumnReferenceExp node, final Context<Void> ctx) {
            return Optional.of(new UnqualifiedColumnReferenceExp(node.getColumnName()));
        }
    };
    final Expression leftExpressionUnqualified = ExpressionTreeRewriter.rewriteWith(unqualifiedRewritter::process, leftExpression);
    final ExpressionEvaluator expressionEvaluator = codeGenRunner.buildCodeGenFromParseTree(leftExpressionUnqualified, "Left Join Expression");
    final SqlType fkType = expressionEvaluator.getExpressionType();
    final SqlType rightKeyType = Iterables.getOnlyElement(rightNode.getSchema().key()).type();
    verifyJoinConditionTypes(fkType, rightKeyType, leftExpression, rightExpression, joinInfo.hasFlippedJoinCondition());
    if (((DataSourceNode) rightNode).isWindowed()) {
        throw new KsqlException("Foreign-key table-table joins are not supported on windowed tables.");
    }
    return Optional.of(leftExpression);
}
Also used : Context(io.confluent.ksql.engine.rewrite.ExpressionTreeRewriter.Context) DataSourceNode(io.confluent.ksql.planner.plan.DataSourceNode) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) Optional(java.util.Optional) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) JoinType(io.confluent.ksql.planner.plan.JoinNode.JoinType) KsqlException(io.confluent.ksql.util.KsqlException) VisitParentExpressionVisitor(io.confluent.ksql.execution.expression.tree.VisitParentExpressionVisitor) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) ExpressionEvaluator(io.confluent.ksql.execution.transform.ExpressionEvaluator) Expression(io.confluent.ksql.execution.expression.tree.Expression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Aggregations

SqlType (io.confluent.ksql.schema.ksql.types.SqlType)140 Test (org.junit.Test)80 Expression (io.confluent.ksql.execution.expression.tree.Expression)47 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)38 KsqlException (io.confluent.ksql.util.KsqlException)33 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)30 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)29 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)29 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)29 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)29 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)29 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)29 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)29 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)29 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)29 Optional (java.util.Optional)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)15 Result (io.confluent.ksql.schema.ksql.SqlValueCoercer.Result)14 Struct (org.apache.kafka.connect.data.Struct)14 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)13