示例#1
0
  static TupleMRConfig parse(JsonNode node) throws IOException {
    try {
      TupleMRConfig result = new TupleMRConfig();
      Iterator<JsonNode> sources = node.get("sourceSchemas").getElements();
      while (sources.hasNext()) {
        JsonNode sourceNode = sources.next();
        result.addIntermediateSchema(Schema.parse(sourceNode));
      }
      Iterator<String> schemaNames = node.get("fieldAliases").getFieldNames();
      while (schemaNames.hasNext()) {
        String schemaName = schemaNames.next();
        JsonNode aliasNode = node.get("fieldAliases").get(schemaName);
        Aliases aliases = Aliases.parse(aliasNode);
        result.schemaFieldAliases.put(schemaName, aliases.getAliases());
      }

      result.schemaFieldAliases = Collections.unmodifiableMap(result.schemaFieldAliases);

      Iterator<JsonNode> groupFieldsNode = node.get("groupByFields").getElements();
      List<String> groupFields = new ArrayList<String>();
      while (groupFieldsNode.hasNext()) {
        groupFields.add(groupFieldsNode.next().getTextValue());
      }
      result.groupByFields = Collections.unmodifiableList(groupFields);

      if (node.get("rollupFrom") != null) {
        result.rollupFrom = node.get("rollupFrom").getTextValue();
      }

      if (node.get("customPartitionFields") != null) {
        Iterator<JsonNode> partitionNodes = node.get("customPartitionFields").getElements();
        List<String> partitionFields = new ArrayList<String>();
        while (partitionNodes.hasNext()) {
          partitionFields.add(partitionNodes.next().getTextValue());
        }
        result.customPartitionFields = partitionFields;
      }

      JsonNode commonSortByNode = node.get("commonOrderBy");
      result.commonCriteria = Criteria.parse(commonSortByNode);
      result.schemasOrder = Order.valueOf(node.get("schemasOrder").getTextValue());

      Iterator<JsonNode> specificNode = node.get("specificOrderBys").getElements();
      result.specificCriterias = new ArrayList<Criteria>();
      while (specificNode.hasNext()) {
        JsonNode n = specificNode.next();
        result.specificCriterias.add(n.isNull() ? null : Criteria.parse(n));
      }

      return result;
    } catch (TupleMRException e) {
      throw new IOException(e);
    }
  }