diff --git a/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGenerator.scala b/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGenerator.scala index fb8adaf94..78fcdd33c 100644 --- a/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGenerator.scala +++ b/zion/src/main/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGenerator.scala @@ -144,16 +144,17 @@ class SQLPPGenerator extends AsterixQueryGenerator { ParsedResult(Seq.empty, exprMap) } else { val producedExprs = mutable.LinkedHashMap.newBuilder[String, FieldExpr] + appends.foreach { append => val as = append.as - producedExprs += append.as.name -> FieldExpr(s"$appendVar.${as.name}", append.definition) + producedExprs += append.as.name -> FieldExpr(s"$appendVar.$quote${as.name}$quote", append.definition) } - exprMap.foreach { - case (field, expr) => - producedExprs += field -> FieldExpr(s"$appendVar.$field", s"${expr.refExpr}") + val producedExprMap = producedExprs.result().toMap + val selectStr = parseProject(producedExprMap)+s",$sourceVar" + + val newExprMap = producedExprMap ++ exprMap.mapValues{expr=> + FieldExpr(s"$appendVar.${expr.refExpr}", s"${expr.defExpr}") } - val newExprMap = producedExprs.result().toMap - val selectStr = parseProject(newExprMap) queryBuilder.insert(0, s"from ($selectStr\n") queryBuilder.append(s") $appendVar") ParsedResult(Seq.empty, newExprMap) diff --git a/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGeneratorTest.scala b/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGeneratorTest.scala index 46f522eb7..05779e639 100644 --- a/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGeneratorTest.scala +++ b/zion/src/test/scala/edu/uci/ics/cloudberry/zion/model/impl/SQLPPGeneratorTest.scala @@ -673,10 +673,10 @@ class SQLPPGeneratorTest extends Specification { removeEmptyLine(result) must_== unifyNewLine( """ |select `hour` as `hour`,coll_count(g) as `count` - |from (select length(lang) as `lang_len`,t.`favorite_count` as `favorite_count`,t.`geo_tag`.`countyID` as `geo_tag.countyID`,t.`user_mentions` as `user_mentions`,t as `geo`,t.`user`.`id` as `user.id`,t.`geo_tag`.`cityID` as `geo_tag.cityID`,t.`is_retweet` as `is_retweet`,t.`text` as `text`,t.`retweet_count` as `retweet_count`,t.`in_reply_to_user` as `in_reply_to_user`,t.`id` as `id`,t.`coordinate` as `coordinate`,t.`in_reply_to_status` as `in_reply_to_status`,t.`user`.`status_count` as `user.status_count`,t.`geo_tag`.`stateID` as `geo_tag.stateID`,t.`create_at` as `create_at`,t.`lang` as `lang`,t.`hashtags` as `hashtags` + |from (select length(lang) as `lang_len`,t |from twitter.ds_tweet t) ta - |where ta.lang_len >= 1 - |group by get_interval_start_datetime(interval_bin(ta.create_at, datetime('1990-01-01T00:00:00.000Z'), day_time_duration("PT1H") )) as `hour` group as g; + |where ta.`lang_len` >= 1 + |group by get_interval_start_datetime(interval_bin(ta.t.`create_at`, datetime('1990-01-01T00:00:00.000Z'), day_time_duration("PT1H") )) as `hour` group as g; |""".stripMargin.trim) } @@ -692,11 +692,11 @@ class SQLPPGeneratorTest extends Specification { """ |select tt.`state` as `state`,tt.`avgLangLen` as `avgLangLen`,ll0.`population` as `population` |from ( - |select `state` as `state`,coll_avg( (select value g.ta.lang_len from g) ) as `avgLangLen` - |from (select length(lang) as `lang_len`,t.`favorite_count` as `favorite_count`,t.`geo_tag`.`countyID` as `geo_tag.countyID`,t.`user_mentions` as `user_mentions`,t as `geo`,t.`user`.`id` as `user.id`,t.`geo_tag`.`cityID` as `geo_tag.cityID`,t.`is_retweet` as `is_retweet`,t.`text` as `text`,t.`retweet_count` as `retweet_count`,t.`in_reply_to_user` as `in_reply_to_user`,t.`id` as `id`,t.`coordinate` as `coordinate`,t.`in_reply_to_status` as `in_reply_to_status`,t.`user`.`status_count` as `user.status_count`,t.`geo_tag`.`stateID` as `geo_tag.stateID`,t.`create_at` as `create_at`,t.`lang` as `lang`,t.`hashtags` as `hashtags` + |select `state` as `state`,coll_avg( (select value g.ta.`lang_len` from g) ) as `avgLangLen` + |from (select length(lang) as `lang_len`,t |from twitter.ds_tweet t) ta - |where ftcontains(ta.text, ['zika','virus'], {'mode':'all'}) - |group by ta.geo.geo_tag.stateID as `state` group as g + |where ftcontains(ta.t.`text`, ['zika','virus'], {'mode':'all'}) + |group by ta.t.geo_tag.stateID as `state` group as g |) tt |left outer join twitter.US_population ll0 on ll0.`stateID` = tt.`state`; |""".stripMargin.trim