aboutsummaryrefslogtreecommitdiff
path: root/contrib/format-ltsv/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/format-ltsv/src/test')
-rw-r--r--contrib/format-ltsv/src/test/java/org/apache/drill/exec/store/ltsv/TestLTSVRecordReader.java100
-rw-r--r--contrib/format-ltsv/src/test/resources/emptylines.ltsv4
-rw-r--r--contrib/format-ltsv/src/test/resources/invalid.ltsv1
-rw-r--r--contrib/format-ltsv/src/test/resources/simple.ltsv2
4 files changed, 107 insertions, 0 deletions
diff --git a/contrib/format-ltsv/src/test/java/org/apache/drill/exec/store/ltsv/TestLTSVRecordReader.java b/contrib/format-ltsv/src/test/java/org/apache/drill/exec/store/ltsv/TestLTSVRecordReader.java
new file mode 100644
index 000000000..61f65f473
--- /dev/null
+++ b/contrib/format-ltsv/src/test/java/org/apache/drill/exec/store/ltsv/TestLTSVRecordReader.java
@@ -0,0 +1,100 @@
+/*
+ * 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.store.ltsv;
+
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.common.logical.FormatPluginConfig;
+import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class TestLTSVRecordReader extends ClusterTest {
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ startCluster(ClusterFixture.builder(dirTestWatcher));
+
+ DrillbitContext context = cluster.drillbit().getContext();
+ FileSystemConfig original = (FileSystemConfig) context.getStorage().getPlugin("cp").getConfig();
+ Map<String, FormatPluginConfig> newFormats = new HashMap<>(original.getFormats());
+ newFormats.put("ltsv", new LTSVFormatPluginConfig());
+ FileSystemConfig pluginConfig = new FileSystemConfig(original.getConnection(), original.getConfig(), original.getWorkspaces(), newFormats);
+ pluginConfig.setEnabled(true);
+ context.getStorage().createOrUpdate("cp", pluginConfig, true);
+ }
+
+ @Test
+ public void testWildcard() throws Exception {
+ testBuilder()
+ .sqlQuery("SELECT * FROM cp.`simple.ltsv`")
+ .unOrdered()
+ .baselineColumns("host", "forwardedfor", "req", "status", "size", "referer", "ua", "reqtime", "apptime", "vhost")
+ .baselineValues("xxx.xxx.xxx.xxx", "-", "GET /v1/xxx HTTP/1.1", "200", "4968", "-", "Java/1.8.0_131", "2.532", "2.532", "api.example.com")
+ .baselineValues("xxx.xxx.xxx.xxx", "-", "GET /v1/yyy HTTP/1.1", "200", "412", "-", "Java/1.8.0_201", "3.580", "3.580", "api.example.com")
+ .go();
+ }
+
+ @Test
+ public void testSelectColumns() throws Exception {
+ testBuilder()
+ .sqlQuery("SELECT ua, reqtime FROM cp.`simple.ltsv`")
+ .unOrdered()
+ .baselineColumns("ua", "reqtime")
+ .baselineValues("Java/1.8.0_131", "2.532")
+ .baselineValues("Java/1.8.0_201", "3.580")
+ .go();
+ }
+
+ @Test
+ public void testQueryWithConditions() throws Exception {
+ testBuilder()
+ .sqlQuery("SELECT * FROM cp.`simple.ltsv` WHERE reqtime > 3.0")
+ .unOrdered()
+ .baselineColumns("host", "forwardedfor", "req", "status", "size", "referer", "ua", "reqtime", "apptime", "vhost")
+ .baselineValues("xxx.xxx.xxx.xxx", "-", "GET /v1/yyy HTTP/1.1", "200", "412", "-", "Java/1.8.0_201", "3.580", "3.580", "api.example.com")
+ .go();
+ }
+
+ @Test
+ public void testSkipEmptyLines() throws Exception {
+ assertEquals(2, queryBuilder().sql("SELECT * FROM cp.`emptylines.ltsv`").run().recordCount());
+ }
+
+ @Test
+ public void testReadException() throws Exception {
+ try {
+ run("SELECT * FROM cp.`invalid.ltsv`");
+ fail();
+ } catch (UserException e) {
+ assertEquals(UserBitShared.DrillPBError.ErrorType.DATA_READ, e.getErrorType());
+ assertTrue(e.getMessage().contains("Failure while reading messages from /invalid.ltsv. Record reader was at record: 1"));
+ }
+ }
+
+}
diff --git a/contrib/format-ltsv/src/test/resources/emptylines.ltsv b/contrib/format-ltsv/src/test/resources/emptylines.ltsv
new file mode 100644
index 000000000..2cdfe4efd
--- /dev/null
+++ b/contrib/format-ltsv/src/test/resources/emptylines.ltsv
@@ -0,0 +1,4 @@
+time:30/Nov/2016:00:55:08 +0900 host:xxx.xxx.xxx.xxx
+
+
+time:30/Nov/2016:00:56:37 +0900 host:xxx.xxx.xxx.xxx
diff --git a/contrib/format-ltsv/src/test/resources/invalid.ltsv b/contrib/format-ltsv/src/test/resources/invalid.ltsv
new file mode 100644
index 000000000..2395e0af5
--- /dev/null
+++ b/contrib/format-ltsv/src/test/resources/invalid.ltsv
@@ -0,0 +1 @@
+time:30/Nov/2016:00:55:08 +0900 :xxx.xxx.xxx.xxx
diff --git a/contrib/format-ltsv/src/test/resources/simple.ltsv b/contrib/format-ltsv/src/test/resources/simple.ltsv
new file mode 100644
index 000000000..d09ce0c97
--- /dev/null
+++ b/contrib/format-ltsv/src/test/resources/simple.ltsv
@@ -0,0 +1,2 @@
+host:xxx.xxx.xxx.xxx forwardedfor:- req:GET /v1/xxx HTTP/1.1 status:200 size:4968 referer:- ua:Java/1.8.0_131 reqtime:2.532 apptime:2.532 vhost:api.example.com
+host:xxx.xxx.xxx.xxx forwardedfor:- req:GET /v1/yyy HTTP/1.1 status:200 size:412 referer:- ua:Java/1.8.0_201 reqtime:3.580 apptime:3.580 vhost:api.example.com