-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARQUET-2418: Add integration test for BYTE_STREAM_SPLIT (#1255)
- Loading branch information
Showing
6 changed files
with
167 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/InterOpTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.parquet.hadoop; | ||
|
||
import java.io.IOException; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class InterOpTester { | ||
private static final String PARQUET_TESTING_REPO = "https://github.com/apache/parquet-testing/raw/"; | ||
private static final String PARQUET_TESTING_PATH = "target/parquet-testing/"; | ||
private static final Logger LOG = LoggerFactory.getLogger(InterOpTester.class); | ||
private OkHttpClient httpClient = new OkHttpClient(); | ||
|
||
public Path GetInterOpFile(String fileName, String changeset) throws IOException { | ||
return GetInterOpFile(fileName, changeset, "data"); | ||
} | ||
|
||
/** | ||
* Get interOp file from parquet-testing repo, possibly downloading it. | ||
* | ||
* @param fileName The name of the file to get. | ||
* @param changeset The changeset ID in the parquet-testing repo. | ||
* @param subdir The subdirectory the file lives in inside the repo (for example "data"). | ||
* @return Path The local path to the interOp file. | ||
*/ | ||
public Path GetInterOpFile(String fileName, String changeset, String subdir) throws IOException { | ||
Path rootPath = new Path(PARQUET_TESTING_PATH, subdir); | ||
Configuration conf = new Configuration(); | ||
FileSystem fs = rootPath.getFileSystem(conf); | ||
if (!fs.exists(rootPath)) { | ||
LOG.info("Create folder for interOp files: " + rootPath); | ||
if (!fs.mkdirs(rootPath)) { | ||
throw new IOException("Cannot create path " + rootPath); | ||
} | ||
} | ||
|
||
Path file = new Path(rootPath, fileName); | ||
if (!fs.exists(file)) { | ||
String downloadUrl = String.format("%s/%s/%s/%s", PARQUET_TESTING_REPO, changeset, subdir, fileName); | ||
LOG.info("Download interOp file: " + downloadUrl); | ||
Request request = new Request.Builder().url(downloadUrl).build(); | ||
try (Response response = httpClient.newCall(request).execute()) { | ||
if (!response.isSuccessful()) { | ||
throw new IOException("Failed to download file: " + response); | ||
} | ||
try (FSDataOutputStream fdos = fs.create(file)) { | ||
fdos.write(response.body().bytes()); | ||
} | ||
} | ||
} | ||
return file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInterOpReadByteStreamSplit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.parquet.hadoop; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.parquet.example.data.Group; | ||
import org.apache.parquet.hadoop.example.GroupReadSupport; | ||
import org.junit.Test; | ||
|
||
public class TestInterOpReadByteStreamSplit { | ||
private InterOpTester interop = new InterOpTester(); | ||
private static final String FLOATS_FILE = "byte_stream_split.zstd.parquet"; | ||
private static final String CHANGESET = "4cb3cff"; | ||
|
||
@Test | ||
public void testReadFloats() throws IOException { | ||
Path floatsFile = interop.GetInterOpFile(FLOATS_FILE, CHANGESET); | ||
final int expectRows = 300; | ||
|
||
try (ParquetReader<Group> reader = | ||
ParquetReader.builder(new GroupReadSupport(), floatsFile).build()) { | ||
for (int i = 0; i < expectRows; ++i) { | ||
Group group = reader.read(); | ||
assertTrue(group != null); | ||
float fval = group.getFloat("f32", 0); | ||
double dval = group.getDouble("f64", 0); | ||
// Values are from the normal distribution | ||
assertTrue(Math.abs(fval) < 4.0); | ||
assertTrue(Math.abs(dval) < 4.0); | ||
switch (i) { | ||
case 0: | ||
assertEquals(1.7640524f, fval, 0.0); | ||
assertEquals(-1.3065268517353166, dval, 0.0); | ||
break; | ||
case 1: | ||
assertEquals(0.4001572f, fval, 0.0); | ||
assertEquals(1.658130679618188, dval, 0.0); | ||
break; | ||
case expectRows - 2: | ||
assertEquals(-0.39944902f, fval, 0.0); | ||
assertEquals(-0.9301565025243212, dval, 0.0); | ||
break; | ||
case expectRows - 1: | ||
assertEquals(0.37005588f, fval, 0.0); | ||
assertEquals(-0.17858909208732915, dval, 0.0); | ||
break; | ||
} | ||
} | ||
assertTrue(reader.read() == null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.