use of io.confluent.ksql.schema.ksql.types.SqlArray in project ksql by confluentinc.
the class ParamTypes method areCompatible.
// CHECKSTYLE_RULES.OFF: CyclomaticComplexity
// CHECKSTYLE_RULES.OFF: NPathComplexity
public static boolean areCompatible(final SqlArgument argument, final ParamType declared, final boolean allowCast) {
// CHECKSTYLE_RULES.ON: CyclomaticComplexity
// CHECKSTYLE_RULES.ON: NPathComplexity
final Optional<SqlLambda> sqlLambdaOptional = argument.getSqlLambda();
if (sqlLambdaOptional.isPresent() && declared instanceof LambdaType) {
final LambdaType declaredLambda = (LambdaType) declared;
final SqlLambda sqlLambda = sqlLambdaOptional.get();
if (sqlLambda instanceof SqlLambdaResolved) {
final SqlLambdaResolved sqlLambdaResolved = (SqlLambdaResolved) sqlLambda;
if (sqlLambdaResolved.getInputType().size() != declaredLambda.inputTypes().size()) {
return false;
}
int i = 0;
for (final ParamType paramType : declaredLambda.inputTypes()) {
if (!areCompatible(SqlArgument.of(sqlLambdaResolved.getInputType().get(i)), paramType, allowCast)) {
return false;
}
i++;
}
return areCompatible(SqlArgument.of(sqlLambdaResolved.getReturnType()), declaredLambda.returnType(), allowCast);
} else {
return sqlLambda.getNumInputs() == declaredLambda.inputTypes().size();
}
}
if (argument.getSqlIntervalUnit().isPresent() && declared instanceof IntervalUnitType) {
return true;
} else if (argument.getSqlIntervalUnit().isPresent() || declared instanceof IntervalUnitType) {
return false;
}
final SqlType argumentSqlType = argument.getSqlTypeOrThrow();
if (argumentSqlType.baseType() == SqlBaseType.ARRAY && declared instanceof ArrayType) {
return areCompatible(SqlArgument.of(((SqlArray) argumentSqlType).getItemType()), ((ArrayType) declared).element(), allowCast);
}
if (argumentSqlType.baseType() == SqlBaseType.MAP && declared instanceof MapType) {
final SqlMap sqlType = (SqlMap) argumentSqlType;
final MapType mapType = (MapType) declared;
return areCompatible(SqlArgument.of(sqlType.getKeyType()), mapType.key(), allowCast) && areCompatible(SqlArgument.of(sqlType.getValueType()), mapType.value(), allowCast);
}
if (argumentSqlType.baseType() == SqlBaseType.STRUCT && declared instanceof StructType) {
return isStructCompatible(argumentSqlType, declared);
}
return isPrimitiveMatch(argumentSqlType, declared, allowCast);
}
use of io.confluent.ksql.schema.ksql.types.SqlArray in project ksql by confluentinc.
the class SqlTypeWalker method visitArray.
private static <S, F> S visitArray(final SqlTypeWalker.Visitor<S, F> visitor, final SqlType type) {
final SqlArray array = (SqlArray) type;
final S element = visit(array.getItemType(), visitor);
return visitor.visitArray(array, element);
}
use of io.confluent.ksql.schema.ksql.types.SqlArray in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldVisitArray.
@Test
public void shouldVisitArray() {
// Given:
final SqlArray type = SqlTypes.array(SqlTypes.BIGINT);
when(visitor.visitBigInt(any())).thenReturn("Expected-element");
when(visitor.visitArray(any(), any())).thenReturn("Expected");
// When:
final String result = SqlTypeWalker.visit(type, visitor);
// Then:
verify(visitor).visitBigInt(same(SqlTypes.BIGINT));
verify(visitor).visitArray(same(type), eq("Expected-element"));
assertThat(result, is("Expected"));
}
Aggregations