Search in sources :

Example 41 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project hive by apache.

the class Vertex method extractOpTree.

/**
 * @throws JSONException
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 * @throws Exception
 *           We assume that there is a single top-level Map Operator Tree or a
 *           Reduce Operator Tree in a vertex
 */
public void extractOpTree() throws JSONException, JsonParseException, JsonMappingException, IOException, Exception {
    if (vertexObject.length() != 0) {
        for (String key : JSONObject.getNames(vertexObject)) {
            if (key.equals("Map Operator Tree:")) {
                extractOp(vertexObject.getJSONArray(key).getJSONObject(0), null);
            } else if (key.equals("Reduce Operator Tree:") || key.equals("Processor Tree:")) {
                extractOp(vertexObject.getJSONObject(key), null);
            } else if (key.equals("Join:")) {
                // this is the case when we have a map-side SMB join
                // one input of the join is treated as a dummy vertex
                JSONArray array = vertexObject.getJSONArray(key);
                for (int index = 0; index < array.length(); index++) {
                    JSONObject mpOpTree = array.getJSONObject(index);
                    Vertex v = new Vertex(null, mpOpTree, this.stage, parser);
                    v.extractOpTree();
                    v.dummy = true;
                    mergeJoinDummyVertexs.add(v);
                }
            } else if (key.equals("Merge File Operator")) {
                JSONObject opTree = vertexObject.getJSONObject(key);
                if (opTree.has("Map Operator Tree:")) {
                    extractOp(opTree.getJSONArray("Map Operator Tree:").getJSONObject(0), null);
                } else {
                    throw new Exception("Merge File Operator does not have a Map Operator Tree");
                }
            } else if (key.equals("Execution mode:")) {
                executionMode = " " + vertexObject.getString(key);
            } else if (key.equals("tagToInput:")) {
                JSONObject tagToInput = vertexObject.getJSONObject(key);
                for (String tag : JSONObject.getNames(tagToInput)) {
                    this.tagToInput.put(tag, (String) tagToInput.get(tag));
                }
            } else if (key.equals("tag:")) {
                this.tag = vertexObject.getString(key);
            } else if (key.equals("Local Work:")) {
                extractOp(vertexObject.getJSONObject(key), null);
            } else {
                LOG.warn("Skip unsupported " + key + " in vertex " + this.name);
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JSONException(org.json.JSONException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 42 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project wonderdog by infochimps-labs.

the class ElasticSearchStorage method putNext.

/**
 *       Here we handle both the delimited record case and the json case.
 */
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple t) throws IOException {
    UDFContext context = UDFContext.getUDFContext();
    Properties property = context.getUDFProperties(ResourceSchema.class);
    MapWritable record = new MapWritable();
    String isJson = property.getProperty(ES_IS_JSON);
    // Handle delimited records (ie. isJson == false)
    if (isJson != null && isJson.equals("false")) {
        String[] fieldNames = property.getProperty(PIG_ES_FIELD_NAMES).split(COMMA);
        for (int i = 0; i < t.size(); i++) {
            if (i < fieldNames.length) {
                try {
                    record.put(new Text(fieldNames[i]), new Text(t.get(i).toString()));
                } catch (NullPointerException e) {
                // LOG.info("Increment null field counter.");
                }
            }
        }
    } else {
        if (!t.isNull(0)) {
            String jsonData = t.get(0).toString();
            // parse json data and put into mapwritable record
            try {
                HashMap<String, Object> data = mapper.readValue(jsonData, HashMap.class);
                record = (MapWritable) toWritable(data);
            } catch (JsonParseException e) {
                e.printStackTrace();
            } catch (JsonMappingException e) {
                e.printStackTrace();
            }
        }
    }
    try {
        writer.write(NullWritable.get(), record);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : UDFContext(org.apache.pig.impl.util.UDFContext) IOException(java.io.IOException) Properties(java.util.Properties) JsonParseException(org.codehaus.jackson.JsonParseException) InterruptedException(java.lang.InterruptedException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)42 IOException (java.io.IOException)34 JsonParseException (org.codehaus.jackson.JsonParseException)33 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)15 TypeReference (org.codehaus.jackson.type.TypeReference)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 ByteString (com.linkedin.data.ByteString)2 PhysicalSourceConfig (com.linkedin.databus2.relay.config.PhysicalSourceConfig)2 InputStream (java.io.InputStream)2