use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldVisitDouble.
@Test
public void shouldVisitDouble() {
// Given:
final SqlPrimitiveType type = SqlTypes.DOUBLE;
when(visitor.visitDouble(any())).thenReturn("Expected");
// When:
final String result = SqlTypeWalker.visit(type, visitor);
// Then:
verify(visitor).visitDouble(same(type));
assertThat(result, is("Expected"));
}
use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldVisitString.
@Test
public void shouldVisitString() {
// Given:
final SqlPrimitiveType type = SqlTypes.STRING;
when(visitor.visitString(any())).thenReturn("Expected");
// When:
final String result = SqlTypeWalker.visit(type, visitor);
// Then:
verify(visitor).visitString(same(type));
assertThat(result, is("Expected"));
}
use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldStartWalkingFromField.
@Test
public void shouldStartWalkingFromField() {
// Given:
final SqlPrimitiveType type = SqlTypes.BOOLEAN;
final Field field = mock(Field.class);
when(field.type()).thenReturn(type);
when(visitor.visitBoolean(any())).thenReturn("Expected");
when(visitor.visitField(any(), any())).thenReturn(22);
// When:
final Integer result = SqlTypeWalker.visit(field, visitor);
// Then:
verify(visitor).visitBoolean(same(type));
verify(visitor).visitField(same(field), eq("Expected"));
assertThat(result, is(22));
}
use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType in project ksql by confluentinc.
the class SqlTypeWalkerTest method shouldVisitPrimitives.
@Test
public void shouldVisitPrimitives() {
// Given:
visitor = new Visitor<String, Integer>() {
@Override
public String visitPrimitive(final SqlPrimitiveType type) {
return "Expected";
}
};
primitiveTypes().forEach(type -> {
// When:
final String result = SqlTypeWalker.visit(type, visitor);
// Then:
assertThat(result, is("Expected"));
});
}
use of io.confluent.ksql.schema.ksql.types.SqlPrimitiveType 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