|
@@ -2,6 +2,7 @@ package com.winhc.bigdata.spark.utils
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils
|
|
import org.apache.commons.lang3.StringUtils
|
|
import com.winhc.bigdata.spark.implicits.MapHelper._
|
|
import com.winhc.bigdata.spark.implicits.MapHelper._
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @Author: XuJiakai
|
|
* @Author: XuJiakai
|
|
* @Date: 2020/7/7 13:59
|
|
* @Date: 2020/7/7 13:59
|
|
@@ -16,22 +17,15 @@ object ChangeExtractUtils {
|
|
|
|
|
|
//获取指定字段集的标签Json
|
|
//获取指定字段集的标签Json
|
|
def getTags(fldMap: Map[String, String], type_val: String, fields: Array[String]): String = {
|
|
def getTags(fldMap: Map[String, String], type_val: String, fields: Array[String]): String = {
|
|
- val json: StringBuilder = new StringBuilder(s"""{"type":${getValueOrNull(type_val)},""")
|
|
|
|
- fields.foreach(item =>
|
|
|
|
- if (item.contains("->")) {
|
|
|
|
- val Array(key, keyAlias) = item.split("->")
|
|
|
|
- json.append(s"${getValueOrNull(keyAlias)}")
|
|
|
|
- json.append(s":${getValueOrNull(fldMap(key))},")
|
|
|
|
- } else {
|
|
|
|
- json.append(s"${getValueOrNull(item)}")
|
|
|
|
- json.append(s":${getValueOrNull(fldMap(item))},")
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- json.deleteCharAt(json.lastIndexOf(",")).append("}").toString.trim
|
|
|
|
|
|
+ val json = fldMap.toJson(fields).substring(1)
|
|
|
|
+ if (json.length == 1) {
|
|
|
|
+ s"""{"type":${getValueOrNull(type_val)}""" + json
|
|
|
|
+ } else {
|
|
|
|
+ s"""{"type":${getValueOrNull(type_val)},""" + json
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
private def getValueOrNull(value: String): String = {
|
|
private def getValueOrNull(value: String): String = {
|
|
if (StringUtils.isNotBlank(value)) {
|
|
if (StringUtils.isNotBlank(value)) {
|
|
"\"" + value + "\""
|
|
"\"" + value + "\""
|
|
@@ -42,7 +36,8 @@ object ChangeExtractUtils {
|
|
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
def main(args: Array[String]): Unit = {
|
|
- val map = Map("a"->"b","b"->"c")
|
|
|
|
- println(map.toJson(Seq("a->你","b")))
|
|
|
|
|
|
+ val map = Map("a" -> "b", "b" -> "c")
|
|
|
|
+ println(map.toJson(Seq()))
|
|
|
|
+ println(getTags(map, "a", Array[String]()))
|
|
}
|
|
}
|
|
}
|
|
}
|