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_r331771661
########## 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() Review comment: OK, but might be better to use the newer RowSet/SchemaBuilder techniques. ---------------------------------------------------------------- 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