spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ayan guha <guha.a...@gmail.com>
Subject Re: IF in SQL statement
Date Sat, 16 May 2015 15:17:48 GMT
Try like this

SELECT name, case when ts>0 then price else 0 end from table

On Sun, May 17, 2015 at 12:21 AM, Antony Mayi <antonymayi@yahoo.com.invalid>
wrote:

> Hi,
>
> is it expected I can't reference a column inside of IF statement like this:
>
> sctx.sql("SELECT name, IF(ts>0, price, 0) FROM table").collect()
>
> I get an error:
>
> org.apache.spark.sql.AnalysisException: unresolved operator 'Project
> [name#0,if ((CAST(ts#1, DoubleType) > CAST(0, DoubleType))) price#2 else 0
> AS c1#378];
>
> it works ok if I use value instead of column ref:
>
> sctx.sql("SELECT name, IF(ts>0, 1, 0) FROM table").collect()
>
> thx,
> Antony.
>
>


-- 
Best Regards,
Ayan Guha

Mime
View raw message