julianhyde commented on code in PR #3013:
URL: https://github.com/apache/calcite/pull/3013#discussion_r1066360132
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -188,6 +188,26 @@ private SqlLibraryOperators() {
.andThen(SqlTypeTransforms.TO_NULLABLE_ALL),
OperandTypes.SAME_SAME);
+ /**The "LPAD(original_value, return_length[, pattern])" function. */
+ @LibraryOperator(libraries = {BIG_QUERY, ORACLE})
+ public static final SqlFunction LPAD =
+ SqlBasicFunction.create(
+ "LPAD",
+ ReturnTypes.ARG0_NULLABLE_VARYING,
+ OperandTypes.STRING_NUMERIC_OPTIONAL_STRING,
+ SqlFunctionCategory.STRING
+ );
Review Comment:
no spaces before parentheses
##########
babel/src/test/resources/sql/big-query.iq:
##########
@@ -2596,4 +2596,74 @@ FROM items;
!ok
+#####################################################################
+# LPAD(original_value, return_length, pattern) {
+#
+# Returns a STRING or BYTES value that consists of original_value prepended
with pattern.
+#
+# This function supports specifying collation.
+WITH Examples AS (
+ SELECT LPAD('12345', 8, 'a') as example UNION ALL
+ SELECT LPAD('12345', 8) UNION ALL
+ SELECT LPAD('12345', 8, 'aba') UNION ALL
+ SELECT LPAD('12345', 3) UNION ALL
+ SELECT LPAD(x'aa', 4, x'bb') UNION ALL
+ SELECT LPAD(x'aa', 4) UNION ALL
+ SELECT LPAD(x'aaaaaa', 2) UNION ALL
+ SELECT LPAD(x'aaaaaa', 2, x'bb')
+)
+SELECT
+ *
+FROM Examples;
++----------+
+| example |
++----------+
+| aaa12345 |
+| 12345 |
+| aba12345 |
+| 123 |
+| bbbbbbaa |
+| 202020aa |
+| aaaa |
+| aaaa |
++----------+
+(8 rows)
+
+!ok
+
+#####################################################################
+# RPAD(original_value, return_length, pattern) {
+#
+# Returns a STRING or BYTES value that consists of original_value prepended
with pattern.
+#
+# This function supports specifying collation.
+WITH Examples AS (
Review Comment:
add a column to distinguish the examples
##########
site/_docs/reference.md:
##########
@@ -2634,6 +2634,7 @@ semantics.
| m | JSON_STORAGE_SIZE(jsonValue) | Returns the number of
bytes used to store the binary representation of *jsonValue*
| b o | LEAST(expr [, expr ]* ) | Returns the least of
the expressions
| b m p | LEFT(string, length) | Returns the leftmost
*length* characters from the *string*
+| b o | LPAD(string, length, pattern) | Returns a string or
bytes value that consists of *string* prepended with *pattern*
Review Comment:
change "prepended" to "prepended to *length*"?
##########
site/_docs/reference.md:
##########
@@ -2646,6 +2647,7 @@ semantics.
| b m p | RIGHT(string, length) | Returns the rightmost
*length* characters from the *string*
| h s | string1 RLIKE string2 | Whether *string1*
matches regex pattern *string2* (similar to `LIKE`, but uses Java regex)
| h s | string1 NOT RLIKE string2 | Whether *string1* does
not match regex pattern *string2* (similar to `NOT LIKE`, but uses Java regex)
+| b o | RPAD(string, length, pattern) | Returns a string or
bytes value that consists of *string* appended with *pattern*.
Review Comment:
no '.'
##########
babel/src/test/resources/sql/big-query.iq:
##########
@@ -2596,4 +2596,74 @@ FROM items;
!ok
+#####################################################################
Review Comment:
can you move this section somewhere besides the end of the file? Appends
cause merge conflicts
##########
site/_docs/reference.md:
##########
@@ -2646,6 +2647,7 @@ semantics.
| b m p | RIGHT(string, length) | Returns the rightmost
*length* characters from the *string*
| h s | string1 RLIKE string2 | Whether *string1*
matches regex pattern *string2* (similar to `LIKE`, but uses Java regex)
| h s | string1 NOT RLIKE string2 | Whether *string1* does
not match regex pattern *string2* (similar to `NOT LIKE`, but uses Java regex)
+| b o | RPAD(string, length, pattern) | Returns a string or
bytes value that consists of *string* appended with *pattern*.
Review Comment:
", pattern" should be "[, pattern ]". Ditto LPAD
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]