drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject drill git commit: DRILL-5834: Add Networking Functions
Date Tue, 07 Nov 2017 01:31:33 GMT
Repository: drill
Updated Branches:
  refs/heads/master 7a2fc87ee -> 29e054769


DRILL-5834: Add Networking Functions

close apache/drill#1018


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/29e05476
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/29e05476
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/29e05476

Branch: refs/heads/master
Commit: 29e054769ea1cfd36f08df991d6263781374c92c
Parents: 7a2fc87
Author: cgivre <cgivre@gmail.com>
Authored: Wed Nov 1 14:15:38 2017 -0400
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Mon Nov 6 17:25:04 2017 -0800

----------------------------------------------------------------------
 exec/java-exec/pom.xml                          |  17 +-
 .../exec/expr/fn/impl/NetworkFunctions.java     | 563 +++++++++++++++++++
 .../exec/fn/impl/TestNetworkFunctions.java      | 134 +++++
 exec/jdbc-all/pom.xml                           |   8 +
 4 files changed, 721 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/29e05476/exec/java-exec/pom.xml
----------------------------------------------------------------------
diff --git a/exec/java-exec/pom.xml b/exec/java-exec/pom.xml
index 4cd7158..2ac5c1e 100644
--- a/exec/java-exec/pom.xml
+++ b/exec/java-exec/pom.xml
@@ -447,7 +447,22 @@
       <artifactId>joda-time</artifactId>
       <version>2.9</version>
     </dependency>
-
+    <dependency>
+      <groupId>commons-net</groupId>
+      <artifactId>commons-net</artifactId>
+      <version>3.6</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-validator</groupId>
+      <artifactId>commons-validator</artifactId>
+      <version>1.4.1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-common</artifactId>

