diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java index 93bcb92f58062a..5cf4a3c6940c6a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java @@ -651,6 +651,12 @@ public static void validateDefaultValue(Type type, String defaultValue, DefaultV case BOOLEAN: new BoolLiteral(defaultValue); break; + case IPV4: + new IPv4Literal(defaultValue); + break; + case IPV6: + new IPv6Literal(defaultValue); + break; default: throw new AnalysisException("Unsupported type: " + type); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv4Literal.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv4Literal.java index 6fa84d18b25f41..871062b04b296c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv4Literal.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv4Literal.java @@ -89,6 +89,7 @@ private static long parseIPv4toLong(String ipv4) { private static String parseLongToIPv4(long ipv4) { StringBuilder sb = new StringBuilder(); + sb.append("\""); for (int i = 3; i >= 0; i--) { short octet = (short) ((ipv4 >> (i * 8)) & 0xFF); sb.append(octet); @@ -96,6 +97,7 @@ private static String parseLongToIPv4(long ipv4) { sb.append("."); } } + sb.append("\""); return sb.toString(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv6Literal.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv6Literal.java index a3ec7a3a349824..d8257d6175047f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv6Literal.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IPv6Literal.java @@ -101,7 +101,7 @@ public int compareLiteral(LiteralExpr expr) { @Override public String getStringValue() { - return this.value; + return "\"" + this.value + "\""; } @Override diff --git a/regression-test/data/datatype_p0/ip/test_ip_basic.out b/regression-test/data/datatype_p0/ip/test_ip_basic.out index b69f9708a1b1fc..9f70d29305f41e 100644 --- a/regression-test/data/datatype_p0/ip/test_ip_basic.out +++ b/regression-test/data/datatype_p0/ip/test_ip_basic.out @@ -373,3 +373,7 @@ ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 4 -- !sql -- 1 false 127.0.0.1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff +-- !sql -- +1 5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b 0.0.0.1 +2 :: 127.0.0.1 + diff --git a/regression-test/suites/datatype_p0/ip/test_ip_basic.groovy b/regression-test/suites/datatype_p0/ip/test_ip_basic.groovy index 468b6f6f146e14..72d10467560d4a 100644 --- a/regression-test/suites/datatype_p0/ip/test_ip_basic.groovy +++ b/regression-test/suites/datatype_p0/ip/test_ip_basic.groovy @@ -160,4 +160,11 @@ suite("test_ip_basic") { qt_sql """ select * from table_ip where col0 = 1""" sql """ Update table_ip set col25 = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' where col0 = 1 """ qt_sql """ select * from table_ip where col0 = 1""" + + // test ip with default value + sql """ DROP TABLE IF EXISTS table_ip_default """ + sql """ CREATE TABLE IF NOT EXISTS `table_ip_default` (`col0` bigint NOT NULL, `col4` ipv6 NULL DEFAULT "::", `col24` ipv4 NULL DEFAULT "127.0.0.1") ENGINE=OLAP UNIQUE KEY(`col0`) DISTRIBUTED BY HASH(`col0`) BUCKETS 4 PROPERTIES ("replication_allocation" = "tag.location.default: 1") """ + sql """ insert into table_ip_default values (1, "5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b", "0.0.0.1") """ + sql """ insert into table_ip_default(col0) values (2); """ + qt_sql """ select * from table_ip_default order by col0"""; }