Search in sources :

Example 1 with JsonParser

use of org.apache.apex.malhar.contrib.parser.JsonParser in project apex-malhar by apache.

the class EnricherAppWithJSONFile method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    dataGenerator = dag.addOperator("DataGenerator", DataGenerator.class);
    JsonParser parser = dag.addOperator("Parser", JsonParser.class);
    /**
     * FSLoader is used to configure Enricher backend. Property of FSLoader file which is fileName is set in
     * properties.xml file.
     * The format that is used to read the file is present as an example in resources/circleMapping.txt file.
     */
    JsonFSLoader fsLoader = new JsonFSLoader();
    POJOEnricher enrich = dag.addOperator("Enrich", POJOEnricher.class);
    enrich.setStore(fsLoader);
    ArrayList<String> includeFields = new ArrayList<>();
    includeFields.add("circleName");
    ArrayList<String> lookupFields = new ArrayList<>();
    lookupFields.add("circleId");
    enrich.setIncludeFields(includeFields);
    enrich.setLookupFields(lookupFields);
    MapFunctionOperator<Object, ?> out = dag.addOperator("out", new MapFunctionOperator<>(outputFn));
    dag.addStream("Parse", dataGenerator.output, parser.in);
    dag.addStream("Enrich", parser.out, enrich.input);
    dag.addStream("Console", enrich.output, out.input);
}
Also used : ArrayList(java.util.ArrayList) POJOEnricher(org.apache.apex.malhar.contrib.enrich.POJOEnricher) JsonParser(org.apache.apex.malhar.contrib.parser.JsonParser) JsonFSLoader(org.apache.apex.malhar.contrib.enrich.JsonFSLoader)

Example 2 with JsonParser

use of org.apache.apex.malhar.contrib.parser.JsonParser in project apex-malhar by apache.

the class Application method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    JsonGenerator generator = dag.addOperator("JsonGenerator", JsonGenerator.class);
    JsonParser jsonParser = dag.addOperator("jsonParser", JsonParser.class);
    CsvFormatter formatter = dag.addOperator("formatter", CsvFormatter.class);
    formatter.setSchema(SchemaUtils.jarResourceFileToString(filename));
    dag.setInputPortAttribute(formatter.in, PortContext.TUPLE_CLASS, PojoEvent.class);
    HDFSOutputOperator<String> hdfsOutput = dag.addOperator("HDFSOutputOperator", HDFSOutputOperator.class);
    hdfsOutput.setLineDelimiter("");
    dag.addStream("parserStream", generator.out, jsonParser.in);
    dag.addStream("formatterStream", jsonParser.out, formatter.in);
    dag.addStream("outputStream", formatter.out, hdfsOutput.input);
}
Also used : CsvFormatter(org.apache.apex.malhar.contrib.formatter.CsvFormatter) JsonParser(org.apache.apex.malhar.contrib.parser.JsonParser)

Aggregations

JsonParser (org.apache.apex.malhar.contrib.parser.JsonParser)2 ArrayList (java.util.ArrayList)1 JsonFSLoader (org.apache.apex.malhar.contrib.enrich.JsonFSLoader)1 POJOEnricher (org.apache.apex.malhar.contrib.enrich.POJOEnricher)1 CsvFormatter (org.apache.apex.malhar.contrib.formatter.CsvFormatter)1