Skip to content

[CALCITE-6550] Improve SQL function overloading#3954

Closed
normanj-bitquill wants to merge 2 commits intoapache:mainfrom
Bit-Quill:calcite-6550
Closed

[CALCITE-6550] Improve SQL function overloading#3954
normanj-bitquill wants to merge 2 commits intoapache:mainfrom
Bit-Quill:calcite-6550

Conversation

@normanj-bitquill
Copy link
Contributor

  • RexImpTable can better handle collisions in the scalar function map
  • Return the implementor if only one implementor is found for an operator key
  • If there are multiple implementors for an operator key, look for one with the exact same operator
  • An operator key is the operator name and kind

The main idea here is to allow collisions in the scalar function map. The collisions are resolved as described above. Much of the change here is managing the scalar function map in RexImpTable.

Alternate solutions:

  • Fix up the hashcode and equals methods for SqlBasicFunction options. There will still be some collisions in RexImpTable, since a function could be defined multiple times (ie it is in multiple function libraries with different implementations).
  • Reconsider putting all functions in RexImpTable. We should only need the functions for selected libraries at any given time.

* the SqlOperator to select the correct operator since the hash of operators
* may not be unique.
*/
private static class OpImplementatorPair {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use Pair<SqlOperator, RexCallImplementor> instead? I don't think hashCode or equals are ever called on the values in a map or array-list-multimap.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, maybe better, change scalarMap to type Map<SqlOperator, ImmutablePairList<SqlOperator, RexCallImplementor>>.

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 have rebased this on top of your change to refactor RexImpTable. I am now using ImmutablePairList.

@normanj-bitquill normanj-bitquill force-pushed the calcite-6550 branch 2 times, most recently from 97bf906 to 5909e8b Compare September 10, 2024 22:39
julianhyde and others added 2 commits September 10, 2024 15:42
Split class Builder into subclass and superclass to prevent
code in populate() from accessing map directly.
* RexImpTable can better handle collisions in the scalar function map
* Return the implementor if only one implementor is found for an operator key
* If there are multiple implementors for an operator key, look for one with the exact same operator
* An operator key is the operator name and kind
@sonarqubecloud
Copy link

Copy link
Member

@caicancai caicancai left a comment

Choose a reason for hiding this comment

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

I will test it locally in the next few days to see if there are any other problems. Overall, it is good.

@normanj-bitquill If I test next week this week, I think we can merge this PR next week without introducing more conflicts

Copy link
Member

@caicancai caicancai left a comment

Choose a reason for hiding this comment

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

LGTM

@mihaibudiu
Copy link
Contributor

@julianhyde you asked for changes, please approve if you are satisfied.

julianhyde added a commit to julianhyde/calcite that referenced this pull request Sep 16, 2024
julianhyde added a commit to julianhyde/calcite that referenced this pull request Sep 16, 2024
Use forbiddenApis to prevent use of Locale.setDefault;
if you really need it, call Unsafe.setDefaultLocale.

Close apache#3954
julianhyde pushed a commit to julianhyde/calcite that referenced this pull request Sep 17, 2024
Remove usage of Locale.setDefault in tests where possible.

Add Locale.setDefault to forbiddenApis, add method
Unsafe.setDefaultLocale(Locale), and change the remaining
uses of Locale.setDefault to go via Unsafe.

The implementation of the Postgres TO_CHAR function (and related functions) now get
Locale and TimeZone from DataContext.

Rework unit tests for PostgresqlDateTimeFormatter to be less
repetitive, more readable.

Minimize usage of ZoneId.systemDefault().

Close apache#3954
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.

4 participants