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()));
}
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));
}
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));
}
}
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));
}
}
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);
}
Aggregations