diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/ColumnStatisticsImpl.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/ColumnStatisticsImpl.java
index 7cfbd81d85e40f50e572a17150d1b38f62db2739..ffba3c680bcb5b4aa56d4fd8b5d863fb878d95eb 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/ColumnStatisticsImpl.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/ColumnStatisticsImpl.java
@@ -699,12 +699,18 @@ void merge(ColumnStatisticsImpl other) {
@Override
public Date getMinimum() {
+ if (minimum == null) {
+ return null;
+ }
minDate.set(minimum);
return minDate.get();
}
@Override
public Date getMaximum() {
+ if (maximum == null) {
+ return null;
+ }
maxDate.set(maximum);
return maxDate.get();
}
@@ -793,14 +799,12 @@ void merge(ColumnStatisticsImpl other) {
@Override
public Timestamp getMinimum() {
- Timestamp minTimestamp = new Timestamp(minimum);
- return minTimestamp;
+ return minimum == null ? null : new Timestamp(minimum);
}
@Override
public Timestamp getMaximum() {
- Timestamp maxTimestamp = new Timestamp(maximum);
- return maxTimestamp;
+ return maximum == null ? null : new Timestamp(maximum);
}
@Override
@@ -808,9 +812,9 @@ public String toString() {
StringBuilder buf = new StringBuilder(super.toString());
if (getNumberOfValues() != 0) {
buf.append(" min: ");
- buf.append(minimum);
+ buf.append(getMinimum());
buf.append(" max: ");
- buf.append(maximum);
+ buf.append(getMaximum());
}
return buf.toString();
}
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FileDump.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FileDump.java
index cd4db752746cfaef2422cbbd88935806750659ff..3bab509cb3e3b351de0f4eb37907524cfafd9f2d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FileDump.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FileDump.java
@@ -6,9 +6,9 @@
* 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
- *
+ *
+ * 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.
@@ -50,10 +50,11 @@
* A tool for printing out the file structure of ORC files.
*/
public final class FileDump {
- private static final String UNKNOWN = "UNKNOWN";
+ public static final String UNKNOWN = "UNKNOWN";
// not used
- private FileDump() {}
+ private FileDump() {
+ }
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
@@ -77,13 +78,20 @@ public static void main(String[] args) throws Exception {
}
}
- boolean printTimeZone = false;
- if (cli.hasOption('t')) {
- printTimeZone = true;
- }
+ boolean printTimeZone = cli.hasOption('t');
+ boolean jsonFormat = cli.hasOption('j');
String[] files = cli.getArgs();
- if (dumpData) printData(Arrays.asList(files), conf);
- else printMetaData(Arrays.asList(files), conf, rowIndexCols, printTimeZone);
+ if (dumpData) {
+ printData(Arrays.asList(files), conf);
+ } else {
+ if (jsonFormat) {
+ boolean prettyPrint = cli.hasOption('p');
+ JsonFileDump.printJsonMetaData(Arrays.asList(files), conf, rowIndexCols, prettyPrint,
+ printTimeZone);
+ } else {
+ printMetaData(Arrays.asList(files), conf, rowIndexCols, printTimeZone);
+ }
+ }
}
private static void printData(List files, Configuration conf) throws IOException,
@@ -100,7 +108,7 @@ private static void printMetaData(List files, Configuration conf,
Path path = new Path(filename);
Reader reader = OrcFile.createReader(path, OrcFile.readerOptions(conf));
System.out.println("File Version: " + reader.getFileVersion().getName() +
- " with " + reader.getWriterVersion());
+ " with " + reader.getWriterVersion());
RecordReaderImpl rows = (RecordReaderImpl) reader.rows();
System.out.println("Rows: " + reader.getNumberOfRows());
System.out.println("Compression: " + reader.getCompression());
@@ -121,7 +129,7 @@ private static void printMetaData(List files, Configuration conf,
ColumnStatistics[] stats = reader.getStatistics();
int colCount = stats.length;
System.out.println("\nFile Statistics:");
- for(int i=0; i < stats.length; ++i) {
+ for (int i = 0; i < stats.length; ++i) {
System.out.println(" Column " + i + ": " + stats[i].toString());
}
System.out.println("\nStripes:");
@@ -140,7 +148,7 @@ private static void printMetaData(List files, Configuration conf,
System.out.println(" Stripe: " + stripe.toString());
}
long sectionStart = stripeStart;
- for(OrcProto.Stream section: footer.getStreamsList()) {
+ for (OrcProto.Stream section : footer.getStreamsList()) {
String kind = section.hasKind() ? section.getKind().name() : UNKNOWN;
System.out.println(" Stream: column " + section.getColumn() +
" section " + kind + " start: " + sectionStart +
@@ -270,7 +278,7 @@ private static String getFormattedRowIndices(int col, RowIndex[] rowGroupIndex)
return buf.toString();
}
- private static long getTotalPaddingSize(Reader reader) throws IOException {
+ public static long getTotalPaddingSize(Reader reader) throws IOException {
long paddedBytes = 0;
List stripes = reader.getStripes();
for (int i = 1; i < stripes.size(); i++) {
@@ -309,19 +317,28 @@ static Options createOptions() {
.hasArg()
.create());
+ result.addOption(OptionBuilder
+ .withLongOpt("json")
+ .withDescription("Print metadata in JSON format")
+ .create('j'));
+
+ result.addOption(OptionBuilder
+ .withLongOpt("pretty")
+ .withDescription("Pretty print json metadata output")
+ .create('p'));
return result;
}
private static void printMap(JSONWriter writer,
- Map