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
52eaf0dd
authored
Mar 13, 2025
by
魏建枢
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
代码优化
parent
317b825e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
81 deletions
eagleEye-udf/src/main/java/com/cloud/udf/CollectLogDeviceIdUpgrade.java
eagleEye-udf/src/main/java/com/cloud/udf/CollectLogDeviceIdUpgrade.java
View file @
52eaf0dd
...
...
@@ -2,6 +2,7 @@ package com.cloud.udf;
import
java.util.ArrayList
;
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
;
...
...
@@ -10,6 +11,18 @@ 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
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.cloud.udf.enums.AppTypeEnum
;
import
com.cloud.udf.util.GenDeviceIdV1
;
import
com.cloud.udf.vo.device.android.AndroidCollectionBody
;
import
com.cloud.udf.vo.device.android.deviceInfo.AndroidA1
;
import
com.cloud.udf.vo.device.android.envInfo.AndroidEnvInfo
;
import
com.cloud.udf.vo.device.android.otherInfo.OtherInfo
;
import
com.cloud.udf.vo.device.ios.IosCollectionBody
;
import
com.cloud.udf.vo.device.ios.IosDeviceInfo
;
import
com.cloud.udf.vo.device.ios.IosEnvInfo
;
/**
* @author wjs
* @version 创建时间:2025-3-12 10:48:22
...
...
@@ -17,101 +30,81 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn
*/
public
class
CollectLogDeviceIdUpgrade
extends
GenericUDTF
{
private
ArrayList
<
Object
[]>
result
=
new
ArrayList
<
Object
[]>();
@Override
public
StructObjectInspector
initialize
(
ObjectInspector
[]
argOIs
)
throws
UDFArgumentException
{
// 检测参数数量
if
(
argOIs
.
length
!=
21
)
{
throw
new
UDFArgumentException
(
"需要二十一个输入参数:id,device_id,uid,strategy_group_id,strategy_version,send_time,create_time,app_key,app_type,app_channel,zone_code,zone_name,zone_type,sdk_version,user_agent,other_info,device_info,env_info,user_properties,unique_id,dt"
);
}
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade initialize start! >>>>>>>"
+
(
argOIs
!=
null
?
argOIs
.
length
:
0
));
ArrayList
<
String
>
fieldNames
=
new
ArrayList
<
String
>();
ArrayList
<
ObjectInspector
>
fieldOIs
=
new
ArrayList
<
ObjectInspector
>();
fieldNames
.
add
(
"id"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"device_id"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"uid"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"strategy_group_id"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"strategy_version"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"send_time"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"create_time"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"app_key"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"app_type"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"app_channel"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"zone_code"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"zone_name"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"zone_type"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"sdk_version"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"user_agent"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"other_info"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"device_info"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"env_info"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"user_properties"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"unique_id"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
fieldNames
.
add
(
"dt"
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
try
{
// 初始化输出字段(所有字段类型为String)
String
[]
fields
=
{
"id"
,
"device_id"
,
"device_id_v1"
,
"uid"
,
"app_key"
,
"app_type"
,
"other_info"
,
"device_info"
,
"env_info"
,
"user_properties"
,
"unique_id"
,
"create_time"
,
"dt"
};
for
(
String
field
:
fields
)
{
fieldNames
.
add
(
field
);
fieldOIs
.
add
(
PrimitiveObjectInspectorFactory
.
javaStringObjectInspector
);
}
}
catch
(
Exception
e
)
{
throw
new
UDFArgumentException
(
"需要十二个输入参数:id,device_id,uid,app_key,app_type,other_info,device_info,env_info,user_properties,unique_id,create_time,dt >>>>>>:"
+
argOIs
.
length
);
}
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade 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
);
if
(
args
.
length
!=
21
)
{
throw
new
UDFArgumentException
(
"需要二十一个输入参数:id,device_id,uid,strategy_group_id,strategy_version,send_time,create_time,app_key,app_type,app_channel,zone_code,zone_name,zone_type,sdk_version,user_agent,other_info,device_info,env_info,user_properties,unique_id,dt"
);
}
String
id
=
args
[
0
].
toString
();
String
device_id
=
args
[
1
].
toString
();
String
uid
=
args
[
2
].
toString
();
String
strategy_group_id
=
args
[
3
].
toString
();
String
strategy_version
=
args
[
4
].
toString
();
String
send_time
=
args
[
5
].
toString
();
String
create_time
=
args
[
6
].
toString
();
String
app_key
=
args
[
7
].
toString
();
String
app_type
=
args
[
8
].
toString
();
String
app_channel
=
args
[
9
].
toString
();
String
zone_code
=
args
[
10
].
toString
();
String
zone_name
=
args
[
11
].
toString
();
String
zone_type
=
args
[
12
].
toString
();
String
sdk_version
=
args
[
13
].
toString
();
String
user_agent
=
args
[
14
].
toString
();
String
other_info
=
args
[
15
].
toString
();
String
device_info
=
args
[
16
].
toString
();
String
env_info
=
args
[
17
].
toString
();
String
user_properties
=
args
[
18
].
toString
();
String
unique_id
=
args
[
19
].
toString
();
String
dt
=
args
[
20
].
toString
();
result
.
add
(
new
Object
[]{
id
,
device_id
,
uid
,
strategy_group_id
,
strategy_version
,
send_time
,
create_time
,
app_key
,
app_type
,
app_channel
,
zone_code
,
zone_name
,
zone_type
,
sdk_version
,
user_agent
,
other_info
,
device_info
,
env_info
,
user_properties
,
unique_id
,
dt
});
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade process end!"
);
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
uid
=
args
[
2
]
!=
null
?
args
[
2
].
toString
()
:
null
;
String
app_key
=
args
[
3
]
!=
null
?
args
[
3
].
toString
()
:
null
;
String
app_type
=
args
[
4
]
!=
null
?
args
[
4
].
toString
()
:
null
;
String
other_info
=
args
[
5
]
!=
null
?
args
[
5
].
toString
()
:
null
;
String
device_info
=
args
[
6
]
!=
null
?
args
[
6
].
toString
()
:
null
;
String
env_info
=
args
[
7
]
!=
null
?
args
[
7
].
toString
()
:
null
;
String
user_properties
=
args
[
8
]
!=
null
?
args
[
8
].
toString
()
:
null
;
String
unique_id
=
args
[
9
]
!=
null
?
args
[
9
].
toString
()
:
null
;
String
create_time
=
args
[
10
]
!=
null
?
args
[
10
].
toString
()
:
null
;
String
dt
=
args
[
11
]
!=
null
?
args
[
11
].
toString
()
:
null
;
String
device_id_v1
=
genDeviceId
(
app_type
,
other_info
,
device_info
,
env_info
);
forward
(
new
Object
[]{
id
,
device_id
,
device_id_v1
,
uid
,
app_key
,
app_type
,
other_info
,
device_info
,
env_info
,
user_properties
,
unique_id
,
create_time
,
dt
});
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade process end!"
);
}
catch
(
Exception
e
)
{
throw
new
UDFArgumentException
(
"需要十二个输入参数:id,device_id,uid,app_key,app_type,other_info,device_info,env_info,user_properties,unique_id,create_time,dt >>>>>:"
+
args
.
length
);
}
System
.
out
.
println
(
"CollectLogDeviceIdUpgrade process end!"
);
}
@Override
public
void
close
()
throws
HiveException
{
for
(
Object
[]
r
:
result
)
{
forward
(
r
);
}
result
.
clear
();
}
private
String
genDeviceId
(
String
appType
,
String
other_info
,
String
device_info
,
String
env_info
)
{
String
deviceId
=
null
;
if
(
StringUtils
.
equals
(
appType
,
AppTypeEnum
.
ANDROID
.
getCode
()))
{
AndroidA1
a1
=
JSONObject
.
parseObject
(
device_info
,
new
TypeReference
<
AndroidA1
>(){});
AndroidEnvInfo
g1
=
JSONObject
.
parseObject
(
env_info
,
new
TypeReference
<
AndroidEnvInfo
>(){});
OtherInfo
i1
=
JSONObject
.
parseObject
(
other_info
,
new
TypeReference
<
OtherInfo
>(){});
AndroidCollectionBody
androidBodyObj
=
new
AndroidCollectionBody
();
androidBodyObj
.
setA1
(
a1
);
androidBodyObj
.
setG1
(
g1
);
androidBodyObj
.
setI1
(
i1
);
deviceId
=
GenDeviceIdV1
.
genAndroidDeviceIdHashV1
(
androidBodyObj
);
}
else
if
(
StringUtils
.
equals
(
appType
,
AppTypeEnum
.
IOS
.
getCode
()))
{
IosDeviceInfo
a1
=
JSONObject
.
parseObject
(
device_info
,
new
TypeReference
<
IosDeviceInfo
>(){});
IosEnvInfo
g1
=
JSONObject
.
parseObject
(
env_info
,
new
TypeReference
<
IosEnvInfo
>(){});
IosCollectionBody
iosBodyObj
=
new
IosCollectionBody
();
iosBodyObj
.
setA1
(
a1
);
iosBodyObj
.
setG1
(
g1
);
deviceId
=
GenDeviceIdV1
.
genIosDeviceIdHash
(
iosBodyObj
);
}
return
deviceId
;
}
}
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