This is an automated email from the ASF dual-hosted git repository.
pacinogong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 84a9044a1f [INLONG-8514][Manager] Support ClickHouse field type with
Nullable modifier (#8515)
84a9044a1f is described below
commit 84a9044a1f352ea043fb8504e5c3c01cb1f9c4dc
Author: chestnufang <[email protected]>
AuthorDate: Mon Jul 17 16:30:40 2023 +0800
[INLONG-8514][Manager] Support ClickHouse field type with Nullable modifier
(#8515)
---
.../fieldtype/strategy/ClickHouseFieldTypeStrategy.java | 15 +++++++++++++++
.../inlong/manager/pojo/sort/util/FieldInfoUtilsTest.java | 2 +-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/fieldtype/strategy/ClickHouseFieldTypeStrategy.java
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/fieldtype/strategy/ClickHouseFieldTypeStrategy.java
index eb9931f4e0..b464367b04 100644
---
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/fieldtype/strategy/ClickHouseFieldTypeStrategy.java
+++
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/fieldtype/strategy/ClickHouseFieldTypeStrategy.java
@@ -22,6 +22,9 @@ import
org.apache.inlong.manager.common.fieldtype.FieldTypeMappingReader;
import org.apache.commons.lang3.StringUtils;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import static
org.apache.inlong.manager.common.consts.InlongConstants.LEFT_BRACKET;
/**
@@ -31,12 +34,24 @@ public class ClickHouseFieldTypeStrategy implements
FieldTypeMappingStrategy {
private final FieldTypeMappingReader reader;
+ private final static String NULLABLE_PATTERN = "^NULLABLE\\((.*)\\)$";
+
+ private static final Pattern PATTERN = Pattern.compile(NULLABLE_PATTERN);
+
public ClickHouseFieldTypeStrategy() {
this.reader = new FieldTypeMappingReader(DataNodeType.CLICKHOUSE);
}
@Override
public String getFieldTypeMapping(String sourceType) {
+ // support clickHouse field type special modifier Nullable
+ 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.getFIELD_TYPE_MAPPING_MAP().getOrDefault(dataType,
sourceType.toUpperCase());
}
diff --git
a/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sort/util/FieldInfoUtilsTest.java
b/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sort/util/FieldInfoUtilsTest.java
index 79d5911713..30dd2bb66d 100644
---
a/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sort/util/FieldInfoUtilsTest.java
+++
b/inlong-manager/manager-pojo/src/test/java/org/apache/inlong/manager/pojo/sort/util/FieldInfoUtilsTest.java
@@ -105,7 +105,7 @@ public class FieldInfoUtilsTest {
StreamField streamField = new StreamField();
streamField.setIsMetaField(0);
streamField.setFieldName("age");
- streamField.setFieldType("uint8");
+ streamField.setFieldType("Nullable(uint8(12))");
FieldInfo fieldInfo = FieldInfoUtils.parseStreamFieldInfo(streamField,
"nodeId", new ClickHouseFieldTypeStrategy());
TypeInfo typeInfo = fieldInfo.getFormatInfo().getTypeInfo();