Пример #1
0
  public void store(OutputStream os) throws IOException {
    Document doc = XmlUtils.createDocument();

    Element root = doc.createElement("AllColumns");
    root.setAttribute("firstLineHeader", firstLineHeader ? "true" : "false");
    doc.appendChild(root);

    String pigLoad = "loaded = LOAD 'filename' USING PigStorage() AS (";
    String comma = "";

    for (Column c : columns) {
      pigLoad += comma + c.getName();
      comma = ", ";
      Element node = doc.createElement("Column");
      root.appendChild(node);
      node.setAttribute("name", c.getName());
      node.setAttribute("type", c.getType().toString());
      if (c.getCount() > 0) {
        node.setAttribute("count", Long.toString(c.getCount()));
      }
      if (c.getType() == FactorType.Numeric) {
        if (c.getSum() > 0.0) {
          node.setAttribute("sum", Double.toString(c.getSum()));
        }
        if (c.getMin() <= c.getMax()) {
          node.setAttribute("min", Double.toString(c.getMin()));
          node.setAttribute("max", Double.toString(c.getMax()));
        }
        if (c.isQuartile1Valid()) {
          node.setAttribute("quartile1", Double.toString(c.getQuartile1()));
        }
        if (c.isQuartile2Valid()) {
          node.setAttribute("quartile2", Double.toString(c.getQuartile2()));
        }
        if (c.isQuartile3Valid()) {
          node.setAttribute("quartile3", Double.toString(c.getQuartile3()));
        }
      }
    }

    pigLoad += ");";

    Comment c = doc.createComment(pigLoad);
    root.appendChild(c);

    XmlUtils.writeDocument(doc, new OutputStreamWriter(os));
  }