-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
New parquet tools commands #132
Open
swapnilushinde
wants to merge
8
commits into
apache:master
Choose a base branch
from
swapnilushinde:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f910f6f
New commands to get row count & file sizes matching glob pattern.
75e18f1
Scripts for rowcount & size commands
26a8f88
Changes asked by committer.
6e2bb54
commit before merge--dont push
972f9ac
Merge remote-tracking branch 'upstream/master'
b795463
commit before pull
0feb74a
Merge branch 'master' of https://github.com/apache/incubator-parquet-mr
e7e96cf
row count command with globs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
97 changes: 97 additions & 0 deletions
97
parquet-tools/src/main/java/parquet/tools/command/RowCountCommand.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,97 @@ | ||
/* | ||
* 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 parquet.tools.command; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.OptionBuilder; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import parquet.hadoop.Footer; | ||
import parquet.hadoop.ParquetFileReader; | ||
import parquet.hadoop.metadata.BlockMetaData; | ||
import parquet.tools.Main; | ||
|
||
public class RowCountCommand extends ArgsOnlyCommand { | ||
private FileStatus[] inputFileStatuses; | ||
private Configuration conf; | ||
private Path inputPath; | ||
private PrintWriter out; | ||
public static final String[] USAGE = new String[] { | ||
"<input>", | ||
"where <input> is the parquet file to count rows to stdout" | ||
}; | ||
|
||
public static final Options OPTIONS; | ||
static { | ||
OPTIONS = new Options(); | ||
Option detailed = OptionBuilder.withLongOpt("detailed") | ||
.withDescription("Detailed rowcount of each matching file") | ||
.create('d'); | ||
OPTIONS.addOption(detailed); | ||
} | ||
|
||
public RowCountCommand() { | ||
super(1, 1); | ||
} | ||
|
||
@Override | ||
public Options getOptions() { | ||
return OPTIONS; | ||
} | ||
|
||
@Override | ||
public String[] getUsageDescription() { | ||
return USAGE; | ||
} | ||
|
||
@Override | ||
public void execute(CommandLine options) throws Exception { | ||
super.execute(options); | ||
|
||
String[] args = options.getArgs(); | ||
String input = args[0]; | ||
out = new PrintWriter(Main.out, true); | ||
inputPath = new Path(input); | ||
conf = new Configuration(); | ||
inputFileStatuses = inputPath.getFileSystem(conf).globStatus(inputPath); | ||
long rowCount = 0; | ||
|
||
for(FileStatus fs : inputFileStatuses){ | ||
long fileRowCount=0; | ||
for(Footer f : ParquetFileReader.readFooters(conf, fs, false)){ | ||
for(BlockMetaData b : f.getParquetMetadata().getBlocks()){ | ||
rowCount += b.getRowCount(); | ||
fileRowCount += b.getRowCount(); | ||
} | ||
} | ||
if(options.hasOption('d')){ | ||
out.format("%s row count: %d\n", fs.getPath().getName(), fileRowCount); | ||
} | ||
} | ||
|
||
out.format("Total RowCount: %d", rowCount); | ||
out.println(); | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
parquet-tools/src/main/java/parquet/tools/command/SizeCommand.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,140 @@ | ||
/* | ||
* 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 parquet.tools.command; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.OptionBuilder; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import parquet.hadoop.Footer; | ||
import parquet.hadoop.ParquetFileReader; | ||
import parquet.hadoop.metadata.BlockMetaData; | ||
import parquet.tools.Main; | ||
|
||
public class SizeCommand extends ArgsOnlyCommand { | ||
private FileStatus[] inputFileStatuses; | ||
private Configuration conf; | ||
private Path inputPath; | ||
private PrintWriter out; | ||
private static final double ONE_KB = 1024; | ||
private static final double ONE_MB = ONE_KB * 1024; | ||
private static final double ONE_GB = ONE_MB * 1024; | ||
private static final double ONE_TB = ONE_GB * 1024; | ||
private static final double ONE_PB = ONE_TB * 1024; | ||
|
||
public static final String[] USAGE = new String[] { | ||
"<input>", | ||
"where <input> is the parquet file to get size & human readable size to stdout" | ||
}; | ||
|
||
public static final Options OPTIONS; | ||
static { | ||
OPTIONS = new Options(); | ||
Option help = OptionBuilder.withLongOpt("pretty") | ||
.withDescription("Pretty size") | ||
.create('p'); | ||
OPTIONS.addOption(help); | ||
Option uncompressed = OptionBuilder.withLongOpt("uncompressed") | ||
.withDescription("Uncompressed size") | ||
.create('u'); | ||
OPTIONS.addOption(uncompressed); | ||
Option detailed = OptionBuilder.withLongOpt("detailed") | ||
.withDescription("Detailed size of each matching file") | ||
.create('d'); | ||
OPTIONS.addOption(detailed); | ||
} | ||
|
||
public SizeCommand() { | ||
super(1, 1); | ||
} | ||
|
||
@Override | ||
public Options getOptions() { | ||
return OPTIONS; | ||
} | ||
|
||
@Override | ||
public String[] getUsageDescription() { | ||
return USAGE; | ||
} | ||
|
||
@Override | ||
public void execute(CommandLine options) throws Exception { | ||
super.execute(options); | ||
|
||
String[] args = options.getArgs(); | ||
String input = args[0]; | ||
out = new PrintWriter(Main.out, true); | ||
inputPath = new Path(input); | ||
conf = new Configuration(); | ||
inputFileStatuses = inputPath.getFileSystem(conf).globStatus(inputPath); | ||
long size = 0; | ||
for(FileStatus fs : inputFileStatuses){ | ||
long fileSize = 0; | ||
for(Footer f : ParquetFileReader.readFooters(conf, fs, false)){ | ||
for(BlockMetaData b : f.getParquetMetadata().getBlocks()){ | ||
size += (options.hasOption('u') ? b.getTotalByteSize() : b.getCompressedSize()); | ||
fileSize += (options.hasOption('u') ? b.getTotalByteSize() : b.getCompressedSize()); | ||
} | ||
} | ||
if(options.hasOption('d')){ | ||
if(options.hasOption('p')){ | ||
out.format("%s: %s\n", fs.getPath().getName(), getPrettySize(fileSize)); | ||
} | ||
else{ | ||
out.format("%s: %d bytes\n", fs.getPath().getName(), fileSize); | ||
} | ||
} | ||
} | ||
|
||
if(options.hasOption('p')){ | ||
out.format("Total Size: %s", getPrettySize(size)); | ||
} | ||
else{ | ||
out.format("Total Size: %d bytes", size); | ||
} | ||
out.println(); | ||
} | ||
|
||
public String getPrettySize(long bytes){ | ||
if (bytes/ONE_KB < 1){ | ||
return String.format("%d", bytes) + " bytes"; | ||
} | ||
if (bytes/ONE_MB < 1){ | ||
return String.format("%.3f", bytes/ONE_KB) + " KB"; | ||
} | ||
if (bytes/ONE_GB < 1){ | ||
return String.format("%.3f", bytes/ONE_MB) + " MB"; | ||
} | ||
if (bytes/ONE_TB < 1){ | ||
return String.format("%.3f", bytes/ONE_GB) + " GB"; | ||
} | ||
if (bytes/ONE_PB < 1){ | ||
return String.format("%.3f", bytes/ONE_TB) + " TB"; | ||
} | ||
return String.format("%.3f", bytes/ONE_PB) + " PB"; | ||
} | ||
} |
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,25 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright 2013 ARRIS, Inc. | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
# The name of the top-level script | ||
TOPSCRIPT="parquet-tools" | ||
|
||
# Determine the path to the script's directory | ||
APPPATH=$( cd "$(dirname "$0")" ; pwd -P ) | ||
|
||
# Run the application | ||
exec "${APPPATH}/${TOPSCRIPT}" rowcount "$@" |
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,25 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright 2013 ARRIS, Inc. | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
# The name of the top-level script | ||
TOPSCRIPT="parquet-tools" | ||
|
||
# Determine the path to the script's directory | ||
APPPATH=$( cd "$(dirname "$0")" ; pwd -P ) | ||
|
||
# Run the application | ||
exec "${APPPATH}/${TOPSCRIPT}" size "$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work as the other commands do, without globbing the input path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glob input path removed for rowcount command.