Search in sources :

Example 1 with SQLExecEnvironment

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"));
}
Also used : StreamEndpoint(org.apache.apex.malhar.sql.table.StreamEndpoint) CSVMessageFormat(org.apache.apex.malhar.sql.table.CSVMessageFormat) SQLExecEnvironment(org.apache.apex.malhar.sql.SQLExecEnvironment) KafkaSinglePortInputOperator(org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator) CsvParser(org.apache.apex.malhar.contrib.parser.CsvParser) FileEndpoint(org.apache.apex.malhar.sql.table.FileEndpoint)

Aggregations

CsvParser (org.apache.apex.malhar.contrib.parser.CsvParser)1 KafkaSinglePortInputOperator (org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator)1 SQLExecEnvironment (org.apache.apex.malhar.sql.SQLExecEnvironment)1 CSVMessageFormat (org.apache.apex.malhar.sql.table.CSVMessageFormat)1 FileEndpoint (org.apache.apex.malhar.sql.table.FileEndpoint)1 StreamEndpoint (org.apache.apex.malhar.sql.table.StreamEndpoint)1