JNSimba commented on code in PR #167:
URL:
https://github.com/apache/doris-flink-connector/pull/167#discussion_r1281849015
##########
flink-doris-connector/src/main/java/org/apache/doris/flink/sink/writer/JsonDebeziumSchemaSerializer.java:
##########
@@ -277,6 +371,68 @@ private String authHeader() {
return "Basic " + new
String(Base64.encodeBase64((dorisOptions.getUsername() + ":" +
dorisOptions.getPassword()).getBytes(StandardCharsets.UTF_8)));
}
+ private void fillOriginSchema(JsonNode columns) {
+ if (Objects.nonNull(originFieldSchemaMap)) {
+ for (JsonNode column : columns) {
+ String fieldName = column.get("name").asText();
+ if (originFieldSchemaMap.containsKey(fieldName)) {
+ JsonNode length = column.get("length");
+ JsonNode scale = column.get("scale");
+ String type =
MysqlType.toDorisType(column.get("typeName").asText(),
+ length == null ? 0 : length.asInt(),
+ scale == null ? 0 : scale.asInt());
+ String defaultValue =
handleDefaultValue(extractJsonNode(column, "defaultValueExpression"));
+ String comment = extractJsonNode(column, "comment");
+ FieldSchema fieldSchema =
originFieldSchemaMap.get(fieldName);
+ fieldSchema.setName(fieldName);
+ fieldSchema.setTypeString(type);
+ fieldSchema.setComment(comment);
+ fieldSchema.setDefaultValue(defaultValue);
+ }
+ }
+ } else {
+ originFieldSchemaMap = new LinkedHashMap<>();
+ columns.forEach(column -> buildFieldSchema(originFieldSchemaMap,
column));
+ }
+ firstSchemaChange = false;
+ firstLoad = false;
+ }
+
+ private void buildFieldSchema(Map<String, FieldSchema> filedSchemaMap,
JsonNode column) {
+ String fieldName = column.get("name").asText();
+ JsonNode length = column.get("length");
+ JsonNode scale = column.get("scale");
+ String type = MysqlType.toDorisType(column.get("typeName").asText(),
+ length == null ? 0 : length.asInt(), scale == null ? 0 :
scale.asInt());
+ String defaultValue = handleDefaultValue(extractJsonNode(column,
"defaultValueExpression"));
+ String comment = extractJsonNode(column, "comment");
+ filedSchemaMap.put(fieldName, new FieldSchema(fieldName, type,
defaultValue, comment));
+ }
+
+ private String handleDefaultValue(String defaultValue) {
+ if (StringUtils.isNullOrWhitespaceOnly(defaultValue)) {
+ return null;
+ }
+ // Due to historical reasons, doris needs to add quotes to the default
value of the new column
+ if (Pattern.matches("['\"].*?['\"]", defaultValue)) {
Review Comment:
It is recommended to write an example on the comments
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]