Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
eagleEye
/
eagleEye-udf
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3daa838d
authored
Mar 18, 2025
by
魏建枢
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
udtf
parent
105020b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
306 additions
and
99 deletions
eagleEye-udf/src/main/java/com/cloud/udf/AndoridJsonToRow.java
eagleEye-udf/src/main/java/com/cloud/udf/IpToConvert.java
eagleEye-udf/src/main/java/com/cloud/udf/JsonToRow.java
eagleEye-udf/src/main/java/com/cloud/udf/vo/jsonToRow/UserProperties.java
eagleEye-udf/src/main/java/com/cloud/udf/AndoridJsonToRow.java
0 → 100644
View file @
3daa838d
package
com
.
cloud
.
udf
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.hadoop.hive.ql.exec.UDFArgumentException
;
import
org.apache.hadoop.hive.ql.metadata.HiveException
;
import
org.apache.hadoop.hive.ql.udf.generic.GenericUDTF
;
import
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector
;
import
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory
;
import
org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector
;
import
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
;
import
org.apache.hive.com.esotericsoftware.minlog.Log
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.cloud.udf.vo.jsonToRow.EventLog
;
import
com.cloud.udf.vo.jsonToRow.UserProperties
;
/**
* @author wjs
* @version 创建时间:2025-3-18 10:58:29
* 类说明
*/
public
class
AndoridJsonToRow
extends
GenericUDTF
{
@Override
public
StructObjectInspector
initialize
(
ObjectInspector
[]
argOIs
)
throws
UDFArgumentException
{
// 检测参数数量
ArrayList
<
String
>
fieldNames
=
new
ArrayList
<
String
>();
ArrayList
<
ObjectInspector
>
fieldOIs
=
new
ArrayList
<
ObjectInspector
>();
try
{
// 初始化输出字段(所有字段类型为String)
String
[]
fields
=
{
"id"
,
"device_id"
,
"unique_id"
,
"uid"
,
"app_key"
,
"view_type"
,
"view_id"
,
"content"
,
"screen_name"
,
"touch_pressure"
,
"draw_point"
,
"cid"
,
"phone"
,
"nick"
,
"route_ip"
,
"send_time"
,
"event"
,
"event_time"
,
"zone_code"
,
"dt"
};
for
(
String
field
:
fields
)
{
fieldNames
.
add
(
field
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
}
}
catch
(
Exception
e
)
{
throw
new
UDFArgumentException
(
"需要十个输入参数:id,device_id,unique_id,uid,app_key,event_list,route_ip,send_time,dt,user_properties,zone_code >>>>>:"
+
argOIs
.
length
);
}
System
.
out
.
println
(
"AndoridJsonToRow initialize end! >>>>>>> fieldNames:"
+
fieldNames
+
"<<<<<<<<<:"
+
fieldOIs
);
return
ObjectInspectorFactory
.
getStandardStructObjectInspector
(
fieldNames
,
fieldOIs
);
}
@Override
public
void
process
(
Object
[]
args
)
throws
HiveException
{
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade process start! args:"
+
(
args
!=
null
?
args
.
length
:
0
));
try
{
String
id
=
args
[
0
]
!=
null
?
args
[
0
].
toString
()
:
null
;
String
device_id
=
args
[
1
]
!=
null
?
args
[
1
].
toString
()
:
null
;
String
unique_id
=
args
[
2
]
!=
null
?
args
[
2
].
toString
()
:
null
;
String
uid
=
args
[
3
]
!=
null
?
args
[
3
].
toString
()
:
null
;
String
app_key
=
args
[
4
]
!=
null
?
args
[
4
].
toString
()
:
null
;
String
jsonStr
=
args
[
5
]
!=
null
?
args
[
5
].
toString
()
:
null
;
String
route_ip
=
args
[
6
]
!=
null
?
args
[
6
].
toString
()
:
null
;
String
send_time
=
args
[
7
]
!=
null
?
args
[
7
].
toString
()
:
null
;
String
dt
=
args
[
8
]
!=
null
?
args
[
8
].
toString
()
:
null
;
String
user_properties
=
args
[
9
]
!=
null
?
args
[
9
].
toString
()
:
null
;
String
zone_code
=
args
[
10
]
!=
null
?
args
[
10
].
toString
()
:
null
;
String
cid
=
null
;
String
phone
=
null
;
String
nick
=
null
;
if
(
StringUtils
.
isNotEmpty
(
user_properties
))
{
List
<
UserProperties
>
userProperties
=
JSONObject
.
parseObject
(
user_properties
,
new
TypeReference
<
List
<
UserProperties
>>(){});
if
(
userProperties
!=
null
&&
userProperties
.
size
()
>
0
)
{
for
(
UserProperties
user
:
userProperties
)
{
if
(
StringUtils
.
isNotEmpty
(
user
.
getCid
()))
{
cid
=
user
.
getCid
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getPhone
()))
{
phone
=
user
.
getPhone
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getId
()))
{
cid
=
user
.
getId
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getNick
()))
{
nick
=
user
.
getNick
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getEmail
()))
{
nick
=
user
.
getEmail
();
}
}
System
.
out
.
println
(
cid
+
">>"
+
phone
+
">>"
+
nick
);
}
}
if
(
StringUtils
.
isNotEmpty
(
jsonStr
))
{
List
<
EventLog
>
eventList
=
JSONObject
.
parseObject
(
jsonStr
,
new
TypeReference
<
List
<
EventLog
>>(){});
System
.
out
.
println
(
"AndoridJsonToRow process eventList:"
+
eventList
!=
null
?
eventList
.
size
():
0
);
if
(
eventList
!=
null
&&
eventList
.
size
()
>
0
)
{
for
(
EventLog
eventLog
:
eventList
)
{
String
event
=
eventLog
.
getR7
();
Long
event_time
=
eventLog
.
getR9
();
String
view_type
=
eventLog
.
getR8
().
getR1
();
String
view_id
=
eventLog
.
getR8
().
getR2
();
String
content
=
eventLog
.
getR8
().
getR3
();
String
screen_name
=
eventLog
.
getR8
().
getR4
();
String
touch_pressure
=
eventLog
.
getR8
().
getR5
();
String
draw_point
=
eventLog
.
getR8
().
getR6
()
==
null
?
null
:
eventLog
.
getR8
().
getR6
().
toString
();
forward
(
new
Object
[]{
id
,
device_id
,
unique_id
,
uid
,
app_key
,
view_type
,
view_id
,
content
,
screen_name
,
touch_pressure
,
draw_point
,
cid
,
phone
,
nick
,
route_ip
,
send_time
,
event
,
event_time
,
zone_code
,
dt
});
}
}
Log
.
info
(
"AndoridJsonToRow process eventList end!"
);
}
System
.
out
.
println
(
"AndoridJsonToRow process end!"
);
}
catch
(
Exception
e
)
{
throw
new
UDFArgumentException
(
"需要十个输入参数:id,device_id,unique_id,uid,app_key,event_list,route_ip,send_time,dt,user_properties,zone_code >>>>>:"
+
args
.
length
);
}
System
.
out
.
println
(
"AndoridJsonToRow process end!"
);
}
@Override
public
void
close
()
throws
HiveException
{
// TODO Auto-generated method stub
}
public
static
void
main
(
String
[]
args
)
{
String
user_properties
=
"[{\"id\":\"5676jypto\"}, {\"phone\":\"18177755676\"}, {\"nick\":\"DW20戴维支持\"}]"
;
List
<
UserProperties
>
userProperties
=
JSONObject
.
parseObject
(
user_properties
,
new
TypeReference
<
List
<
UserProperties
>>(){});
if
(
userProperties
!=
null
&&
userProperties
.
size
()
>
0
)
{
String
cid
=
null
;
String
phone
=
null
;
String
nick
=
null
;
for
(
UserProperties
user
:
userProperties
)
{
if
(
StringUtils
.
isNotEmpty
(
user
.
getCid
()))
{
cid
=
user
.
getCid
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getPhone
()))
{
phone
=
user
.
getPhone
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getId
()))
{
cid
=
user
.
getId
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getNick
()))
{
nick
=
user
.
getNick
();
}
else
if
(
StringUtils
.
isNotEmpty
(
user
.
getEmail
()))
{
nick
=
user
.
getEmail
();
}
}
System
.
out
.
println
(
cid
+
">>"
+
phone
+
">>"
+
nick
);
}
}
}
eagleEye-udf/src/main/java/com/cloud/udf/IpToConvert.java
View file @
3daa838d
...
...
@@ -23,80 +23,47 @@ import com.cloud.udf.util.SearcherUtil;
*/
public
class
IpToConvert
extends
GenericUDTF
{
private
ArrayList
<
Object
[]>
result
=
new
ArrayList
<
Object
[]>();
@Override
public
StructObjectInspector
initialize
(
ObjectInspector
[]
argOIs
)
throws
UDFArgumentException
{
// 检测参数数量
if
(
argOIs
.
length
!=
6
)
{
throw
new
UDFArgumentException
(
"需要六个输入参数:id,ip,cid,phone,nick,dt"
);
}
ArrayList
<
String
>
fieldNames
=
new
ArrayList
<
String
>();
ArrayList
<
ObjectInspector
>
fieldOIs
=
new
ArrayList
<
ObjectInspector
>();
fieldNames
.
add
(
"id"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"ip"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"area_name"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"cid"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"phone"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"nick"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"dt"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
try
{
// 初始化输出字段(所有字段类型为String)
String
[]
fields
=
{
"id"
,
"ip"
,
"area_name"
,
"cid"
,
"phone"
,
"nick"
,
"dt"
};
for
(
String
field
:
fields
)
{
fieldNames
.
add
(
field
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
}
}
catch
(
Exception
e
)
{
throw
new
UDFArgumentException
(
"需要六个输入参数:id,ip,cid,phone,nick,dt"
);
}
return
ObjectInspectorFactory
.
getStandardStructObjectInspector
(
fieldNames
,
fieldOIs
);
}
@Override
public
void
process
(
Object
[]
args
)
throws
HiveException
{
System
.
out
.
println
(
"IpToConvert process start! args:"
+
args
!=
null
?
args
.
length
:
0
);
if
(
args
.
length
!=
6
)
{
throw
new
HiveException
(
"需要六个输入参数:id,ip,cid,phone,nick,dt"
);
}
String
id
=
null
;
if
(
args
[
0
]
!=
null
)
{
id
=
args
[
0
].
toString
();
}
String
ip
=
args
[
1
].
toString
();
String
cid
=
null
;
if
(
args
[
2
]
!=
null
)
{
cid
=
args
[
2
].
toString
();
}
String
phone
=
null
;
if
(
args
[
3
]
!=
null
)
{
phone
=
args
[
3
].
toString
();
}
String
nick
=
null
;
if
(
args
[
4
]
!=
null
)
{
nick
=
args
[
4
].
toString
();
}
String
dt
=
null
;
if
(
args
[
5
]
!=
null
)
{
dt
=
args
[
5
].
toString
();
}
String
area_name
=
null
;
try
{
area_name
=
SearcherUtil
.
getCityInfoByFile
(
ip
);
try
{
String
id
=
args
[
0
]
!=
null
?
args
[
0
].
toString
()
:
null
;
String
ip
=
args
[
1
]
!=
null
?
args
[
1
].
toString
()
:
null
;
String
cid
=
args
[
2
]
!=
null
?
args
[
2
].
toString
()
:
null
;
String
phone
=
args
[
3
]
!=
null
?
args
[
3
].
toString
()
:
null
;
String
nick
=
args
[
4
]
!=
null
?
args
[
4
].
toString
()
:
null
;
String
dt
=
args
[
5
]
!=
null
?
args
[
5
].
toString
()
:
null
;
String
area_name
=
SearcherUtil
.
getCityInfoByFile
(
ip
);
forward
(
new
Object
[]{
id
,
ip
,
area_name
,
cid
,
phone
,
nick
,
dt
});
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"ip:"
+
ip
+
"e:"
+
e
.
toString
());
System
.
out
.
println
(
"e:"
+
e
.
toString
());
throw
new
HiveException
(
"需要六个输入参数:id,ip,cid,phone,nick,dt"
);
}
result
.
add
(
new
Object
[]{
id
,
ip
,
area_name
,
cid
,
phone
,
nick
,
dt
});
System
.
out
.
println
(
"IpToConvert process end!"
);
}
@Override
public
void
close
()
throws
HiveException
{
for
(
Object
[]
r
:
result
)
{
forward
(
r
);
}
result
.
clear
();
}
private
Boolean
ipv6
(
String
ip
)
{
...
...
eagleEye-udf/src/main/java/com/cloud/udf/JsonToRow.java
View file @
3daa838d
package
com
.
cloud
.
udf
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -16,6 +17,8 @@ import com.alibaba.fastjson.JSONException;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.cloud.udf.vo.jsonToRow.EventLog
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
/**
* @author wjs
...
...
@@ -27,7 +30,7 @@ import com.cloud.udf.vo.jsonToRow.EventLog;
//https://blog.51cto.com/u_16175470/8961128 udtf
public
class
JsonToRow
extends
GenericUDTF
{
private
ArrayList
<
Object
[]>
result
=
new
ArrayList
<
Object
[]>();
//
private ArrayList<Object[]> result = new ArrayList<Object[]>();
@Override
public
StructObjectInspector
initialize
(
ObjectInspector
[]
argOIs
)
throws
UDFArgumentException
{
...
...
@@ -89,26 +92,26 @@ public class JsonToRow extends GenericUDTF{
throw
new
HiveException
(
"需要按顺序输入二十个参数:id,send_time,create_time,strategy_group_id,app_key,app_type,app_channel,zone_code,zone_name,zone_type,sdk_version,user_agent,device_id,uid,strategy_version,event_list,route_ip,user_properties,unique_id,dt"
);
}
String
id
=
args
[
0
].
toString
()
;
String
send_time
=
args
[
1
]
.
toString
()
;
String
create_time
=
args
[
2
]
.
toString
()
;
String
strategy_group_id
=
args
[
3
]
.
toString
()
;
String
app_key
=
args
[
4
]
.
toString
()
;
String
app_type
=
args
[
5
]
.
toString
()
;
String
app_channel
=
args
[
6
]
.
toString
()
;
String
zone_code
=
args
[
7
]
.
toString
()
;
String
zone_name
=
args
[
8
]
.
toString
()
;
String
zone_type
=
args
[
9
]
.
toString
()
;
String
sdk_version
=
args
[
10
]
.
toString
()
;
String
user_agent
=
args
[
11
]
.
toString
()
;
String
device_id
=
args
[
12
]
.
toString
()
;
String
uid
=
args
[
13
]
.
toString
()
;
String
strategy_version
=
args
[
14
]
.
toString
()
;
String
jsonStr
=
args
[
15
]
.
toString
()
;
String
route_ip
=
args
[
16
]
.
toString
()
;
String
user_properties
=
args
[
17
]
.
toString
()
;
String
unique_id
=
args
[
18
]
.
toString
()
;
String
dt
=
args
[
19
]
.
toString
()
;
String
id
=
args
[
0
]
!=
null
?
args
[
0
].
toString
()
:
null
;
String
send_time
=
args
[
1
]
!=
null
?
args
[
1
].
toString
()
:
null
;
String
create_time
=
args
[
2
]
!=
null
?
args
[
2
].
toString
()
:
null
;
String
strategy_group_id
=
args
[
3
]
!=
null
?
args
[
3
].
toString
()
:
null
;
String
app_key
=
args
[
4
]
!=
null
?
args
[
4
].
toString
()
:
null
;
String
app_type
=
args
[
5
]
!=
null
?
args
[
5
].
toString
()
:
null
;
String
app_channel
=
args
[
6
]
!=
null
?
args
[
6
].
toString
()
:
null
;
String
zone_code
=
args
[
7
]
!=
null
?
args
[
7
].
toString
()
:
null
;
String
zone_name
=
args
[
8
]
!=
null
?
args
[
8
].
toString
()
:
null
;
String
zone_type
=
args
[
9
]
!=
null
?
args
[
9
].
toString
()
:
null
;
String
sdk_version
=
args
[
10
]
!=
null
?
args
[
10
].
toString
()
:
null
;
String
user_agent
=
args
[
11
]
!=
null
?
args
[
11
].
toString
()
:
null
;
String
device_id
=
args
[
12
]
!=
null
?
args
[
12
].
toString
()
:
null
;
String
uid
=
args
[
13
]
!=
null
?
args
[
13
].
toString
()
:
null
;
String
strategy_version
=
args
[
14
]
!=
null
?
args
[
14
].
toString
()
:
null
;
String
jsonStr
=
args
[
15
]
!=
null
?
args
[
15
].
toString
()
:
null
;
String
route_ip
=
args
[
16
]
!=
null
?
args
[
16
].
toString
()
:
null
;
String
user_properties
=
args
[
17
]
!=
null
?
args
[
17
].
toString
()
:
null
;
String
unique_id
=
args
[
18
]
!=
null
?
args
[
18
].
toString
()
:
null
;
String
dt
=
args
[
19
]
!=
null
?
args
[
19
].
toString
()
:
null
;
try
{
List
<
EventLog
>
eventList
=
JSONObject
.
parseObject
(
jsonStr
,
new
TypeReference
<
List
<
EventLog
>>(){});
...
...
@@ -122,12 +125,29 @@ public class JsonToRow extends GenericUDTF{
jsonObj
.
put
(
"r9"
,
eventLog
.
getR9
());
String
event_list
=
jsonObj
.
toJSONString
();
result
.
ad
d
(
new
Object
[]{
id
,
send_time
,
create_time
,
strategy_group_id
,
app_key
,
app_type
,
app_channel
,
zone_code
,
zone_name
,
zone_type
,
sdk_version
,
user_agent
,
device_id
,
uid
,
strategy_version
,
event_list
,
route_ip
,
user_properties
,
unique_id
,
dt
});
forwar
d
(
new
Object
[]{
id
,
send_time
,
create_time
,
strategy_group_id
,
app_key
,
app_type
,
app_channel
,
zone_code
,
zone_name
,
zone_type
,
sdk_version
,
user_agent
,
device_id
,
uid
,
strategy_version
,
event_list
,
route_ip
,
user_properties
,
unique_id
,
dt
});
}
}
Log
.
info
(
"JsonToRow process eventList end!"
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
jsonStr
.
replaceAll
(
"(\\w+):"
,
"\"$1\":"
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
// 解析 JSON 数组
JsonNode
jsonArray
=
objectMapper
.
readTree
(
jsonStr
);
for
(
JsonNode
jsonNode
:
jsonArray
)
{
EventLog
eventLog
=
JSONObject
.
parseObject
(
jsonNode
.
asText
(),
new
TypeReference
<
EventLog
>(){});
JSONObject
jsonObj
=
new
JSONObject
();
jsonObj
.
put
(
"r7"
,
eventLog
.
getR7
());
jsonObj
.
put
(
"r8"
,
eventLog
.
getR8
());
jsonObj
.
put
(
"r9"
,
eventLog
.
getR9
());
String
event_list
=
jsonObj
.
toJSONString
();
forward
(
new
Object
[]{
id
,
send_time
,
create_time
,
strategy_group_id
,
app_key
,
app_type
,
app_channel
,
zone_code
,
zone_name
,
zone_type
,
sdk_version
,
user_agent
,
device_id
,
uid
,
strategy_version
,
event_list
,
route_ip
,
user_properties
,
unique_id
,
dt
});
// result.add(new Object[]{id,send_time,create_time,strategy_group_id,app_key,app_type,app_channel,zone_code,zone_name,zone_type,sdk_version,user_agent,device_id,uid,strategy_version,event_list,route_ip,user_properties,unique_id,dt});
}
}
catch
(
IOException
e1
)
{
System
.
out
.
println
(
"JsonToRow process e:"
+
e1
.
toString
());
}
System
.
out
.
println
(
"JsonToRow process e:"
+
e
.
toString
());
}
finally
{
System
.
out
.
println
(
"JsonToRow process end!"
);
...
...
@@ -136,30 +156,53 @@ public class JsonToRow extends GenericUDTF{
@Override
public
void
close
()
throws
HiveException
{
for
(
Object
[]
r
:
result
)
{
forward
(
r
);
}
result
.
clear
();
//
for (Object[] r : result) {
//
forward(r);
//
}
//
result.clear();
}
public
static
void
main
(
String
[]
args
)
{
String
jsonStr
=
"[{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"303.00&.2603.333328\",\"300.67&631.00\",\"300.67&631.00\",\"299.67&664.67\",\"299.67&703.33\",\"299.67&703.33\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355286000},{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"282.33&.2594.000000\",\"282.33&596.33\",\"282.33&596.33\",\"282.33&599.00\",\"283.00&601.00\",\"283.67&602.00\",\"283.67&603.00\",\"283.67&603.33\",\"283.67&603.00\",\"283.67&603.00\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355287000},{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"39.67&.2681.666656\",\"47.00&681.67\",\"47.00&681.67\",\"54.67&681.67\",\"63.67&681.67\",\"75.33&679.33\",\"92.67&675.00\",\"116.00&667.67\",\"128.67&663.33\",\"165.00&651.67\",\"191.00&640.67\",\"206.67&634.33\",\"206.67&634.33\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355288000}]"
;
List
<
EventLog
>
eventList
=
JSONObject
.
parseObject
(
jsonStr
,
new
TypeReference
<
List
<
EventLog
>>(){});
System
.
out
.
println
(
"JsonToRow process eventList:"
+
eventList
!=
null
?
eventList
.
size
():
0
);
ArrayList
<
Object
[]>
result
=
new
ArrayList
<
Object
[]>();
if
(
eventList
!=
null
&&
eventList
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
eventList
.
size
();
i
++)
{
EventLog
eventLog
=
eventList
.
get
(
i
);
JSONObject
jsonObj
=
new
JSONObject
();
jsonObj
.
put
(
"r7"
,
eventLog
.
getR7
());
jsonObj
.
put
(
"r8"
,
eventLog
.
getR8
());
jsonObj
.
put
(
"r9"
,
eventLog
.
getR9
());
String
event_list
=
jsonObj
.
toJSONString
();
result
.
add
(
new
Object
[]{
event_list
});
}
// String jsonStr = "[{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"303.00&.2603.333328\",\"300.67&631.00\",\"300.67&631.00\",\"299.67&664.67\",\"299.67&703.33\",\"299.67&703.33\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355286000},{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"282.33&.2594.000000\",\"282.33&596.33\",\"282.33&596.33\",\"282.33&599.00\",\"283.00&601.00\",\"283.67&602.00\",\"283.67&603.00\",\"283.67&603.33\",\"283.67&603.00\",\"283.67&603.00\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355287000},{\"r7\":\"r10\",\"r8\":{\"r2\":12299,\"r3\":\"\",\"r6\":[\"39.67&.2681.666656\",\"47.00&681.67\",\"47.00&681.67\",\"54.67&681.67\",\"63.67&681.67\",\"75.33&679.33\",\"92.67&675.00\",\"116.00&667.67\",\"128.67&663.33\",\"165.00&651.67\",\"191.00&640.67\",\"206.67&634.33\",\"206.67&634.33\"],\"s2\":[{\"cid\":\"7647hcmut\"},{\"phone\":\"16631557647\"},{\"nick\":\"共享母猪\"}],\"r1\":\"RCTView\"},\"r9\":1740355288000}]";
// List<EventLog> eventList = JSONObject.parseObject(jsonStr,new TypeReference<List<EventLog>>(){});
// System.out.println("JsonToRow process eventList:"+eventList !=null ? eventList.size():0);
// ArrayList<Object[]> result = new ArrayList<Object[]>();
// if(eventList != null && eventList.size() > 0) {
// for (int i = 0; i < eventList.size(); i++) {
// EventLog eventLog = eventList.get(i);
// JSONObject jsonObj = new JSONObject();
// jsonObj.put("r7", eventLog.getR7());
// jsonObj.put("r8", eventLog.getR8());
// jsonObj.put("r9", eventLog.getR9());
//
// String event_list=jsonObj.toJSONString();
// result.add(new Object[]{event_list});
// }
// }
// System.out.println(">>>>>>>>>>>>>>:"+result);
//json解析
String
jsonStr
=
"[\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460777000,\\\"r8\\\":{\\\"r4\\\":\\\"MessageScreen\\\",\\\"r3\\\":\\\"2 王大锤 19:59 分几次转就可以了\\\",\\\"r6\\\":\\\"[\\\\\\\"199.33&221.00\\\\\\\"]\\\",\\\"r2\\\":215,\\\"r1\\\":\\\"RCTView\\\"}}\",\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460788000,\\\"r8\\\":{\\\"r4\\\":\\\"SingleChat\\\",\\\"r6\\\":\\\"[\\\\\\\"199.33&221.00\\\\\\\"]\\\",\\\"r2\\\":23367,\\\"r1\\\":\\\"RCTMultilineTextInputView\\\"}}\",\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460793000,\\\"r8\\\":{\\\"r4\\\":\\\"SingleChat\\\",\\\"r6\\\":\\\"[\\\\\\\"31.67&70.67\\\\\\\"]\\\",\\\"r2\\\":23325,\\\"r1\\\":\\\"RCTView\\\"}}\",\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460798000,\\\"r8\\\":{\\\"r4\\\":\\\"MessageScreen\\\",\\\"r3\\\":\\\"王大锤 19:59 分几次转就可以了\\\",\\\"r6\\\":\\\"[\\\\\\\"251.00&205.67\\\\\\\"]\\\",\\\"r2\\\":215,\\\"r1\\\":\\\"RCTView\\\"}}\",\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460799000,\\\"r8\\\":{\\\"r4\\\":\\\"SingleChat\\\",\\\"r6\\\":\\\"[\\\\\\\"251.00&205.67\\\\\\\"]\\\",\\\"r2\\\":24227,\\\"r1\\\":\\\"RCTMultilineTextInputView\\\"}}\",\"{\\\"r7\\\":\\\"r10\\\",\\\"r9\\\":1737460811000,\\\"r8\\\":{\\\"r4\\\":\\\"SingleChat\\\",\\\"r6\\\":\\\"[\\\\\\\"362.33&464.67\\\\\\\"]\\\",\\\"r2\\\":25045,\\\"r1\\\":\\\"RCTView\\\"}}\"]"
;
try
{
jsonStr
.
replaceAll
(
"(\\w+):"
,
"\"$1\":"
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
// 解析 JSON 数组
JsonNode
jsonArray
=
objectMapper
.
readTree
(
jsonStr
);
for
(
JsonNode
jsonNode
:
jsonArray
)
{
String
aa
=
jsonNode
.
asText
();
EventLog
eventList
=
JSONObject
.
parseObject
(
aa
,
new
TypeReference
<
EventLog
>(){});
System
.
out
.
println
(
eventList
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
toString
());
}
System
.
out
.
println
(
">>>>>>>>>>>>>>:"
+
result
);
}
}
eagleEye-udf/src/main/java/com/cloud/udf/vo/jsonToRow/UserProperties.java
0 → 100644
View file @
3daa838d
package
com
.
cloud
.
udf
.
vo
.
jsonToRow
;
import
java.io.Serializable
;
/**
* @author wjs
* @version 创建时间:2025-3-18 11:15:27
* 类说明
*/
public
class
UserProperties
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
String
cid
;
private
String
id
;
private
String
phone
;
private
String
email
;
private
String
nick
;
public
String
getCid
()
{
return
cid
;
}
public
void
setCid
(
String
cid
)
{
this
.
cid
=
cid
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getNick
()
{
return
nick
;
}
public
void
setNick
(
String
nick
)
{
this
.
nick
=
nick
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment