-
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
f910f6f
75e18f1
26a8f88
6e2bb54
972f9ac
b795463
0feb74a
e7e96cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* 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. | ||
*/ | ||
package parquet.tools.command; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.List; | ||
|
||
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. glob input path removed for rowcount command. |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just removed --detailed option for rowcount command. Same thing can be done externally so this is not really needed for rowcount |
||
} | ||
} | ||
out.format("Total RowCount: %d", rowCount); | ||
out.println(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/** | ||
* Copyright 2013 ARRIS, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use the Apache copyright header? You can copy it from files in other parquet modules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rdblue I had used header in other classes in parquet-tool. I have changed headers in my classes. Do you want to fix all other classes to use Apache copyright also? It is my first open source contribution so many common mistakes, won't repeat !! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @swapnilushinde, don't worry about it, this is good stuff. There are always things to fix, which is why everything gets reviewed. There's also no way you would know about the headers. Copying them from the other commands is reasonable, we are just moving to the Apache one so new files should use it. Thanks for offering to update the others, but we are already talking with ARRIS to get that done so we'll handle it separately. |
||
* | ||
* 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. | ||
*/ | ||
package parquet.tools.command; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.List; | ||
|
||
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; | ||
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){ | ||
double oneKB = 1024; | ||
double oneMB = oneKB * 1024; | ||
double oneGB = oneMB * 1014; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: should be multiplied by 1024. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rdblue typo is corrected and I have tested edge cases with prettySize method. |
||
double oneTB = oneGB * 1024; | ||
double onePB = oneTB * 1024; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be constants rather than calculated each time the method runs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
if (bytes/oneKB < 1){ | ||
return String.format("%.3f", bytes) + " bytes"; | ||
} | ||
if (bytes/oneMB < 1){ | ||
return String.format("%.3f", bytes/oneKB) + " KB"; | ||
} | ||
if (bytes/oneGB < 1){ | ||
return String.format("%.3f", bytes/oneMB) + " MB"; | ||
} | ||
if (bytes/oneTB < 1){ | ||
return String.format("%.3f", bytes/oneGB) + " GB"; | ||
} | ||
return String.valueOf(bytes/onePB) + " PB"; | ||
} | ||
} |
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 "$@" |
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 "$@" |
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.
Nit: It looks like you're mixing spaces and tabs. The rest of the project uses 2-space indentation, which would really help the readability of this code.
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.
All tabs are removed.