Skip to content

Commit

Permalink
Add Postgres compliant name aliasing for String Functions. (#12795)
Browse files Browse the repository at this point in the history
Certain String function names are not Postgres compliant, added aliasing
to fix that.
- left
- right
- split_part
- string_to_array
  • Loading branch information
mayankshriv authored Apr 5, 2024
1 parent 3174e91 commit de3d803
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public enum TransformFunctionType {
// string functions
SPLIT("split", ReturnTypes.TO_ARRAY, OperandTypes.family(
ImmutableList.of(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER, SqlTypeFamily.INTEGER),
ordinal -> ordinal > 1), "split"),
ordinal -> ordinal > 1), "split", "string_to_array"),

// array functions
// The only column accepted by "cardinality" function is multi-value array, thus putting "cardinality" as alias.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static String rtrim(String input) {
* @param input
* @return get substring starting from the first index and extending upto specified length.
*/
@ScalarFunction
@ScalarFunction(names = {"leftSubStr", "left"})
public static String leftSubStr(String input, int length) {
return StringUtils.left(input, length);
}
Expand All @@ -253,7 +253,7 @@ public static String leftSubStr(String input, int length) {
* @param input
* @return get substring ending at the last index with specified length
*/
@ScalarFunction
@ScalarFunction(names = {"rightSubStr", "right"})
public static String rightSubStr(String input, int length) {
return StringUtils.right(input, length);
}
Expand Down Expand Up @@ -565,7 +565,7 @@ public static String normalize(String input, String form) {
* @param delimiter
* @return splits string on specified delimiter and returns an array.
*/
@ScalarFunction
@ScalarFunction(names = {"split", "string_to_array"})
public static String[] split(String input, String delimiter) {
return StringUtils.splitByWholeSeparator(input, delimiter);
}
Expand All @@ -576,7 +576,7 @@ public static String[] split(String input, String delimiter) {
* @param limit
* @return splits string on specified delimiter limiting the number of results till the specified limit
*/
@ScalarFunction
@ScalarFunction(names = {"split", "string_to_array"})
public static String[] split(String input, String delimiter, int limit) {
return StringUtils.splitByWholeSeparator(input, delimiter, limit);
}
Expand All @@ -588,7 +588,7 @@ public static String[] split(String input, String delimiter, int limit) {
* @param index
* @return splits string on specified delimiter and returns String at specified index from the split.
*/
@ScalarFunction
@ScalarFunction(names = {"splitPart", "split_part"})
public static String splitPart(String input, String delimiter, int index) {
String[] splitString = StringUtils.splitByWholeSeparator(input, delimiter);
if (index < splitString.length) {
Expand Down

0 comments on commit de3d803

Please sign in to comment.