Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void execute(File arrowFile, File jsonFile) throws IOException {
Schema schema = footer.getSchema();
LOGGER.debug("Input file size: " + arrowFile.length());
LOGGER.debug("Found schema: " + schema);
try (JsonFileWriter writer = new JsonFileWriter(jsonFile);) {
try (JsonFileWriter writer = new JsonFileWriter(jsonFile, JsonFileWriter.config().pretty(true));) {
writer.start(schema);
List<ArrowBlock> recordBatches = footer.getRecordBatches();
for (ArrowBlock rbBlock : recordBatches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import static org.apache.arrow.tools.ArrowFileTestFixtures.writeInput;
import static org.junit.Assert.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.util.Map;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
Expand All @@ -44,6 +47,11 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter.NopIndenter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class TestIntegration {

@Rule
Expand All @@ -69,7 +77,7 @@ public void testValid() throws Exception {
File testOutFile = testFolder.newFile("testOut.arrow");
testOutFile.delete();

// generate an arow file
// generate an arrow file
writeInput(testInFile, allocator);

Integration integration = new Integration();
Expand All @@ -90,6 +98,50 @@ public void testValid() throws Exception {
integration.run(args3);
}

@Test
public void testJSONRoundTripWithVariableWidth() throws Exception {
File testJSONFile = new File("../../integration/data/simple.json");
File testOutFile = testFolder.newFile("testOut.arrow");
File testRoundTripJSONFile = testFolder.newFile("testOut.json");
testOutFile.delete();
testRoundTripJSONFile.delete();

Integration integration = new Integration();

// convert to arrow
String[] args1 = { "-arrow", testOutFile.getAbsolutePath(), "-json", testJSONFile.getAbsolutePath(), "-command", Command.JSON_TO_ARROW.name()};
integration.run(args1);

// convert back to json
String[] args2 = { "-arrow", testOutFile.getAbsolutePath(), "-json", testRoundTripJSONFile.getAbsolutePath(), "-command", Command.ARROW_TO_JSON.name()};
integration.run(args2);

BufferedReader orig = readNormalized(testJSONFile);
BufferedReader rt = readNormalized(testRoundTripJSONFile);
String i, o;
int j = 0;
while ((i = orig.readLine()) != null && (o = rt.readLine()) != null) {
Assert.assertEquals("line: " + j, i, o);
++j;
}
}

private ObjectMapper om = new ObjectMapper();
{
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
prettyPrinter.indentArraysWith(NopIndenter.instance);
om.setDefaultPrettyPrinter(prettyPrinter);
om.enable(SerializationFeature.INDENT_OUTPUT);
om.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
}

private BufferedReader readNormalized(File f) throws IOException {
Map<?,?> tree = om.readValue(f, Map.class);
String normalized = om.writeValueAsString(tree);
return new BufferedReader(new StringReader(normalized));
}


@Test
public void testInvalid() throws Exception {
File testValidInFile = testFolder.newFile("testValidIn.arrow");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.fasterxml.jackson.core.JsonToken.START_ARRAY;
import static com.fasterxml.jackson.core.JsonToken.START_OBJECT;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.arrow.vector.schema.ArrowVectorType.OFFSET;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -128,15 +129,12 @@ private void readVector(Field field, FieldVector vector) throws JsonParseExcepti
valueVector.allocateNew();
Mutator mutator = valueVector.getMutator();

int innerVectorCount = count;
if (vectorType.getName() == "OFFSET") {
innerVectorCount++;
}
mutator.setValueCount(innerVectorCount);
int innerVectorCount = vectorType.equals(OFFSET) ? count + 1 : count;
for (int i = 0; i < innerVectorCount; i++) {
parser.nextToken();
setValueFromParser(valueVector, i);
}
mutator.setValueCount(innerVectorCount);
readToken(END_ARRAY);
}
// if children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ public String getName() {
public String toString() {
return getName();
}

@Override
public int hashCode() {
return type;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ArrowVectorType) {
ArrowVectorType other = (ArrowVectorType) obj;
return type == other.type;
}
return false;
}

}