Skip to content

Commit

Permalink
Fix a bug of appendField (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen01 authored May 6, 2017
1 parent 056a445 commit 081b66d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand Down

0 comments on commit 081b66d

Please sign in to comment.