[ 
https://issues.apache.org/jira/browse/DRILL-7343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16922533#comment-16922533
 ] 

ASF GitHub Bot commented on DRILL-7343:
---------------------------------------

KazydubB commented on pull request #1840: DRILL-7343: Add User-Agent UDFs to 
Drill
URL: https://github.com/apache/drill/pull/1840#discussion_r320781926
 
 

 ##########
 File path: 
contrib/udfs/src/test/java/org/apache/drill/exec/udfs/TestUserAgentFunctions.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.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 TestUserAgentFunctions extends ClusterTest {
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
+    startCluster(builder);
+  }
+
+  @Test
+  public void testParseUserAgentString() throws Exception {
+    String query = "SELECT t1.ua.DeviceClass AS DeviceClass,\n" +
+      "t1.ua.DeviceName AS DeviceName,\n" +
+      "t1.ua.DeviceBrand AS DeviceBrand,\n" +
+      "t1.ua.DeviceCpuBits AS DeviceCpuBits,\n" +
+      "t1.ua.OperatingSystemClass AS OperatingSystemClass,\n" +
+      "t1.ua.OperatingSystemName AS OperatingSystemName,\n" +
+      "t1.ua.OperatingSystemVersion AS OperatingSystemVersion,\n" +
+      "t1.ua.OperatingSystemVersionMajor AS OperatingSystemVersionMajor,\n" +
+      "t1.ua.OperatingSystemNameVersion AS OperatingSystemNameVersion,\n" +
+      "t1.ua.OperatingSystemNameVersionMajor AS 
OperatingSystemNameVersionMajor,\n" +
+      "t1.ua.LayoutEngineClass AS LayoutEngineClass,\n" +
+      "t1.ua.LayoutEngineName AS LayoutEngineName,\n" +
+      "t1.ua.LayoutEngineVersion AS LayoutEngineVersion,\n" +
+      "t1.ua.LayoutEngineVersionMajor AS LayoutEngineVersionMajor,\n" +
+      "t1.ua.LayoutEngineNameVersion AS LayoutEngineNameVersion,\n" +
+      "t1.ua.LayoutEngineBuild AS LayoutEngineBuild,\n" +
+      "t1.ua.AgentClass AS AgentClass,\n" +
+      "t1.ua.AgentName AS AgentName,\n" +
+      "t1.ua.AgentVersion AS AgentVersion,\n" +
+      "t1.ua.AgentVersionMajor AS AgentVersionMajor,\n" +
+      "t1.ua.AgentNameVersionMajor AS AgentNameVersionMajor,\n" +
+      "t1.ua.AgentLanguage AS AgentLanguage,\n" +
+      "t1.ua.AgentLanguageCode AS AgentLanguageCode,\n" +
+      "t1.ua.AgentSecurity AS AgentSecurity\n" +
+      "FROM (SELECT parse_user_agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; 
en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11') AS ua FROM (values(1))) 
AS t1";
+
+    testBuilder().sqlQuery(query).unOrdered()
+      .baselineColumns("DeviceClass", "DeviceName", 
"DeviceBrand","DeviceCpuBits","OperatingSystemClass", 
"OperatingSystemName","OperatingSystemVersion",
+        
"OperatingSystemVersionMajor","OperatingSystemNameVersion","OperatingSystemNameVersionMajor","LayoutEngineClass","LayoutEngineName","LayoutEngineVersion",
+        
"LayoutEngineVersionMajor","LayoutEngineNameVersion","LayoutEngineBuild","AgentClass","AgentName","AgentVersion","AgentVersionMajor","AgentNameVersionMajor",
+        "AgentLanguage","AgentLanguageCode","AgentSecurity")
+      .baselineValues("Desktop","Desktop", "Unknown","32", "Desktop", "Windows 
NT", "XP", "XP", "Windows XP", "Windows XP", "Browser", "Gecko", "1.8.1.11", 
"1", "Gecko 1.8.1.11",
+        "20071127", "Browser", "Firefox", "2.0.0.11", "2", "Firefox 2", 
"English (United States)", "en-us","Strong security")
+      .go();
+  }
+
+  @Test
+  public void testGetHostName() throws Exception {
+    String query = "SELECT parse_user_agent('Mozilla/5.0 (Windows; U; Windows 
NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11', 'AgentSecurity') 
AS agent FROM " +
+      "(values" +
+      "(1))";
+    
testBuilder().sqlQuery(query).ordered().baselineColumns("agent").baselineValues("Strong
 security").go();
+
+    query = "SELECT parse_user_agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; 
en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11', '') AS agent FROM " +
 
 Review comment:
   @cgivre have you tried having `@Param NullableVarCharHolder input` and 
passing `CAST(null as VARCHAR)` (i.e., specifying the correct type of input) 
for `NULL` input value in case of `@Output BaseWriter.ComplexWriter outWriter`. 
Is it still not accepted?
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add User-Agent UDFs to Drill
> ----------------------------
>
>                 Key: DRILL-7343
>                 URL: https://issues.apache.org/jira/browse/DRILL-7343
>             Project: Apache Drill
>          Issue Type: New Feature
>    Affects Versions: 1.17.0
>            Reporter: Charles Givre
>            Assignee: Charles Givre
>            Priority: Major
>             Fix For: 1.17.0
>
>
> This collection of UDFs adds the ability to parse user agent strings which is 
> useful for security data analysis. 



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to