aloyszhang commented on code in PR #10329:
URL: https://github.com/apache/inlong/pull/10329#discussion_r1625566038
##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/fieldtype/strategy/DefaultFieldTypeStrategy.java:
##########
@@ -17,13 +17,50 @@
package org.apache.inlong.manager.common.fieldtype.strategy;
+import org.apache.inlong.manager.common.fieldtype.FieldTypeMappingReader;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static
org.apache.inlong.manager.common.consts.InlongConstants.LEFT_BRACKET;
+
/**
* The default field type mapping strategy
*/
-public class DefaultFieldTypeStrategy implements FieldTypeMappingStrategy {
+@Service
+public abstract class DefaultFieldTypeStrategy implements
FieldTypeMappingStrategy {
+
+ private final static String NULLABLE_PATTERN = "^NULLABLE\\((.*)\\)$";
+
+ private static final Pattern PATTERN = Pattern.compile(NULLABLE_PATTERN);
+
+ protected FieldTypeMappingReader reader = null;
+
+ @Override
+ public String getSourceToSinkFieldTypeMapping(String sourceType) {
+ if (reader == null) {
+ return sourceType;
+ }
+ String dataType = StringUtils.substringBefore(sourceType,
LEFT_BRACKET).toUpperCase();
+ return
reader.getSOURCE_TO_SINK_FIELD_TYPE_MAPPING_MAP().getOrDefault(dataType,
sourceType.toUpperCase());
+ }
@Override
- public String getFieldTypeMapping(String sourceType) {
- return sourceType;
+ public String getStreamToSinkFieldTypeMapping(String sourceType) {
+ if (reader == null) {
+ return sourceType;
+ }
+ if (StringUtils.isNotBlank(sourceType)) {
+ Matcher matcher = PATTERN.matcher(sourceType.toUpperCase());
+ if (matcher.matches()) {
+ // obtain the field type modified by Nullable, for example,
uint8(12) in Nullable(uint8(12))
+ sourceType = matcher.group(1);
+ }
+ }
+ String dataType = StringUtils.substringBefore(sourceType,
LEFT_BRACKET).toUpperCase();
+ return
reader.getSOURCE_TO_SINK_FIELD_TYPE_MAPPING_MAP().getOrDefault(dataType,
sourceType.toUpperCase());
Review Comment:
getSOURCE_TO_SINK_FIELD_TYPE_MAPPING_MAP ->
getSTERAM_TO_SINK_FIELD_TYPE_MAPPING_MAP
--
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]