Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Support NULL literal as function argument #985

Conversation

dai-chen
Copy link
Member

@dai-chen dai-chen commented Jan 12, 2021

Issue #, if available: #927, #715

Description of changes:

  1. Add undefined type for NULL literal
  2. Change JDBC driver to map undefined type to JDBC NULL type

Documentation: https://github.com/dai-chen/sql/blob/support-null-literal-as-function-argument/docs/user/general/datatypes.rst#undefined-data-type

Design: A new undefined data type is added as narrowest and root of data type tree.

  1. UNDEFINED represents only the type of NULL literal for now (probably represent some other special literals in future)
  2. UNKNOWN represents type not supported yet. For example, some new Elasticsearch type is given as function argument which yet to be added to core engine.

With this new type, we're able to support NULL literal. For example, given ABS(NULL), the distance between NULL and INTEGER and DOUBLE are 1 and 2 respectively, so function signature ABS(INTEGER) is used to evaluate its value. Previously NULL literal's type is unknown which caused exception thrown.

null-literal

Testing: Add UT and IT. Because SQLite and H2 has different result type for expression with NULL literal, a NullLiteralIT is added manually.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dai-chen dai-chen added enhancement New feature or request SQL labels Jan 12, 2021
@dai-chen dai-chen self-assigned this Jan 12, 2021
@codecov
Copy link

codecov bot commented Jan 12, 2021

Codecov Report

Merging #985 (d7526fd) into develop (47d50d2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #985   +/-   ##
==========================================
  Coverage      99.87%   99.87%           
- Complexity      2397     2400    +3     
==========================================
  Files            234      234           
  Lines           5513     5517    +4     
  Branches         357      357           
==========================================
+ Hits            5506     5510    +4     
  Misses             5        5           
  Partials           2        2           
Impacted Files Coverage Δ Complexity Δ
...elasticsearch/sql/data/model/ExprMissingValue.java 100.00% <100.00%> (ø) 9.00 <1.00> (ø)
...forelasticsearch/sql/data/model/ExprNullValue.java 100.00% <100.00%> (ø) 9.00 <1.00> (ø)
...roforelasticsearch/sql/data/type/ExprCoreType.java 100.00% <100.00%> (ø) 13.00 <9.00> (+3.00)
...h/sql/expression/conditional/cases/CaseClause.java 100.00% <100.00%> (ø) 14.00 <2.00> (ø)
...ion/operator/predicate/UnaryPredicateOperator.java 100.00% <100.00%> (ø) 23.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47d50d2...d7526fd. Read the comment docs.

@dai-chen dai-chen marked this pull request as ready for review January 14, 2021 01:29
Copy link
Member

@chloe-zh chloe-zh left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes!

Copy link
Contributor

@harold-wang harold-wang left a comment

Choose a reason for hiding this comment

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

Thanks for the change!

@dai-chen dai-chen merged commit 6899363 into opendistro-for-elasticsearch:develop Jan 15, 2021
@dai-chen dai-chen deleted the support-null-literal-as-function-argument branch January 15, 2021 01:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request SQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants