paul-rogers commented on a change in pull request #1778: Drill-7233: Format 
Plugin for HDF5
URL: https://github.com/apache/drill/pull/1778#discussion_r331771711
 
 

 ##########
 File path: 
contrib/format-hdf5/src/test/java/org/apache/drill/exec/store/hdf5/TestHDF5Format.java
 ##########
 @@ -0,0 +1,758 @@
+/*
+ * 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.hdf5;
+
+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.test.ClusterTest;
+import org.apache.drill.test.BaseDirTestWatcher;
+import org.apache.drill.exec.physical.rowSet.RowSet;
+import org.apache.drill.exec.physical.rowSet.RowSetBuilder;
+import org.apache.drill.test.ClusterFixture;
+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 java.util.ArrayList;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestHDF5Format extends ClusterTest {
+  @ClassRule
+  public static final BaseDirTestWatcher dirTestWatcher = new 
BaseDirTestWatcher();
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    
ClusterTest.startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));
+    dirTestWatcher.copyResourceToRoot(Paths.get("hdf5"));
+    HDF5FormatConfig sampleConfig = new HDF5FormatConfig();
+    sampleConfig.setExtension("h5");
+
+    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 testExplicitQuery() throws RpcException {
+    String sql = "SELECT path, data_type, file_name FROM cp.`hdf5/dset.h5`";
+    RowSet results = client.queryBuilder().sql(sql).rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .add("path", TypeProtos.MinorType.VARCHAR, 
TypeProtos.DataMode.OPTIONAL)
+            .add("data_type", TypeProtos.MinorType.VARCHAR, 
TypeProtos.DataMode.OPTIONAL)
+            .add("file_name", TypeProtos.MinorType.VARCHAR, 
TypeProtos.DataMode.OPTIONAL)
+            .buildSchema();
+
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow("/dset", "DATASET", "dset.h5")
+            .build();
+    new RowSetComparison(expected).unorderedVerifyAndClearAll(results);
+  }
+
+  @Test
+  public void testStarQuery() throws Exception {
+    List<Integer> t1 = Arrays.asList(1, 2, 3, 4, 5, 6);
+    List<Integer> t2 = Arrays.asList(7, 8, 9, 10, 11, 12);
+    List<Integer> t3 = Arrays.asList(13, 14, 15, 16, 17, 18);
+    List<Integer> t4 = Arrays.asList(19, 20, 21, 22, 23, 24);
+    ArrayList<List<Integer>> finalList = new ArrayList<>();
+    finalList.add(t1);
+    finalList.add(t2);
+    finalList.add(t3);
+    finalList.add(t4);
+
+    testBuilder()
+            .sqlQuery("SELECT * FROM cp.`hdf5/dset.h5`")
+            .unOrdered()
+            .baselineColumns("path", "data_type", "file_name", "int_data")
+            .baselineValues("/dset", "DATASET", "dset.h5", finalList)
+            .build()
+            .run();
+  }
+
+  @Test
+  public void testSimpleExplicitQuery() throws Exception {
+    List<Integer> t1 = Arrays.asList(1, 2, 3, 4, 5, 6);
+    List<Integer> t2 = Arrays.asList(7, 8, 9, 10, 11, 12);
+    List<Integer> t3 = Arrays.asList(13, 14, 15, 16, 17, 18);
+    List<Integer> t4 = Arrays.asList(19, 20, 21, 22, 23, 24);
+    ArrayList<List<Integer>> finalList = new ArrayList<>();
+    finalList.add(t1);
+    finalList.add(t2);
+    finalList.add(t3);
+    finalList.add(t4);
+
+    testBuilder()
+            .sqlQuery("SELECT path, data_type, file_name, int_data FROM 
cp.`hdf5/dset.h5`")
+            .ordered()
+            .baselineColumns("path", "data_type", "file_name", "int_data")
+            .baselineValues("/dset", "DATASET", "dset.h5", finalList)
+            .build()
+            .run();
+  }
+
+  @Test
+  public void testFlattenColumnQuery() throws RpcException {
+    String sql = "SELECT data[0] AS col1,\n" +
+            "data[1] as col2,\n" +
+            "data[2] as col3\n" +
+            "FROM \n" +
+            "(\n" +
+            "SELECT FLATTEN(double_data) AS data \n" +
+            "FROM cp.`hdf5/browsing.h5` \n" +
+            ")";
+    RowSet results = client.queryBuilder().sql(sql).rowSet();
+    TupleMetadata expectedSchema = new SchemaBuilder()
+            .add("col1", TypeProtos.MinorType.FLOAT8, 
TypeProtos.DataMode.OPTIONAL)
+            .add("col2", TypeProtos.MinorType.FLOAT8, 
TypeProtos.DataMode.OPTIONAL)
+            .add("col3", TypeProtos.MinorType.FLOAT8, 
TypeProtos.DataMode.OPTIONAL)
+            .buildSchema();
+    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+            .addRow(1.1, 2.2, 3.3)
+            .addRow(4.4, 5.5, 6.6)
+            .addRow(7.7, 8.8, 9.9)
+            .build();
+    new RowSetComparison(expected).verifyAndClearAll(results);
+  }
+
+  @Test
+  public void testFilterWithNonProjectedFieldQuery() throws RpcException {
+    String sql = "SELECT `path` FROM cp.`hdf5/browsing.h5` WHERE 
data_type='DATASET'";
 
 Review comment:
   I see, we are using the `WHERE` clause, but the predicate is not pushed into 
the reader. We are likely reading all the data, then throwing away what we 
don't want. I wonder if there is a way to read only what we want. Else, we've 
got some rather complex schemas going on behind the scenes that are likely to 
cause issues/slowness at some point.

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to