@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToVarchar(@SqlType(StandardTypes.SMALLINT) long value) { // todo optimize me return utf8Slice(String.valueOf(value)); }
@LiteralParameters({"p", "s"}) @SqlType(StandardTypes.BIGINT) public static long hashCode(@SqlType("decimal(p, s)") Slice value) { return UnscaledDecimal128Arithmetic.hash(value); } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToVarchar(@SqlType(StandardTypes.TINYINT) long value) { // todo optimize me return utf8Slice(String.valueOf(value)); }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToVarchar(@SqlType(StandardTypes.BIGINT) long value) { // todo optimize me return utf8Slice(String.valueOf(value)); }
@LiteralParameters("x") @ScalarOperator(CAST) @SqlType(StandardTypes.INTEGER) public static long castToInteger(@SqlType("varchar(x)") Slice slice) { try { return Integer.parseInt(slice.toStringUtf8()); } catch (Exception e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to INT", slice.toStringUtf8())); } }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(LikePatternType.NAME) public static Regex castVarcharToLikePattern(@SqlType("varchar(x)") Slice pattern) { return likePattern(pattern); }
@LiteralParameters("x") @ScalarOperator(XX_HASH_64) @SqlType(StandardTypes.BIGINT) public static long xxHash64(@SqlType("char(x)") Slice slice) { return XxHash64.hash(slice); }
@LiteralParameters("x") @ScalarOperator(OperatorType.CAST) @SqlType(JoniRegexpType.NAME) public static Regex castVarcharToJoniRegexp(@SqlType("varchar(x)") Slice pattern) { return joniRegexp(pattern); }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(LikePatternType.NAME) public static Regex castCharToLikePattern(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice pattern) { return likePattern(padSpaces(pattern, charLength.intValue())); }
@Description("difference of the given dates in the given unit") @ScalarFunction("date_diff") @LiteralParameters("x") @SqlType(StandardTypes.BIGINT) public static long diffDate(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.DATE) long date1, @SqlType(StandardTypes.DATE) long date2) { return getDateField(UTC_CHRONOLOGY, unit).getDifferenceAsLong(DAYS.toMillis(date2), DAYS.toMillis(date1)); }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType("varchar(x)") public static Slice castToSlice(@SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long value) { return utf8Slice(printTimeWithTimeZone(value)); }
@Description("removes substrings matching a regular expression") @ScalarFunction @LiteralParameters("x") @SqlType("varchar(x)") public static Slice regexpReplace(@SqlType("varchar(x)") Slice source, @SqlType(Re2JRegexpType.NAME) Re2JRegexp pattern) { return regexpReplace(source, pattern, Slices.EMPTY_SLICE); }
@SqlNullable @ScalarFunction("json_array_contains") @LiteralParameters("x") @SqlType(StandardTypes.BOOLEAN) public static Boolean varcharJsonArrayContains(@SqlType("varchar(x)") Slice json, @SqlType(StandardTypes.BIGINT) long value) { return jsonArrayContains(json, value); }
@SqlNullable @ScalarFunction("json_array_contains") @LiteralParameters("x") @SqlType(StandardTypes.BOOLEAN) public static Boolean varcharJsonArrayContains(@SqlType("varchar(x)") Slice json, @SqlType(StandardTypes.DOUBLE) double value) { return jsonArrayContains(json, value); }
@LiteralParameters({"p", "s", "rp", "rs"}) @SqlType("decimal(rp, rs)") @Constraint(variable = "rp", expression = "min(38, p - s + min(1, s))") @Constraint(variable = "rs", expression = "0") public static long roundLongShort(@LiteralParameter("s") long numScale, @SqlType("decimal(p, s)") Slice num) { return unscaledDecimalToUnscaledLong(rescale(num, -(int) numScale)); } }
@Description("add the specified amount of time to the given timestamp") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long addFieldValueTimestampWithTimeZone( @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).add(unpackMillisUtc(timestampWithTimeZone), toIntExact(value)); return updateMillisUtc(millis, timestampWithTimeZone); }
@Description("add the specified amount of time to the given time") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIME) public static long addFieldValueTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME) long time) { if (session.isLegacyTimestamp()) { ISOChronology chronology = getChronology(session.getTimeZoneKey()); return modulo24Hour(chronology, getTimeField(chronology, unit).add(time, toIntExact(value))); } return modulo24Hour(getTimeField(UTC_CHRONOLOGY, unit).add(time, toIntExact(value))); }
@LiteralParameters({"p", "s", "rp"}) @SqlType("decimal(rp, s)") @Constraint(variable = "rp", expression = "min(38, p + 1)") public static Slice roundNShortLong( @LiteralParameter("s") long numScale, @LiteralParameter("rp") long resultPrecision, @SqlType("decimal(p, s)") long num, @SqlType(StandardTypes.INTEGER) long decimals) { return roundNLong(numScale, resultPrecision, unscaledDecimal(num), decimals); } }
@ScalarFunction("from_iso8601_timestamp") @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long fromISO8601Timestamp(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser() .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed(); return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8())); }
@Description("difference of the given times in the given unit") @ScalarFunction("date_diff") @LiteralParameters("x") @SqlType(StandardTypes.BIGINT) public static long diffTimeWithTimeZone( @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone1, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone2) { return getTimeField(unpackChronology(timeWithTimeZone1), unit).getDifferenceAsLong(unpackMillisUtc(timeWithTimeZone2), unpackMillisUtc(timeWithTimeZone1)); }