This is an automated email from the ASF dual-hosted git repository.

HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 66598c852d4 [fix](fe) Fix IPv4 and IPv6 hash distribution pruning 
(#71284)
66598c852d4 is described below

commit 66598c852d43d3ddce9260364ef854e2e6c74959
Author: HappenLee <[email protected]>
AuthorDate: Thu Dec 3 11:15:47 2026 +0800

    [fix](fe) Fix IPv4 and IPv6 hash distribution pruning (#71284)
    
    ### Background
    
    Doris hashes distribution keys when writing rows to tablets. The FE must
    hash query literals identically to prune tablets or route a
    short-circuit point query to the tablet holding the row.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #24965 (introduced the IP literal implementations)
    PR Type: Bugfix
    
    Problem Summary:
    
    Equality and IN predicates on IPv4/IPv6 hash distribution columns can
    silently miss existing rows because the FE hashes IP text while the BE
    hashes binary values. Encode both IP literal types as the same
    little-endian 4/16-byte values used by existing BE writes. This fixes
    ordinary scans and short-circuit point queries without redistributing
    stored data; most of the diff is tests and generated expectations.
    
    For example, with three buckets, `198.51.100.169` is written to bucket
    2, but the old FE hashes its text and selects bucket 1. The corrected FE
    selects bucket 2.
    
    ### Details
    
    - **Change map:** 25 production lines, 215 unit-test lines, 84 SQL-suite
    lines, and 393 generated expectation lines.
    - **Frequency:** Deterministic for keys whose text and binary CRC32
    hashes select different buckets. Single-bucket tables mask the defect.
    - **Root cause:** `IPv4Literal` and `IPv6Literal` inherit the UTF-8
    implementation of `LiteralExpr.getHashValue()`. `PartitionKey` feeds
    those bytes to CRC32, whereas BE tablet routing hashes the binary IP
    value.
    - **Why existing tests missed it:** `LiteralExprEqualsTest` and
    `LiteralExprCompareLiteralTest` exercise equality/comparison, not
    distribution encoding. The existing pruner tests do not cover IP keys.
    BE `DataTypeIPTest.Crc32Test` compares BE paths with one another.
    Regression suites such as `test_ip_crud` and `test_ip_basic` distribute
    by other columns, leaving the IP pruning path untested.
    - **Fix:** Override the two literal encoders, reuse the existing IPv6
    parser, and preserve BE routing. Test independent byte/CRC goldens,
    equality/IN pruning, compound keys, IPv6 aliases, mapped addresses, and
    NULLs.
    - **Other paths and branches:** Both normal and short-circuit routing
    share the corrected method. Auditing supported scalar literals found no
    additional instance of this text/binary mismatch; 22 scalar encoding
    cases cover integers, decimals, dates/timestamps, UUID, strings,
    booleans and NULL. FLOAT/DOUBLE and complex types are rejected as
    distribution keys; TIME and VARBINARY cannot be stored in OLAP tables.
    The same missing IP overrides exist in `branch-3.1`, `branch-4.0`,
    `branch-4.1`, and `branch-4.2`; backports need adapting the older
    source/test module paths and IPv6 parser helper.
    - **Behavior change:** IP predicates now find existing rows in the
    correct tablet; write routing, storage formats and configuration remain
    unchanged.
    
    ### Testing
    
    - `run-fe-ut.sh --run` with `IpLiteralHashTest`,
    `DistributionLiteralEncodingTest`, `HashDistributionPrunerTest`, and
    `PartitionKeyTest`: 56 cases passed locally. The 11 IP encoding cases
    failed on the unmodified baseline and passed after the fix.
    - `build.sh --fe -j48`: passed, including Java Checkstyle.
    - `run-regression-test.sh --run -d datatype_p0/ip -s
    test_ip_hash_distribution`: generated expectations, then passed normal
    comparison. Independently checked all 124 result sections against
    inserted values. Covers 1/2/3/8 buckets, both query modes, missing keys,
    IN, IPv6 aliases, and nullable composite keys.
    - SQL ran with the candidate FE and an existing BE build
    (`049410596f4`), using isolated fresh storage. Matching-head BE CI is
    pending. The new p0 suite has no Docker/nonConcurrent requirement and is
    not excluded by the P0 configuration.
    
    ### Release note
    
    Fix missing rows when querying hash-distributed IPv4 or IPv6 columns,
    including short-circuit point queries.
    
    ### Check List (For Author)
    
    - Test: Unit tests and local regression (see Testing)
    - Behavior changed: Yes (see Details)
    - Does this need documentation: No
    - Pre-submission status: Ready
    
    ### AI Disclosure
    
    - Tool: Codex (GPT-6)
    - Generated: Implementation, tests, analysis and this description.
    - Human review: The author approved the fix direction; no human review
    of the generated patch has been reported. Codex performed the local
    self-review.
    - Prompts: Asked to fix IP hash routing, submit a PR, and check whether
    other data types have the same problem.
---
 .../org/apache/doris/analysis/IPv4Literal.java     |  12 +
 .../org/apache/doris/analysis/IPv6Literal.java     |  13 +
 .../analysis/DistributionLiteralEncodingTest.java  |  90 +++++
 .../apache/doris/analysis/IpLiteralHashTest.java   |  67 ++++
 .../doris/planner/HashDistributionPrunerTest.java  |  58 +++
 .../datatype_p0/ip/test_ip_hash_distribution.out   | 393 +++++++++++++++++++++
 .../ip/test_ip_hash_distribution.groovy            |  84 +++++
 7 files changed, 717 insertions(+)

diff --git 
a/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv4Literal.java 
b/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv4Literal.java
index 1c57e69cf9b..c455993fe52 100644
--- a/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv4Literal.java
+++ b/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv4Literal.java
@@ -17,11 +17,15 @@
 
 package org.apache.doris.analysis;
 
+import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 
 import com.google.gson.annotations.SerializedName;
 
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
 public class IPv4Literal extends LiteralExpr {
 
     public static final long IPV4_MIN = 0L;             // 0.0.0.0
@@ -154,6 +158,14 @@ public class IPv4Literal extends LiteralExpr {
         return 31 * super.hashCode() + Long.hashCode(value);
     }
 
+    @Override
+    public ByteBuffer getHashValue(PrimitiveType type) {
+        ByteBuffer buffer = 
ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
+        buffer.putInt((int) value);
+        buffer.flip();
+        return buffer;
+    }
+
     @Override
     public String getStringValue() {
         return parseLongToIPv4(this.value);
diff --git 
a/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv6Literal.java 
b/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv6Literal.java
index fb9a06b7ac8..44a736de745 100644
--- a/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv6Literal.java
+++ b/fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv6Literal.java
@@ -17,12 +17,15 @@
 
 package org.apache.doris.analysis;
 
+import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 
 import com.google.gson.annotations.SerializedName;
 import com.googlecode.ipv6.IPv6Address;
 
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 import java.util.regex.Pattern;
 
 public class IPv6Literal extends LiteralExpr {
@@ -123,6 +126,16 @@ public class IPv6Literal extends LiteralExpr {
         return 31 * super.hashCode() + parseAddress(this.value).hashCode();
     }
 
+    @Override
+    public ByteBuffer getHashValue(PrimitiveType type) {
+        IPv6Address address = parseAddress(value);
+        ByteBuffer buffer = 
ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
+        buffer.putLong(address.getLowBits());
+        buffer.putLong(address.getHighBits());
+        buffer.flip();
+        return buffer;
+    }
+
     // IPv6Address keeps the full 128-bit value for IPv4-mapped literals
     // (e.g. ::ffff:0.0.0.1, ::ffff:0:1) and matches the canonicalization used 
by
     // the Nereids IPv6Literal, so dedup/range logic stays consistent across 
both
diff --git 
a/fe/fe-catalog/src/test/java/org/apache/doris/analysis/DistributionLiteralEncodingTest.java
 
b/fe/fe-catalog/src/test/java/org/apache/doris/analysis/DistributionLiteralEncodingTest.java
new file mode 100644
index 00000000000..fd296ac3553
--- /dev/null
+++ 
b/fe/fe-catalog/src/test/java/org/apache/doris/analysis/DistributionLiteralEncodingTest.java
@@ -0,0 +1,90 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.util.HexFormat;
+import java.util.stream.Stream;
+import java.util.zip.CRC32;
+
+class DistributionLiteralEncodingTest {
+    @ParameterizedTest
+    @MethodSource("distributionLiterals")
+    void testMatchesBeRoutingBytes(LiteralExpr literal, PrimitiveType type, 
String bytes, long expectedCrc) {
+        ByteBuffer buffer = literal.getHashValue(type);
+        Assertions.assertEquals(bytes, 
HexFormat.of().formatHex(buffer.array(), 0, buffer.limit()));
+        CRC32 crc = new CRC32();
+        crc.update(buffer.array(), 0, buffer.limit());
+        Assertions.assertEquals(expectedCrc, crc.getValue());
+    }
+
+    private static Stream<Arguments> distributionLiterals() throws 
AnalysisException {
+        // Fixed byte sequences follow RawValue::zlib_crc32, including its 
legacy date/decimal formats.
+        return Stream.of(
+                Arguments.of(new BoolLiteral(false), PrimitiveType.BOOLEAN, 
"00", 3523407757L),
+                Arguments.of(new BoolLiteral(true), PrimitiveType.BOOLEAN, 
"01", 2768625435L),
+                Arguments.of(new IntLiteral(-123), PrimitiveType.TINYINT, 
"85", 1339070498L),
+                Arguments.of(new IntLiteral(-12345), PrimitiveType.SMALLINT, 
"c7cf", 3468266583L),
+                Arguments.of(new IntLiteral(-123456789), PrimitiveType.INT, 
"eb32a4f8", 2128096024L),
+                Arguments.of(new IntLiteral(-1234567890123L), 
PrimitiveType.BIGINT,
+                        "35fb048ee0feffff", 2352131499L),
+                Arguments.of(new 
LargeIntLiteral(BigInteger.ONE.shiftLeft(100).negate().add(BigInteger.valueOf(12345))),
+                        PrimitiveType.LARGEINT, 
"393000000000000000000000f0ffffff", 2326237452L),
+                Arguments.of(decimal(9), PrimitiveType.DECIMAL32, "c7cfffff", 
3993750049L),
+                Arguments.of(decimal(18), PrimitiveType.DECIMAL64, 
"c7cfffffffffffff", 3742315142L),
+                Arguments.of(decimal(38), PrimitiveType.DECIMAL128, 
"c7cfffffffffffffffffffffffffffff", 1897905511L),
+                Arguments.of(decimal(76), PrimitiveType.DECIMAL256,
+                        
"c7cfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 
3529620757L),
+                Arguments.of(new DecimalLiteral(new BigDecimal("-12.345"),
+                        ScalarType.createDecimalType(PrimitiveType.DECIMALV2, 
27, 9)),
+                        PrimitiveType.DECIMALV2, "f4ffffffffffffffc0b76feb", 
2001809772L),
+                Arguments.of(new DateLiteral(2024, 2, 29, Type.DATEV2), 
PrimitiveType.DATEV2,
+                        "5dd00f00", 305275292L),
+                Arguments.of(new DateLiteral(2024, 2, 29, 12, 34, 56, 123456,
+                        ScalarType.createDatetimeV2Type(6)), 
PrimitiveType.DATETIMEV2,
+                        "40e2818bac0bfa01", 1508285625L),
+                Arguments.of(new DateLiteral(2024, 2, 29, 12, 34, 56, 123456,
+                        ScalarType.createTimeStampTzType(6)), 
PrimitiveType.TIMESTAMPTZ,
+                        "40e2818bac0bfa01", 1508285625L),
+                Arguments.of(new TimeStampNsLiteral(1969, 12, 31, 23, 59, 59, 
123456789),
+                        PrimitiveType.TIMESTAMP_NS, "1503c1cbffffffff", 
4200320643L),
+                Arguments.of(new StringLiteral("abc"), PrimitiveType.CHAR, 
"616263", 891568578L),
+                Arguments.of(new StringLiteral("中文"), PrimitiveType.VARCHAR, 
"e4b8ade69687", 1510599991L),
+                Arguments.of(new StringLiteral("中文"), PrimitiveType.STRING, 
"e4b8ade69687", 1510599991L),
+                Arguments.of(new 
UuidLiteral("00112233-4455-6677-8899-aabbccddeeff"), PrimitiveType.UUID,
+                        "ffeeddccbbaa99887766554433221100", 1460664532L),
+                Arguments.of(new NullLiteral(), PrimitiveType.IPV4, 
"00000000", 558161692L),
+                Arguments.of(new NullLiteral(), PrimitiveType.IPV6, 
"00000000", 558161692L));
+    }
+
+    private static DecimalLiteral decimal(int precision) {
+        return new DecimalLiteral(new BigDecimal("-123.45"), 
ScalarType.createDecimalV3Type(precision, 2));
+    }
+}
diff --git 
a/fe/fe-catalog/src/test/java/org/apache/doris/analysis/IpLiteralHashTest.java 
b/fe/fe-catalog/src/test/java/org/apache/doris/analysis/IpLiteralHashTest.java
new file mode 100644
index 00000000000..0cbf0f91822
--- /dev/null
+++ 
b/fe/fe-catalog/src/test/java/org/apache/doris/analysis/IpLiteralHashTest.java
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.common.AnalysisException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.nio.ByteBuffer;
+import java.util.HexFormat;
+import java.util.zip.CRC32;
+
+class IpLiteralHashTest {
+    @ParameterizedTest
+    @CsvSource({
+            "0.0.0.0, 00000000, 558161692",
+            "128.0.0.1, 01000080, 1950366553",
+            "198.51.100.169, a96433c6, 3633703130",
+            "255.255.255.255, ffffffff, 4294967295"
+    })
+    void testIpv4DistributionHash(String address, String bytes, long crc) 
throws AnalysisException {
+        assertHash(new IPv4Literal(address), PrimitiveType.IPV4, bytes, crc);
+    }
+
+    @ParameterizedTest
+    @CsvSource({
+            "::, 00000000000000000000000000000000, 3971697493",
+            "::1, 01000000000000000000000000000000, 1121180356",
+            "2001:db8::1, 010000000000000000000000b80d0120, 2964864619",
+            "2001:0DB8:0:0:0:0:0:1, 010000000000000000000000b80d0120, 
2964864619",
+            "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff, 
ffffffffffffffffffffffffffffffff, 1068746266",
+            "::ffff:192.0.2.1, 010200c0ffff00000000000000000000, 3683663142",
+            "::ffff:c000:201, 010200c0ffff00000000000000000000, 3683663142"
+    })
+    void testIpv6DistributionHash(String address, String bytes, long crc) 
throws AnalysisException {
+        assertHash(new IPv6Literal(address), PrimitiveType.IPV6, bytes, crc);
+    }
+
+    private static void assertHash(LiteralExpr literal, PrimitiveType type, 
String bytes, long expectedCrc) {
+        // BE tablet routing hashes the little-endian 4/16-byte value with 
zlib CRC32.
+        ByteBuffer buffer = literal.getHashValue(type);
+        Assertions.assertEquals(0, buffer.position());
+        Assertions.assertEquals(bytes.length() / 2, buffer.limit());
+        Assertions.assertArrayEquals(HexFormat.of().parseHex(bytes), 
buffer.array());
+        CRC32 crc = new CRC32();
+        crc.update(buffer.array(), 0, buffer.limit());
+        Assertions.assertEquals(expectedCrc, crc.getValue());
+    }
+}
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java
index 7d565bccfc7..f6af2aa097d 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/planner/HashDistributionPrunerTest.java
@@ -18,7 +18,10 @@
 package org.apache.doris.planner;
 
 import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.IPv4Literal;
+import org.apache.doris.analysis.IPv6Literal;
 import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
 import org.apache.doris.analysis.SlotRef;
 import org.apache.doris.analysis.StringLiteral;
 import org.apache.doris.catalog.Column;
@@ -27,6 +30,7 @@ import org.apache.doris.catalog.MaterializedIndex;
 import org.apache.doris.catalog.PartitionKey;
 import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.Tablet;
+import org.apache.doris.common.AnalysisException;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -41,6 +45,60 @@ import java.util.Set;
 
 public class HashDistributionPrunerTest {
 
+    @Test
+    public void testIpEqualityAndInPredicates() throws AnalysisException {
+        // CRC32 values from BE's binary tablet routing, not from 
PartitionKey.getHashValue().
+        assertIpPruning(PrimitiveType.IPV4,
+                List.of(new IPv4Literal("198.51.100.169"), new 
IPv4Literal("128.0.0.1")),
+                List.of(3633703130L, 1950366553L));
+        assertIpPruning(PrimitiveType.IPV6,
+                List.of(new IPv6Literal("::"), new IPv6Literal("2001:db8::1"),
+                        new IPv6Literal("::ffff:192.0.2.1")),
+                List.of(3971697493L, 2964864619L, 3683663142L));
+    }
+
+    private static void assertIpPruning(PrimitiveType type, List<LiteralExpr> 
literals, List<Long> hashes) {
+        for (int buckets : new int[] {1, 2, 3, 8}) {
+            MaterializedIndex index = new MaterializedIndex();
+            List<Tablet> tablets = Lists.newArrayList();
+            for (int i = 0; i < buckets; i++) {
+                tablets.add(new LocalTablet(1000 + i));
+            }
+            index.appendTablets(tablets);
+            PartitionColumnFilter filter = new PartitionColumnFilter();
+            Map<String, PartitionColumnFilter> filters = new 
CaseInsensitiveMap();
+            filters.put("ip", filter);
+            HashDistributionPruner pruner = new HashDistributionPruner(null, 
index,
+                    List.of(new Column("ip", type, false)), filters, buckets, 
true);
+            Set<Long> expectedInTablets = Sets.newHashSet();
+            for (int i = 0; i < literals.size(); i++) {
+                filter.setLowerBound(literals.get(i), true);
+                filter.setUpperBound(literals.get(i), true);
+                long expectedTablet = 1000 + hashes.get(i) % buckets;
+                Assertions.assertEquals(List.of(expectedTablet), 
pruner.prune());
+                expectedInTablets.add(expectedTablet);
+                filter = new PartitionColumnFilter();
+                filters.put("ip", filter);
+            }
+            filter.setInPredicate(new InPredicate(new SlotRef(null, "ip"),
+                    Lists.newArrayList(literals), false));
+            Assertions.assertEquals(expectedInTablets, 
Sets.newHashSet(pruner.prune()));
+        }
+    }
+
+    @Test
+    public void testCompositeIpDistributionHash() throws AnalysisException {
+        PartitionKey key = new PartitionKey();
+        key.pushColumn(new IPv4Literal("198.51.100.169"), PrimitiveType.IPV4);
+        key.pushColumn(new IPv6Literal("2001:db8::1"), PrimitiveType.IPV6);
+        Assertions.assertEquals(2166269152L, key.getHashValue());
+
+        PartitionKey reversed = new PartitionKey();
+        reversed.pushColumn(new IPv6Literal("2001:db8::1"), 
PrimitiveType.IPV6);
+        reversed.pushColumn(new IPv4Literal("198.51.100.169"), 
PrimitiveType.IPV4);
+        Assertions.assertEquals(4248487806L, reversed.getHashValue());
+    }
+
     @Test
     public void testEqualityWithInPredicate() {
         List<Tablet> tablets = Lists.newArrayList();
diff --git a/regression-test/data/datatype_p0/ip/test_ip_hash_distribution.out 
b/regression-test/data/datatype_p0/ip/test_ip_hash_distribution.out
new file mode 100644
index 00000000000..d051b80dc50
--- /dev/null
+++ b/regression-test/data/datatype_p0/ip/test_ip_hash_distribution.out
@@ -0,0 +1,393 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !IPV4_1_all --
+0
+1
+2
+3
+
+-- !IPV4_1_false_0 --
+0
+
+-- !IPV4_1_false_1 --
+1
+
+-- !IPV4_1_false_2 --
+2
+
+-- !IPV4_1_false_3 --
+3
+
+-- !absent_IPV4_1_false --
+
+-- !IPV4_1_true_0 --
+0
+
+-- !IPV4_1_true_1 --
+1
+
+-- !IPV4_1_true_2 --
+2
+
+-- !IPV4_1_true_3 --
+3
+
+-- !absent_IPV4_1_true --
+
+-- !in_IPV4_1 --
+0
+2
+
+-- !IPV6_1_all --
+0
+1
+2
+3
+4
+
+-- !IPV6_1_false_0 --
+0
+
+-- !IPV6_1_false_1 --
+1
+
+-- !IPV6_1_false_2 --
+2
+
+-- !IPV6_1_false_3 --
+3
+
+-- !IPV6_1_false_4 --
+4
+
+-- !alias_1_false --
+2
+
+-- !mapped_1_false --
+4
+
+-- !absent_IPV6_1_false --
+
+-- !IPV6_1_true_0 --
+0
+
+-- !IPV6_1_true_1 --
+1
+
+-- !IPV6_1_true_2 --
+2
+
+-- !IPV6_1_true_3 --
+3
+
+-- !IPV6_1_true_4 --
+4
+
+-- !alias_1_true --
+2
+
+-- !mapped_1_true --
+4
+
+-- !absent_IPV6_1_true --
+
+-- !in_IPV6_1 --
+0
+2
+
+-- !IPV4_2_all --
+0
+1
+2
+3
+
+-- !IPV4_2_false_0 --
+0
+
+-- !IPV4_2_false_1 --
+1
+
+-- !IPV4_2_false_2 --
+2
+
+-- !IPV4_2_false_3 --
+3
+
+-- !absent_IPV4_2_false --
+
+-- !IPV4_2_true_0 --
+0
+
+-- !IPV4_2_true_1 --
+1
+
+-- !IPV4_2_true_2 --
+2
+
+-- !IPV4_2_true_3 --
+3
+
+-- !absent_IPV4_2_true --
+
+-- !in_IPV4_2 --
+0
+2
+
+-- !IPV6_2_all --
+0
+1
+2
+3
+4
+
+-- !IPV6_2_false_0 --
+0
+
+-- !IPV6_2_false_1 --
+1
+
+-- !IPV6_2_false_2 --
+2
+
+-- !IPV6_2_false_3 --
+3
+
+-- !IPV6_2_false_4 --
+4
+
+-- !alias_2_false --
+2
+
+-- !mapped_2_false --
+4
+
+-- !absent_IPV6_2_false --
+
+-- !IPV6_2_true_0 --
+0
+
+-- !IPV6_2_true_1 --
+1
+
+-- !IPV6_2_true_2 --
+2
+
+-- !IPV6_2_true_3 --
+3
+
+-- !IPV6_2_true_4 --
+4
+
+-- !alias_2_true --
+2
+
+-- !mapped_2_true --
+4
+
+-- !absent_IPV6_2_true --
+
+-- !in_IPV6_2 --
+0
+2
+
+-- !IPV4_3_all --
+0
+1
+2
+3
+
+-- !IPV4_3_false_0 --
+0
+
+-- !IPV4_3_false_1 --
+1
+
+-- !IPV4_3_false_2 --
+2
+
+-- !IPV4_3_false_3 --
+3
+
+-- !absent_IPV4_3_false --
+
+-- !IPV4_3_true_0 --
+0
+
+-- !IPV4_3_true_1 --
+1
+
+-- !IPV4_3_true_2 --
+2
+
+-- !IPV4_3_true_3 --
+3
+
+-- !absent_IPV4_3_true --
+
+-- !in_IPV4_3 --
+0
+2
+
+-- !IPV6_3_all --
+0
+1
+2
+3
+4
+
+-- !IPV6_3_false_0 --
+0
+
+-- !IPV6_3_false_1 --
+1
+
+-- !IPV6_3_false_2 --
+2
+
+-- !IPV6_3_false_3 --
+3
+
+-- !IPV6_3_false_4 --
+4
+
+-- !alias_3_false --
+2
+
+-- !mapped_3_false --
+4
+
+-- !absent_IPV6_3_false --
+
+-- !IPV6_3_true_0 --
+0
+
+-- !IPV6_3_true_1 --
+1
+
+-- !IPV6_3_true_2 --
+2
+
+-- !IPV6_3_true_3 --
+3
+
+-- !IPV6_3_true_4 --
+4
+
+-- !alias_3_true --
+2
+
+-- !mapped_3_true --
+4
+
+-- !absent_IPV6_3_true --
+
+-- !in_IPV6_3 --
+0
+2
+
+-- !IPV4_8_all --
+0
+1
+2
+3
+
+-- !IPV4_8_false_0 --
+0
+
+-- !IPV4_8_false_1 --
+1
+
+-- !IPV4_8_false_2 --
+2
+
+-- !IPV4_8_false_3 --
+3
+
+-- !absent_IPV4_8_false --
+
+-- !IPV4_8_true_0 --
+0
+
+-- !IPV4_8_true_1 --
+1
+
+-- !IPV4_8_true_2 --
+2
+
+-- !IPV4_8_true_3 --
+3
+
+-- !absent_IPV4_8_true --
+
+-- !in_IPV4_8 --
+0
+2
+
+-- !IPV6_8_all --
+0
+1
+2
+3
+4
+
+-- !IPV6_8_false_0 --
+0
+
+-- !IPV6_8_false_1 --
+1
+
+-- !IPV6_8_false_2 --
+2
+
+-- !IPV6_8_false_3 --
+3
+
+-- !IPV6_8_false_4 --
+4
+
+-- !alias_8_false --
+2
+
+-- !mapped_8_false --
+4
+
+-- !absent_IPV6_8_false --
+
+-- !IPV6_8_true_0 --
+0
+
+-- !IPV6_8_true_1 --
+1
+
+-- !IPV6_8_true_2 --
+2
+
+-- !IPV6_8_true_3 --
+3
+
+-- !IPV6_8_true_4 --
+4
+
+-- !alias_8_true --
+2
+
+-- !mapped_8_true --
+4
+
+-- !absent_IPV6_8_true --
+
+-- !in_IPV6_8 --
+0
+2
+
+-- !composite --
+1
+
+-- !null_ipv6 --
+2
+
+-- !null_ipv4 --
+3
+
+-- !null_both --
+4
+
diff --git 
a/regression-test/suites/datatype_p0/ip/test_ip_hash_distribution.groovy 
b/regression-test/suites/datatype_p0/ip/test_ip_hash_distribution.groovy
new file mode 100644
index 00000000000..a18fb71f116
--- /dev/null
+++ b/regression-test/suites/datatype_p0/ip/test_ip_hash_distribution.groovy
@@ -0,0 +1,84 @@
+
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_ip_hash_distribution", "p0") {
+    sql "SET enable_sql_cache = false"
+
+    def addresses = [
+        "IPV4": ["0.0.0.0", "128.0.0.1", "198.51.100.169", "255.255.255.255"],
+        "IPV6": ["::", "::1", "2001:db8::1", 
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
+                 "::ffff:192.0.2.1"]
+    ]
+    for (int buckets : [1, 2, 3, 8]) {
+        addresses.each { type, values ->
+            def table = "ip_hash_${type.toLowerCase()}_${buckets}"
+            sql "DROP TABLE IF EXISTS ${table}"
+            sql """CREATE TABLE ${table} (k ${type} NOT NULL, v INT)
+                   UNIQUE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS ${buckets}
+                   PROPERTIES("replication_num"="1", 
"enable_unique_key_merge_on_write"="true",
+                              "store_row_column"="true")"""
+            def rows = values.withIndex().collect { address, index -> 
"('${address}', ${index})" }.join(",")
+            sql "INSERT INTO ${table} VALUES ${rows}"
+            "order_qt_${type}_${buckets}_all"("SELECT v FROM ${table}")
+
+            for (boolean pointQuery : [false, true]) {
+                sql "SET enable_short_circuit_query = ${pointQuery}"
+                values.eachWithIndex { address, index ->
+                    def query = "SELECT v FROM ${table} WHERE k = 
CAST('${address}' AS ${type})"
+                    explain {
+                        sql query
+                        if (pointQuery) {
+                            contains "SHORT-CIRCUIT"
+                        } else {
+                            contains "tablets=1/${buckets}"
+                        }
+                    }
+                    "order_qt_${type}_${buckets}_${pointQuery}_${index}"(query)
+                }
+                if (type == "IPV6") {
+                    "order_qt_alias_${buckets}_${pointQuery}"("""SELECT v FROM 
${table}
+                        WHERE k = CAST('2001:0DB8:0:0:0:0:0:1' AS IPV6)""")
+                    "order_qt_mapped_${buckets}_${pointQuery}"("""SELECT v 
FROM ${table}
+                        WHERE k = CAST('::ffff:c000:201' AS IPV6)""")
+                }
+                def absent = type == "IPV4" ? "198.51.100.170" : "2001:db8::2"
+                "order_qt_absent_${type}_${buckets}_${pointQuery}"("""SELECT v 
FROM ${table}
+                    WHERE k = CAST('${absent}' AS ${type})""")
+            }
+
+            sql "SET enable_short_circuit_query = false"
+            "order_qt_in_${type}_${buckets}"("""SELECT v FROM ${table}
+                WHERE k IN (CAST('${values[0]}' AS ${type}), 
CAST('${values[2]}' AS ${type}))""")
+        }
+    }
+
+    sql "DROP TABLE IF EXISTS ip_hash_composite"
+    sql """CREATE TABLE ip_hash_composite (id INT, ip4 IPV4, ip6 IPV6)
+           DUPLICATE KEY(id) DISTRIBUTED BY HASH(ip4, ip6) BUCKETS 3
+           PROPERTIES("replication_num"="1")"""
+    sql """INSERT INTO ip_hash_composite VALUES
+           (1, '198.51.100.169', '2001:db8::1'),
+           (2, '198.51.100.169', NULL), (3, NULL, '::'), (4, NULL, NULL)"""
+    order_qt_composite """SELECT id FROM ip_hash_composite
+        WHERE ip4 = CAST('198.51.100.169' AS IPV4) AND ip6 = 
CAST('2001:db8::1' AS IPV6)"""
+    order_qt_null_ipv6 """SELECT id FROM ip_hash_composite
+        WHERE ip4 = CAST('198.51.100.169' AS IPV4) AND ip6 IS NULL"""
+    order_qt_null_ipv4 """SELECT id FROM ip_hash_composite
+        WHERE ip4 IS NULL AND ip6 = CAST('::' AS IPV6)"""
+    order_qt_null_both "SELECT id FROM ip_hash_composite WHERE ip4 IS NULL AND 
ip6 IS NULL"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to