Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdliu3 committed Jul 18, 2024
1 parent 1d7f959 commit f55c017
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 175 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.apache.seatunnel.connectors.doris.sink.writer.LoadConstants.JSON;
import static org.apache.seatunnel.connectors.doris.sink.writer.LoadConstants.NULL_VALUE;

public class SeaTunnelRowSerializer extends SeaTunnelRowConverter implements DorisSerializer {
public class SeaTunnelRowSerializer implements DorisSerializer {
String type;
private final SeaTunnelRowType seaTunnelRowType;
private final String fieldDelimiter;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public JsonNode convert(ObjectMapper mapper, JsonNode reuse, Object value) {
return createArrayConverter((ArrayType) type);
case MAP:
MapType mapType = (MapType) type;
return createMapConverter(
mapType.toString(), mapType.getKeyType(), mapType.getValueType());
return createMapConverter(mapType.getKeyType(), mapType.getValueType());
default:
throw new SeaTunnelJsonFormatException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,
Expand Down Expand Up @@ -270,15 +269,10 @@ public JsonNode convert(ObjectMapper mapper, JsonNode reuse, Object value) {
}

private RowToJsonConverter createMapConverter(
String typeSummary, SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {
if (!SqlType.STRING.equals(keyType.getSqlType())) {
throw new SeaTunnelJsonFormatException(
CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,
"JSON format doesn't support non-string as key type of map. The type is: "
+ typeSummary);
}

SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {
final RowToJsonConverter keyConverter = createConverter(keyType);
final RowToJsonConverter valueConverter = createConverter(valueType);

return new RowToJsonConverter() {
@Override
public JsonNode convert(ObjectMapper mapper, JsonNode reuse, Object value) {
Expand All @@ -292,9 +286,12 @@ public JsonNode convert(ObjectMapper mapper, JsonNode reuse, Object value) {
node.removeAll();
}

Map<String, ?> mapData = (Map) value;
for (Map.Entry<String, ?> entry : mapData.entrySet()) {
String fieldName = entry.getKey();
Map<?, ?> mapData = (Map) value;
for (Map.Entry<?, ?> entry : mapData.entrySet()) {
// Convert the key to a string using the key converter
JsonNode keyNode = keyConverter.convert(mapper, null, entry.getKey());
String fieldName = keyNode.isTextual() ? keyNode.asText() : keyNode.toString();

node.set(
fieldName,
valueConverter.convert(mapper, node.get(fieldName), entry.getValue()));
Expand Down

0 comments on commit f55c017

Please sign in to comment.