Search in sources :

Example 1 with OrderedJSONObject

use of org.apache.wink.json4j.OrderedJSONObject in project incubator-systemml by apache.

the class MapReduceTool method metaDataToString.

public static String metaDataToString(ValueType vt, ValueType[] schema, DataType dt, MatrixCharacteristics mc, OutputInfo outinfo, FileFormatProperties formatProperties) throws JSONException, DMLRuntimeException {
    // maintain order in output file
    OrderedJSONObject mtd = new OrderedJSONObject();
    //handle data type and value types (incl schema for frames)
    mtd.put(DataExpression.DATATYPEPARAM, dt.toString().toLowerCase());
    if (schema == null) {
        mtd.put(DataExpression.VALUETYPEPARAM, vt.toString().toLowerCase());
    } else {
        StringBuffer schemaSB = new StringBuffer();
        for (int i = 0; i < schema.length; i++) {
            if (schema[i] == ValueType.UNKNOWN)
                schemaSB.append("*");
            else
                schemaSB.append(schema[i].toString());
            schemaSB.append(DataExpression.DEFAULT_DELIM_DELIMITER);
        }
        mtd.put(DataExpression.SCHEMAPARAM, schemaSB.toString());
    }
    //handle output dimensions
    if (!dt.isScalar()) {
        mtd.put(DataExpression.READROWPARAM, mc.getRows());
        mtd.put(DataExpression.READCOLPARAM, mc.getCols());
        // handle output nnz and binary block configuration
        if (dt.isMatrix()) {
            if (outinfo == OutputInfo.BinaryBlockOutputInfo) {
                mtd.put(DataExpression.ROWBLOCKCOUNTPARAM, mc.getRowsPerBlock());
                mtd.put(DataExpression.COLUMNBLOCKCOUNTPARAM, mc.getColsPerBlock());
            }
            mtd.put(DataExpression.READNUMNONZEROPARAM, mc.getNonZeros());
        }
    }
    //handle format type and additional arguments	
    mtd.put(DataExpression.FORMAT_TYPE, OutputInfo.outputInfoToStringExternal(outinfo));
    if (outinfo == OutputInfo.CSVOutputInfo) {
        CSVFileFormatProperties csvProperties = (formatProperties == null) ? new CSVFileFormatProperties() : (CSVFileFormatProperties) formatProperties;
        mtd.put(DataExpression.DELIM_HAS_HEADER_ROW, csvProperties.hasHeader());
        mtd.put(DataExpression.DELIM_DELIMITER, csvProperties.getDelim());
    }
    if (formatProperties != null) {
        String description = formatProperties.getDescription();
        if (StringUtils.isNotEmpty(description)) {
            String jsonDescription = StringEscapeUtils.escapeJson(description);
            mtd.put(DataExpression.DESCRIPTIONPARAM, jsonDescription);
        }
    }
    String userName = System.getProperty("user.name");
    if (StringUtils.isNotEmpty(userName)) {
        mtd.put(DataExpression.AUTHORPARAM, userName);
    } else {
        mtd.put(DataExpression.AUTHORPARAM, "SystemML");
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    mtd.put(DataExpression.CREATEDPARAM, sdf.format(new Date()));
    // indent with 4 spaces	
    return mtd.toString(4);
}
Also used : CSVFileFormatProperties(org.apache.sysml.runtime.matrix.data.CSVFileFormatProperties) OrderedJSONObject(org.apache.wink.json4j.OrderedJSONObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 CSVFileFormatProperties (org.apache.sysml.runtime.matrix.data.CSVFileFormatProperties)1 OrderedJSONObject (org.apache.wink.json4j.OrderedJSONObject)1