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

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

paul-rogers commented on pull request #1749: DRILL-7177: Format Plugin for 
Excel Files
URL: https://github.com/apache/drill/pull/1749#discussion_r336788543
 
 

 ##########
 File path: 
contrib/format-excel/src/test/java/org/apache/drill/exec/store/excel/TestExcelFormat.java
 ##########
 @@ -0,0 +1,274 @@
+/*
+ * 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.excel;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.physical.rowSet.RowSet;
+import org.apache.drill.exec.physical.rowSet.RowSetBuilder;
+import org.apache.drill.test.BaseDirTestWatcher;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.apache.drill.test.QueryBuilder;
+import org.apache.drill.test.rowSet.RowSetComparison;
+import org.apache.drill.exec.record.metadata.SchemaBuilder;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.ClassRule;
+import org.junit.experimental.categories.Category;
+import org.apache.drill.categories.RowSetTests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category(RowSetTests.class)
+public class TestExcelFormat extends ClusterTest {
+
+  @ClassRule
+  public static final BaseDirTestWatcher dirTestWatcher = new 
BaseDirTestWatcher();
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    ClusterTest.startCluster(ClusterFixture.builder(dirTestWatcher));
+    definePlugin();
+  }
+
+  private static void definePlugin() throws ExecutionSetupException {
+    ExcelFormatConfig sampleConfig = new ExcelFormatConfig();
+
+    // Define a temporary plugin for the "cp" storage plugin.
+    Drillbit drillbit = cluster.drillbit();
+    final StoragePluginRegistry pluginRegistry = 
drillbit.getContext().getStorage();
+    final FileSystemPlugin plugin = (FileSystemPlugin) 
pluginRegistry.getPlugin("cp");
+    final FileSystemConfig pluginConfig = (FileSystemConfig) 
plugin.getConfig();
+    pluginConfig.getFormats().put("sample", sampleConfig);
+    pluginRegistry.createOrUpdate("cp", pluginConfig, false);
+  }
+
+  @Test
+  public void testStarQuery() throws Exception {
+    String sql = "SELECT * FROM cp.`excel/test_data.xlsx` LIMIT 5";
+
+    testBuilder()
+      .sqlQuery(sql)
+      .ordered()
+      .baselineColumns("id", "first_name", "last_name", "email", "gender", 
"birthdate", "balance", "order_count", "average_order")
+      .baselineValues(1.0, "Cornelia", "Matej", "cmat...@mtv.com", "Female", 
"10/31/1974", 735.29, 22.0, 33.42227272727273)
+      .baselineValues(2.0, "Nydia", "Heintsch", "nheints...@godaddy.com", 
"Female", "12/10/1966", 784.14, 22.0, 35.64272727272727)
+      .baselineValues(3.0, "Waiter", "Sherel", "wsher...@utexas.edu", "Male", 
"3/12/1961", 172.36, 17.0, 10.138823529411766)
+      .baselineValues(4.0, "Cicely", "Lyver", "clyv...@mysql.com", "Female", 
"5/4/2000", 987.39, 6.0, 164.565)
+      .baselineValues(5.0, "Dorie", "Doe", "dd...@spotify.com", "Female", 
"12/28/1955", 852.48, 17.0, 50.14588235294118)
+      .go();
+  }
+
+  @Test
+  public void testExplicitAllQuery() throws RpcException {
+    String sql = "SELECT id, first_name, last_name, email, gender, birthdate, 
balance, order_count, average_order FROM cp.`excel/test_data.xlsx` LIMIT 5";
+
+    //RowSet results = client.queryBuilder().sql(sql).rowSet();
+    QueryBuilder q = client.queryBuilder().sql(sql);
+    RowSet results = q.rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .addNullable("id", TypeProtos.MinorType.FLOAT8)
+            .addNullable("first_name", TypeProtos.MinorType.VARCHAR)
+            .addNullable("last_name", TypeProtos.MinorType.VARCHAR)
+            .addNullable("email", TypeProtos.MinorType.VARCHAR)
+            .addNullable("gender", TypeProtos.MinorType.VARCHAR)
+            .addNullable("birthdate", TypeProtos.MinorType.VARCHAR)
+            .addNullable("balance", TypeProtos.MinorType.FLOAT8)
+            .addNullable("order_count", TypeProtos.MinorType.FLOAT8)
+            .addNullable("average_order", TypeProtos.MinorType.FLOAT8)
+            .buildSchema();
+
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow(1.0, "Cornelia", "Matej", "cmat...@mtv.com", "Female", 
"10/31/1974", 735.29, 22.0, 33.42227273)
+            .addRow(2.0, "Nydia", "Heintsch", "nheints...@godaddy.com", 
"Female", "12/10/1966", 784.14, 22.0, 35.64272727)
+            .addRow(3.0, "Waiter", "Sherel", "wsher...@utexas.edu", "Male", 
"3/12/1961", 172.36, 17.0, 10.13882353)
+            .addRow(4.0, "Cicely", "Lyver", "clyv...@mysql.com", "Female", 
"5/4/2000", 987.39, 6.0, 164.565)
+            .addRow(5.0, "Dorie", "Doe", "dd...@spotify.com", "Female", 
"12/28/1955", 852.48, 17.0, 50.14588235)
+            .build();
+    new RowSetComparison(expected).verifyAndClearAll(results);
+  }
+
+  @Test
+  public void testExplicitSomeQuery() throws RpcException {
+    String sql = "SELECT id, first_name, order_count FROM 
cp.`excel/test_data.xlsx` LIMIT 5";
+
+    RowSet results = client.queryBuilder().sql(sql).rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .addNullable("id", TypeProtos.MinorType.FLOAT8)
+            .addNullable("first_name", TypeProtos.MinorType.VARCHAR)
+            .addNullable("order_count", TypeProtos.MinorType.FLOAT8)
+            .buildSchema();
+
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow(1.0, "Cornelia", 22.0)
+            .addRow(2.0, "Nydia", 22.0)
+            .addRow(3.0, "Waiter", 17.0)
+            .addRow(4.0, "Cicely", 6.0)
+            .addRow(5.0, "Dorie", 17.0)
+            .build();
+    new RowSetComparison(expected).verifyAndClearAll(results);
+  }
+
+  @Test
+  public void testNonDefaultSheetQuery() throws RpcException {
+    String sql = "SELECT * FROM  table(cp.`excel/test_data.xlsx` (type => 
'excel', sheetName => 'secondSheet')) LIMIT 5";
+
+    RowSet results = client.queryBuilder().sql(sql).rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .addNullable("event_date", TypeProtos.MinorType.VARCHAR)
+            .addNullable("ip_address", TypeProtos.MinorType.VARCHAR)
+            .addNullable("user_agent", TypeProtos.MinorType.VARCHAR)
+            .buildSchema();
+
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow("2019-02-17 11:21:45", "166.11.144.176", "Mozilla/5.0 
(Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.19.4 (KHTML, like Gecko) 
Version/5.0.3 Safari/533.19.4")
+            .addRow("2019-03-03 04:10:31", "203.221.176.215", "Mozilla/5.0 
(Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) 
Chrome/13.0.782.215 Safari/535.1")
+            .addRow("2018-04-05 08:17:17", "11.134.119.132", "Mozilla/5.0 
(Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.813.0 
Safari/535.1")
+            .addRow("2018-12-05 05:36:10", "68.145.168.82", "Mozilla/5.0 
(Windows NT 6.1; WOW64) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.940.0 
Safari/535.8")
+            .addRow("2018-04-01 16:25:18", "21.12.166.184", "Mozilla/5.0 
(Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like 
Gecko) Version/5.0.4 Safari/533.20.27")
+            .build();
+    new RowSetComparison(expected).verifyAndClearAll(results);
+  }
+
+  @Test
+  public void testExplicitNonDefaultSheetQuery() throws RpcException {
+    String sql = "SELECT event_date, ip_address, user_agent FROM  
table(cp.`excel/test_data.xlsx` (type => 'excel', sheetName => 
'secondSheet'))LIMIT 5";
+
+    RowSet results = client.queryBuilder().sql(sql).rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .addNullable("event_date", TypeProtos.MinorType.VARCHAR)
+            .addNullable("ip_address", TypeProtos.MinorType.VARCHAR)
+            .addNullable("user_agent", TypeProtos.MinorType.VARCHAR)
+            .buildSchema();
+
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow("2019-02-17 11:21:45", "166.11.144.176", "Mozilla/5.0 
(Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.19.4 (KHTML, like Gecko) 
Version/5.0.3 Safari/533.19.4")
+            .addRow("2019-03-03 04:10:31", "203.221.176.215", "Mozilla/5.0 
(Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) 
Chrome/13.0.782.215 Safari/535.1")
+            .addRow("2018-04-05 08:17:17", "11.134.119.132", "Mozilla/5.0 
(Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.813.0 
Safari/535.1")
+            .addRow("2018-12-05 05:36:10", "68.145.168.82", "Mozilla/5.0 
(Windows NT 6.1; WOW64) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.940.0 
Safari/535.8")
+            .addRow("2018-04-01 16:25:18", "21.12.166.184", "Mozilla/5.0 
(Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like 
Gecko) Version/5.0.4 Safari/533.20.27")
+            .build();
+    new RowSetComparison(expected).verifyAndClearAll(results);
+  }
+
+  /**
+   * This test verifies that when a user attempts to open a sheet that doesn't 
exist, the plugin will throw an error
+   */
+  @Test
+  public void testInvalidSheetQuery() throws Exception {
+    String sql = "SELECT * FROM  table(cp.`excel/test_data.xlsx` (type => 
'excel', sheetName => 'noSuchSheet')) LIMIT 1";
+    try {
+      run(sql);
+      fail();
+    } catch (DrillRuntimeException e) {
+      assertTrue(e.getMessage().contains("Could not open sheet "));
+    }
+  }
+
+  @Test
+  public void testDefineColumnsQuery() throws RpcException {
 
 Review comment:
   Should be test:
   
   * Empty sheet
   * No column headers
   * No data rows
   * Data cells with missing values
   * Missing data cells (if Excel allows such)
   * Changing of data types within a column
   * A run of missing values followed by a data type
 
----------------------------------------------------------------
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


> Format Plugin for Excel Files
> -----------------------------
>
>                 Key: DRILL-7177
>                 URL: https://issues.apache.org/jira/browse/DRILL-7177
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.17.0
>            Reporter: Charles Givre
>            Assignee: Charles Givre
>            Priority: Major
>              Labels: doc-impacting
>             Fix For: 1.17.0
>
>
> This pull request adds the functionality which enables Drill to query 
> Microsoft Excel files. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to