use of io.confluent.ksql.function.types.ArrayType in project ksql by confluentinc.
the class GenericsUtilTest method shouldIdentifyArrayGeneric.
@Test
public void shouldIdentifyArrayGeneric() {
// Given:
final ArrayType a = ArrayType.of(GenericType.of("A"));
final SqlArgument instance = SqlArgument.of(SqlTypes.array(SqlTypes.STRING));
// When:
final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
// Then:
assertThat(mapping, hasEntry(a.element(), SqlTypes.STRING));
}
use of io.confluent.ksql.function.types.ArrayType in project ksql by confluentinc.
the class DescribeFunctionExecutor method getFunctionInfo.
private static FunctionInfo getFunctionInfo(final List<ParameterInfo> argTypes, final ParamType returnTypeSchema, final String description, final boolean variadic) {
final List<ArgumentInfo> args = new ArrayList<>();
for (int i = 0; i < argTypes.size(); i++) {
final ParameterInfo param = argTypes.get(i);
final boolean isVariadic = variadic && i == (argTypes.size() - 1);
final String type = isVariadic ? ((ArrayType) param.type()).element().toString() : param.type().toString();
args.add(new ArgumentInfo(param.name(), type, param.description(), isVariadic));
}
return new FunctionInfo(args, returnTypeSchema.toString(), description);
}
use of io.confluent.ksql.function.types.ArrayType in project ksql by confluentinc.
the class UdfIndexTest method shouldMatchNestedGenericMethodWithMultipleGenerics.
@Test
public void shouldMatchNestedGenericMethodWithMultipleGenerics() {
// Given:
final ArrayType generic = ArrayType.of(GenericType.of("A"));
givenFunctions(function(EXPECTED, false, generic, generic));
// When:
final KsqlScalarFunction fun = udfIndex.getFunction(ImmutableList.of(SqlArgument.of(SqlArray.of(SqlTypes.INTEGER)), SqlArgument.of(SqlArray.of(SqlTypes.INTEGER))));
// Then:
assertThat(fun.name(), equalTo(EXPECTED));
}
use of io.confluent.ksql.function.types.ArrayType in project ksql by confluentinc.
the class UdfIndexTest method shouldNotMatchNestedGenericMethodWithAlreadyReservedTypes.
@Test
public void shouldNotMatchNestedGenericMethodWithAlreadyReservedTypes() {
// Given:
final ArrayType generic = ArrayType.of(GenericType.of("A"));
givenFunctions(function(EXPECTED, false, generic, generic));
// When:
final Exception e = assertThrows(KsqlException.class, () -> udfIndex.getFunction(ImmutableList.of(SqlArgument.of(SqlArray.of(SqlTypes.INTEGER)), SqlArgument.of(SqlArray.of(SqlTypes.STRING)))));
// Then:
assertThat(e.getMessage(), containsString("Function 'name' does not accept parameters " + "(ARRAY<INTEGER>, ARRAY<STRING>)"));
}
use of io.confluent.ksql.function.types.ArrayType in project ksql by confluentinc.
the class GenericsUtil method applyResolved.
/**
* Replaces all generics in a schema with concrete schemas defined in {@code resolved}
*
* @param schema the schema which may contain generics
* @param resolved the mapping from generics to resolved types
* @return a schema with the same structure as {@code schema} but with no generics
*
* @throws KsqlException if there is a generic in {@code schema} that is not present
* in {@code mapping}
*/
public static SqlType applyResolved(final ParamType schema, final Map<GenericType, SqlType> resolved) {
if (schema instanceof ArrayType) {
return SqlTypes.array(applyResolved(((ArrayType) schema).element(), resolved));
}
if (schema instanceof MapType) {
final MapType mapType = (MapType) schema;
final SqlType keyType = applyResolved(mapType.key(), resolved);
final SqlType valueType = applyResolved(mapType.value(), resolved);
return SqlTypes.map(keyType, valueType);
}
if (schema instanceof StructType) {
final Builder struct = SqlTypes.struct();
((StructType) schema).getSchema().forEach((fieldName, type) -> struct.field(fieldName, applyResolved(type, resolved)));
return struct.build();
}
if (schema instanceof GenericType) {
final SqlType instance = resolved.get(schema);
if (instance == null) {
throw new KsqlException("Could not find mapping for generic type: " + schema);
}
return instance;
}
return SchemaConverters.functionToSqlConverter().toSqlType(schema);
}
Aggregations