Skip to content

[WIP][SPARK-30203][SQL] store assignable if there is an appropriate user-defined cast function#26833

Closed
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:SPARK-30203
Closed

[WIP][SPARK-30203][SQL] store assignable if there is an appropriate user-defined cast function#26833
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:SPARK-30203

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Dec 10, 2019

What changes were proposed in this pull request?

9.2 Store assignment

Syntax Rules
  1. Let T be the TARGET and let V be the VALUE in an application of the Syntax Rules of this Subclause.
  2. Let TD and SD be the declared types of T and V, respectively.
  3. If TD is character string, binary string, numeric, boolean, datetime, interval, or a user-defined type, then either SD shall be assignable to TD or there shall exist an appropriate user-defined cast function UDCF from SD to TD.
    NOTE 319 — “Appropriate user-defined cast function” is defined in Subclause 4.11, “Data conversions”

4.11 Data conversions

Implicit type conversion can occur in expressions, fetch operations, single row select operations, inserts, deletes, and updates. Explicit type conversions can be specified by the use of the CAST operator.

The current implementation for ANSI store assignment is totally out of context.

According to this rule, there shall exist an appropriate user-defined cast function UDCF, the spark legacy store assignment is just fine because we do have appropriate cast functions.

At least according to the ansi cast rule, the current ANSI assignment policy is too strict to the ANSI cast rules

* (SD) --------------------- (TD) -------------------------
*     | EN  AN  C  D  T  TS  YM  DT  BO  UDT  B  RT  CT  RW
* EN  |  Y   Y  Y  N  N   N   M   M   N   M   N   M   N   N
* AN  |  Y   Y  Y  N  N   N   N   N   N   M   N   M   N   N
*  C  |  Y   Y  Y  Y  Y   Y   Y   Y   Y   M   N   M   N   N
*  D  |  N   N  Y  Y  N   Y   N   N   N   M   N   M   N   N
*  T  |  N   N  Y  N  Y   Y   N   N   N   M   N   M   N   N
* TS  |  N   N  Y  Y  Y   Y   N   N   N   M   N   M   N   N
* YM  |  M   N  Y  N  N   N   Y   N   N   M   N   M   N   N
* DT  |  M   N  Y  N  N   N   N   Y   N   M   N   M   N   N
* BO  |  N   N  Y  N  N   N   N   N   Y   M   N   M   N   N
* UDT |  M   M  M  M  M   M   M   M   M   M   M   M   M   N
*  B  |  N   N  N  N  N   N   N   N   N   M   Y   M   N   N
* RT  |  M   M  M  M  M   M   M   M   M   M   M   M   N   N
* CT  |  N   N  N  N  N   N   N   N   N   M   N   N   M   N
* RW  |  N   N  N  N  N   N   N   N   N   N   N   N   N   M
*
* Where:
* EN = Exact Numeric
* AN = Approximate Numeric
* C = Character (Fixed- or Variable-Length, or Character Large Object)
* D = Date
* T = Time
* TS = Timestamp
* YM = Year-Month Interval
* DT = Day-Time Interval
* BO = Boolean
* UDT = User-Defined Type
* B = Binary (Fixed- or Variable-Length or Binary Large Object)
* RT = Reference type
* CT = Collection type
* RW = Row type

Why are the changes needed?

the current ansi store assignment rule is not ansi.

Does this PR introduce any user-facing change?

yes, pending

How was this patch tested?

add uts.

@yaooqinn
Copy link
Member Author

cc @cloud-fan @maropu @HyukjinKwon @gengliangwang @gatorsmile @dongjoon-hyun, IIUC, the current implementation for store assignment might go wrong with ANSI's context.

@SparkQA
Copy link

SparkQA commented Dec 10, 2019

Test build #115103 has finished for PR 26833 at commit b1b39ea.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gengliangwang
Copy link
Member

gengliangwang commented Dec 10, 2019

@yaooqinn I think the store assignment rule is independent of the casting rule.
In PostgreSQL, if you try inserting a string column to an integer column, there will be an error. It works with inserting literals though.

there shall exist an appropriate user-defined cast function UDCF from SD to TD

IIUC, there is no UDCF support in Spark.

@yaooqinn
Copy link
Member Author

I got it. thanks. @gengliangwang

@yaooqinn yaooqinn closed this Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants