@Description("absolute value") @ScalarFunction("abs") @SqlType(StandardTypes.REAL) public static long absFloat(@SqlType(StandardTypes.REAL) long num) { return floatToRawIntBits(Math.abs(intBitsToFloat((int) num))); }
private static String getDescription(AnnotatedElement annotatedElement) { Description description = annotatedElement.getAnnotation(Description.class); return (description == null) ? null : description.value(); } }
@Description("round to integer by dropping digits after decimal point") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double truncate(@SqlType(StandardTypes.DOUBLE) double num) { return Math.signum(num) * Math.floor(Math.abs(num)); }
@Description("constant representing not-a-number") @ScalarFunction("nan") @SqlType(StandardTypes.DOUBLE) public static double NaN() { return Double.NaN; }
@Description("remainder of given quotient") @ScalarFunction("mod") @SqlType(StandardTypes.REAL) public static long modFloat(@SqlType(StandardTypes.REAL) long num1, @SqlType(StandardTypes.REAL) long num2) { return floatToRawIntBits(intBitsToFloat((int) num1) % intBitsToFloat((int) num2)); }
@Description("absolute value") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double abs(@SqlType(StandardTypes.DOUBLE) double num) { return Math.abs(num); }
@Description("arc cosine") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double acos(@SqlType(StandardTypes.DOUBLE) double num) { return Math.acos(num); }
@Description("Euler's number raised to the given power") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double exp(@SqlType(StandardTypes.DOUBLE) double num) { return Math.exp(num); }
@Description("signum") @ScalarFunction("sign") @SqlType(StandardTypes.INTEGER) public static long signInteger(@SqlType(StandardTypes.INTEGER) long num) { return (long) Math.signum(num); }
@Description("converts an angle in radians to degrees") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double degrees(@SqlType(StandardTypes.DOUBLE) double radians) { return Math.toDegrees(radians); }
@Description("a pseudo-random value") @ScalarFunction(alias = "rand", deterministic = false) @SqlType(StandardTypes.DOUBLE) public static double random() { return ThreadLocalRandom.current().nextDouble(); }
@Description("signum") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double sign(@SqlType(StandardTypes.DOUBLE) double num) { return Math.signum(num); }
@Description("a pseudo-random number between 0 and value (exclusive)") @ScalarFunction(value = "random", alias = "rand", deterministic = false) @SqlType(StandardTypes.TINYINT) public static long randomTinyint(@SqlType(StandardTypes.TINYINT) long value) { checkCondition(value > 0, INVALID_FUNCTION_ARGUMENT, "bound must be positive"); return ThreadLocalRandom.current().nextInt((int) value); }
@Description("a pseudo-random number between 0 and value (exclusive)") @ScalarFunction(alias = "rand", deterministic = false) @SqlType(StandardTypes.BIGINT) public static long random(@SqlType(StandardTypes.BIGINT) long value) { checkCondition(value > 0, INVALID_FUNCTION_ARGUMENT, "bound must be positive"); return ThreadLocalRandom.current().nextLong(value); }
@ScalarFunction("scalar_with_nullable_complex") @Description("Simple scalar with nullable complex type") public static class WithNullableComplexArgScalarFunction { @SqlType(StandardTypes.DOUBLE) public static double fun( @SqlType(StandardTypes.DOUBLE) double v, @SqlNullable @SqlType(StandardTypes.DOUBLE) Double v2) { return v; } }
@ScalarFunction("fixed_type_parameter_scalar_function") @Description("Parametric scalar that uses TypeParameter with fixed type") public static final class FixedTypeParameterScalarFunction { @SqlType(StandardTypes.BIGINT) public static long fun( @TypeParameter("ROW(ARRAY(BIGINT),ROW(ROW(CHAR)),BIGINT,MAP(BIGINT,CHAR))") Type type, @SqlType(StandardTypes.BIGINT) long value) { return value; } }
@Description("encode binary data as hex") @ScalarFunction @SqlType(StandardTypes.VARCHAR) public static Slice toHex(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.utf8Slice(BaseEncoding.base16().encode(slice.getBytes())); }
@Description("encode value as a big endian varbinary according to IEEE 754 double-precision floating-point format") @ScalarFunction("to_ieee754_64") @SqlType(StandardTypes.VARBINARY) public static Slice toIEEE754Binary64(@SqlType(StandardTypes.DOUBLE) double value) { Slice slice = Slices.allocate(Double.BYTES); slice.setLong(0, Long.reverseBytes(Double.doubleToLongBits(value))); return slice; }
@Description("round up to nearest integer") @ScalarFunction(alias = "ceil") @SqlType(StandardTypes.BIGINT) public static long ceiling(@SqlType(StandardTypes.BIGINT) long num) { return num; }
@Description("round down to nearest integer") @ScalarFunction("floor") @SqlType(StandardTypes.INTEGER) public static long floorInteger(@SqlType(StandardTypes.INTEGER) long num) { return num; }