开发者社区> 问答> 正文

scala编译的时候报错unclosed character literal

求老师来解答:
scala编译的时候报错regexp_replace(regexp_replace(regexp_replace(p_parameters,'""','"'),'\"\{','{'),'}"','}') as p_parameter
_

代码如下:
import java.text.SimpleDateFormat

import com.alibaba.fastjson.JSONObject
import org.apache.hadoop.hive.metastore.api.Date
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.{SparkConf, SparkContext}

object user_friend_visit {
val conf = new SparkConf().setAppName("user_friend_visit")
val sc = new SparkContext(conf)
val hiveContext = new HiveContext(sc)

val format = new java.text.SimpleDateFormat("yyyy-MM-dd");
var today = new java.util.Date();
val eventFormat = new SimpleDateFormat("yyyyMMdd")
val yesterday = new Date(today.getTime - 1000 60 60 * 24)
val todayFormat = format.format(today)
val yesterDayFormat = format.format(yesterday)
val todayEventFormat = eventFormat.format(today)
val yesterDayEventFormat = eventFormat.format(yesterday)
val startTime = yesterDayFormat + " 20:00:00"
val endTime = todayFormat + " 20:00:00"

var df = hiveContext.sql("with t as (select t.distinct_id frienduuid,t1.memberID entryuuid,max(t.time) visit_time,count(t.distinct_id) as vists_num from( select distinct_id ,regexp_replace(regexp_replace(regexp_replace(p_parameters ,'""','"'),'\\"\\{','{'),'}"','}') as p_parameters ,time from mart_operation_platform.event_ros_p1 where substr(day,1,6)='201808' and p_topage in('jdbclient://trade/tradeDetail/index', 'jdbclient://user/guest/index') and distinct_id='541274831941513909' )t lateral view json_tuple(t.p_parameters,'memberID') t1 as memberID group by t.distinct_id,t1.memberID) select t.entryuuid ,concat_ws('|',t.frienduuid,'') frienduuids ,concat_ws('|',t.visit_time,'') visit_times ,t.vists_num from t where t.entryuuid is not null |group by t.entryuuid,concat_ws('|',t.frienduuid,''),concat_ws('|',t.visit_time,''),t.vists_num" )

df.foreachPartition(p => {

p.foreach(r => {
  val entryUuid = r.getString(0)
  val memberIDs = r.getString(1).split("|")
  val visitTimes = r.getString(2).split("|")
  val visiNum = r.getInt(3)
  import java.util
  val jsonObject = new JSONObject();
  jsonObject.put("entryUuid", entryUuid)

  var jsonObjects = new util.ArrayList[JSONObject]();
  val jsonObject1 = new JSONObject();
  val jsonObject2 = new JSONObject();
  var i = 0
  var jsonStr = ""
  for (i <- 0 to visiNum - 1) {
    jsonObject1.put("memberID", memberIDs.apply(i))
    jsonObject1.put("visitTime", visitTimes.apply(i))
    jsonObjects.add(jsonObject1)
  }
  jsonObject.put("friendDatas", jsonObjects)
  println(jsonObject)
  //mqProducer("test", jsonStr.getBytes())

})

})

展开
收起
数据boy 2018-08-21 13:47:54 6189 0
1 条回答
写回答
取消 提交回答
  • 前一个帐号wangccsy@126.com不知道怎么的就成了企业帐号,改不成个人。所以重新注册了一个个人帐号。老程序员。精通JAVA,C#,数据库,对软件开发过程和流程熟悉。考取系统分析师,项目管理师和系统架构设计师等软件资格考试认证。愿意和大家一起前进。

    regexp_replace(regexp_replace(regexp_replace(p_parameters,'""','"'),'"{','{'),'}"','}') 有的转义有的没转义。试试都加上转义。

    2019-07-17 23:01:44
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
JDK8新特性与生产-for“华东地区scala爱好者聚会” 立即下载
Just Enough Scala for Spark 立即下载
低代码开发师(初级)实战教程 立即下载