public CastFunction(AbstractType<I> inputType, AbstractType<O> outputType) { super(getFunctionName(outputType), outputType, inputType); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(CQL3Type outputType) { return FUNCTION_NAME_PREFIX + WordUtils.capitalize(toLowerCaseString(outputType)); }
/** * Adds to the list a function converting the input type in to the output type if they are not the same. * * @param functions the list to add to * @param inputType the input type * @param outputType the output type * @param converter the function use to convert the input type into the output type */ private static <I, O> void addFunctionIfNeeded(List<Function> functions, AbstractType<I> inputType, AbstractType<O> outputType, java.util.function.Function<I, O> converter) { if (!inputType.equals(outputType)) functions.add(wrapJavaFunction(inputType, outputType, converter)); }
addFunctionIfNeeded(functions, inputType, ByteType.instance, Number::byteValue); addFunctionIfNeeded(functions, inputType, ShortType.instance, Number::shortValue); addFunctionIfNeeded(functions, inputType, Int32Type.instance, Number::intValue); addFunctionIfNeeded(functions, inputType, LongType.instance, Number::longValue); addFunctionIfNeeded(functions, inputType, FloatType.instance, Number::floatValue); addFunctionIfNeeded(functions, inputType, DoubleType.instance, Number::doubleValue); addFunctionIfNeeded(functions, inputType, DecimalType.instance, getDecimalConversionFunction(inputType)); addFunctionIfNeeded(functions, inputType, IntegerType.instance, p -> BigInteger.valueOf(p.longValue())); functions.add(CastAsTextFunction.create(inputType, AsciiType.instance)); functions.add(CastAsTextFunction.create(inputType, UTF8Type.instance));
private static Functions functions() { return Functions.builder() .add(UuidFcts.all()) .add(TimeFcts.all()) .add(BytesConversionFcts.all()) .add(AggregateFcts.all()) .add(CastFcts.all()) .build(); }
addFunctionIfNeeded(functions, inputType, ByteType.instance, Number::byteValue); addFunctionIfNeeded(functions, inputType, ShortType.instance, Number::shortValue); addFunctionIfNeeded(functions, inputType, Int32Type.instance, Number::intValue); addFunctionIfNeeded(functions, inputType, LongType.instance, Number::longValue); addFunctionIfNeeded(functions, inputType, FloatType.instance, Number::floatValue); addFunctionIfNeeded(functions, inputType, DoubleType.instance, Number::doubleValue); addFunctionIfNeeded(functions, inputType, DecimalType.instance, p -> BigDecimal.valueOf(p.doubleValue())); addFunctionIfNeeded(functions, inputType, IntegerType.instance, p -> BigInteger.valueOf(p.longValue())); functions.add(CastAsTextFunction.create(inputType, AsciiType.instance)); functions.add(CastAsTextFunction.create(inputType, UTF8Type.instance));
addFunctionIfNeeded(functions, inputType, ByteType.instance, Number::byteValue); addFunctionIfNeeded(functions, inputType, ShortType.instance, Number::shortValue); addFunctionIfNeeded(functions, inputType, Int32Type.instance, Number::intValue); addFunctionIfNeeded(functions, inputType, LongType.instance, Number::longValue); addFunctionIfNeeded(functions, inputType, FloatType.instance, Number::floatValue); addFunctionIfNeeded(functions, inputType, DoubleType.instance, Number::doubleValue); addFunctionIfNeeded(functions, inputType, DecimalType.instance, getDecimalConversionFunction(inputType)); addFunctionIfNeeded(functions, inputType, IntegerType.instance, p -> BigInteger.valueOf(p.longValue())); functions.add(CastAsTextFunction.create(inputType, AsciiType.instance)); functions.add(CastAsTextFunction.create(inputType, UTF8Type.instance));
private static Functions functions() { return Functions.builder() .add(UuidFcts.all()) .add(TimeFcts.all()) .add(BytesConversionFcts.all()) .add(AggregateFcts.all()) .add(CastFcts.all()) .build(); }
public CastFunction(AbstractType<I> inputType, AbstractType<O> outputType) { super(getFunctionName(outputType), outputType, inputType); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(CQL3Type outputType) { return FUNCTION_NAME_PREFIX + WordUtils.capitalize(toLowerCaseString(outputType)); }
private static Functions functions() { return Functions.builder() .add(UuidFcts.all()) .add(TimeFcts.all()) .add(BytesConversionFcts.all()) .add(AggregateFcts.all()) .add(CastFcts.all()) .build(); }
/** * Adds to the list a function converting the input type in to the output type if they are not the same. * * @param functions the list to add to * @param inputType the input type * @param outputType the output type * @param converter the function use to convert the input type into the output type */ private static <I, O> void addFunctionIfNeeded(List<Function> functions, AbstractType<I> inputType, AbstractType<O> outputType, java.util.function.Function<I, O> converter) { if (!inputType.equals(outputType)) functions.add(wrapJavaFunction(inputType, outputType, converter)); }
public CastFunction(AbstractType<I> inputType, AbstractType<O> outputType) { super(getFunctionName(outputType), outputType, inputType); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(CQL3Type outputType) { return FUNCTION_NAME_PREFIX + WordUtils.capitalize(toLowerCaseString(outputType)); }
/** * Adds to the list a function converting the input type in to the output type if they are not the same. * * @param functions the list to add to * @param inputType the input type * @param outputType the output type * @param converter the function use to convert the input type into the output type */ private static <I, O> void addFunctionIfNeeded(List<Function> functions, AbstractType<I> inputType, AbstractType<O> outputType, java.util.function.Function<I, O> converter) { if (!inputType.equals(outputType)) functions.add(wrapJavaFunction(inputType, outputType, converter)); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(AbstractType<?> outputType) { return getFunctionName(outputType.asCQL3Type()); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(AbstractType<?> outputType) { return getFunctionName(outputType.asCQL3Type()); }
/** * Creates the name of the cast function use to cast to the specified type. * * @param outputType the output type * @return the name of the cast function use to cast to the specified type */ public static String getFunctionName(AbstractType<?> outputType) { return getFunctionName(outputType.asCQL3Type()); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { List<Selectable> args = Collections.singletonList(arg); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, null, cfm, defs, boundNames); Selector.Factory factory = factories.get(0); // If the user is trying to cast a type on its own type we simply ignore it. if (type.getType().equals(factory.getReturnType())) return factory; FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type)); Function fun = FunctionResolver.get(cfm.ksName, name, args, cfm.ksName, cfm.cfName, null); if (fun == null) { throw new InvalidRequestException(String.format("%s cannot be cast to %s", defs.get(0).name, type)); } return AbstractFunctionSelector.newFactory(fun, factories); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { List<Selectable> args = Collections.singletonList(arg); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, null, cfm, defs, boundNames); Selector.Factory factory = factories.get(0); // If the user is trying to cast a type on its own type we simply ignore it. if (type.getType().equals(factory.getReturnType())) return factory; FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type)); Function fun = FunctionResolver.get(cfm.ksName, name, args, cfm.ksName, cfm.cfName, null); if (fun == null) { throw new InvalidRequestException(String.format("%s cannot be cast to %s", defs.get(0).name, type)); } return AbstractFunctionSelector.newFactory(fun, factories); }