Search in sources :

Example 1 with CastFunction

use of io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction 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);
}
Also used : CastTerm(io.confluent.ksql.execution.interpreter.terms.CastTerm) DecimalUtil(io.confluent.ksql.util.DecimalUtil) Time(java.sql.Time) Date(java.util.Date) SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ByteBuffer(java.nio.ByteBuffer) SqlDoubles(io.confluent.ksql.schema.ksql.SqlDoubles) SqlTimeTypes(io.confluent.ksql.schema.ksql.SqlTimeTypes) BigDecimal(java.math.BigDecimal) Term(io.confluent.ksql.execution.interpreter.terms.Term) Map(java.util.Map) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) CastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction) SqlBooleans(io.confluent.ksql.schema.ksql.SqlBooleans) Timestamp(java.sql.Timestamp) KsqlConfig(io.confluent.ksql.util.KsqlConfig) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray) Objects(java.util.Objects) CastEvaluator(io.confluent.ksql.execution.codegen.helpers.CastEvaluator) List(java.util.List) ComparableCastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.ComparableCastFunction) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) KsqlException(io.confluent.ksql.util.KsqlException) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) CastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction) ComparableCastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.ComparableCastFunction) KsqlException(io.confluent.ksql.util.KsqlException)

Example 2 with CastFunction

use of io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction in project ksql by confluentinc.

the class CastInterpreter method castToArrayFunction.

public static CastFunction castToArrayFunction(final SqlType from, final SqlType to, final KsqlConfig config) {
    if (from.baseType() == SqlBaseType.ARRAY && to.baseType() == SqlBaseType.ARRAY) {
        final SqlArray fromArray = (SqlArray) from;
        final SqlArray toArray = (SqlArray) to;
        final CastFunction itemCastFunction = castFunction(fromArray.getItemType(), toArray.getItemType(), config);
        return o -> CastEvaluator.castArray((List<?>) o, itemCastFunction::cast);
    }
    throw new KsqlException(getErrorMessage(from, to));
}
Also used : CastTerm(io.confluent.ksql.execution.interpreter.terms.CastTerm) DecimalUtil(io.confluent.ksql.util.DecimalUtil) Time(java.sql.Time) Date(java.util.Date) SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ByteBuffer(java.nio.ByteBuffer) SqlDoubles(io.confluent.ksql.schema.ksql.SqlDoubles) SqlTimeTypes(io.confluent.ksql.schema.ksql.SqlTimeTypes) BigDecimal(java.math.BigDecimal) Term(io.confluent.ksql.execution.interpreter.terms.Term) Map(java.util.Map) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) CastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction) SqlBooleans(io.confluent.ksql.schema.ksql.SqlBooleans) Timestamp(java.sql.Timestamp) KsqlConfig(io.confluent.ksql.util.KsqlConfig) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray) Objects(java.util.Objects) CastEvaluator(io.confluent.ksql.execution.codegen.helpers.CastEvaluator) List(java.util.List) ComparableCastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.ComparableCastFunction) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) KsqlException(io.confluent.ksql.util.KsqlException) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) CastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction) ComparableCastFunction(io.confluent.ksql.execution.interpreter.terms.CastTerm.ComparableCastFunction) KsqlException(io.confluent.ksql.util.KsqlException) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray)

Aggregations

CastEvaluator (io.confluent.ksql.execution.codegen.helpers.CastEvaluator)2 CastTerm (io.confluent.ksql.execution.interpreter.terms.CastTerm)2 CastFunction (io.confluent.ksql.execution.interpreter.terms.CastTerm.CastFunction)2 ComparableCastFunction (io.confluent.ksql.execution.interpreter.terms.CastTerm.ComparableCastFunction)2 Term (io.confluent.ksql.execution.interpreter.terms.Term)2 SqlBooleans (io.confluent.ksql.schema.ksql.SqlBooleans)2 SqlDoubles (io.confluent.ksql.schema.ksql.SqlDoubles)2 SqlTimeTypes (io.confluent.ksql.schema.ksql.SqlTimeTypes)2 SqlArray (io.confluent.ksql.schema.ksql.types.SqlArray)2 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)2 SqlDecimal (io.confluent.ksql.schema.ksql.types.SqlDecimal)2 SqlMap (io.confluent.ksql.schema.ksql.types.SqlMap)2 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)2 SqlTypes (io.confluent.ksql.schema.ksql.types.SqlTypes)2 DecimalUtil (io.confluent.ksql.util.DecimalUtil)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlException (io.confluent.ksql.util.KsqlException)2 BigDecimal (java.math.BigDecimal)2 ByteBuffer (java.nio.ByteBuffer)2 Time (java.sql.Time)2