Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
799702f6
Commit
799702f6
authored
Jan 15, 2025
by
liuwenhui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kafka添加key
parent
602845f1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
KeySerializationSchema.java
...main/java/org/dinky/cdc/kafka/KeySerializationSchema.java
+38
-0
No files found.
dinky-cdc/dinky-cdc-core/src/main/java/org/dinky/cdc/kafka/KeySerializationSchema.java
0 → 100644
View file @
799702f6
package
org
.
dinky
.
cdc
.
kafka
;
import
org.apache.flink.api.common.serialization.SerializationSchema
;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
KeySerializationSchema
implements
SerializationSchema
<
String
>
{
private
static
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
@Override
public
byte
[]
serialize
(
String
element
)
{
try
{
Map
<
String
,
Object
>
map
=
OBJECT_MAPPER
.
readValue
(
element
,
Map
.
class
);
LinkedHashMap
source
=
(
LinkedHashMap
)
map
.
get
(
"source"
);
String
db
=
source
.
get
(
"db"
).
toString
();
String
tableName
=
source
.
get
(
"table"
).
toString
();
String
schema
=
source
.
containsKey
(
"schema"
)
?
source
.
get
(
"schema"
).
toString
()
:
""
;
if
(
schema
.
isEmpty
())
{
return
(
db
+
"."
+
tableName
).
getBytes
();
}
else
{
return
(
db
+
"."
+
schema
+
"."
+
tableName
).
getBytes
();
}
}
catch
(
Exception
e
)
{
// 记录更详细的日志信息
System
.
err
.
println
(
"Failed to serialize element: "
+
element
);
e
.
printStackTrace
();
// 返回空字节数组,避免返回 null
return
new
byte
[
0
];
}
}
}
\ No newline at end of file
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