use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlRemoteTable method testSinkEndToEndWithoutKey.
@Test(expected = AssertionError.class)
public void testSinkEndToEndWithoutKey() throws SamzaSqlValidatorException {
int numMessages = 20;
RemoteStoreIOResolverTestFactory.records.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
String sql = "Insert into testRemoteStore.testTable.`$table`(id,name) select id, name from testavro.SIMPLE1";
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);
Assert.assertEquals(numMessages, RemoteStoreIOResolverTestFactory.records.size());
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlRemoteTable method testJoinEndToEndWithUdfHelper.
void testJoinEndToEndWithUdfHelper(boolean enableOptimizer) throws SamzaSqlValidatorException {
int numMessages = 20;
TestAvroSystemFactory.messages.clear();
RemoteStoreIOResolverTestFactory.records.clear();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
populateProfileTable(staticConfigs, 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 testRemoteStore.Profile.`$table` as p " + "join testavro.PAGEVIEW as pv " + " on p.__key__ = BuildOutputRecord('id', pv.profileId)";
List<String> sqlStmts = Arrays.asList(sql);
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_ENABLE_PLAN_OPTIMIZER, Boolean.toString(enableOptimizer));
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 TestSamzaSqlRemoteTable method testSinkEndToEndWithKeyWithNullRecords.
@Test
@Ignore("Disabled due to flakiness related to data generation; Refer Pull Request #905 for details")
public void testSinkEndToEndWithKeyWithNullRecords() throws SamzaSqlValidatorException {
int numMessages = 20;
RemoteStoreIOResolverTestFactory.records.clear();
Map<String, String> props = new HashMap<>();
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(props, numMessages, false, true);
String sql1 = "Insert into testRemoteStore.testTable.`$table` select __key__, id, name from testavro.SIMPLE1";
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);
Assert.assertEquals(numMessages, RemoteStoreIOResolverTestFactory.records.size());
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlRemoteTable method testJoinConditionMissing__key__.
@Test(expected = SamzaException.class)
public void testJoinConditionMissing__key__() throws SamzaSqlValidatorException {
int numMessages = 20;
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(new HashMap<>(), numMessages, true);
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 testRemoteStore.Profile.`$table` as p " + "right join testavro.PAGEVIEW as pv " + " on p.id = pv.profileId where p.name is null or p.name <> '0'";
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);
}
use of org.apache.samza.sql.planner.SamzaSqlValidator in project samza by apache.
the class TestSamzaSqlRemoteTable method testNonKeyWithDeleteOpValidation.
@Test(expected = SamzaSqlValidatorException.class)
public void testNonKeyWithDeleteOpValidation() throws SamzaSqlValidatorException {
int numMessages = 1;
Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(new HashMap<>(), numMessages, true);
String sql = "Insert into testRemoteStore.Profile.`$table` " + "select p.__key__ as pageKey, 'UPDATE' as __op__ " + "from testRemoteStore.Profile.`$table` as p " + "join testavro.PAGEVIEW as pv " + " on p.__key__ = 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);
}
Aggregations