-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-815] Add an option to allow empty strings to represent null values #4462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| boolean supportsUnsignedTypes(); | ||
|
|
||
| /** | ||
| * Whether to convert empty string to null.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the redundant .
| public static final SqlFunction LTRIM = | ||
| SqlBasicFunction.create(SqlKind.LTRIM, | ||
| ReturnTypes.ARG0.andThen(SqlTypeTransforms.TO_NULLABLE) | ||
| ReturnTypes.ARG0.andThen(SqlTypeTransforms.FORCE_NULLABLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it only possible to change this in the Oracle mode here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this makes the functions return null even if no argements is null.
| * {@link SqlConformanceEnum#ORACLE_12}; | ||
| * false otherwise. | ||
| */ | ||
| boolean emptyStringIsNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
treatEmptyStringAsNull ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is discussed in JIRA, I think emptyStringIsNull is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
| // Translate | ||
| // LTRIM/RTRIM(operand0[,operand1,...]) | ||
| // | ||
| // to the following if we want Oracle semantics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we convert LTRIM(A) to the following expression: CASE WHEN LTRIM(A) = '' THEN NULL ELSE LTRIM(A) END. LTRIM(A) is calculated multiple times. If LTRIM(A) is a non-deterministic function, it may lead to an uncontrolled final result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we convert LTRIM(A) to the following expression: CASE WHEN LTRIM(A) = '' THEN NULL ELSE LTRIM(A) END. LTRIM(A) is calculated multiple times. If LTRIM(A) is a non-deterministic function, it may lead to an uncontrolled final result.
Nondeterministic is not allowed during runtime, I've added some tests and throw exception when it occurs.
| return rexBuilder.makeCall(pos, SqlStdOperatorTable.CASE, | ||
| rexBuilder.makeCall(pos, SqlStdOperatorTable.EQUALS, rawCall, | ||
| rexBuilder.makeLiteral("")), | ||
| rexBuilder.makeNullLiteral(typeFactory.createSqlType(SqlTypeName.NULL)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NULL type here should be the same as that of LTRIM(A)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, NULL type now is consistent with call's.
|
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |



The following functions will return null if the result is an empty string under Oracle semantics: