Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions java/tools/src/java/org/apache/orc/tools/ScanData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -37,12 +38,13 @@
*/
public class ScanData {

private static final Options OPTIONS = new Options()
.addOption("v", "verbose", false, "Print exceptions")
.addOption("s", "schema", false, "Print schema")
.addOption("h", "help", false, "Provide help");

static CommandLine parseCommandLine(String[] args) throws ParseException {
Options options = new Options()
.addOption("s", "schema", false, "Print schema")
.addOption("h", "help", false, "Provide help");
return new DefaultParser().parse(options, args);
return new DefaultParser().parse(OPTIONS, args);
}

static int calculateBestVectorSize(int indexStride) {
Expand Down Expand Up @@ -84,15 +86,15 @@ static LocationInfo findStripeInfo(Reader reader, long row) {
long firstRow = 0;
int stripeId = 0;
for (StripeInformation stripe: reader.getStripes()) {
stripeId += 1;
long lastRow = firstRow + stripe.getNumberOfRows();
if (firstRow <= row && row < lastRow) {
return new LocationInfo(firstRow, lastRow, stripeId, row);
}
firstRow = lastRow;
stripeId += 1;
}
return new LocationInfo(reader.getNumberOfRows(),
reader.getNumberOfRows(), -1, row);
reader.getNumberOfRows(), reader.getStripes().size(), row);
}

/**
Expand All @@ -113,7 +115,8 @@ static LocationInfo findRecoveryPoint(Reader reader, LocationInfo current,
result = current.followingRow;
} else {
long rowInStripe = current.row + batchSize - current.firstRow;
result = current.firstRow + (rowInStripe + stride - 1) / stride * stride;
result = Math.min(current.followingRow,
current.firstRow + (rowInStripe + stride - 1) / stride * stride);
}
return findStripeInfo(reader, result);
}
Expand Down Expand Up @@ -149,10 +152,12 @@ static boolean findBadColumns(Reader reader, LocationInfo current, int batchSize
static void main(Configuration conf, String[] args) throws ParseException {
CommandLine cli = parseCommandLine(args);
if (cli.hasOption('h') || cli.getArgs().length == 0) {
System.err.println("usage: java -jar orc-tools-*.jar scan [--schema] [--help] <orc file>*");
new HelpFormatter().printHelp("java -jar orc-tools-*.jar scan",
OPTIONS);
System.exit(1);
} else {
boolean printSchema = cli.hasOption('s');
final boolean printSchema = cli.hasOption('s');
final boolean printExceptions = cli.hasOption('v');
List<String> badFiles = new ArrayList<>();
for (String file : cli.getArgs()) {
try (Reader reader = FileDump.getReader(new Path(file), conf, badFiles)) {
Expand Down Expand Up @@ -182,11 +187,13 @@ static void main(Configuration conf, String[] args) throws ParseException {
LocationInfo recover = findRecoveryPoint(reader, current, batchSize);
System.out.println("Unable to read batch at " + current +
", recovery at " + recover);
e.printStackTrace();
if (printExceptions) {
e.printStackTrace();
}
findBadColumns(reader, current, batchSize, reader.getSchema(),
new boolean[reader.getSchema().getMaximumId() + 1]);
// There are no more rows, so break the loop
if (recover.stripeId == -1) {
// If we are at the end of the file, get out
if (recover.row >= reader.getNumberOfRows()) {
break;
} else {
rows.seekToRow(recover.row);
Expand All @@ -203,7 +210,9 @@ static void main(Configuration conf, String[] args) throws ParseException {
} catch (Exception e) {
badFiles.add(file);
System.err.println("Unable to open file: " + file);
e.printStackTrace();
if (printExceptions) {
e.printStackTrace();
}
}
}
System.exit(badFiles.size());
Expand Down