Search in sources :

Example 6 with JdbcExtractionNamespace

use of org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace in project druid by druid-io.

the class JdbcExtractionNamespaceTest method testMappingWithFilter.

@Test(timeout = 60_000L)
public void testMappingWithFilter() throws InterruptedException {
    final JdbcExtractionNamespace extractionNamespace = new JdbcExtractionNamespace(derbyConnectorRule.getMetadataConnectorConfig(), TABLE_NAME, KEY_NAME, VAL_NAME, tsColumn, FILTER_COLUMN + "='1'", new Period(0), null, new JdbcAccessSecurityConfig());
    try (CacheScheduler.Entry entry = scheduler.schedule(extractionNamespace)) {
        CacheSchedulerTest.waitFor(entry);
        final Map<String, String> map = entry.getCache();
        for (Map.Entry<String, String[]> e : RENAMES.entrySet()) {
            String key = e.getKey();
            String[] val = e.getValue();
            String field = val[0];
            String filterVal = val[1];
            if ("1".equals(filterVal)) {
                Assert.assertEquals("non-null check", NullHandling.emptyToNullIfNeeded(field), NullHandling.emptyToNullIfNeeded(map.get(key)));
            } else {
                Assert.assertEquals("non-null check", null, NullHandling.emptyToNullIfNeeded(map.get(key)));
            }
        }
    }
}
Also used : JdbcAccessSecurityConfig(org.apache.druid.server.initialization.JdbcAccessSecurityConfig) Period(org.joda.time.Period) JdbcExtractionNamespace(org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 7 with JdbcExtractionNamespace

use of org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace in project druid by druid-io.

the class JdbcExtractionNamespaceTest method testMappingWithoutFilter.

@Test(timeout = 60_000L)
public void testMappingWithoutFilter() throws InterruptedException {
    final JdbcExtractionNamespace extractionNamespace = new JdbcExtractionNamespace(derbyConnectorRule.getMetadataConnectorConfig(), TABLE_NAME, KEY_NAME, VAL_NAME, tsColumn, null, new Period(0), null, new JdbcAccessSecurityConfig());
    try (CacheScheduler.Entry entry = scheduler.schedule(extractionNamespace)) {
        CacheSchedulerTest.waitFor(entry);
        final Map<String, String> map = entry.getCache();
        for (Map.Entry<String, String[]> e : RENAMES.entrySet()) {
            String key = e.getKey();
            String[] val = e.getValue();
            String field = val[0];
            Assert.assertEquals("non-null check", NullHandling.emptyToNullIfNeeded(field), NullHandling.emptyToNullIfNeeded(map.get(key)));
        }
        Assert.assertEquals("null check", null, map.get("baz"));
    }
}
Also used : JdbcAccessSecurityConfig(org.apache.druid.server.initialization.JdbcAccessSecurityConfig) Period(org.joda.time.Period) JdbcExtractionNamespace(org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

JdbcExtractionNamespace (org.apache.druid.query.lookup.namespace.JdbcExtractionNamespace)7 Test (org.junit.Test)5 JdbcAccessSecurityConfig (org.apache.druid.server.initialization.JdbcAccessSecurityConfig)4 Period (org.joda.time.Period)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 Std (com.fasterxml.jackson.databind.InjectableValues.Std)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)1 CacheGenerator (org.apache.druid.query.lookup.namespace.CacheGenerator)1 ExtractionNamespace (org.apache.druid.query.lookup.namespace.ExtractionNamespace)1 JdbcCacheGenerator (org.apache.druid.server.lookup.namespace.JdbcCacheGenerator)1