@ScalarOperator(MODULUS) @SqlType(StandardTypes.DOUBLE) public static double modulus(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right) { try { return left % right; } catch (ArithmeticException e) { throw new PrestoException(DIVISION_BY_ZERO, e); } }
@Description("encodes the string to UTF-8") @ScalarFunction @LiteralParameters("x") @SqlType(StandardTypes.VARBINARY) public static Slice toUtf8(@SqlType("varchar(x)") Slice slice) { return slice; }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToVarchar(@SqlType(StandardTypes.BOOLEAN) boolean value) { return value ? TRUE : FALSE; }
@LiteralParameters("x") @ScalarOperator(CAST) @SqlType(StandardTypes.DOUBLE) public static double castToDouble(@SqlType("varchar(x)") Slice slice) { try { return Double.parseDouble(slice.toStringUtf8()); } catch (Exception e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DOUBLE", slice.toStringUtf8())); } }
@TypeParameter("E") @SqlType(StandardTypes.BIGINT) public static long arrayCardinality(@SqlType("array(E)") Block block) { return block.getPositionCount(); } }
@TypeParameter("E") @SqlType("array(E)") public Block remove( @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"E", "E"}) MethodHandle equalsFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block array, @SqlType("E") double value) { return remove(equalsFunction, type, array, (Object) value); }
@ScalarFunction @SqlType(StandardTypes.BIGINT) @TypeParameter("bad") public static long bad(@TypeParameter("array(bad)") Type type, @SqlType(StandardTypes.BIGINT) long value) { return value; } }
@TypeParameter("E") @SqlNullable @SqlType("E") public static Object generic(@TypeParameter("E") Type type, @SqlNullable @SqlType("E") Object object) { return object; }
@ScalarOperator(DIVIDE) @SqlType(StandardTypes.SMALLINT) public static long divide(@SqlType(StandardTypes.SMALLINT) long left, @SqlType(StandardTypes.SMALLINT) long right) { try { return left / right; } catch (ArithmeticException e) { throw new PrestoException(DIVISION_BY_ZERO, e); } }
@LiteralParameters("x") @ScalarOperator(CAST) @SqlType(StandardTypes.SMALLINT) public static long castToSmallint(@SqlType("varchar(x)") Slice slice) { try { return Short.parseShort(slice.toStringUtf8()); } catch (Exception e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to SMALLINT", slice.toStringUtf8())); } }
@Description("remove the longest string containing only given characters from the beginning and end of a string") @ScalarFunction("trim") @LiteralParameters("x") @SqlType("varchar(x)") public static Slice trim(@SqlType("varchar(x)") Slice slice, @SqlType(CodePointsType.NAME) int[] codePointsToTrim) { return SliceUtf8.trim(slice, codePointsToTrim); }
@LiteralParameters("x") @ScalarOperator(LESS_THAN_OR_EQUAL) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThanOrEqual(@SqlType("varchar(x)") Slice left, @SqlType("varchar(x)") Slice right) { return left.compareTo(right) <= 0; }
@TypeParameter("K") @TypeParameter("V") @SqlType(StandardTypes.BIGINT) public static long mapCardinality(@SqlType("map(K,V)") Block block) { return block.getPositionCount() / 2; } }
@TypeParameter("E") @SqlType("array(E)") public Block remove( @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"E", "E"}) MethodHandle equalsFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block array, @SqlType("E") boolean value) { return remove(equalsFunction, type, array, (Object) value); }
@ScalarFunction @SqlType(StandardTypes.BIGINT) @TypeParameter("E12") @TypeParameter("F34") public static long good2( @TypeParameter("ROW(ARRAY(E12),JSON,TIME,VARBINARY,ROW(ROW(F34)))") Type type, @SqlType(StandardTypes.BIGINT) long value) { return value; } }
@InputFunction @TypeParameter("T") public static void input( @TypeParameter("T") Type type, @AggregationState NullableDoubleState state, @SqlType("T") double value) { // noop this is only for annotation testing puproses }
@ScalarOperator(DIVIDE) @SqlType(StandardTypes.INTEGER) public static long divide(@SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return left / right; } catch (ArithmeticException e) { throw new PrestoException(DIVISION_BY_ZERO, e); } }
@LiteralParameters("x") @ScalarOperator(CAST) @SqlType(StandardTypes.TINYINT) public static long castToTinyint(@SqlType("varchar(x)") Slice slice) { try { return Byte.parseByte(slice.toStringUtf8()); } catch (Exception e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to TINYINT", slice.toStringUtf8())); } }
@Description("string(s) extracted using the given pattern") @ScalarFunction @LiteralParameters("x") @SqlType("array(varchar(x))") public static Block regexpExtractAll(@SqlType("varchar(x)") Slice source, @SqlType(JoniRegexpType.NAME) Regex pattern) { return regexpExtractAll(source, pattern, 0); }
@LiteralParameters("x") @ScalarOperator(LESS_THAN) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThan(@SqlType("char(x)") Slice left, @SqlType("char(x)") Slice right) { return compareChars(left, right) < 0; }