Skip to content

Commit

Permalink
Merge c049257 into ebe78dc
Browse files Browse the repository at this point in the history
  • Loading branch information
jackylk committed Jul 13, 2019
2 parents ebe78dc + c049257 commit ea82253
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public class CarbonWriterBuilder {
private int pageSizeInMb;
private int blockSize;
private long timestamp;
private Map<String, String> options;

// use TreeMap as keys need to be case insensitive
private Map<String, String> options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

private String taskNo;
private int localDictionaryThreshold;
private boolean isLocalDictionaryEnabled = Boolean.parseBoolean(
Expand Down Expand Up @@ -239,10 +242,6 @@ public CarbonWriterBuilder withLoadOptions(Map<String, String> options) {
}
}

if (this.options == null) {
// convert it to treeMap as keys need to be case insensitive
this.options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
}
this.options.putAll(options);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,59 @@ public void testWriteAndReadFiles() throws IOException, InterruptedException {
FileUtils.deleteDirectory(new File(path));
}

@Test
public void testWriteAndReadJson() throws IOException, InterruptedException {
int numRows = 100;
String path = "./testWriteFiles";
FileUtils.deleteDirectory(new File(path));

String json = "{\"name\":\"bob\", \"age\":10}";

Schema schema = new Schema(
new Field[]{
new Field("name", "string"),
new Field("age", "int")});

try {
CarbonWriter writer = CarbonWriter.builder().outputPath(path)
.withJsonInput(schema).writtenBy("AvroCarbonWriterTest").build();

for (int i = 0; i < numRows; i++) {
writer.write(json);
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}

File[] dataFiles = new File(path).listFiles(new FileFilter() {
@Override public boolean accept(File pathname) {
return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT);
}
});
Assert.assertNotNull(dataFiles);
Assert.assertEquals(1, dataFiles.length);

// read it and verify

CarbonReader reader = CarbonReader.builder(path, "_temp")
.projection(new String[]{"name", "age"}).build();

int i = 0;
while (reader.hasNext()) {
Object[] row = (Object[]) reader.readNextRow();
Assert.assertEquals("bob", row[0]);
Assert.assertEquals(10, row[1]);
i++;
}
Assert.assertEquals(i, numRows);

reader.close();

FileUtils.deleteDirectory(new File(path));
}

@Test public void testReadWithZeroBatchSize() throws Exception {
String path = "./testWriteFiles";
FileUtils.deleteDirectory(new File(path));
Expand Down

0 comments on commit ea82253

Please sign in to comment.