Skip to content

Commit

Permalink
ORC-584: Add missing brackets toJson method
Browse files Browse the repository at this point in the history
Fixes #464

Signed-off-by: Owen O'Malley <omalley@apache.org>
  • Loading branch information
akin authored and omalley committed Jan 10, 2020
1 parent c26ff4c commit 20da4a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
26 changes: 9 additions & 17 deletions java/core/src/java/org/apache/orc/TypeDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@

package org.apache.orc;

import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.Decimal64ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.ListColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.MapColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.StructColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.UnionColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.orc.impl.ParserUtils;
import org.apache.orc.impl.SchemaEvolution;
import org.apache.orc.impl.TypeUtils;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -43,6 +26,11 @@
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.orc.impl.ParserUtils;
import org.apache.orc.impl.TypeUtils;
import org.jetbrains.annotations.NotNull;

/**
* This is the description of the types in an ORC file.
*/
Expand Down Expand Up @@ -368,6 +356,7 @@ public int getId() {
return id;
}

@Override
public TypeDescription clone() {
TypeDescription result = new TypeDescription(category);
result.maxLength = maxLength;
Expand Down Expand Up @@ -718,6 +707,7 @@ public void printToBuffer(StringBuilder buffer) {
}
}

@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
printToBuffer(buffer);
Expand Down Expand Up @@ -765,8 +755,10 @@ private void printJsonToBuffer(String prefix, StringBuilder buffer,
buffer.append(", \"fields\": [");
for(int i=0; i < children.size(); ++i) {
buffer.append('\n');
buffer.append('{');
children.get(i).printJsonToBuffer("\"" + fieldNames.get(i) + "\": ",
buffer, indent + 2);
buffer.append('}');
if (i != children.size() - 1) {
buffer.append(',');
}
Expand Down
40 changes: 24 additions & 16 deletions java/core/src/test/org/apache/orc/TestTypeDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class TestTypeDescription {
@Rule
public ExpectedException thrown= ExpectedException.none();
Expand All @@ -49,10 +49,15 @@ public void testJson() {
.addField("f3", TypeDescription.createDecimal());
assertEquals("struct<f1:int,f2:string,f3:decimal(38,10)>",
struct.toString());
assertEquals("{\"category\": \"struct\", \"id\": 0, \"max\": 3, \"fields\": [\n"
+ " \"f1\": {\"category\": \"int\", \"id\": 1, \"max\": 1},\n"
+ " \"f2\": {\"category\": \"string\", \"id\": 2, \"max\": 2},\n"
+ " \"f3\": {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 38, \"scale\": 10}]}",
assertEquals("{"
+ "\"category\": \"struct\", "
+ "\"id\": 0, \"max\": 3, "
+ "\"fields\": [\n"
+ "{ \"f1\": {\"category\": \"int\", \"id\": 1, \"max\": 1}},\n"
+ "{ \"f2\": {\"category\": \"string\", \"id\": 2, \"max\": 2}},\n"
+ "{ \"f3\": {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 38, \"scale\": 10}}"
+ "]"
+ "}",
struct.toJson());
struct = TypeDescription.createStruct()
.addField("f1", TypeDescription.createUnion()
Expand All @@ -67,15 +72,18 @@ public void testJson() {
assertEquals("struct<f1:uniontype<tinyint,decimal(20,10)>,f2:struct<f3:date,f4:double,f5:boolean>,f6:char(100)>",
struct.toString());
assertEquals(
"{\"category\": \"struct\", \"id\": 0, \"max\": 8, \"fields\": [\n" +
" \"f1\": {\"category\": \"uniontype\", \"id\": 1, \"max\": 3, \"children\": [\n" +
"{\"category\": \"struct\", "
+ "\"id\": 0, "
+ "\"max\": 8, "
+ "\"fields\": [\n" +
"{ \"f1\": {\"category\": \"uniontype\", \"id\": 1, \"max\": 3, \"children\": [\n" +
" {\"category\": \"tinyint\", \"id\": 2, \"max\": 2},\n" +
" {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 20, \"scale\": 10}]},\n" +
" \"f2\": {\"category\": \"struct\", \"id\": 4, \"max\": 7, \"fields\": [\n" +
" \"f3\": {\"category\": \"date\", \"id\": 5, \"max\": 5},\n" +
" \"f4\": {\"category\": \"double\", \"id\": 6, \"max\": 6},\n" +
" \"f5\": {\"category\": \"boolean\", \"id\": 7, \"max\": 7}]},\n" +
" \"f6\": {\"category\": \"char\", \"id\": 8, \"max\": 8, \"length\": 100}]}",
" {\"category\": \"decimal\", \"id\": 3, \"max\": 3, \"precision\": 20, \"scale\": 10}]}},\n" +
"{ \"f2\": {\"category\": \"struct\", \"id\": 4, \"max\": 7, \"fields\": [\n" +
"{ \"f3\": {\"category\": \"date\", \"id\": 5, \"max\": 5}},\n" +
"{ \"f4\": {\"category\": \"double\", \"id\": 6, \"max\": 6}},\n" +
"{ \"f5\": {\"category\": \"boolean\", \"id\": 7, \"max\": 7}}]}},\n" +
"{ \"f6\": {\"category\": \"char\", \"id\": 8, \"max\": 8, \"length\": 100}}]}",
struct.toJson());
}

Expand Down

0 comments on commit 20da4a1

Please sign in to comment.