use of org.apache.drill.exec.util.JsonStringHashMap in project drill by axbaretto.
the class TestFlatten method testFlatten_Drill2162_complex.
@Test
@Category(UnlikelyTest.class)
public void testFlatten_Drill2162_complex() throws Exception {
String jsonRecords = BaseTestQuery.getFile("flatten/complex_transaction_example_data.json");
int numCopies = 700;
new TestConstantFolding.SmallFileCreator(pathDir).setRecord(jsonRecords).createFiles(1, numCopies, "json");
@SuppressWarnings("unchecked") List<JsonStringHashMap<String, Object>> data = Lists.newArrayList(mapOf("uid", 1l, "lst_lst_0", listOf(1l, 2l, 3l, 4l, 5l), "lst_lst_1", listOf(2l, 3l, 4l, 5l, 6l), "lst_lst", listOf(listOf(1l, 2l, 3l, 4l, 5l), listOf(2l, 3l, 4l, 5l, 6l))), mapOf("uid", 2l, "lst_lst_0", listOf(1l, 2l, 3l, 4l, 5l), "lst_lst_1", listOf(2l, 3l, 4l, 5l, 6l), "lst_lst", listOf(listOf(1l, 2l, 3l, 4l, 5l), listOf(2l, 3l, 4l, 5l, 6l))));
List<JsonStringHashMap<String, Object>> result = flatten(flatten(flatten(data, "lst_lst_1"), "lst_lst_0"), "lst_lst");
TestBuilder builder = testBuilder().sqlQuery("select uid, flatten(d.lst_lst[1]) lst1, flatten(d.lst_lst[0]) lst0, flatten(d.lst_lst) lst from " + "dfs.`%s/bigfile/bigfile.json` d", TEST_DIR).unOrdered().baselineColumns("uid", "lst1", "lst0", "lst");
for (int i = 0; i < numCopies; i++) {
for (JsonStringHashMap<String, Object> record : result) {
builder.baselineValues(record.get("uid"), record.get("lst_lst_1"), record.get("lst_lst_0"), record.get("lst_lst"));
}
}
builder.go();
}
use of org.apache.drill.exec.util.JsonStringHashMap in project drill by axbaretto.
the class TestBuilder method mapOf.
/**
* Convenience method to create a {@link JsonStringHashMap<String, Object> map} instance with the given key value sequence.
*
* Key value sequence consists of key - value pairs such that a key precedes its value. For instance:
*
* mapOf("name", "Adam", "age", 41) corresponds to {"name": "Adam", "age": 41} in JSON.
*/
public static JsonStringHashMap<String, Object> mapOf(Object... keyValueSequence) {
Preconditions.checkArgument(keyValueSequence.length % 2 == 0, "Length of key value sequence must be even");
final JsonStringHashMap<String, Object> map = new JsonStringHashMap<>();
for (int i = 0; i < keyValueSequence.length; i += 2) {
Object value = keyValueSequence[i + 1];
if (value instanceof CharSequence) {
value = new Text(value.toString());
}
map.put(String.class.cast(keyValueSequence[i]), value);
}
return map;
}
use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.
the class AvroFormatTest method testLinkedList.
@Test
public void testLinkedList() throws Exception {
int numRows = 5;
String file = dataGenerator.generateLinkedList(numRows);
TestBuilder testBuilder = testBuilder().sqlQuery("select * from dfs.`%s` t", file).unOrdered().baselineColumns("value", "next");
for (long i = 0; i < numRows; i++) {
if (i == numRows - 1) {
// last row
testBuilder.baselineValues(i, mapOf("next", new JsonStringHashMap<>()));
continue;
}
testBuilder.baselineValues(i, mapOf("value", i + 1, "next", new JsonStringHashMap<>()));
}
testBuilder.go();
}
use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.
the class TestBuilder method mapOf.
/**
* Convenience method to create a {@link JsonStringHashMap<String, Object>} map instance with the given key value sequence.
*
* Key value sequence consists of key - value pairs such that a key precedes its value. For instance:
*
* mapOf("name", "Adam", "age", 41) corresponds to {"name": "Adam", "age": 41} in JSON.
*/
public static JsonStringHashMap<String, Object> mapOf(Object... keyValueSequence) {
Preconditions.checkArgument(keyValueSequence.length % 2 == 0, "Length of key value sequence must be even");
final JsonStringHashMap<String, Object> map = new JsonStringHashMap<>();
for (int i = 0; i < keyValueSequence.length; i += 2) {
Object value = keyValueSequence[i + 1];
if (value instanceof CharSequence) {
value = new Text(value.toString());
}
map.put(String.class.cast(keyValueSequence[i]), value);
}
return map;
}
use of org.apache.drill.exec.util.JsonStringHashMap in project drill by apache.
the class TestFlatten method testFlatten_Drill2162_simple.
@Test
public void testFlatten_Drill2162_simple() throws Exception {
List<Long> inputList = Lists.newArrayList();
String jsonRecord = "{ \"int_list\" : [";
final int listSize = 30;
for (int i = 1; i < listSize; i++) {
jsonRecord += i + ", ";
inputList.add((long) i);
}
jsonRecord += listSize + "] }";
inputList.add((long) listSize);
int numRecords = 3000;
new TestConstantFolding.SmallFileCreator(pathDir).setRecord(jsonRecord).createFiles(1, numRecords, "json");
List<JsonStringHashMap<String, Object>> data = Lists.newArrayList(mapOf("int_list", inputList));
List<JsonStringHashMap<String, Object>> result = flatten(data, "int_list");
TestBuilder builder = testBuilder().sqlQuery("select flatten(int_list) as int_list from dfs.`%s/bigfile/bigfile.json`", TEST_DIR).unOrdered().baselineColumns("int_list");
for (int i = 0; i < numRecords; i++) {
for (JsonStringHashMap<String, Object> record : result) {
builder.baselineValues(record.get("int_list"));
}
}
builder.go();
}
Aggregations