Exemple #1
0
  void toJson(JsonGenerator gen) throws IOException {
    gen.writeStartObject();
    gen.writeArrayFieldStart("sourceSchemas");
    for (Schema schema : schemas) {
      schema.toJson(gen);
    }
    gen.writeEndArray();
    gen.writeObjectFieldStart("fieldAliases");
    for (Map.Entry<String, Map<String, String>> entry : schemaFieldAliases.entrySet()) {
      String schemaName = entry.getKey();
      Map<String, String> aliases = entry.getValue();
      gen.writeObjectField(schemaName, aliases);
    }
    gen.writeEndObject();

    gen.writeArrayFieldStart("groupByFields");
    for (String field : groupByFields) {
      gen.writeString(field);
    }
    gen.writeEndArray();

    if (customPartitionFields != null && !customPartitionFields.isEmpty()) {
      gen.writeArrayFieldStart("customPartitionFields");
      for (String field : customPartitionFields) {
        gen.writeString(field);
      }
      gen.writeEndArray();
    }

    if (rollupFrom != null) {
      gen.writeFieldName("rollupFrom");
      gen.writeString(rollupFrom);
    }

    gen.writeFieldName("commonOrderBy");
    commonCriteria.toJson(gen);

    gen.writeStringField("schemasOrder", schemasOrder.toString());

    // TODO this code should write a map with sourceName
    if (specificCriterias == null || specificCriterias.isEmpty()) {
      initSecondaryCriteriasWithNull();
    }
    gen.writeArrayFieldStart("specificOrderBys");
    for (Criteria c : specificCriterias) {
      if (c == null) {
        gen.writeNull();
      } else {
        c.toJson(gen);
      }
    }
    gen.writeEndArray();
    gen.writeEndObject();
  }
Exemple #2
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);
    }
  }