use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class GenericRecordFactory method resolveValues.
private static Map<ColumnName, Object> resolveValues(final List<ColumnName> columns, final List<Expression> expressions, final LogicalSchema schema, final FunctionRegistry functionRegistry, final KsqlConfig config) {
final Map<ColumnName, Object> values = new HashMap<>();
for (int i = 0; i < columns.size(); i++) {
final ColumnName column = columns.get(i);
final SqlType columnType = columnType(column, schema);
final Expression valueExp = expressions.get(i);
final Object value = new GenericExpressionResolver(columnType, column, functionRegistry, config, "insert value", false).resolve(valueExp);
values.put(column, value);
}
return values;
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class FunctionLoaderUtils method handleUdfSchemaProviderAnnotation.
private static Function<List<SqlArgument>, SqlType> handleUdfSchemaProviderAnnotation(final String schemaProviderName, final Class theClass, final String functionName) {
// throws exception if it cannot find the method
final Method m = findSchemaProvider(theClass, schemaProviderName);
final Object instance = FunctionLoaderUtils.instantiateFunctionInstance(theClass, functionName);
return parameterSchemas -> invokeSchemaProviderMethod(instance, m, parameterSchemas, functionName);
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldThrowIfCannotCoerce.
@Test
public void shouldThrowIfCannotCoerce() {
// Given:
final SqlType type = SqlTypes.array(SqlTypes.INTEGER);
final Expression exp = new IntegerLiteral(1);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp));
// Then:
assertThat(e.getMessage(), containsString("Expected type ARRAY<INTEGER> for field `FOO` but got INTEGER(1)"));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldParseDate.
@Test
public void shouldParseDate() {
// Given:
final SqlType type = SqlTypes.DATE;
final Expression exp = new StringLiteral("2021-01-09");
// When:
Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
// Then:
assertTrue(o instanceof Date);
assertThat(((Date) o).getTime(), is(1610150400000L));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldParseTimestamp.
@Test
public void shouldParseTimestamp() {
// Given:
final SqlType type = SqlTypes.TIMESTAMP;
final Expression exp = new StringLiteral("2021-01-09T04:40:02");
// When:
Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
// Then:
assertTrue(o instanceof Timestamp);
assertThat(((Timestamp) o).getTime(), is(1610167202000L));
}
Aggregations