Search in sources :

Example 1 with MyTestUdf

use of org.apache.samza.sql.util.MyTestUdf in project samza by apache.

the class TestSamzaSqlEndToEnd method testEndToEndUdfPolymorphism.

@Test
public void testEndToEndUdfPolymorphism() throws Exception {
    int numMessages = 20;
    TestAvroSystemFactory.messages.clear();
    Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
    String sql1 = "Insert into testavro.outputTopic(id, bool_value, long_value) " + "select MyTestPoly(id) as long_value, NOT(id = 5) as bool_value, MyTestPoly(name) as id from testavro.SIMPLE1";
    List<String> sqlStmts = Collections.singletonList(sql1);
    staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
    Config config = new MapConfig(staticConfigs);
    new SamzaSqlValidator(config).validate(sqlStmts);
    runApplication(config);
    LOG.info("output Messages " + TestAvroSystemFactory.messages);
    List<Integer> outMessages = TestAvroSystemFactory.messages.stream().map(x -> Integer.valueOf(((GenericRecord) x.getMessage()).get("long_value").toString())).sorted().collect(Collectors.toList());
    Assert.assertEquals(outMessages.size(), numMessages);
    MyTestUdf udf = new MyTestUdf();
    Assert.assertTrue(IntStream.range(0, numMessages).map(udf::execute).boxed().collect(Collectors.toList()).equals(outMessages));
}
Also used : SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MyTestUdf(org.apache.samza.sql.util.MyTestUdf) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 2 with MyTestUdf

use of org.apache.samza.sql.util.MyTestUdf in project samza by apache.

the class TestSamzaSqlEndToEnd method testEndToEndUdf.

@Test
public void testEndToEndUdf() throws Exception {
    int numMessages = 20;
    TestAvroSystemFactory.messages.clear();
    Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
    String sql1 = "Insert into testavro.outputTopic(id, bool_value, long_value) " + "select id, NOT(id = 5) as bool_value, MYTest(id) as long_value from testavro.SIMPLE1;;";
    List<String> sqlStmts = Collections.singletonList(sql1);
    staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
    Config config = new MapConfig(staticConfigs);
    new SamzaSqlValidator(config).validate(sqlStmts);
    runApplication(config);
    LOG.info("output Messages " + TestAvroSystemFactory.messages);
    List<Integer> outMessages = TestAvroSystemFactory.messages.stream().map(x -> Integer.valueOf(((GenericRecord) x.getMessage()).get("long_value").toString())).sorted().collect(Collectors.toList());
    Assert.assertEquals(outMessages.size(), numMessages);
    MyTestUdf udf = new MyTestUdf();
    Assert.assertTrue(IntStream.range(0, numMessages).map(udf::execute).boxed().collect(Collectors.toList()).equals(outMessages));
}
Also used : SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MyTestUdf(org.apache.samza.sql.util.MyTestUdf) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Aggregations

Config (org.apache.samza.config.Config)2 MapConfig (org.apache.samza.config.MapConfig)2 SamzaSqlValidator (org.apache.samza.sql.planner.SamzaSqlValidator)2 SamzaSqlApplicationConfig (org.apache.samza.sql.runner.SamzaSqlApplicationConfig)2 MyTestUdf (org.apache.samza.sql.util.MyTestUdf)2 SamzaSqlTestConfig (org.apache.samza.sql.util.SamzaSqlTestConfig)2 Test (org.junit.Test)2