|
11 | 11 | import org.datayoo.moql.*; |
12 | 12 | import org.datayoo.moql.core.RecordSetImpl; |
13 | 13 | import org.datayoo.moql.metadata.*; |
| 14 | +import org.datayoo.moql.operand.OperandContextArrayList; |
14 | 15 | import org.datayoo.moql.operand.OperandFactory; |
15 | 16 | import org.datayoo.moql.operand.factory.OperandFactoryImpl; |
16 | 17 | import org.datayoo.moql.parser.MoqlParser; |
@@ -377,55 +378,76 @@ protected void toMap(JsonObject jsonObject, Map<String, Object> record) { |
377 | 378 | toMap((JsonObject) entry.getValue(), record); |
378 | 379 | continue; |
379 | 380 | } |
380 | | - Object value = entry.getValue(); |
381 | | - if (value instanceof JsonArray) { |
382 | | - toArrayRecord(entry.getKey(), (JsonArray) entry.getValue(), record); |
383 | | - } else if (value instanceof JsonObject) { |
384 | | - value = value.toString(); |
385 | | - record.put(entry.getKey(), value); |
386 | | - } else if (entry.getValue() instanceof JsonPrimitive) { |
387 | | - value = getValue((JsonPrimitive) entry.getValue()); |
388 | | - record.put(entry.getKey(), value); |
389 | | - } |
| 381 | + JsonElement je = entry.getValue(); |
| 382 | + record.put(entry.getKey(), getObject(je)); |
390 | 383 | } |
391 | 384 | } |
392 | 385 |
|
393 | | - protected void toArrayRecord(String prefix, JsonArray array, |
394 | | - Map<String, Object> record) { |
395 | | - // 先把旧的数据集加入结果 |
396 | | - record.put(prefix, array.toString()); |
397 | | - Map<String, JsonArray> arrayMap = new HashMap<>(); |
398 | | - for (JsonElement element : array) { |
399 | | - if (element instanceof JsonObject) { |
400 | | - JsonObject jsonObject = (JsonObject) element; |
401 | | - Set<Map.Entry<String, JsonElement>> set = jsonObject.entrySet(); |
402 | | - |
403 | | - for (Map.Entry<String, JsonElement> entry : set) { |
404 | | - String key = prefix + "." + entry.getKey(); |
405 | | - if (arrayMap.get(key) == null) { |
406 | | - JsonArray jsonArray = new JsonArray(); |
407 | | - jsonArray.add(entry.getValue()); |
408 | | - arrayMap.put(key, jsonArray); |
409 | | - } else { |
410 | | - JsonArray value = arrayMap.get(key); |
411 | | - value.add(entry.getValue()); |
412 | | - arrayMap.put(key, value); |
413 | | - } |
414 | | - } |
415 | | - } |
416 | | - if (element instanceof JsonPrimitive) { |
417 | | - if (record.get(prefix) == null) { |
418 | | - Object value = getValue((JsonPrimitive) element); |
419 | | - record.put(prefix, value); |
420 | | - } |
| 386 | + protected Object getObject(JsonElement je) { |
| 387 | + if (je instanceof JsonObject) { |
| 388 | + return toMap((JsonObject) je); |
| 389 | + } else if (je instanceof JsonArray) { |
| 390 | + return toList((JsonArray) je); |
| 391 | + } else if (je instanceof JsonPrimitive) { |
| 392 | + return getValue((JsonPrimitive) je); |
| 393 | + } |
| 394 | + return null; |
| 395 | + } |
421 | 396 |
|
422 | | - } |
| 397 | + protected Map<String, Object> toMap(JsonObject jo) { |
| 398 | + Map<String, Object> map = new HashMap<>(); |
| 399 | + for (Map.Entry<String, JsonElement> entry : jo.entrySet()) { |
| 400 | + JsonElement je = entry.getValue(); |
| 401 | + map.put(entry.getKey(), getObject(je)); |
423 | 402 | } |
424 | | - for (Map.Entry<String, JsonArray> entry : arrayMap.entrySet()) { |
425 | | - toArrayRecord(entry.getKey(), entry.getValue(), record); |
| 403 | + return map; |
| 404 | + } |
| 405 | + |
| 406 | + protected OperandContextArrayList toList(JsonArray ja) { |
| 407 | + OperandContextArrayList arrayList = new OperandContextArrayList(ja.size()); |
| 408 | + for (int i = 0; i < ja.size(); i++) { |
| 409 | + JsonElement je = ja.get(i); |
| 410 | + arrayList.add(getObject(je)); |
426 | 411 | } |
| 412 | + return arrayList; |
427 | 413 | } |
428 | 414 |
|
| 415 | + // protected void toArrayRecord(String prefix, JsonArray array, |
| 416 | + // Map<String, Object> record) { |
| 417 | + // // 先把旧的数据集加入结果 |
| 418 | + // record.put(prefix, array.toString()); |
| 419 | + // Map<String, JsonArray> arrayMap = new HashMap<>(); |
| 420 | + // for (JsonElement element : array) { |
| 421 | + // if (element instanceof JsonObject) { |
| 422 | + // JsonObject jsonObject = (JsonObject) element; |
| 423 | + // Set<Map.Entry<String, JsonElement>> set = jsonObject.entrySet(); |
| 424 | + // |
| 425 | + // for (Map.Entry<String, JsonElement> entry : set) { |
| 426 | + // String key = prefix + "." + entry.getKey(); |
| 427 | + // if (arrayMap.get(key) == null) { |
| 428 | + // JsonArray jsonArray = new JsonArray(); |
| 429 | + // jsonArray.add(entry.getValue()); |
| 430 | + // arrayMap.put(key, jsonArray); |
| 431 | + // } else { |
| 432 | + // JsonArray value = arrayMap.get(key); |
| 433 | + // value.add(entry.getValue()); |
| 434 | + // arrayMap.put(key, value); |
| 435 | + // } |
| 436 | + // } |
| 437 | + // } |
| 438 | + // if (element instanceof JsonPrimitive) { |
| 439 | + // if (record.get(prefix) == null) { |
| 440 | + // Object value = getValue((JsonPrimitive) element); |
| 441 | + // record.put(prefix, value); |
| 442 | + // } |
| 443 | + // |
| 444 | + // } |
| 445 | + // } |
| 446 | + // for (Map.Entry<String, JsonArray> entry : arrayMap.entrySet()) { |
| 447 | + // toArrayRecord(entry.getKey(), entry.getValue(), record); |
| 448 | + // } |
| 449 | + // } |
| 450 | + |
429 | 451 | protected List<EntityMap> toAggregationEntityMaps(JsonObject jsonObject, |
430 | 452 | List<ColumnDefinition> groupColumns) { |
431 | 453 | List<EntityMap> entityMaps = new LinkedList<EntityMap>(); |
@@ -520,7 +542,7 @@ protected Object[] toRecord(Operand[] operands, EntityMap entityMap) { |
520 | 542 | Object[] record = new Object[operands.length]; |
521 | 543 | for (int i = 0; i < operands.length; i++) { |
522 | 544 | record[i] = entityMap.getEntity(operands[i].getName()); |
523 | | -// record[i] = operands[i].operate(entityMap); |
| 545 | + // record[i] = operands[i].operate(entityMap); |
524 | 546 | } |
525 | 547 | return record; |
526 | 548 | } |
|
0 commit comments