use of org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator 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"));
}
use of org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration conf) {
BatchSequenceGenerator sequenceGenerator = dag.addOperator("sequenceGenerator", BatchSequenceGenerator.class);
PassthroughFailOperator passthroughFailOperator = dag.addOperator("passthrough", PassthroughFailOperator.class);
KafkaSinglePortExactlyOnceOutputOperator<String> kafkaExactlyOnceOutputOperator = dag.addOperator("kafkaExactlyOnceOutputOperator", KafkaSinglePortExactlyOnceOutputOperator.class);
KafkaSinglePortOutputOperator kafkaOutputOperator = dag.addOperator("kafkaOutputOperator", KafkaSinglePortOutputOperator.class);
dag.addStream("sequenceToPassthrough", sequenceGenerator.out, passthroughFailOperator.input);
dag.addStream("linesToKafka", passthroughFailOperator.output, kafkaOutputOperator.inputPort, kafkaExactlyOnceOutputOperator.inputPort);
KafkaSinglePortInputOperator kafkaInputTopicExactly = dag.addOperator("kafkaTopicExactly", KafkaSinglePortInputOperator.class);
kafkaInputTopicExactly.setInitialOffset(KafkaSinglePortInputOperator.InitialOffset.EARLIEST.name());
KafkaSinglePortInputOperator kafkaInputTopicAtLeast = dag.addOperator("kafkaTopicAtLeast", KafkaSinglePortInputOperator.class);
kafkaInputTopicAtLeast.setInitialOffset(KafkaSinglePortInputOperator.InitialOffset.EARLIEST.name());
ValidationToFile validationToFile = dag.addOperator("validationToFile", ValidationToFile.class);
dag.addStream("messagesFromExactly", kafkaInputTopicExactly.outputPort, validationToFile.topicExactlyInput);
dag.addStream("messagesFromAtLeast", kafkaInputTopicAtLeast.outputPort, validationToFile.topicAtLeastInput);
}
use of org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator in project apex-malhar by apache.
the class KafkaApp method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration conf) {
KafkaSinglePortInputOperator in = dag.addOperator("kafkaIn", new KafkaSinglePortInputOperator());
in.setInitialOffset(AbstractKafkaInputOperator.InitialOffset.EARLIEST.name());
LineOutputOperator out = dag.addOperator("fileOut", new LineOutputOperator());
dag.addStream("data", in.outputPort, out.input);
}
use of org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator in project apex-malhar by apache.
the class SerDeTest method testPortEndpoint.
@Test
public void testPortEndpoint() throws IOException, ClassNotFoundException {
LogicalPlan dag = new LogicalPlan();
String schemaIn = "{\"separator\":\",\",\"quoteChar\":\"\\\"\",\"fields\":[" + "{\"name\":\"RowTime\",\"type\":\"Date\",\"constraints\":{\"format\":\"dd/MM/yyyy hh:mm:ss Z\"}}," + "{\"name\":\"id\",\"type\":\"Integer\"}," + "{\"name\":\"Product\",\"type\":\"String\"}," + "{\"name\":\"units\",\"type\":\"Integer\"}]}";
String schemaOut = "{\"separator\":\",\",\"quoteChar\":\"\\\"\",\"fields\":[" + "{\"name\":\"RowTime1\",\"type\":\"Date\",\"constraints\":{\"format\":\"dd/MM/yyyy hh:mm:ss Z\"}}," + "{\"name\":\"RowTime2\",\"type\":\"Date\",\"constraints\":{\"format\":\"dd/MM/yyyy hh:mm:ss Z\"}}," + "{\"name\":\"Product\",\"type\":\"String\"}]}";
KafkaSinglePortInputOperator kafkaInput = dag.addOperator("KafkaInput", KafkaSinglePortInputOperator.class);
kafkaInput.setTopics("testdata0");
kafkaInput.setInitialOffset("EARLIEST");
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, KafkaEndpoint.KEY_DESERIALIZER);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaEndpoint.VALUE_DESERIALIZER);
kafkaInput.setConsumerProps(props);
kafkaInput.setClusters("localhost:9092");
CsvParser csvParser = dag.addOperator("CSVParser", CsvParser.class);
csvParser.setSchema(schemaIn);
dag.addStream("KafkaToCSV", kafkaInput.outputPort, csvParser.in);
CsvFormatter formatter = dag.addOperator("CSVFormatter", CsvFormatter.class);
formatter.setSchema(schemaOut);
KafkaSinglePortOutputOperator kafkaOutput = dag.addOperator("KafkaOutput", KafkaSinglePortOutputOperator.class);
kafkaOutput.setTopic("testresult");
props = new Properties();
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaEndpoint.VALUE_SERIALIZER);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KafkaEndpoint.KEY_SERIALIZER);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
kafkaOutput.setProperties(props);
dag.addStream("CSVToKafka", formatter.out, kafkaOutput.inputPort);
SQLExecEnvironment.getEnvironment().registerTable("ORDERS", new StreamEndpoint(csvParser.out, InputPOJO.class)).registerTable("SALES", new StreamEndpoint(formatter.in, OutputPOJO.class)).registerFunction("APEXCONCAT", FileEndpointTest.class, "apex_concat_str").executeSQL(dag, "INSERT INTO SALES " + "SELECT STREAM ROWTIME, " + "FLOOR(ROWTIME TO DAY), " + "APEXCONCAT('OILPAINT', SUBSTRING(PRODUCT, 6, 7)) " + "FROM ORDERS WHERE ID > 3 " + "AND " + "PRODUCT LIKE 'paint%'");
dag.validate();
}
use of org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator in project apex-malhar by apache.
the class KafkaEndpoint method populateInputDAG.
@Override
public RelInfo populateInputDAG(DAG dag, JavaTypeFactory typeFactory) {
KafkaSinglePortInputOperator kafkaInput = dag.addOperator(OperatorUtils.getUniqueOperatorName("KafkaInput"), KafkaSinglePortInputOperator.class);
kafkaInput.setTopics((String) operands.get(KAFKA_TOPICS));
kafkaInput.setInitialOffset("EARLIEST");
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, operands.get(KAFKA_SERVERS));
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, KEY_DESERIALIZER);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, VALUE_DESERIALIZER);
kafkaInput.setConsumerProps(props);
kafkaInput.setClusters((String) operands.get(KAFKA_SERVERS));
RelInfo spec = messageFormat.populateInputDAG(dag, typeFactory);
dag.addStream(OperatorUtils.getUniqueStreamName("Kafka", "Parser"), kafkaInput.outputPort, spec.getInputPorts().get(0));
return new RelInfo("Input", Lists.<Operator.InputPort>newArrayList(), spec.getOperator(), spec.getOutPort(), messageFormat.getRowType(typeFactory));
}
Aggregations