@Description("removes whitespace from the beginning and end of a string") @ScalarFunction @LiteralParameters("x") @SqlType("varchar(x)") public static Slice trim(@SqlType("varchar(x)") Slice slice) { return SliceUtf8.trim(slice); }
@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); }
@ScalarFunction("date") @ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.DATE) public static long castFromSlice(@SqlType("varchar(x)") Slice value) { try { return parseDate(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to date: " + value.toStringUtf8(), e); } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long castFromSlice(ConnectorSession session, @SqlType("varchar(x)") Slice value) { try { return parseTimestampWithTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp with time zone: " + value.toStringUtf8(), e); } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP) public static long castFromSlice(ConnectorSession session, @SqlType("varchar(x)") Slice value) { // This accepts value with or without time zone if (session.isLegacyTimestamp()) { try { return parseTimestampWithoutTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e); } } else { try { return parseTimestampWithoutTimeZone(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e); } } }
@Description("removes whitespace from the beginning and end of a string") @ScalarFunction @LiteralParameters("x") @SqlType("varchar(x)") public static Slice trim(@SqlType("varchar(x)") Slice slice) { return SliceUtf8.trim(slice); }
@Benchmark public Slice benchmarkTrim(WhitespaceData data) { return trim(data.getBothWhitespace()); }
@Description("removes whitespace from the beginning and end of a string") @ScalarFunction @LiteralParameters("x") @SqlType("varchar(x)") public static Slice trim(@SqlType("varchar(x)") Slice slice) { return SliceUtf8.trim(slice); }
@Benchmark public Slice benchmarkTrim(WhitespaceData data) { return trim(data.getBothWhitespace()); }
@Description("removes whitespace from the beginning and end of a string") @ScalarFunction @LiteralParameters("x") @SqlType("varchar(x)") public static Slice trim(@SqlType("varchar(x)") Slice slice) { return SliceUtf8.trim(slice); }
@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); }
@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); }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long castFromSlice(ConnectorSession session, @SqlType(StandardTypes.VARCHAR) Slice value) { try { return parseTimestampWithTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp with time zone: " + value.toStringUtf8(), e); } }
@ScalarOperator(CAST) @SqlType(StandardTypes.TIMESTAMP) public static long castFromSlice(ConnectorSession session, @SqlType(StandardTypes.VARCHAR) Slice value) { try { return parseTimestampWithoutTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e); } }
@ScalarFunction("date") @ScalarOperator(CAST) @SqlType(StandardTypes.DATE) public static long castFromSlice(@SqlType(StandardTypes.VARCHAR) Slice value) { try { return parseDate(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to date: " + value.toStringUtf8(), e); } }
@ScalarFunction("date") @ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.DATE) public static long castFromSlice(@SqlType("varchar(x)") Slice value) { try { return parseDate(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to date: " + value.toStringUtf8(), e); } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long castFromSlice(ConnectorSession session, @SqlType("varchar(x)") Slice value) { try { return parseTimestampWithTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp with time zone: " + value.toStringUtf8(), e); } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP) public static long castFromSlice(ConnectorSession session, @SqlType("varchar(x)") Slice value) { // This accepts value with or without time zone if (session.isLegacyTimestamp()) { try { return parseTimestampWithoutTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e); } } else { try { return parseTimestampWithoutTimeZone(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e); } } }
@ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long castFromSlice(ConnectorSession session, @SqlType("varchar(x)") Slice value) { try { return parseTimestampWithTimeZone(session.getTimeZoneKey(), trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp with time zone: " + value.toStringUtf8(), e); } }
@ScalarFunction("date") @ScalarOperator(CAST) @LiteralParameters("x") @SqlType(StandardTypes.DATE) public static long castFromSlice(@SqlType("varchar(x)") Slice value) { try { return parseDate(trim(value).toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to date: " + value.toStringUtf8(), e); } }