[CALCITE-6999] Invalid unparse for TRIM in PrestoDialect#4360
[CALCITE-6999] Invalid unparse for TRIM in PrestoDialect#4360mihaibudiu merged 1 commit intoapache:mainfrom
Conversation
135157d to
b9c2983
Compare
caicancai
left a comment
There was a problem hiding this comment.
Why the BigQuery dialect files were modified ?
The logic can be reused by other dialects,so move it to RelToSqlConverterUtil avoid duplicate code. @caicancai |
|
There are two reasons. The first is that you cannot be sure that every dialect has this function and the format is the same. The second is that you did not modify the above comment. |
Yes, here need to adapt system which support trim/ltrim/rtrim functions and presto is supported well(which test result in JIRA:https://issues.apache.org/jira/browse/CALCITE-6999), and I had updated the comments with presto link. thanks for reminder @caicancai |
So now all dialects support trim function parsing? |
This can not confirm,but which need to use(like BigQuery/Presto) to convert right way can use the method. |
| * <a href="https://prestodb.io/docs/current/functions/string.html#trim-string-varchar"> | ||
| * Presto Trim Function</a>. | ||
| */ | ||
| public static void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec, |
There was a problem hiding this comment.
if this function is specific to BigQuery, the function name should reflect that.
I would not abbreviate BQ in the JavaDoc, why force people to try to guess what it is when you can just write it down?
There was a problem hiding this comment.
Yes,make sense, this method not only used for BigQuery,can be used by any need convert trim(both from) to trim/ltrim/rtrim functions, so method name may not need to be changed, I had updated the bbreviate BQ in JavaDoc.Thanks for suggestion @mihaibudiu
There was a problem hiding this comment.
the current name is too generic, this function is not suitable for unparsingTrim for all dialects, as the name would suggest
I think unparseTrimBigQuery is better, or unparseTrimLR if you want.
Many dialects can share it.
There was a problem hiding this comment.
Yes, I thought unparseTrimLR is better, so changed the function to unparseTrimLR~ @mihaibudiu
| call.operand(2).unparse(writer, leftPrec, rightPrec); | ||
|
|
||
| // If the trimmed character is a non-space character, add it to the target SQL. | ||
| // eg: TRIM(BOTH 'A' from 'ABCD' |
There was a problem hiding this comment.
missing parens in comment
| // eg: TRIM(BOTH 'A' from 'ABCD' | ||
| // Output Query: TRIM('ABC', 'A') | ||
| String value = requireNonNull(valueToTrim.toValue(), "valueToTrim.toValue()"); | ||
| if (!value.matches("\\s+")) { |
There was a problem hiding this comment.
is this correct?
is trim(s, "\n") the same as trimming all whitespaces?
There was a problem hiding this comment.
Here should be correct, I had test for it:
select trim(' aa c', ' ');
>aa c
trim with '\n'
select trim(' aa c', '\n');
> aa c
trim(s, "\n") is not the same as trimming all whitespaces.
There was a problem hiding this comment.
What about a literal tab character (not the \t escape sequence)?
There was a problem hiding this comment.
the regexp \s+ will match a tab, or even a sequence of spaces and tabs and newlines
There was a problem hiding this comment.
Yes,you are right,maybe we can use StringUtils.isWhitespace(value) to instead of it? which can only match white spaces. @mihaibudiu
|
Hi @mihaibudiu all comments had been addressed, whether is OK currently? |
| // eg: TRIM(BOTH 'A' from 'ABCD') | ||
| // Output Query: TRIM('ABC', 'A') | ||
| String value = requireNonNull(valueToTrim.toValue(), "valueToTrim.toValue()"); | ||
| if (!StringUtils.isWhitespace(value)) { |
There was a problem hiding this comment.
I still don't think this is correct.
The spec says that the default value is just a single space.
So the test should be for value.equals(" "), or it can be removed altogether.
There was a problem hiding this comment.
Make sense, I agree with it and had changed it, PTAL thanks @mihaibudiu
mihaibudiu
left a comment
There was a problem hiding this comment.
you can squash the commits
7aa2abb to
089c626
Compare
|
Thanks for review,I had squashed commits. @mihaibudiu |
|



As description in JIRA: https://issues.apache.org/jira/browse/CALCITE-6999