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 <antonym...@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

Reply via email to