You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by "cgivre (via GitHub)" <gi...@apache.org> on 2023/03/17 14:09:11 UTC

[PR] DRILL-8413: Add DNS Lookup Functions (drill)

cgivre opened a new pull request, #2778:
URL: https://github.com/apache/drill/pull/2778

   # [DRILL-8413](https://issues.apache.org/jira/browse/DRILL-8413): Add DNS Lookup Functions
   
   
   ## Description
   See below
   
   ## Documentation
   
   These functions enable DNS research using Drill.
   
   * `getHostName(<IP address>)`:  Returns the host name associated with an IP address.
   * `getHostAddress(<host>)`:  Returns an IP address associated with a host name.
   * `dnsLookup(<host>, [<Resolver>])`:  Performs a DNS lookup on a given host.  You can optionally provide a resolver.  Possible resolver values are: `cloudflare`,  `cloudflare_secondary`, `google`, `google_secondary`, `verisign`, `verisign_secondary`, `yandex`, `yandex_secondary`.
   * `whois(<host>, [<Resolver>])`:  Performs a whois lookup on the given host name.  You can optionally provide a resolver URL. Note that not all providers allow bulk automated whois lookups, so please follow the terms fo service for your provider.
   
   ## Testing
   Added unit tests.


-- 
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: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] DRILL-8413: Add DNS Lookup Functions (drill)

Posted by "cgivre (via GitHub)" <gi...@apache.org>.
cgivre merged PR #2778:
URL: https://github.com/apache/drill/pull/2778


-- 
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: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] DRILL-8413: Add DNS Lookup Functions (drill)

Posted by "jnturton (via GitHub)" <gi...@apache.org>.
jnturton commented on code in PR #2778:
URL: https://github.com/apache/drill/pull/2778#discussion_r1141347355


##########
contrib/udfs/src/test/java/org/apache/drill/exec/udfs/TestDNSFunctions.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.udfs;
+
+import org.apache.drill.categories.SqlFunctionTest;
+import org.apache.drill.categories.UnlikelyTest;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterFixtureBuilder;
+import org.apache.drill.test.ClusterTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({UnlikelyTest.class, SqlFunctionTest.class})
+public class TestDNSFunctions extends ClusterTest {
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
+    startCluster(builder);
+  }
+
+  @Test
+  public void testGetHostAddress() throws Exception {
+    String query = "select get_host_address('apache.org') as hostname from (values(1))";
+    testBuilder().sqlQuery(query).ordered().baselineColumns("hostname").baselineValues("151.101.2.132").go();

Review Comment:
   I guess these tests are technically nondeterministic but so seldom that it's nothing to worry about.



##########
contrib/udfs/README.md:
##########
@@ -436,3 +436,11 @@ The functions are:
 
 [1]: https://github.com/target/huntlib
 
+
+# DNS Functions

Review Comment:
   It would be nice to mention that the JRE caches DNS records for their TTL which should mean that these functions can scale to big datasets if the number of distinct domains that need to be looked up is not big.



##########
contrib/udfs/src/main/java/org/apache/drill/exec/udfs/DNSUtils.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.udfs;
+
+import io.netty.buffer.DrillBuf;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.net.whois.WhoisClient;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.SimpleResolver;
+import org.xbill.DNS.TextParseException;
+import org.xbill.DNS.Type;
+
+import java.io.IOException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Utility class which contains various methods for performing DNS resolution and WHOIS lookups in Drill UDFs.
+ */
+public class DNSUtils {
+
+  private static final Logger logger = LoggerFactory.getLogger(DNSUtils.class);
+  /**
+   *  A list of known DNS resolvers.
+   */
+  private static final Map<String, String> KNOWN_RESOLVERS = new HashMap<>();

Review Comment:
   I think Guava has some nice Map builders, not that this is bad.



##########
contrib/udfs/pom.xml:
##########
@@ -31,10 +31,22 @@
   <name>Drill : Contrib : UDFs</name>
 
   <dependencies>
+    <dependency>

Review Comment:
   I think that DNS lookups can be done in the standard JDK without any libraries. But I'm not sure about all of the functions supported by these UDFs.



-- 
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: dev-unsubscribe@drill.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org