@Description("Returns index of first occurrence of a substring (or 0 if not found)") @ScalarFunction("index") @SqlType(StandardTypes.BIGINT) public static long index( @FunctionDependency( name = "strpos", returnType = StandardTypes.BIGINT, argumentTypes = {StandardTypes.VARCHAR, StandardTypes.VARCHAR}) MethodHandle method, @SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice substring) { try { return (long) method.invokeExact(string, substring); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@SqlType(StandardTypes.INTEGER) public static long testRegularConvention( @FunctionDependency(name = "add", returnType = StandardTypes.INTEGER, argumentTypes = {StandardTypes.INTEGER, StandardTypes.INTEGER}, convention = @Convention(arguments = {NEVER_NULL, NEVER_NULL}, result = FAIL_ON_NULL)) MethodHandle function, @SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return (long) function.invokeExact(left, right); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }
@SqlType(StandardTypes.INTEGER) public static long testRegularConvention( @FunctionDependency(name = "add", returnType = StandardTypes.INTEGER, argumentTypes = {StandardTypes.INTEGER, StandardTypes.INTEGER}, convention = @Convention(arguments = {NEVER_NULL, NEVER_NULL}, result = FAIL_ON_NULL)) MethodHandle function, @SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return (long) function.invokeExact(left, right); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }
@SqlType(StandardTypes.INTEGER) public static long testBlockPositionConvention( @FunctionDependency( name = "add", returnType = StandardTypes.INTEGER, argumentTypes = {StandardTypes.INTEGER, StandardTypes.INTEGER}, convention = @Convention(arguments = {NEVER_NULL, BLOCK_POSITION}, result = FAIL_ON_NULL)) MethodHandle function, @SqlType("array(int)") Block array) { long sum = 0; for (int i = 0; i < array.getPositionCount(); i++) { try { sum = (long) function.invokeExact(sum, array, i); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } return sum; } }
@SqlType(StandardTypes.INTEGER) public static long testBlockPositionConvention( @FunctionDependency( name = "add", returnType = StandardTypes.INTEGER, argumentTypes = {StandardTypes.INTEGER, StandardTypes.INTEGER}, convention = @Convention(arguments = {NEVER_NULL, BLOCK_POSITION}, result = FAIL_ON_NULL)) MethodHandle function, @SqlType("array(int)") Block array) { long sum = 0; for (int i = 0; i < array.getPositionCount(); i++) { try { sum = (long) function.invokeExact(sum, array, i); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } return sum; } }