[ 
https://issues.apache.org/jira/browse/SPARK-28435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dongjoon Hyun resolved SPARK-28435.
-----------------------------------
       Resolution: Fixed
    Fix Version/s: 3.0.0

Issue resolved by pull request 25189
[https://github.com/apache/spark/pull/25189]

> Support cast StringType to IntervalType for SQL interface
> ---------------------------------------------------------
>
>                 Key: SPARK-28435
>                 URL: https://issues.apache.org/jira/browse/SPARK-28435
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>    Affects Versions: 3.0.0
>            Reporter: Yuming Wang
>            Assignee: Yuming Wang
>            Priority: Major
>             Fix For: 3.0.0
>
>
> Scala interface support cast string to interval:
> {code:scala}
> import org.apache.spark.sql.types._
> import org.apache.spark.sql.catalyst.expressions._
> Cast(Literal("interval 3 month 1 hours"), CalendarIntervalType).eval()
> res0: Any = interval 3 months 1 hours
> {code}
> But SQL interface does not support it:
> {code:sql}
> scala> spark.sql("SELECT CAST('interval 3 month 1 hour' AS interval)").show
> org.apache.spark.sql.catalyst.parser.ParseException:
> DataType interval is not supported.(line 1, pos 41)
> == SQL ==
> SELECT CAST('interval 3 month 1 hour' AS interval)
> -----------------------------------------^^^
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.$anonfun$visitPrimitiveDataType$1(AstBuilder.scala:1931)
>   at 
> org.apache.spark.sql.catalyst.parser.ParserUtils$.withOrigin(ParserUtils.scala:108)
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.visitPrimitiveDataType(AstBuilder.scala:1909)
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.visitPrimitiveDataType(AstBuilder.scala:52)
>   at 
> org.apache.spark.sql.catalyst.parser.SqlBaseParser$PrimitiveDataTypeContext.accept(SqlBaseParser.java:15397)
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.typedVisit(AstBuilder.scala:58)
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.visitSparkDataType(AstBuilder.scala:1903)
>   at 
> org.apache.spark.sql.catalyst.parser.AstBuilder.$anonfun$visitCast$1(AstBuilder.scala:1334)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

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

Reply via email to