Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EventTracking
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨林
EventTracking
Commits
7220e9e1
Commit
7220e9e1
authored
Jul 23, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
入口文件
parent
c2767332
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
10 deletions
+95
-10
src/main/scala/entry/Entry.scala
src/main/scala/entry/Entry.scala
+95
-10
No files found.
src/main/scala/entry/Entry.scala
View file @
7220e9e1
package
entry
import
flink.GetEnvironment
import
flink.FlinkEnv
import
model.TrackItem
import
org.apache.flink.streaming.api.scala.
{
DataStream
,
createTypeInformation
}
import
org.apache.flink.table.api.SqlDialect
import
org.apache.flink.table.api.bridge.scala.StreamTableEnvironment
import
org.apache.flink.table.catalog.hive.HiveCatalog
import
tools.auth.KerberosAuth
import
tools.dataprocess.DataFormat
import
tools.json.JsonUtils
import
tools.kafka.KafkaConsumer
import
tools.properties.PropertiesTools
import
java.util.Properties
import
scala.language.postfixOps
/**
* Created with IntelliJ IDEA.
...
...
@@ -10,13 +23,85 @@ import flink.GetEnvironment
* Date: 2021-07-16
* Time: 9:34
*/
object
Entry
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
// 创建flink环境
val
env
=
GetEnvironment
.
env
// 添加kafka源
// 添加hive sink
env
.
execute
()
}
object
Entry
extends
App
{
//认证
KerberosAuth
.
auth
()
// 创建flink环境
val
env
=
FlinkEnv
.
env
// 添加kafka源
val
kafka
=
KafkaConsumer
.
getConsumer
// 设置从头开始消费
kafka
.
setStartFromEarliest
()
// 数据处理流程
private
val
dsa
:
DataStream
[
TrackItem
]
=
env
.
addSource
(
kafka
)
// 数据清洗
.
map
(
elem
=>
{
// val res = mutable.HashMap[String, String]()
val
map
=
JsonUtils
parseFirstKey
elem
map
.
getOrElse
(
"data"
,
""
)
})
.
filter
(
_
.
nonEmpty
)
.
map
(
x
=>
DataFormat
.
formatTrack
(
x
)
)
private
val
tEnv
:
StreamTableEnvironment
=
FlinkEnv
.
tEnv
private
val
properties
:
Properties
=
PropertiesTools
.
getProperties
private
val
catalog
:
String
=
properties
.
getProperty
(
"hive.catalog"
)
private
val
hiveDir
:
String
=
properties
.
getProperty
(
"hive.config.path"
)
private
val
hive
=
new
HiveCatalog
(
catalog
,
"default"
,
hiveDir
)
tEnv
.
registerCatalog
(
catalog
,
hive
)
tEnv
.
useCatalog
(
catalog
)
tEnv
.
getConfig
.
setSqlDialect
(
SqlDialect
.
HIVE
)
tEnv
.
useDatabase
(
"qm_tmp"
)
tEnv
.
createTemporaryView
(
"event"
,
dsa
)
private
val
sql
:
String
=
"""
|insert into qm_tmp.event_track partition(dt,hr,mm)
|select
| track_id,
| distinct_id,
| lib_detail,
| lib_version,
| lib,
| app_version,
| lib_method,
| event_name,
| type,
| properties,
| HOST,
| user_agent,
| ua_platform,
| ua_version,
| ua_language,
| connection,
| Pragma,
| cache_control,
| accept,
| accept_encoding,
| ip,
| ip_info,
| url,
| referrer,
| remark,
| user_id,
| created_at,
| from_unixtime(unix_timestamp(created_at),'yyyy-MM-dd') as dt,
| from_unixtime(unix_timestamp(created_at),'HH') as hr,
| from_unixtime(unix_timestamp(created_at),'mm') as mm
| from event
|"""
.
stripMargin
tEnv
.
executeSql
(
sql
).
print
()
env
.
execute
(
"event_track"
)
}
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