Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import org.apache.druid.guice.ExpressionModule;
import org.apache.druid.guice.JsonConfigProvider;
import org.apache.druid.initialization.DruidModule;
import org.apache.druid.query.dimension.LookupDimensionSpec;
import org.apache.druid.query.expression.LookupExprMacro;

import javax.annotation.Nullable;
import java.util.List;

/**
* Variant of {@link LookupModule} that only supports serde of {@link org.apache.druid.query.Query} objects, to allow
* a service to examine queries that might contain for example a {@link RegisteredLookupExtractionFn}, but without
* requiring the service to load the actual lookups.
* a service to examine queries that might contain for example a {@link RegisteredLookupExtractionFn} or a
* {@link LookupExprMacro}, but without requiring the service to load the actual lookups.
*/
public class LookupSerdeModule implements DruidModule
{
Expand All @@ -55,6 +57,7 @@ public void configure(Binder binder)
{
JsonConfigProvider.bind(binder, LookupModule.PROPERTY_BASE, LookupConfig.class);
binder.bind(LookupExtractorFactoryContainerProvider.class).to(NoopLookupExtractorFactoryContainerProvider.class);
ExpressionModule.addExprMacro(binder, LookupExprMacro.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.query.lookup;

import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.inject.Injector;
import com.google.inject.Key;
import org.apache.druid.guice.ExpressionModule;
import org.apache.druid.guice.GuiceInjectors;
import org.apache.druid.guice.annotations.Json;
import org.apache.druid.initialization.DruidModule;
import org.apache.druid.math.expr.ExprMacroTable;
import org.apache.druid.query.dimension.DimensionSpec;
import org.apache.druid.query.dimension.ExtractionDimensionSpec;
import org.apache.druid.query.filter.DimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.segment.VirtualColumn;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.transform.ExpressionTransform;
import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class LookupSerdeModuleTest
{
private Injector injector;
private ObjectMapper objectMapper;

@Before
public void setUp()
{
final ImmutableList<DruidModule> modules = ImmutableList.of(
new ExpressionModule(),
new LookupSerdeModule()
);

injector = GuiceInjectors.makeStartupInjectorWithModules(modules);
objectMapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
objectMapper.setInjectableValues(
new InjectableValues.Std()
.addValue(ExprMacroTable.class, injector.getInstance(ExprMacroTable.class))
.addValue(
LookupExtractorFactoryContainerProvider.class,
injector.getInstance(LookupExtractorFactoryContainerProvider.class)
)
);
modules.stream().flatMap(module -> module.getJacksonModules().stream()).forEach(objectMapper::registerModule);
}

@Test
public void testExpressionVirtualColumnSerde() throws Exception
{
final ExpressionVirtualColumn virtualColumn = new ExpressionVirtualColumn(
"v",
"lookup(xxx, 'beep')",
ValueType.STRING,
injector.getInstance(ExprMacroTable.class)
);

Assert.assertEquals(
virtualColumn,
objectMapper.readValue(objectMapper.writeValueAsBytes(virtualColumn), VirtualColumn.class)
);
}

@Test
public void testExtractionDimensionSerde() throws Exception
{
final ExtractionDimensionSpec dimensionSpec = new ExtractionDimensionSpec(
"xxx",
"d",
new RegisteredLookupExtractionFn(null, "beep", false, null, null, null)
);

Assert.assertEquals(
dimensionSpec,
objectMapper.readValue(objectMapper.writeValueAsBytes(dimensionSpec), DimensionSpec.class)
);
}

@Test
public void testExtractionFilterSere() throws Exception
{
final SelectorDimFilter filter = new SelectorDimFilter(
"xxx",
"d",
new RegisteredLookupExtractionFn(null, "beep", false, null, null, null)
);

Assert.assertEquals(
filter,
objectMapper.readValue(objectMapper.writeValueAsBytes(filter), DimFilter.class)
);
}

@Test
public void testExpressionTransformSerde() throws Exception
{
final ExpressionTransform transform = new ExpressionTransform(
"xxx",
"lookup(xxx, 'beep')",
injector.getInstance(ExprMacroTable.class)
);

Assert.assertEquals(
transform,
objectMapper.readValue(objectMapper.writeValueAsBytes(transform), ExpressionTransform.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.druid.metadata.MetadataSegmentManagerProvider;
import org.apache.druid.metadata.MetadataStorage;
import org.apache.druid.metadata.MetadataStorageProvider;
import org.apache.druid.query.lookup.LookupSerdeModule;
import org.apache.druid.server.audit.AuditManagerProvider;
import org.apache.druid.server.coordinator.BalancerStrategyFactory;
import org.apache.druid.server.coordinator.CachingCostBalancerStrategyConfig;
Expand Down Expand Up @@ -271,6 +272,8 @@ public LoadQueueTaskMaster getLoadQueueTaskMaster(
}
);

modules.add(new LookupSerdeModule());

if (beOverlord) {
modules.addAll(new CliOverlord().getModules(false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.druid.indexing.worker.http.TaskManagementResource;
import org.apache.druid.indexing.worker.http.WorkerResource;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.lookup.LookupSerdeModule;
import org.apache.druid.segment.realtime.firehose.ChatHandlerProvider;
import org.apache.druid.server.DruidNode;
import org.apache.druid.server.initialization.jetty.JettyServerInitializer;
Expand All @@ -64,6 +65,7 @@
import java.util.List;

/**
*
*/
@Command(
name = "middleManager",
Expand Down Expand Up @@ -163,7 +165,8 @@ public WorkerNodeService getWorkerNodeService(WorkerConfig workerConfig)
}
},
new IndexingServiceFirehoseModule(),
new IndexingServiceTaskLogsModule()
new IndexingServiceTaskLogsModule(),
new LookupSerdeModule()
);
}
}
2 changes: 2 additions & 0 deletions services/src/main/java/org/apache/druid/cli/CliOverlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.apache.druid.indexing.overlord.supervisor.SupervisorResource;
import org.apache.druid.indexing.worker.config.WorkerConfig;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.lookup.LookupSerdeModule;
import org.apache.druid.segment.realtime.firehose.ChatHandlerProvider;
import org.apache.druid.server.audit.AuditManagerProvider;
import org.apache.druid.server.coordinator.CoordinatorOverlordServiceConfig;
Expand Down Expand Up @@ -333,6 +334,7 @@ private void configureOverlordHelpers(Binder binder)
},
new IndexingServiceFirehoseModule(),
new IndexingServiceTaskLogsModule(),
new LookupSerdeModule(),
new SamplerModule()
);
}
Expand Down