Hi, 

I want to re-use column alias in the select clause to avoid sub query.

For example:

select check(key) as b, abs(b) as abs, value1, value2, ..., value30
from test

The query above does not work, because b is not defined in the test's
schema. In stead, I should change the query to the following:

select check(key) as b, abs(check(key)) as abs, value1, value2, ..., value30
from test

Apparently, check function are called twice. In my use case, the check
function is time-consuming.

The workaround is to use sub-query :

select b, abs(b), value1, value2, ..., value30 as abs
from (
  select check(key) as b, value1, value2, ..., value30 from test
) t

The problem is that I have to repeat the 30 following column twice. Image
the following case which does not work:

select check(key) as b, abs(b) as absv,  tan(absv) as tanv, value1, value2,
..., value30
from test

In order not to call my check function many times,  I need to change the
query to 3 sub-queries, which makes query too long, hard to read.

I am wondering whether we can reuse column alias in an efficient way ?

Thank you








--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/SPARK-SQL-Re-use-col-alias-in-the-select-clause-to-avoid-sub-query-tp23645.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org

Reply via email to