Search in sources :

Example 1 with UdfSchemaProvider

use of io.confluent.ksql.function.udf.UdfSchemaProvider 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;
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) KsqlException(io.confluent.ksql.util.KsqlException) UdfSchemaProvider(io.confluent.ksql.function.udf.UdfSchemaProvider)

Example 2 with UdfSchemaProvider

use of io.confluent.ksql.function.udf.UdfSchemaProvider in project ksql by confluentinc.

the class Round method provideDecimalSchema.

// Invoked via reflection
@SuppressWarnings("unused")
@UdfSchemaProvider
public static SqlType provideDecimalSchema(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 a parameter.");
    }
    final SqlDecimal param = (SqlDecimal) s0;
    return SqlDecimal.of(param.getPrecision() - param.getScale(), 0);
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) KsqlException(io.confluent.ksql.util.KsqlException) UdfSchemaProvider(io.confluent.ksql.function.udf.UdfSchemaProvider)

Aggregations

UdfSchemaProvider (io.confluent.ksql.function.udf.UdfSchemaProvider)2 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)2 KsqlException (io.confluent.ksql.util.KsqlException)2 SqlDecimal (io.confluent.ksql.schema.ksql.types.SqlDecimal)1