最近在使用神策的时候,要把自己的一部分数据导入神策中
遇到问题:
1.因为 hdfsImporter 无法把数据直接导入到 kudu 中,用户数据都是存在 kudu 中的。所以会经过 kafka 到 kudu
目前机制是,hdfsImporter 导入的用户数据,是会经过 kafka,这个是底层机制,暂时不好修改。
解决:需要您那边订阅出来之后,到根据对应的条件,过滤掉用户画像的数据
2. 神策导入机制对数据格式要求非常严格,这里有json嵌套json的机制
val value = readDF.rdd.map(p => {
val distinct_id = p.getAs[String]("distinct_id")
val `type` = "profile_set"
val time = p.getAs[Long]("time")
val project = "default"
val a= p.getAs[String]("a")
val b = p.getAs[String]("b")
val properties = Properties(a,b)
val ups = Ups(distinct_id, time, `type`, project, properties)
val gson = new Gson()
val jsonStr: String = gson.toJson(ups)
jsonStr
})
//写到hdfs上面 获取路径
val writePath = getWritePath(startDate)
//判断文件夹是否存在,不存在就创建
val bool = HdfsUtil.pathIsExist(writePath)
if (bool) {
val conf = new Configuration()
val fs = FileSystem.get(conf)
fs.delete(new Path(writePath), true)
value.repartition(10).saveAsTextFile(writePath)
} else {
value.repartition(10).saveAsTextFile(writePath)
}
}
def getWritePath(dateStr: String) = {
val finallyPath = "hdfs目录"
finallyPath
}
case class Properties(
a:String,
b: String
)
case class Ups(
distinct_id: String,
time: Long,
`type`: String,
project: String,
properties: Properties
)