use of org.apache.apex.malhar.sql.SQLExecEnvironment in project apex-malhar by apache.
the class FusionStyleSQLApplication method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration conf) {
SQLExecEnvironment env = SQLExecEnvironment.getEnvironment();
env.registerFunction("APEXCONCAT", PureStyleSQLApplication.class, "apex_concat_str");
Map<String, Class> fieldMapping = ImmutableMap.<String, Class>of("RowTime", Date.class, "id", Integer.class, "Product", String.class, "units", Integer.class);
// Add Kafka Input
KafkaSinglePortInputOperator kafkaInput = dag.addOperator("KafkaInput", KafkaSinglePortInputOperator.class);
kafkaInput.setInitialOffset("EARLIEST");
// Add CSVParser
CsvParser csvParser = dag.addOperator("CSVParser", CsvParser.class);
dag.addStream("KafkaToCSV", kafkaInput.outputPort, csvParser.in);
// Register CSV Parser output as input table for first SQL
env.registerTable(conf.get("sqlSchemaInputName"), new StreamEndpoint(csvParser.out, fieldMapping));
// Register FileEndpoint as output table for second SQL.
env.registerTable(conf.get("sqlSchemaOutputName"), new FileEndpoint(conf.get("folderPath"), conf.get("fileName"), new CSVMessageFormat(conf.get("sqlSchemaOutputDef"))));
// Add second SQL to DAG
env.executeSQL(dag, conf.get("sql"));
}
Aggregations