[ 
https://issues.apache.org/jira/browse/SPARK-17212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15699751#comment-15699751
 ] 

Hyukjin Kwon commented on SPARK-17212:
--------------------------------------

Oh wait, I am sorry. I rushed the comments. The problem specified in the 
comment seems a bit different with the problem specified in this JIRA (types 
between {{TimestampType}} and {{DateType}}. The comment says types between 
{{StringType}} and {{DateType}}. Yes, I just checked it does not still work in 
the master.

{code}
spark-sql> select greatest("2015-02-02", date("2015-01-01")) ;
Error in query: cannot resolve 'greatest('2015-02-02', CAST('2015-01-01' AS 
DATE))' due to data type mismatch: The expressions should all have the same 
type, got GREATEST(string, date).; line 1 pos 7;
'Project [unresolvedalias(greatest(2015-02-02, cast(2015-01-01 as date)), None)]
+- OneRowRelation$

spark-sql> select least("2015-02-02", date("2015-01-01")) ;
Error in query: cannot resolve 'least('2015-02-02', CAST('2015-01-01' AS 
DATE))' due to data type mismatch: The expressions should all have the same 
type, got LEAST(string, date).; line 1 pos 7;
'Project [unresolvedalias(least(2015-02-02, cast(2015-01-01 as date)), None)]
+- OneRowRelation$

spark-sql> select greatest(timestamp("2015-02-02"), date("2015-01-01")) ;
2015-02-02 00:00:00
Time taken: 1.707 seconds, Fetched 1 row(s)
{code}

Ah, I see what you mean [~hvanhovell]. {{Leatest}}/{{Greatest}} use 
{{findWiderTypeWithoutStringPromotion}} and when the input type is 
{{StringType}}, it ends up with different types and that's why you said 
{{ImplicitCastInputTypes}}. I see. I can take a look for other DBMS 
implementations and open a JIRA if you are fine (or I am also fine if anyone 
feels up and takes over this).


> TypeCoercion support widening conversion between DateType and TimestampType
> ---------------------------------------------------------------------------
>
>                 Key: SPARK-17212
>                 URL: https://issues.apache.org/jira/browse/SPARK-17212
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>            Reporter: Hyukjin Kwon
>            Assignee: Hyukjin Kwon
>             Fix For: 2.1.0
>
>
> Currently, type-widening does not work between {{TimestampType}} and 
> {{DateType}}.
> This applies to {{SetOperation}}, {{Union}}, {{In}}, {{CaseWhen}}, 
> {{Greatest}}, {{Leatest}}, {{CreateArray}}, {{CreateMap}} and {{Coalesce}}.
> For a simple example, 
> {code}
> Seq(Tuple2(new Timestamp(0), new Date(0))).toDF("a", 
> "b").selectExpr("greatest(a, b)").show()
> {code}
> {code}
> cannot resolve 'greatest(`a`, `b`)' due to data type mismatch: The 
> expressions should all have the same type, got GREATEST(timestamp, date)
> {code}
> or Union as below:
> {code}
> val a = Seq(Tuple1(new Timestamp(0))).toDF()
> val b = Seq(Tuple1(new Date(0))).toDF()
> a.union(b).show()
> {code}
> {code}
> Union can only be performed on tables with the compatible column types. 
> DateType <> TimestampType at the first column of the second table;
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to