Skip to content

Conversation

@ILuffZhe
Copy link
Contributor

@ILuffZhe ILuffZhe commented Jul 8, 2025

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

  • concat (||), UPPER, LOWER, TRIM, OVERLAY, SUBSTRING, INITCAP, REPLACE
  • JDBC functions: INSERT, LCASE, UCASE

boolean supportsUnsignedTypes();

/**
* Whether to convert empty string to null..
Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

treatEmptyStringAsNull ?

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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)),
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 9, 2025

@github-actions
Copy link

github-actions bot commented Aug 9, 2025

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.

@github-actions github-actions bot added the stale label Aug 9, 2025
@github-actions github-actions bot removed the stale label Sep 7, 2025
@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Oct 25, 2025
@github-actions github-actions bot removed the stale label Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants