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));
}
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));
}
Aggregations