Search in sources :

Example 96 with LogicalPlan

use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-malhar by apache.

the class SerDeTest method testJoinFilter.

@Test
public void testJoinFilter() throws IOException, ClassNotFoundException {
    LogicalPlan dag = new LogicalPlan();
    String schemaIn0 = "{\"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 schemaIn1 = "{\"separator\":\",\",\"quoteChar\":\"\\\"\",\"fields\":[" + "{\"name\":\"id\",\"type\":\"Integer\"}," + "{\"name\":\"Category\",\"type\":\"String\"}]}";
    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\"}," + "{\"name\":\"Category\",\"type\":\"String\"}]}";
    String sql = "INSERT INTO SALES SELECT STREAM A.ROWTIME, FLOOR(A.ROWTIME TO DAY), " + "APEXCONCAT('OILPAINT', SUBSTRING(A.PRODUCT, 6, 7)), B.CATEGORY " + "FROM ORDERS AS A JOIN CATEGORY AS B ON A.id = B.id AND A.id > 3" + "WHERE A.PRODUCT LIKE 'paint%'";
    SQLExecEnvironment.getEnvironment().registerTable("ORDERS", new KafkaEndpoint("localhost:9092", "testdata0", new CSVMessageFormat(schemaIn0))).registerTable("CATEGORY", new KafkaEndpoint("localhost:9092", "testdata1", new CSVMessageFormat(schemaIn1))).registerTable("SALES", new KafkaEndpoint("localhost:9092", "testresult", new CSVMessageFormat(schemaOut))).registerFunction("APEXCONCAT", FileEndpointTest.class, "apex_concat_str").executeSQL(dag, sql);
    dag.validate();
}
Also used : CSVMessageFormat(org.apache.apex.malhar.sql.table.CSVMessageFormat) KafkaEndpoint(org.apache.apex.malhar.sql.table.KafkaEndpoint) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) Test(org.junit.Test)

Example 97 with LogicalPlan

use of com.datatorrent.stram.plan.logical.LogicalPlan 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();
}
Also used : StreamEndpoint(org.apache.apex.malhar.sql.table.StreamEndpoint) CsvFormatter(org.apache.apex.malhar.contrib.formatter.CsvFormatter) KafkaSinglePortInputOperator(org.apache.apex.malhar.kafka.KafkaSinglePortInputOperator) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) CsvParser(org.apache.apex.malhar.contrib.parser.CsvParser) Properties(java.util.Properties) KafkaSinglePortOutputOperator(org.apache.apex.malhar.kafka.KafkaSinglePortOutputOperator) Test(org.junit.Test)

Example 98 with LogicalPlan

use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-malhar by apache.

the class ApexStreamImpl method createDag.

@Override
public DAG createDag() {
    LogicalPlan dag = new LogicalPlan();
    populateDag(dag);
    return dag;
}
Also used : LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan)

Example 99 with LogicalPlan

use of com.datatorrent.stram.plan.logical.LogicalPlan in project apex-malhar by apache.

the class DagMeta method buildDAG.

public DAG buildDAG() {
    DAG dag = new LogicalPlan();
    buildDAG(dag);
    return dag;
}
Also used : LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) DAG(com.datatorrent.api.DAG)

Aggregations

LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)99 Test (org.junit.Test)84 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)40 TestPlanContext (com.datatorrent.stram.plan.TestPlanContext)29 PartitioningTest (com.datatorrent.stram.PartitioningTest)27 File (java.io.File)23 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)22 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)19 Checkpoint (com.datatorrent.stram.api.Checkpoint)17 MemoryStorageAgent (com.datatorrent.stram.support.StramTestSupport.MemoryStorageAgent)16 AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)15 StatsListener (com.datatorrent.api.StatsListener)13 StramTestSupport (com.datatorrent.stram.support.StramTestSupport)13 Configuration (org.apache.hadoop.conf.Configuration)13 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)11 NodeReport (org.apache.hadoop.yarn.api.records.NodeReport)10 ContainerStartRequest (com.datatorrent.stram.StreamingContainerAgent.ContainerStartRequest)9 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)9 ArrayList (java.util.ArrayList)9 ConstraintViolationException (javax.validation.ConstraintViolationException)9