Search in sources :

Example 1 with SamzaSqlValidatorException

use of org.apache.samza.sql.planner.SamzaSqlValidatorException in project samza by apache.

the class TestSamzaSqlRemoteTable method testJoinEndToEndWithFilterHelper.

void testJoinEndToEndWithFilterHelper(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__ = pv.profileId" + " where p.name = 'Mike' and pv.profileId = 1";
    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(1, outMessages.size());
    Assert.assertEquals(outMessages.get(0), "home,Mike");
}
Also used : Arrays(java.util.Arrays) GenericRecord(org.apache.avro.generic.GenericRecord) TestAvroSystemFactory(org.apache.samza.sql.system.TestAvroSystemFactory) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlValidatorException(org.apache.samza.sql.planner.SamzaSqlValidatorException) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) RemoteStoreIOResolverTestFactory(org.apache.samza.sql.util.RemoteStoreIOResolverTestFactory) HashMap(java.util.HashMap) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) Test(org.junit.Test) JsonUtil(org.apache.samza.sql.util.JsonUtil) Collectors(java.util.stream.Collectors) SamzaException(org.apache.samza.SamzaException) List(java.util.List) Ignore(org.junit.Ignore) Map(java.util.Map) Config(org.apache.samza.config.Config) Assert(org.junit.Assert) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 2 with SamzaSqlValidatorException

use of org.apache.samza.sql.planner.SamzaSqlValidatorException in project samza by apache.

the class TestSamzaSqlEndToEnd method testEndToEndWithNullRecords.

@Test
public void testEndToEndWithNullRecords() throws SamzaSqlValidatorException {
    int numMessages = 20;
    TestAvroSystemFactory.messages.clear();
    Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(Collections.emptyMap(), numMessages, false, true);
    String sql = "Insert into testavro.simpleOutputTopic select * 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);
    List<Integer> outMessages = TestAvroSystemFactory.messages.stream().map(x -> x.getMessage() == null || ((GenericRecord) x.getMessage()).get("id") == null ? null : Integer.valueOf(((GenericRecord) x.getMessage()).get("id").toString())).filter(Objects::nonNull).sorted().collect(Collectors.toList());
    Assert.assertEquals(numMessages - ((numMessages - 1) / TestAvroSystemFactory.NULL_RECORD_FREQUENCY + 1), outMessages.size());
    Assert.assertEquals(IntStream.range(0, numMessages).boxed().filter(x -> x % TestAvroSystemFactory.NULL_RECORD_FREQUENCY != 0).collect(Collectors.toList()), outMessages);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TestAvroSystemFactory(org.apache.samza.sql.system.TestAvroSystemFactory) SamzaSqlValidatorException(org.apache.samza.sql.planner.SamzaSqlValidatorException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MyTestUdf(org.apache.samza.sql.util.MyTestUdf) HashSet(java.util.HashSet) Map(java.util.Map) MapConfig(org.apache.samza.config.MapConfig) GenericRecord(org.apache.avro.generic.GenericRecord) Logger(org.slf4j.Logger) SampleRelConverterFactory(org.apache.samza.sql.util.SampleRelConverterFactory) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) Set(java.util.Set) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) Test(org.junit.Test) JsonUtil(org.apache.samza.sql.util.JsonUtil) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Ignore(org.junit.Ignore) Optional(java.util.Optional) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Config(org.apache.samza.config.Config) Assert(org.junit.Assert) Collections(java.util.Collections) 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) Objects(java.util.Objects) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 3 with SamzaSqlValidatorException

use of org.apache.samza.sql.planner.SamzaSqlValidatorException in project samza by apache.

the class TestSamzaSqlRemoteTable method testJoinEndToEndWithUdfAndFilterHelper.

void testJoinEndToEndWithUdfAndFilterHelper(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)" + " where p.name = 'Mike' and pv.profileId = 1";
    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(1, outMessages.size());
    Assert.assertEquals(outMessages.get(0), "home,Mike");
}
Also used : Arrays(java.util.Arrays) GenericRecord(org.apache.avro.generic.GenericRecord) TestAvroSystemFactory(org.apache.samza.sql.system.TestAvroSystemFactory) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlValidatorException(org.apache.samza.sql.planner.SamzaSqlValidatorException) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) RemoteStoreIOResolverTestFactory(org.apache.samza.sql.util.RemoteStoreIOResolverTestFactory) HashMap(java.util.HashMap) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) Test(org.junit.Test) JsonUtil(org.apache.samza.sql.util.JsonUtil) Collectors(java.util.stream.Collectors) SamzaException(org.apache.samza.SamzaException) List(java.util.List) Ignore(org.junit.Ignore) Map(java.util.Map) Config(org.apache.samza.config.Config) Assert(org.junit.Assert) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 4 with SamzaSqlValidatorException

