Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.6k
PARQUET-2417: Add statistics support to geometry logical type#2971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6a2e051d354012969b69687ee8ead67e03bccf1c4a35342c2bcfefb7cf615f6c6ae73380a629ee0ec9ef7c728b1fa36d062a1c62ad0e7d3d30d64be29a86b50c4b8b4a56e9ad1ae3d99198642d0cf2de94f0f7eda378a9a698325ad65ba8e1b0f5b9342e4003cc9b68dc05cfd6f1d586e4e3cae69d950fd296c6a93e28b7e688d0501ac560f9585cdb805cf46aa70284536e5ff188341214fd39907acceef83a2ec5d542bc1fb37bdac9ad0e0a319e4fd177d9f0482eebd45a901147014cd8dfd5ec654623af52fd0081be375de5592f45c21ecb5b64c105758937907928109d9d08f92f751eb39916908df461ccf3c49797b98a1079c80c8f6610e73fdef4491e9d26af23c11819b3e3d8ffe0ee88268d398dd0befe8875455d15b5e6579feecd9155c63b4eccd0715ef8e34381eb57de904e3e882ef38e9d2426795549674e94ab9f3d31a136bbf4945ecdff5dd1d0dbc879833d3b771957dcaaec732e476dfffFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * 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.cli.commands; | ||
| import com.beust.jcommander.Parameter; | ||
| import com.beust.jcommander.Parameters; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Lists; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import org.apache.commons.text.TextStringBuilder; | ||
| import org.apache.parquet.cli.BaseCommand; | ||
| import org.apache.parquet.column.statistics.geospatial.GeospatialStatistics; | ||
| import org.apache.parquet.hadoop.ParquetFileReader; | ||
| import org.apache.parquet.hadoop.metadata.BlockMetaData; | ||
| import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; | ||
| import org.apache.parquet.hadoop.metadata.ParquetMetadata; | ||
| import org.apache.parquet.schema.MessageType; | ||
| import org.slf4j.Logger; | ||
| @Parameters(commandDescription = "Print geospatial statistics for a Parquet file") | ||
| public class ShowGeospatialStatisticsCommand extends BaseCommand { | ||
| public ShowGeospatialStatisticsCommand(Logger console) { | ||
| super(console); | ||
| } | ||
| @Parameter(description = "<parquet path>") | ||
| List<String> targets; | ||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public int run() throws IOException { | ||
| Preconditions.checkArgument(targets != null && !targets.isEmpty(), "A Parquet file is required."); | ||
| Preconditions.checkArgument(targets.size() == 1, "Cannot process multiple Parquet files."); | ||
| String source = targets.get(0); | ||
| try (ParquetFileReader reader = ParquetFileReader.open(getConf(), qualifiedPath(source))) { | ||
| ParquetMetadata footer = reader.getFooter(); | ||
| MessageType schema = footer.getFileMetaData().getSchema(); | ||
| console.info("\nFile path: {}", source); | ||
| List<BlockMetaData> rowGroups = footer.getBlocks(); | ||
| for (int index = 0, n = rowGroups.size(); index < n; index++) { | ||
| printRowGroupGeospatialStats(console, index, rowGroups.get(index), schema); | ||
| console.info(""); | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
| private void printRowGroupGeospatialStats(Logger console, int index, BlockMetaData rowGroup, MessageType schema) { | ||
| int maxColumnWidth = Math.max( | ||
| "column".length(), | ||
| rowGroup.getColumns().stream() | ||
| .map(col -> col.getPath().toString().length()) | ||
| .max(Integer::compare) | ||
| .orElse(0)); | ||
| console.info(String.format("\nRow group %d\n%s", index, new TextStringBuilder(80).appendPadding(80, '-'))); | ||
| String formatString = String.format("%%-%ds %%-15s %%-40s", maxColumnWidth); | ||
| console.info(String.format(formatString, "column", "bounding box", "geospatial types")); | ||
| for (ColumnChunkMetaData column : rowGroup.getColumns()) { | ||
| printColumnGeospatialStats(console, column, schema, maxColumnWidth); | ||
| } | ||
| } | ||
| private void printColumnGeospatialStats( | ||
zhangfengcdt marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Logger console, ColumnChunkMetaData column, MessageType schema, int columnWidth) { | ||
| GeospatialStatistics stats = column.getGeospatialStatistics(); | ||
| if (stats != null && stats.isValid()) { | ||
| String boundingBox = | ||
| stats.getBoundingBox() != null ? stats.getBoundingBox().toString() : "-"; | ||
zhangfengcdt marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| String geospatialTypes = stats.getGeospatialTypes() != null | ||
| ? stats.getGeospatialTypes().toString() | ||
| : "-"; | ||
| String formatString = String.format("%%-%ds %%-15s %%-40s", columnWidth); | ||
| console.info(String.format(formatString, column.getPath(), boundingBox, geospatialTypes)); | ||
| } else { | ||
| String formatString = String.format("%%-%ds %%-15s %%-40s", columnWidth); | ||
| console.info(String.format(formatString, column.getPath(), "-", "-")); | ||
| } | ||
| } | ||
| @Override | ||
| public List<String> getExamples() { | ||
| return Lists.newArrayList("# Show geospatial statistics for a Parquet file", "sample.parquet"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * 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.cli.commands; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| public class ShowGeospatialStatisticsCommandTest extends ParquetFileTest { | ||
| @Test | ||
| public void testShowGeospatialStatisticsCommand() throws IOException { | ||
| File file = parquetFile(); | ||
| ShowGeospatialStatisticsCommand command = new ShowGeospatialStatisticsCommand(createLogger()); | ||
| command.targets = Arrays.asList(file.getAbsolutePath()); | ||
| command.setConf(new Configuration()); | ||
| Assert.assertEquals(0, command.run()); | ||
| } | ||
| } |
zhangfengcdt marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.