create database testdb; CREATE TABLE testdb.basetbl ( num INT, col1 INT, col2 INT, col3 INT, col4 INT, col5 DOUBLE, ft2 DOUBLE, mt2 DOUBLE, at2 DOUBLE, yt2 DOUBLE, jt2 DOUBLE, lt2 DOUBLE, ot2 DOUBLE, st2 DOUBLE, ct2 DOUBLE, nt2 DOUBLE, dt2 DOUBLE, et1 DOUBLE, ft1 DOUBLE, mt1 DOUBLE, at1 DOUBLE, yt1 DOUBLE, jt1 DOUBLE, lt1 DOUBLE, gt1 DOUBLE, st1 DOUBLE, ct1 DOUBLE, nt1 DOUBLE, dt1 DOUBLE, et0 DOUBLE, feb_t0 DOUBLE, mt0 DOUBLE, at0 DOUBLE, may_t0 DOUBLE, jt0 DOUBLE, lt0 DOUBLE, gt0 DOUBLE, st0 DOUBLE, ct0 DOUBLE, nt0 DOUBLE, dt0 DOUBLE, ll_ft2 DOUBLE, ll_mt2 DOUBLE, ll_at2 DOUBLE, ll_yt2 DOUBLE, ll_jt2 DOUBLE, ll_lt2 DOUBLE, ll_ot2 DOUBLE, ll_st2 DOUBLE, ll_ct2 DOUBLE, ll_nt2 DOUBLE, ll_dt2 DOUBLE, ll_et1 DOUBLE, ll_ft1 DOUBLE, ll_mt1 DOUBLE, ll_at1 DOUBLE, ll_yt1 DOUBLE, ll_jt1 DOUBLE, ll_lt1 DOUBLE, ll_gt1 DOUBLE, ll_st1 DOUBLE, ll_ct1 DOUBLE, ll_nt1 DOUBLE, ll_dt1 DOUBLE, ll_et0 DOUBLE, ll_feb_t0 DOUBLE, ll_mt0 DOUBLE, ll_at0 DOUBLE, ll_may_t0 DOUBLE, ll_jt0 DOUBLE, ll_lt0 DOUBLE, ll_gt0 DOUBLE, ll_st0 DOUBLE, ll_ct0 DOUBLE, ll_nt0 DOUBLE, ll_dt0 DOUBLE ) STORED AS PARQUET ; explain with view12 as ( select *, 100 as b100_col5, if(ll_ft2 < 0, 100 - (100 * ll_ft2) , 100 + (100 * ll_ft2)) as b100_ft2, if(ll_mt2 < 0, (if(ll_ft2 < 0, 100 - (100 * ll_ft2) , 100 + (100 * ll_ft2)) - (if(ll_ft2 < 0, 100 - (100 * ll_ft2) , 100 + (100 * ll_ft2)) * ll_mt2)) , (if(ll_ft2 < 0, 100 - (100 * ll_ft2) , 100 + (100 * ll_ft2)) + (if(ll_ft2 < 0, 100 - (100 * ll_ft2) , 100 + (100 * ll_ft2)) * ll_mt2))) as b100_mt2 from testdb.basetbl), view22 as ( select *, if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) as b100_at2, if(ll_yt2 < 0, (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) - (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2)) , (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) + (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2))) as b100_yt2, if(ll_jt2 < 0, (if(ll_yt2 < 0, (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) - (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2)) , (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) + (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2))) - (if(ll_yt2 < 0, (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) - (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2)) , (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) + (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2))) * ll_jt2)) , (if(ll_yt2 < 0, (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) - (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2)) , (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) + (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2))) + (if(ll_yt2 < 0, (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) - (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2)) , (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) + (if(ll_at2 < 0, b100_mt2 - (b100_mt2 * ll_at2) , b100_mt2 + (b100_mt2 * ll_at2)) * ll_yt2))) * ll_jt2))) as b100_jt2 from view12), view32 as ( select *, if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) as b100_lt2, if(ll_ot2 < 0, (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) - (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2)) , (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) + (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2))) as b100_ot2, if(ll_st2 < 0, (if(ll_ot2 < 0, (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) - (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2)) , (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) + (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2))) - (if(ll_ot2 < 0, (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) - (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2)) , (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) + (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2))) * ll_st2)) , (if(ll_ot2 < 0, (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) - (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2)) , (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) + (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2))) + (if(ll_ot2 < 0, (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) - (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2)) , (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) + (if(ll_lt2 < 0, b100_jt2 - (b100_jt2 * ll_lt2) , b100_jt2 + (b100_jt2 * ll_lt2)) * ll_ot2))) * ll_st2))) as b100_st2 from view22), view42 as ( select *, if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) as b100_ct2, if(ll_nt2 < 0, (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) - (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2)) , (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) + (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2))) as b100_nt2, if(ll_dt2 < 0, (if(ll_nt2 < 0, (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) - (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2)) , (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) + (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2))) - (if(ll_nt2 < 0, (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) - (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2)) , (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) + (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2))) * ll_dt2)) , (if(ll_nt2 < 0, (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) - (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2)) , (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) + (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2))) + (if(ll_nt2 < 0, (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) - (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2)) , (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) + (if(ll_ct2 < 0, b100_st2 - (b100_st2 * ll_ct2) ,b100_st2 + (b100_st2 * ll_ct2)) * ll_nt2))) * ll_dt2))) as b100_dt2 from view32) select * from view42