http://git-wip-us.apache.org/repos/asf/drill/blob/29e05476/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/NetworkFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/NetworkFunctions.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/NetworkFunctions.java
new file mode 100644
index 0000000..b6073b9
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/NetworkFunctions.java
@@ -0,0 +1,563 @@
+/*
+ * 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.drill.exec.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.holders.BigIntHolder;
+import org.apache.drill.exec.expr.holders.BitHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+import javax.inject.Inject;
+
+public class NetworkFunctions {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(NetworkFunctions.class);
+
+  private NetworkFunctions() {
+  }
+
+  /**
+   * This function takes two arguments, an input IPv4 and a CIDR, and returns true if the
IP is in the given CIDR block
+   */
+  @FunctionTemplate(name = "in_network", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class InNetworkFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputIP;
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    BitHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputIP.start,
inputIP.end, inputIP.buffer);
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+
+      int result = 0;
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      if (utils.getInfo().isInRange(ipString)) {
+        result = 1;
+      }
+
+      out.value = result;
+    }
+  }
+
+
+  /**
+   * This function retunrs the number of IP addresses in the input CIDR block.
+   */
+  @FunctionTemplate(name = "address_count", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class AddressCountFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    BigIntHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      out.value = utils.getInfo().getAddressCount();
+
+    }
+
+  }
+
+  /**
+   * This function returns the broadcast address of a given CIDR block.
+   */
+  @FunctionTemplate(name = "broadcast_address", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class BroadcastAddressFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    VarCharHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      String outputValue = utils.getInfo().getBroadcastAddress();
+
+      out.buffer = buffer;
+      out.start = 0;
+      out.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+
+  }
+
+  /**
+   * This function gets the netmask of the input CIDR block.
+   */
+
+  @FunctionTemplate(name = "netmask", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class NetmaskFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    VarCharHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      String outputValue = utils.getInfo().getNetmask();
+
+      out.buffer = buffer;
+      out.start = 0;
+      out.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+
+  }
+
+  /**
+   * This function gets the numerically lowest IP address in an input CIDR block.
+   */
+  @FunctionTemplate(name = "low_address", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class LowAddressFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    VarCharHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      String outputValue = utils.getInfo().getLowAddress();
+
+      out.buffer = buffer;
+      out.start = 0;
+      out.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+
+  }
+
+  /**
+   * This function gets the numerically highest IP address in an input CIDR block.
+   */
+  @FunctionTemplate(name = "high_address", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class HighAddressFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputCIDR;
+
+    @Output
+    VarCharHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String cidrString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputCIDR.start,
inputCIDR.end, inputCIDR.buffer);
+      org.apache.commons.net.util.SubnetUtils utils = new org.apache.commons.net.util.SubnetUtils(cidrString);
+
+      String outputValue = utils.getInfo().getHighAddress();
+
+      out.buffer = buffer;
+      out.start = 0;
+      out.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+  }
+
+  /**
+   * This function encodes URL strings.
+   */
+  @FunctionTemplate(name = "url_encode", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class urlencodeFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputString;
+
+    @Output
+    VarCharHolder outputString;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String url = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputString.start,
inputString.end, inputString.buffer);
+
+      String outputValue = "";
+      try {
+        outputValue = java.net.URLEncoder.encode(url, "UTF-8");
+      } catch (Exception e) {
+
+      }
+      outputString.buffer = buffer;
+      outputString.start = 0;
+      outputString.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+  }
+
+  /**
+   * This function decodes URL strings.
+   */
+  @FunctionTemplate(name = "url_decode", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class urldecodeFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputString;
+
+    @Output
+    VarCharHolder outputString;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+    public void eval() {
+
+      String url = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputString.start,
inputString.end, inputString.buffer);
+
+      String outputValue = "";
+      try {
+        outputValue = java.net.URLDecoder.decode(url, "UTF-8");
+      } catch (Exception e) {
+
+      }
+      outputString.buffer = buffer;
+      outputString.start = 0;
+      outputString.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+
+    }
+  }
+
+
+  /**
+   * This function converts a BigInt IPv4 into dotted decimal notation.  The opposite of
inet_aton.
+   */
+
+  @FunctionTemplate(name = "inet_ntoa", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class InetNtoaFunction implements DrillSimpleFunc {
+
+    @Param
+    BigIntHolder in;
+
+    @Output
+    VarCharHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+      StringBuilder result = new StringBuilder(15);
+
+      long inputInt = in.value;
+
+      for (int i = 0; i < 4; i++) {
+
+        result.insert(0, Long.toString(inputInt & 0xff));
+
+        if (i < 3) {
+          result.insert(0, '.');
+        }
+
+        inputInt = inputInt >> 8;
+      }
+
+      String outputValue = result.toString();
+
+      out.buffer = buffer;
+      out.start = 0;
+      out.end = outputValue.getBytes().length;
+      buffer.setBytes(0, outputValue.getBytes());
+    }
+
+
+  }
+
+  /**
+   * This function returns true if a given IPv4 address is private, false if not.
+   */
+
+  @FunctionTemplate(name = "is_private_ip", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class IsPrivateIP implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputTextA;
+
+    @Output
+    BitHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputTextA.start,
inputTextA.end, inputTextA.buffer);
+
+      String[] ipAddressInArray = ipString.split("\\.");
+
+      int result = 0;
+
+      int[] octets = new int[3];
+
+      for (int i = 0; i < 3; i++) {
+        octets[i] = Integer.parseInt(ipAddressInArray[i]);
+      }
+
+      if (octets[0] == 192 && octets[1] == 168) {
+        result = 1;
+      } else if (octets[0] == 172 && octets[1] >= 16 && octets[1] <=
31) {
+        result = 1;
+      } else if (octets[0] == 10) {
+        result = 1;
+      } else {
+        result = 0;
+      }
+
+      out.value = result;
+    }
+  }
+
+  /**
+   * This function converts an IPv4 address into a BigInt.  Useful for sorting IPs, or looking
for IP ranges.
+   * IE:
+   * SELECT *
+   * FROM <data>
+   * ORDER BY inet_aton( ip ) ASC
+   */
+  @FunctionTemplate(name = "inet_aton", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class InetAtonFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputTextA;
+
+    @Output
+    BigIntHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputTextA.start,
inputTextA.end, inputTextA.buffer);
+      if (ipString == null || ipString.isEmpty()) {
+        out.value = 0;
+      } else {
+        String[] ipAddressInArray = ipString.split("\\.");
+
+        long result = 0;
+        for (int i = 0; i < ipAddressInArray.length; i++) {
+          int power = 3 - i;
+          int ip = Integer.parseInt(ipAddressInArray[i]);
+          result += ip * Math.pow(256, power);
+        }
+
+        out.value = result;
+      }
+    }
+  }
+
+  /**
+   * Returns true if the input string is a valid IP address
+   */
+  @FunctionTemplate(name = "is_valid_IP", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class IsValidIPFunction implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputIP;
+
+    @Output
+    BitHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputIP.start,
inputIP.end, inputIP.buffer);
+      if (ipString == null || ipString.isEmpty()) {
+        out.value = 0;
+      } else {
+        org.apache.commons.validator.routines.InetAddressValidator validator = org.apache.commons.validator.routines.InetAddressValidator.getInstance();
+
+        boolean valid = validator.isValid(ipString);
+        if (valid) {
+          out.value = 1;
+        } else {
+          out.value = 0;
+        }
+      }
+
+    }
+  }
+
+  /**
+   * Returns true if the input string is a valid IPv4 address
+   */
+  @FunctionTemplate(name = "is_valid_IPv4", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class IsValidIPV4Function implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputIP;
+
+    @Output
+    BitHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+    public void setup() {
+    }
+
+
+    public void eval() {
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputIP.start,
inputIP.end, inputIP.buffer);
+      if (ipString == null || ipString.isEmpty()) {
+        out.value = 0;
+      } else {
+        org.apache.commons.validator.routines.InetAddressValidator validator = org.apache.commons.validator.routines.InetAddressValidator.getInstance();
+
+        boolean valid = validator.isValidInet4Address(ipString);
+        if (valid) {
+          out.value = 1;
+        } else {
+          out.value = 0;
+        }
+      }
+    }
+  }
+
+  /**
+   * Returns true if the input string is a valid IP address
+   */
+  @FunctionTemplate(name = "is_valid_IPv6", scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class IsValidIPv6Function implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder inputIP;
+
+    @Output
+    BitHolder out;
+
+    @Inject
+    DrillBuf buffer;
+
+
+    public void setup() {
+    }
+
+    public void eval() {
+      String ipString = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(inputIP.start,
inputIP.end, inputIP.buffer);
+      if (ipString == null || ipString.isEmpty()) {
+        out.value = 0;
+      } else {
+        org.apache.commons.validator.routines.InetAddressValidator validator = org.apache.commons.validator.routines.InetAddressValidator.getInstance();
+
+        boolean valid = validator.isValidInet6Address(ipString);
+        if (valid) {
+          out.value = 1;
+        } else {
+          out.value = 0;
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/29e05476/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNetworkFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNetworkFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNetworkFunctions.java
new file mode 100644
index 0000000..5beb4d5
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNetworkFunctions.java
@@ -0,0 +1,134 @@
+/*
+ * 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.drill.exec.fn.impl;
+
+import org.apache.drill.BaseTestQuery;
+import org.junit.Test;
+
+public class TestNetworkFunctions extends BaseTestQuery {
+
+  @Test
+  public void testInetAton() throws Exception {
+    final String query = "select inet_aton('192.168.0.1') as inet from (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("inet").baselineValues(Long.parseLong("3232235521")).go();
+  }
+
+  @Test
+  public void testInetNtoa() throws Exception {
+    final String query = "select inet_ntoa(3232235521) as inet from (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("inet").baselineValues("192.168.0.1").go();
+  }
+
+  @Test
+  public void testInNetwork() throws Exception {
+    final String query = "select in_network('192.168.0.1', '192.168.0.0/28') as in_net FROM
(values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("in_net").baselineValues(true).go();
+  }
+
+  @Test
+  public void testNotInNetwork() throws Exception {
+    final String query = "select in_network('10.10.10.10', '192.168.0.0/28') as in_net FROM
(values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("in_net").baselineValues(false).go();
+  }
+
+  @Test
+  public void testBroadcastAddress() throws Exception {
+    final String query = "select broadcast_address( '192.168.0.0/28' ) AS broadcast_address
FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("broadcast_address").baselineValues("192.168.0.15").go();
+  }
+
+  @Test
+  public void testNetmask() throws Exception {
+    final String query = "select netmask('192.168.0.0/28') AS netmask FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("netmask").baselineValues("255.255.255.240").go();
+  }
+
+  @Test
+  public void testLowAddress() throws Exception {
+    final String query = "SELECT low_address('192.168.0.0/28') AS low FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("low").baselineValues("192.168.0.1").go();
+  }
+
+  @Test
+  public void testHighAddress() throws Exception {
+    final String query = "SELECT high_address('192.168.0.0/28') AS high FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("high").baselineValues("192.168.0.14").go();
+  }
+
+  @Test
+  public void testEncodeUrl() throws Exception {
+    final String query = "SELECT url_encode('http://www.test.com/login.php?username=Charles&password=12345')
AS encoded_url FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("encoded_url").baselineValues("http%3A%2F%2Fwww.test.com%2Flogin.php%3Fusername%3DCharles%26password%3D12345").go();
+  }
+
+  @Test
+  public void testDecodeUrl() throws Exception {
+    final String query = "SELECT url_decode('http%3A%2F%2Fwww.test.com%2Flogin.php%3Fusername%3DCharles%26password%3D12345')
AS decoded_url FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("decoded_url").baselineValues("http://www.test.com/login.php?username=Charles&password=12345").go();
+  }
+
+  @Test
+  public void testNotPrivateIP() throws Exception {
+    final String query = "SELECT is_private_ip('8.8.8.8') AS is_private_ip FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_private_ip").baselineValues(false).go();
+  }
+
+  @Test
+  public void testPrivateIP() throws Exception {
+    final String query = "SELECT is_private_ip('192.168.0.1') AS is_private_ip FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_private_ip").baselineValues(true).go();
+  }
+
+  @Test
+  public void testNotValidIP() throws Exception {
+    final String query = "SELECT is_valid_IP('258.257.234.23') AS is_valid_IP FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP").baselineValues(false).go();
+  }
+
+  @Test
+  public void testIsValidIP() throws Exception {
+    final String query = "SELECT is_valid_IP('10.10.10.10') AS is_valid_IP FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP").baselineValues(true).go();
+  }
+
+  @Test
+  public void testNotValidIPv4() throws Exception {
+    final String query = "SELECT is_valid_IPv4( '192.168.0.257') AS is_valid_IP4 FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP4").baselineValues(false).go();
+  }
+
+  @Test
+  public void testIsValidIPv4() throws Exception {
+    final String query = "SELECT is_valid_IPv4( '192.168.0.1') AS is_valid_IP4 FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP4").baselineValues(true).go();
+  }
+
+  @Test
+  public void testIsValidIPv6() throws Exception {
+    final String query = "SELECT is_valid_IPv6('1050:0:0:0:5:600:300c:326b') AS is_valid_IP6
FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP6").baselineValues(true).go();
+  }
+
+  @Test
+  public void testNotValidIPv6() throws Exception {
+    final String query = "SELECT is_valid_IPv6('1050:0:0:0:5:600:300c:326g') AS is_valid_IP6
FROM (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("is_valid_IP6").baselineValues(false).go();
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/29e05476/exec/jdbc-all/pom.xml
----------------------------------------------------------------------
diff --git a/exec/jdbc-all/pom.xml b/exec/jdbc-all/pom.xml
index 9cbdb5a..049fe4b 100644
--- a/exec/jdbc-all/pom.xml
+++ b/exec/jdbc-all/pom.xml
@@ -155,6 +155,14 @@
           <groupId>org.kohsuke</groupId>
           <artifactId>libpam4j</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>commons-net</groupId>
+          <artifactId>commons-net</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>commons-validator</groupId>
+          <artifactId>commons-validator</artifactId>
+        </exclusion>
       </exclusions>
     </dependency>
     <dependency>


Mime
View raw message