This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 218e49711f2 [fix](query) Backport IP hash routing and large OFFSET
fixes to branch-4.2 (#71348)
218e49711f2 is described below
commit 218e49711f264450ac5d508c9b15baa6a56f4be2
Author: HappenLee <[email protected]>
AuthorDate: Fri Dec 4 09:25:23 2026 +0800
[fix](query) Backport IP hash routing and large OFFSET fixes to branch-4.2
(#71348)
### What problem does this PR solve?
Issue Number: None
Related PR: #71284, #71302
Problem Summary:
Combine two merged fixes for branch-4.2:
- IP hash routing: equality and IN predicates on IPv4/IPv6 distribution
keys can prune the tablet holding an existing row, including
short-circuit point queries. Encode FE literals as the same
little-endian 4/16-byte values used by BE writes. Existing data does not
need redistribution.
- Large OFFSET: the single-run sorted merge narrows the remaining offset
to int before computing its skip count. OFFSET 4294967296 can
consequently produce a zero skip and leave the worker looping. Compute
the minimum in size_t, bounded by the current block's remaining rows.
The production changes preserve the implementations merged in #71284 and
#71302. Tests use this branch's fe-core module, tablet-ID pruner
interface, JUnit 4 fixture, and Java 8-compatible Guava utilities. The
scalar-audit test retains UUID and TIMESTAMP_NS coverage supported by
this branch.
### Validation
- `run-fe-ut.sh --run
org.apache.doris.analysis.IpLiteralHashTest,org.apache.doris.analysis.DistributionLiteralEncodingTest,org.apache.doris.planner.HashDistributionPrunerTest,org.apache.doris.catalog.PartitionKeyTest`:
**54 tests passed**, zero failures, errors, or skips. The run compiled
the branch's FE production and test sources using JDK 17 with the
branch's Java 8 release target.
- FE Checkstyle: passed via Maven `validate` with
`-Dcheckstyle.skip=false`.
- BE formatting: repository `clang-format.sh` and `check-format.sh`
passed using clang-format 16.0.6.
- The original IP SQL regression suite and generated expectations are
carried over unchanged from #71284.
- No local full BE build or live-cluster SQL regression was run for
these backports; those remain for CI. The large-OFFSET production change
is identical to #71302.
### Release note
Fix missing rows for hash-distributed IPv4/IPv6 equality and IN queries,
including short-circuit point queries, and prevent sorted-run merging
from stalling on large OFFSET values.
### Check List (For Author)
- Test: focused FE unit tests and style checks; original IP SQL
regression and generated expectations included.
- Behavior changed: Yes; affected IP queries return existing rows and
large-offset merging makes progress.
- Does this need documentation: No.
### AI Disclosure
- Tool: Codex.
- Generated: branch adaptations, validation, and PR description.
- Human review: upstream fixes were reviewed and merged; this combined
backport awaits review.
Co-authored-by: Mryange <[email protected]>
---
be/src/exec/sort/vsorted_run_merger.cpp | 2 +-
.../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 | 56 +++
.../datatype_p0/ip/test_ip_hash_distribution.out | 393 +++++++++++++++++++++
.../ip/test_ip_hash_distribution.groovy | 84 +++++
8 files changed, 716 insertions(+), 1 deletion(-)
diff --git a/be/src/exec/sort/vsorted_run_merger.cpp
b/be/src/exec/sort/vsorted_run_merger.cpp
index 928bb99c16b..db298f6505c 100644
--- a/be/src/exec/sort/vsorted_run_merger.cpp
+++ b/be/src/exec/sort/vsorted_run_merger.cpp
@@ -127,7 +127,7 @@ Status VSortedRunMerger::get_next(Block* output_block,
bool* eos) {
DCHECK(!current->eof());
DCHECK(current->block_ptr() != nullptr);
while (_offset != 0) {
- auto process_rows = std::min(current->rows - current->pos,
(int)_offset);
+ auto process_rows = std::min<size_t>(current->rows - current->pos,
_offset);
current->next(process_rows);
_offset -= process_rows;
if (current->is_last(0)) {
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 1a7f6f03b2d..a9f7913b673 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
@@ -17,6 +17,7 @@
package org.apache.doris.analysis;
+import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
@@ -28,6 +29,9 @@ import org.apache.doris.thrift.TIPv4Literal;
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
@@ -168,6 +172,14 @@ public class IPv4Literal extends LiteralExpr {
return this.value == ((IPv4Literal) obj).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 int hashCode() {
return 31 * super.hashCode() + Long.hashCode(value);
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 6a7bcb7e78a..bb1ea7751aa 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
@@ -17,6 +17,7 @@
package org.apache.doris.analysis;
+import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
@@ -29,6 +30,8 @@ import org.apache.doris.thrift.TIPv6Literal;
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 {
@@ -136,6 +139,16 @@ public class IPv6Literal extends LiteralExpr {
return parseAddress(this.value).equals(parseAddress(((IPv6Literal)
obj).value));
}
+ @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;
+ }
+
@Override
public int hashCode() {
return 31 * super.hashCode() + parseAddress(this.value).hashCode();
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/analysis/DistributionLiteralEncodingTest.java
b/fe/fe-core/src/test/java/org/apache/doris/analysis/DistributionLiteralEncodingTest.java
new file mode 100644
index 00000000000..b396c11044d
--- /dev/null
+++
b/fe/fe-core/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 com.google.common.io.BaseEncoding;
+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.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,
BaseEncoding.base16().lowerCase().encode(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-core/src/test/java/org/apache/doris/analysis/IpLiteralHashTest.java
b/fe/fe-core/src/test/java/org/apache/doris/analysis/IpLiteralHashTest.java
new file mode 100644
index 00000000000..a5f07e3b571
--- /dev/null
+++ b/fe/fe-core/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 com.google.common.io.BaseEncoding;
+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.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(BaseEncoding.base16().lowerCase().decode(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 5c525011d75..a424aa8deff 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,12 +18,16 @@
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;
import org.apache.doris.catalog.PartitionKey;
import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.common.AnalysisException;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -38,6 +42,58 @@ 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,
+ Lists.newArrayList(new IPv4Literal("198.51.100.169"), new
IPv4Literal("128.0.0.1")),
+ Lists.newArrayList(3633703130L, 1950366553L));
+ assertIpPruning(PrimitiveType.IPV6,
+ Lists.newArrayList(new IPv6Literal("::"), new
IPv6Literal("2001:db8::1"),
+ new IPv6Literal("::ffff:192.0.2.1")),
+ Lists.newArrayList(3971697493L, 2964864619L, 3683663142L));
+ }
+
+ private static void assertIpPruning(PrimitiveType type, List<LiteralExpr>
literals, List<Long> hashes) {
+ for (int buckets : new int[] {1, 2, 3, 8}) {
+ List<Long> tabletIds = Lists.newArrayList();
+ for (int i = 0; i < buckets; i++) {
+ tabletIds.add(1000L + i);
+ }
+ PartitionColumnFilter filter = new PartitionColumnFilter();
+ Map<String, PartitionColumnFilter> filters = new
CaseInsensitiveMap();
+ filters.put("ip", filter);
+ HashDistributionPruner pruner = new HashDistributionPruner(null,
tabletIds,
+ Lists.newArrayList(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;
+ Assert.assertEquals(Lists.newArrayList(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));
+ Assert.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);
+ Assert.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);
+ Assert.assertEquals(4248487806L, reversed.getHashValue());
+ }
+
@Test
public void testEqualityWithInPredicate() {
List<Long> tabletIds = 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]