use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlEndToEnd method testEndToEndStreamTableNestedJoinWithPrimaryKeys.
@Test
public void testEndToEndStreamTableNestedJoinWithPrimaryKeys() throws Exception {
int numMessages = 20;
TestAvroSystemFactory.messages.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql = "Insert into testavro.enrichedPageViewTopic " + "select pv.pageKey as __key__, pv.pageKey as pageKey, c.name as companyName, p.name as profileName," + " p.address as profileAddress " + "from testavro.PAGEVIEW as pv " + "join testavro.PROFILE.`$table` as p " + " on MyTest(p.__key__) = MyTest(pv.profileId) " + " join testavro.COMPANY.`$table` as c " + " on MyTest(p.companyId) = MyTest(c.__key__)";
List<String> sqlStmts = Arrays.asList(sql);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
Config config = new MapConfig(staticConfigs);
new SamzaSqlValidator(config).validate(sqlStmts);
runApplication(config);
List<String> outMessages = TestAvroSystemFactory.messages.stream().map(x -> ((GenericRecord) x.getMessage()).get("pageKey").toString() + "," + ((GenericRecord) x.getMessage()).get("profileName").toString() + "," + ((GenericRecord) x.getMessage()).get("companyName").toString()).collect(Collectors.toList());
Assert.assertEquals(numMessages, outMessages.size());
List<String> expectedOutMessages = TestAvroSystemFactory.getPageKeyProfileCompanyNameJoin(numMessages);
Assert.assertEquals(expectedOutMessages, outMessages);
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlEndToEnd method testEndToEndComplexRecord.
@Test
public void testEndToEndComplexRecord() throws SamzaSqlValidatorException {
int numMessages = 10;
TestAvroSystemFactory.messages.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql1 = "Insert into testavro.outputTopic" + " select bool_value, map_values['key0'] as string_value, union_value, array_values, map_values, id, bytes_value," + " fixed_value, float_value0 from testavro.COMPLEX1";
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);
List<OutgoingMessageEnvelope> outMessages = new ArrayList<>(TestAvroSystemFactory.messages);
Assert.assertEquals(numMessages, outMessages.size());
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlEndToEnd method testEndToEndStreamTableInnerJoinWithUdf.
@Test
public void testEndToEndStreamTableInnerJoinWithUdf() throws Exception {
int numMessages = 20;
TestAvroSystemFactory.messages.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql = "Insert into testavro.enrichedPageViewTopic " + "select pv.pageKey as __key__, pv.pageKey as pageKey, coalesce(null, 'N/A') as companyName," + " p.name as profileName, p.address as profileAddress " + "from testavro.PROFILE.`$table` as p " + "join testavro.PAGEVIEW as pv " + " on MyTest(p.id) = MyTest(pv.profileId)";
List<String> sqlStmts = Arrays.asList(sql);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
Config config = new MapConfig(staticConfigs);
new SamzaSqlValidator(config).validate(sqlStmts);
runApplication(config);
List<String> outMessages = TestAvroSystemFactory.messages.stream().map(x -> ((GenericRecord) x.getMessage()).get("pageKey").toString() + "," + (((GenericRecord) x.getMessage()).get("profileName") == null ? "null" : ((GenericRecord) x.getMessage()).get("profileName").toString())).collect(Collectors.toList());
Assert.assertEquals(numMessages, outMessages.size());
List<String> expectedOutMessages = TestAvroSystemFactory.getPageKeyProfileNameJoin(numMessages);
Assert.assertEquals(expectedOutMessages, outMessages);
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlEndToEnd method testEndToEndCompoundBooleanCheck.
@Test
public void testEndToEndCompoundBooleanCheck() throws SamzaSqlValidatorException {
int numMessages = 20;
TestAvroSystemFactory.messages.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql1 = "Insert into testavro.outputTopic" + " select * from testavro.COMPLEX1 where id >= 0 and bool_value IS TRUE";
List<String> sqlStmts = Arrays.asList(sql1);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
Config config = new MapConfig(staticConfigs);
new SamzaSqlValidator(config).validate(sqlStmts);
runApplication(config);
List<OutgoingMessageEnvelope> outMessages = new ArrayList<>(TestAvroSystemFactory.messages);
Assert.assertEquals(numMessages / 2, outMessages.size());
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlEndToEnd method testEndToEndStreamTableNestedJoinWithSubQuery.
@Test
public void testEndToEndStreamTableNestedJoinWithSubQuery() throws Exception {
int numMessages = 20;
TestAvroSystemFactory.messages.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql = "Insert into testavro.enrichedPageViewTopic " + "select t.pageKey as __key__, t.pageKey as pageKey, c.name as companyName, t.profileName as profileName," + " address as profileAddress " + "from (select p.companyId as companyId, p.name as profileName, p.address as address, pv.pageKey as pageKey" + " from testavro.PAGEVIEW as pv " + " join testavro.PROFILE.`$table` as p " + " on MyTest(p.__key__) = MyTest(pv.profileId)) as t " + "join testavro.COMPANY.`$table` as c " + "on MyTest(t.companyId) = MyTest(c.__key__)";
List<String> sqlStmts = Arrays.asList(sql);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
Config config = new MapConfig(staticConfigs);
new SamzaSqlValidator(config).validate(sqlStmts);
runApplication(config);
List<String> outMessages = TestAvroSystemFactory.messages.stream().map(x -> ((GenericRecord) x.getMessage()).get("pageKey").toString() + "," + ((GenericRecord) x.getMessage()).get("profileName").toString() + "," + ((GenericRecord) x.getMessage()).get("companyName").toString()).collect(Collectors.toList());
Assert.assertEquals(numMessages, outMessages.size());
List<String> expectedOutMessages = TestAvroSystemFactory.getPageKeyProfileCompanyNameJoin(numMessages);
Assert.assertEquals(expectedOutMessages, outMessages);
}
Aggregations