求老师来解答:
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())
})
})
regexp_replace(regexp_replace(regexp_replace(p_parameters,'""','"'),'"{','{'),'}"','}') 有的转义有的没转义。试试都加上转义。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。