use of org.apache.samza.sql.planner.SamzaSqlValidatorException in project samza by apache.

the class TestSamzaSqlRemoteTable method testSourceEndToEndWithKeyWithNullForeignKeys.

@Test
public void testSourceEndToEndWithKeyWithNullForeignKeys() throws SamzaSqlValidatorException {
    int numMessages = 20;
    TestAvroSystemFactory.messages.clear();
    RemoteStoreIOResolverTestFactory.records.clear();
    Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(new HashMap<>(), numMessages, true);
    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__ = 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 / 2, outMessages.size());
    List<String> expectedOutMessages = TestAvroSystemFactory.getPageKeyProfileNameJoinWithNullForeignKeys(numMessages);
    Assert.assertEquals(expectedOutMessages, outMessages);
}
Also used : Arrays(java.util.Arrays) GenericRecord(org.apache.avro.generic.GenericRecord) TestAvroSystemFactory(org.apache.samza.sql.system.TestAvroSystemFactory) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlValidatorException(org.apache.samza.sql.planner.SamzaSqlValidatorException) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) RemoteStoreIOResolverTestFactory(org.apache.samza.sql.util.RemoteStoreIOResolverTestFactory) HashMap(java.util.HashMap) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) Test(org.junit.Test) JsonUtil(org.apache.samza.sql.util.JsonUtil) Collectors(java.util.stream.Collectors) SamzaException(org.apache.samza.SamzaException) List(java.util.List) Ignore(org.junit.Ignore) Map(java.util.Map) Config(org.apache.samza.config.Config) Assert(org.junit.Assert) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.junit.Test)

Example 5 with SamzaSqlValidatorException

use of org.apache.samza.sql.planner.SamzaSqlValidatorException 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);
}
Also used : Arrays(java.util.Arrays) GenericRecord(org.apache.avro.generic.GenericRecord) TestAvroSystemFactory(org.apache.samza.sql.system.TestAvroSystemFactory) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlValidatorException(org.apache.samza.sql.planner.SamzaSqlValidatorException) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) RemoteStoreIOResolverTestFactory(org.apache.samza.sql.util.RemoteStoreIOResolverTestFactory) HashMap(java.util.HashMap) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) Test(org.junit.Test) JsonUtil(org.apache.samza.sql.util.JsonUtil) Collectors(java.util.stream.Collectors) SamzaException(org.apache.samza.SamzaException) List(java.util.List) Ignore(org.junit.Ignore) Map(java.util.Map) Config(org.apache.samza.config.Config) Assert(org.junit.Assert) MapConfig(org.apache.samza.config.MapConfig) SamzaSqlValidator(org.apache.samza.sql.planner.SamzaSqlValidator) SamzaSqlTestConfig(org.apache.samza.sql.util.SamzaSqlTestConfig) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) GenericRecord(org.apache.avro.generic.GenericRecord)

Aggregations

Arrays (java.util.Arrays)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 GenericRecord (org.apache.avro.generic.GenericRecord)7 Config (org.apache.samza.config.Config)7 MapConfig (org.apache.samza.config.MapConfig)7 SamzaSqlValidator (org.apache.samza.sql.planner.SamzaSqlValidator)7 SamzaSqlValidatorException (org.apache.samza.sql.planner.SamzaSqlValidatorException)7 SamzaSqlApplicationConfig (org.apache.samza.sql.runner.SamzaSqlApplicationConfig)7 TestAvroSystemFactory (org.apache.samza.sql.system.TestAvroSystemFactory)7 JsonUtil (org.apache.samza.sql.util.JsonUtil)7 SamzaSqlTestConfig (org.apache.samza.sql.util.SamzaSqlTestConfig)7 Assert (org.junit.Assert)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 SamzaException (org.apache.samza.SamzaException)6 RemoteStoreIOResolverTestFactory (org.apache.samza.sql.util.RemoteStoreIOResolverTestFactory)6 ArrayList (java.util.ArrayList)1