Search in sources :

Example 1 with ReflectionBasedUdfResolver

use of org.apache.samza.sql.udf.ReflectionBasedUdfResolver in project samza by apache.

the class SamzaSqlApplicationConfig method createUdfResolver.

private UdfResolver createUdfResolver(Map<String, String> config) {
    String udfResolveValue = config.get(CFG_UDF_RESOLVER);
    Validate.notEmpty(udfResolveValue, "udfResolver config is not set or empty");
    HashMap<String, String> domainConfig = getDomainProperties(config, String.format(CFG_FMT_UDF_RESOLVER_DOMAIN, udfResolveValue), false);
    Properties props = new Properties();
    props.putAll(domainConfig);
    HashMap<String, String> udfConfig = getDomainProperties(config, CFG_UDF_CONFIG_DOMAIN, false);
    // TODO: SAMZA-2355: Make the UDFResolver pluggable.
    return new ReflectionBasedUdfResolver(new MapConfig(udfConfig));
}
Also used : ReflectionBasedUdfResolver(org.apache.samza.sql.udf.ReflectionBasedUdfResolver) MapConfig(org.apache.samza.config.MapConfig) Properties(java.util.Properties)

Example 2 with ReflectionBasedUdfResolver

use of org.apache.samza.sql.udf.ReflectionBasedUdfResolver in project samza by apache.

the class TestReflectionBasedUdfResolver method testUDfResolverShouldReturnAllUDFInClassPath.

@Test
public void testUDfResolverShouldReturnAllUDFInClassPath() throws NoSuchMethodException {
    Config config = new MapConfig(ImmutableMap.of("samza.sql.udf.resolver.package.filter", "org.apache.samza.sql.udf.impl"));
    ReflectionBasedUdfResolver reflectionBasedUdfResolver = new ReflectionBasedUdfResolver(config);
    Collection<UdfMetadata> udfMetadataList = reflectionBasedUdfResolver.getUdfs();
    Method method = TestSamzaSqlUdf.class.getMethod("execute", String.class);
    UdfMetadata udfMetadata = new UdfMetadata("TestSamzaSqlUdf", "Test samza sql udf implementation", method, new MapConfig(), ImmutableList.of(SamzaSqlFieldType.STRING), SamzaSqlFieldType.STRING, true);
    Assert.assertArrayEquals(new UdfMetadata[] { udfMetadata }, udfMetadataList.toArray(new UdfMetadata[0]));
}
Also used : ReflectionBasedUdfResolver(org.apache.samza.sql.udf.ReflectionBasedUdfResolver) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) Method(java.lang.reflect.Method) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Example 3 with ReflectionBasedUdfResolver

use of org.apache.samza.sql.udf.ReflectionBasedUdfResolver in project samza by apache.

the class TestReflectionBasedUdfResolver method testShouldReturnNothingWhenNoUDFIsInPackagePrefix.

@Test
public void testShouldReturnNothingWhenNoUDFIsInPackagePrefix() {
    Config config = new MapConfig(ImmutableMap.of("samza.sql.udf.resolver.package.prefix", "org.apache.samza.udf.blah.blah"));
    ReflectionBasedUdfResolver reflectionBasedUdfResolver = new ReflectionBasedUdfResolver(config);
    Collection<UdfMetadata> udfMetadataList = reflectionBasedUdfResolver.getUdfs();
    Assert.assertEquals(0, udfMetadataList.size());
}
Also used : ReflectionBasedUdfResolver(org.apache.samza.sql.udf.ReflectionBasedUdfResolver) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MapConfig(org.apache.samza.config.MapConfig) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata) Test(org.junit.Test)

Aggregations

MapConfig (org.apache.samza.config.MapConfig)3 ReflectionBasedUdfResolver (org.apache.samza.sql.udf.ReflectionBasedUdfResolver)3 Config (org.apache.samza.config.Config)2 UdfMetadata (org.apache.samza.sql.interfaces.UdfMetadata)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1