github-actions[bot] commented on code in PR #63481:
URL: https://github.com/apache/doris/pull/63481#discussion_r3296461636
##########
fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv6Literal.java:
##########
@@ -90,7 +92,45 @@ public boolean isMinValue() {
@Override
public int compareLiteral(LiteralExpr expr) {
- return 0;
+ if (expr instanceof PlaceHolderExpr) {
+ return this.compareLiteral(((PlaceHolderExpr) expr).getLiteral());
+ }
+ if (expr instanceof NullLiteral) {
+ return 1;
+ }
+ if (expr == MaxLiteral.MAX_VALUE) {
+ return -1;
+ }
+ if (expr instanceof IPv6Literal) {
+ return
toUnsigned128(this.value).compareTo(toUnsigned128(((IPv6Literal) expr).value));
+ }
+ throw new RuntimeException("Cannot compare two values with different
data types: "
+ + this + " (" + this.type + ") vs " + expr + " (" + expr.type
+ ")");
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof IPv6Literal)) {
+ return false;
+ }
+ return toUnsigned128(this.value).equals(toUnsigned128(((IPv6Literal)
obj).value));
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * super.hashCode() + toUnsigned128(this.value).hashCode();
+ }
+
+ private static BigInteger toUnsigned128(String ipv6) {
+ try {
+ byte[] bytes = InetAddress.getByName(ipv6).getAddress();
+ return new BigInteger(1, bytes);
Review Comment:
This helper is incorrect for IPv4-mapped IPv6 literals, which this class
accepts via `IPV6_MAPPED_REGEX` and also through compressed forms like
`::ffff:0:1`. `InetAddress.getByName("::ffff:0.0.0.1")` returns an
`Inet4Address` with only four bytes `[0,0,0,1]`, so the `BigInteger` becomes
`1` and compares/hash-equals to `::1`. That means predicates involving mapped
IPv6 literals can still be deduplicated incorrectly or ordered in the wrong
range. Please preserve the full 128-bit IPv6 value for mapped addresses, for
example by parsing/canonicalizing into 16 bytes instead of using the 4-byte
`Inet4Address` result, and add coverage for `::ffff:0.0.0.1` vs `::1`.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]