public static Slice padSpaces(Slice slice, Type type) { requireNonNull(type, "type is null"); if (!isCharType(type)) { throw new IllegalArgumentException("type must be the instance of CharType"); } return padSpaces(slice, CharType.class.cast(type)); }
public static Slice padSpaces(Slice slice, CharType charType) { requireNonNull(charType, "charType is null"); return padSpaces(slice, charType.getLength()); }
@ScalarOperator(OperatorType.CAST) @SqlType("varchar(y)") @LiteralParameters({"x", "y"}) public static Slice charToVarcharCast(@LiteralParameter("x") Long x, @LiteralParameter("y") Long y, @SqlType("char(x)") Slice slice) { if (x.intValue() <= y.intValue()) { return padSpaces(slice, x.intValue()); } return padSpaces(truncateToLength(slice, y.intValue()), y.intValue()); }
@ScalarOperator(OperatorType.CAST) @SqlType("varchar(y)") @LiteralParameters({"x", "y"}) public static Slice charToVarcharCast(@LiteralParameter("x") Long x, @LiteralParameter("y") Long y, @SqlType("char(x)") Slice slice) { if (x.intValue() <= y.intValue()) { return padSpaces(slice, x.intValue()); } return padSpaces(truncateToLength(slice, y.intValue()), y.intValue()); }
public static Re2JRegexp castToRegexp(int dfaStatesLimit, int dfaRetries, boolean padSpaces, long typeLength, Slice pattern) { try { if (padSpaces) { pattern = padSpaces(pattern, (int) typeLength); } return new Re2JRegexp(dfaStatesLimit, dfaRetries, pattern); } catch (Exception e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } } }
public static Re2JRegexp castToRegexp(int dfaStatesLimit, int dfaRetries, boolean padSpaces, long typeLength, Slice pattern) { try { if (padSpaces) { pattern = padSpaces(pattern, (int) typeLength); } return new Re2JRegexp(dfaStatesLimit, dfaRetries, pattern); } catch (Exception e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } } }
@ScalarOperator(OperatorType.CAST) @SqlType(CodePointsType.NAME) @LiteralParameters("x") public static int[] castCharToCodePoints(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice slice) { return castToCodePoints(padSpaces(slice, charLength.intValue())); }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(JoniRegexpType.NAME) public static Regex castCharToJoniRegexp(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice pattern) { return joniRegexp(padSpaces(pattern, charLength.intValue())); }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(JoniRegexpType.NAME) public static Regex castCharToJoniRegexp(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice pattern) { return joniRegexp(padSpaces(pattern, charLength.intValue())); }
@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())); }
@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())); }
@ScalarOperator(OperatorType.CAST) @SqlType(CodePointsType.NAME) @LiteralParameters("x") public static int[] castCharToCodePoints(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice slice) { return castToCodePoints(padSpaces(slice, charLength.intValue())); }
@ScalarFunction(value = "like", hidden = true) @LiteralParameters("x") @SqlType(StandardTypes.BOOLEAN) public static boolean likeChar(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice value, @SqlType(LikePatternType.NAME) Regex pattern) { return likeVarchar(padSpaces(value, x.intValue()), pattern); }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(JsonPathType.NAME) public static JsonPath castCharToJsonPath(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice pattern) { return new JsonPath(padSpaces(pattern, charLength.intValue()).toStringUtf8()); }
@ScalarOperator(OperatorType.CAST) @LiteralParameters("x") @SqlType(JsonPathType.NAME) public static JsonPath castCharToJsonPath(@LiteralParameter("x") Long charLength, @SqlType("char(x)") Slice pattern) { return new JsonPath(padSpaces(pattern, charLength.intValue()).toStringUtf8()); }
@ScalarFunction(value = "like", hidden = true) @LiteralParameters("x") @SqlType(StandardTypes.BOOLEAN) public static boolean likeChar(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice value, @SqlType(LikePatternType.NAME) Regex pattern) { return likeVarchar(padSpaces(value, x.intValue()), pattern); }
filter.add(padSpaces(slice, type).toStringUtf8());
@Description("concatenates given character strings") @ScalarFunction @LiteralParameters({"x", "y", "u"}) @Constraint(variable = "u", expression = "x + y") @SqlType("char(u)") public static Slice concat(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice left, @SqlType("char(y)") Slice right) { int rightLength = right.length(); if (rightLength == 0) { return left; } Slice paddedLeft = padSpaces(left, x.intValue()); int leftLength = paddedLeft.length(); Slice result = Slices.allocate(leftLength + rightLength); result.setBytes(0, paddedLeft); result.setBytes(leftLength, right); return result; } }
@Description("concatenates given character strings") @ScalarFunction @LiteralParameters({"x", "y", "u"}) @Constraint(variable = "u", expression = "x + y") @SqlType("char(u)") public static Slice concat(@LiteralParameter("x") Long x, @SqlType("char(x)") Slice left, @SqlType("char(y)") Slice right) { int rightLength = right.length(); if (rightLength == 0) { return left; } Slice paddedLeft = padSpaces(left, x.intValue()); int leftLength = paddedLeft.length(); Slice result = Slices.allocate(leftLength + rightLength); result.setBytes(0, paddedLeft); result.setBytes(leftLength, right); return result; } }