sb89594 commented on code in PR #15212:
URL: https://github.com/apache/druid/pull/15212#discussion_r1366588245


##########
processing/src/main/java/org/apache/druid/query/expression/IPv6AddressMatchExprMacro.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.druid.query.expression;
+
+import inet.ipaddr.AddressStringException;
+import inet.ipaddr.IPAddress;
+import inet.ipaddr.IPAddressString;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.math.expr.Expr;
+import org.apache.druid.math.expr.ExprEval;
+import org.apache.druid.math.expr.ExprMacroTable;
+import org.apache.druid.math.expr.ExpressionType;
+ 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.List;
+ 
+/**
+  * <pre>
+  * Implements an expression that checks if an IPv6 address belongs to a 
subnet.
+  *
+  * Expression signatures:
+  * - long ipv6_match(string address, string subnet)
+  *
+  * Valid "address" argument formats are:
+  * - IPv6 address string (e.g., "2001:4860:4860::8888")
+  *
+  * The argument format for the "subnet" argument should be a literal in CIDR 
notation
+  * (e.g., "2001:db8::/64 ").
+  *
+  * If the "address" argument does not represent an IPv6 address then false is 
returned.
+  * </pre>
+  *
+*/
+public class IPv6AddressMatchExprMacro implements ExprMacroTable.ExprMacro
+{
+  public static final String FN_NAME = "IPV6_MATCH";
+  private static final int ARG_SUBNET = 1;
+ 
+  @Override
+  public String name()
+  {
+    return FN_NAME;
+  }
+ 
+  @Override
+  public Expr apply(final List<Expr> args)
+  {
+    validationHelperCheckArgumentCount(args, 2);
+ 
+    try {
+      final Expr arg = args.get(0);
+      final IPAddressString blockString = getSubnetInfo(args);
+      final IPAddress block = blockString.toAddress().toPrefixBlock();

Review Comment:
   Removed unused variable and changed catch as `AddressStringException` is no 
longer thrown



-- 
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]

Reply via email to