use of io.confluent.ksql.schema.ksql.types.SqlBaseType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method shouldCoerceAlmostUsingSameRulesAsBaseTypeUpCastRules.
@Test
public void shouldCoerceAlmostUsingSameRulesAsBaseTypeUpCastRules() {
for (final SqlBaseType fromBaseType : supportedTypes()) {
// Given:
final Map<Boolean, List<SqlBaseType>> partitioned = supportedTypes().stream().collect(Collectors.partitioningBy(toBaseType -> coercionShouldBeSupported(fromBaseType, toBaseType)));
final List<SqlBaseType> shouldUpCast = partitioned.getOrDefault(true, ImmutableList.of());
final List<SqlBaseType> shouldNotUpCast = partitioned.getOrDefault(false, ImmutableList.of());
// Then:
shouldUpCast.forEach(toBaseType -> assertThat("should coerce " + fromBaseType + " to " + toBaseType, coercer.coerce(getInstance(fromBaseType, toBaseType), getType(toBaseType)), is(not(Result.failure()))));
shouldNotUpCast.forEach(toBaseType -> assertThat("should not coerce " + fromBaseType + " to " + toBaseType, coercer.coerce(getInstance(fromBaseType, toBaseType), getType(toBaseType)), is(Result.failure())));
}
}
use of io.confluent.ksql.schema.ksql.types.SqlBaseType in project ksql by confluentinc.
the class OperatorTest method shouldThrowExceptionWhenNullType.
@Test
public void shouldThrowExceptionWhenNullType() {
allOperations().forEach(op -> {
for (final SqlBaseType leftBaseType : SqlBaseType.values()) {
// When:
final Throwable exception = assertThrows(KsqlException.class, () -> op.resultType(getType(leftBaseType), null));
// Then:
assertEquals(String.format("Arithmetic on types %s and null are not supported.", getType(leftBaseType)), exception.getMessage());
}
});
allOperations().forEach(op -> {
for (final SqlBaseType rightBaseType : SqlBaseType.values()) {
// When:
final Throwable exception = assertThrows(KsqlException.class, () -> op.resultType(null, getType(rightBaseType)));
// Then:
assertEquals(String.format("Arithmetic on types null and %s are not supported.", getType(rightBaseType)), exception.getMessage());
}
});
}
use of io.confluent.ksql.schema.ksql.types.SqlBaseType in project ksql by confluentinc.
the class SchemaConvertersTest method shouldGetJavaTypesForAllSqlTypes.
@Test
public void shouldGetJavaTypesForAllSqlTypes() {
for (final Entry<SqlBaseType, Class<?>> entry : SQL_TO_JAVA.entrySet()) {
final SqlBaseType sqlType = entry.getKey();
final Class<?> javaType = entry.getValue();
final Class<?> result = SchemaConverters.sqlToJavaConverter().toJavaType(sqlType);
assertThat(result, equalTo(javaType));
}
}
use of io.confluent.ksql.schema.ksql.types.SqlBaseType in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldThrowOnUnknownType.
@Test
public void shouldThrowOnUnknownType() {
// Given:
final SqlBaseType unknownType = mock(SqlBaseType.class, "bob");
final SqlType type = mock(SqlType.class);
when(type.baseType()).thenReturn(unknownType);
// When:
final UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> SqlTypeWalker.visit(type, visitor));
// Then:
assertThat(e.getMessage(), containsString("Unsupported schema type: bob"));
}
use of io.confluent.ksql.schema.ksql.types.SqlBaseType in project ksql by confluentinc.
the class UdafAggregateFunctionFactory method buildAllParams.
private List<SqlArgument> buildAllParams(final List<SqlArgument> argTypeList, final AggregateFunctionInitArguments initArgs) {
if (initArgs.args().isEmpty()) {
return argTypeList;
}
final List<SqlArgument> allParams = new ArrayList<>(argTypeList.size() + initArgs.args().size());
allParams.addAll(argTypeList);
for (final Object arg : initArgs.args()) {
if (arg == null) {
allParams.add(null);
continue;
}
final SqlBaseType baseType = SchemaConverters.javaToSqlConverter().toSqlType(arg.getClass());
try {
// Only primitive types currently supported:
final SqlPrimitiveType primitiveType = SqlPrimitiveType.of(baseType);
allParams.add(SqlArgument.of(primitiveType));
} catch (final Exception e) {
throw new KsqlFunctionException("Only primitive init arguments are supported by UDAF " + getName() + ", but got " + arg, e);
}
}
return allParams;
}
Aggregations