use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class Round method provideDecimalSchemaWithDecimalPlaces.
// Invoked via reflection
@SuppressWarnings("unused")
@UdfSchemaProvider
public static SqlType provideDecimalSchemaWithDecimalPlaces(final List<SqlArgument> params) {
final SqlType s0 = params.get(0).getSqlTypeOrThrow();
if (s0.baseType() != SqlBaseType.DECIMAL) {
throw new KsqlException("The schema provider method for round expects a BigDecimal parameter" + "type as first parameter.");
}
final SqlType s1 = params.get(1).getSqlTypeOrThrow();
if (s1.baseType() != SqlBaseType.INTEGER) {
throw new KsqlException("The schema provider method for round expects an Integer parameter" + "type as second parameter.");
}
// the scale of the return type. See https://github.com/confluentinc/ksql/issues/6235.
return s0;
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class MinAggFunctionFactory method createAggregateFunction.
@Override
public KsqlAggregateFunction createAggregateFunction(final List<SqlArgument> argTypeList, final AggregateFunctionInitArguments initArgs) {
KsqlPreconditions.checkArgument(argTypeList.size() == 1, "expected exactly one argument to aggregate MAX function");
final SqlType argSchema = argTypeList.get(0).getSqlTypeOrThrow();
switch(argSchema.baseType()) {
case INTEGER:
return new IntegerMinKudaf(FUNCTION_NAME, initArgs.udafIndex());
case BIGINT:
return new LongMinKudaf(FUNCTION_NAME, initArgs.udafIndex());
case DOUBLE:
return new DoubleMinKudaf(FUNCTION_NAME, initArgs.udafIndex());
case DECIMAL:
return new DecimalMinKudaf(FUNCTION_NAME, initArgs.udafIndex(), argSchema);
default:
throw new KsqlException("No Max aggregate function with " + argTypeList.get(0) + " " + " argument type exists!");
}
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class TopKAggregateFunctionFactory method createAggregateFunction.
@Override
public KsqlAggregateFunction createAggregateFunction(final List<SqlArgument> argumentType, final AggregateFunctionInitArguments initArgs) {
if (argumentType.isEmpty()) {
throw new KsqlException("TOPK function should have two arguments.");
}
final int tkValFromArg = (Integer) (initArgs.arg(0));
final SqlType argSchema = argumentType.get(0).getSqlTypeOrThrow();
switch(argSchema.baseType()) {
case INTEGER:
return new TopkKudaf<>(NAME, initArgs.udafIndex(), tkValFromArg, SqlTypes.array(SqlTypes.INTEGER), Collections.singletonList(ParamTypes.INTEGER), Integer.class);
case BIGINT:
return new TopkKudaf<>(NAME, initArgs.udafIndex(), tkValFromArg, SqlTypes.array(SqlTypes.BIGINT), Collections.singletonList(ParamTypes.LONG), Long.class);
case DOUBLE:
return new TopkKudaf<>(NAME, initArgs.udafIndex(), tkValFromArg, SqlTypes.array(SqlTypes.DOUBLE), Collections.singletonList(ParamTypes.DOUBLE), Double.class);
case STRING:
return new TopkKudaf<>(NAME, initArgs.udafIndex(), tkValFromArg, SqlTypes.array(SqlTypes.STRING), Collections.singletonList(ParamTypes.STRING), String.class);
default:
throw new KsqlException("No TOPK aggregate function with " + argumentType.get(0) + " argument type exists!");
}
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ExpressionEvaluatorParityTest method init.
@Before
public void init() {
metaStore = MetaStoreFixture.getNewMetaStore(TestFunctionRegistry.INSTANCE.get());
ksqlConfig = new KsqlConfig(Collections.emptyMap());
SqlType itemInfoType = metaStore.getSource(SourceName.of("ORDERS")).getSchema().findColumn(ColumnName.of("ITEMINFO")).get().type();
final Schema itemInfoTypeSchema = SchemaConverters.sqlToConnectConverter().toConnectSchema(itemInfoType);
final Schema categorySchema = itemInfoTypeSchema.field("CATEGORY").schema();
Struct itemInfo = new Struct(itemInfoTypeSchema).put("ITEMID", ITEM_ITEM_ID).put("NAME", ITEM_NAME).put("CATEGORY", new Struct(categorySchema).put("ID", CATEGORY_ID).put("NAME", CATEGORY_NAME));
final List<Double> doubleArray = ImmutableList.of(3.5d, 5.25d);
final Map<String, Double> map = ImmutableMap.of("abc", 6.75d, "def", 9.5d);
// Note key isn't included first since it's assumed that it's provided as a value
ordersRow = GenericRow.genericRow(ORDER_ID, ITEM_ID, itemInfo, ORDER_UNITS, doubleArray, map, null, TIMESTAMP, TIME, DATE, BYTES, ROW_TIME, ROWPARTITION, ROWOFFSET, ORDER_TIME);
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class CastInterpreter method castToMapFunction.
public static CastFunction castToMapFunction(final SqlType from, final SqlType to, final KsqlConfig config) {
if (from.baseType() == SqlBaseType.MAP && to.baseType() == SqlBaseType.MAP) {
final SqlMap fromMap = (SqlMap) from;
final SqlMap toMap = (SqlMap) to;
final CastFunction keyCastFunction = castFunction(fromMap.getKeyType(), toMap.getKeyType(), config);
final CastFunction valueCastFunction = castFunction(fromMap.getValueType(), toMap.getValueType(), config);
return o -> CastEvaluator.castMap((Map<?, ?>) o, keyCastFunction::cast, valueCastFunction::cast);
}
throw new KsqlException("Unsupported cast to " + to + ": " + from);
}
Aggregations