2018-12-13 14:47:20 -05:00
---
2019-08-21 00:48:59 -04:00
id: lookups
2018-12-13 14:47:20 -05:00
title: "Lookups"
---
2018-11-13 12:38:37 -05:00
<!--
~ 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.
-->
2015-06-16 20:17:41 -04:00
2019-08-21 00:48:59 -04:00
> Lookups are an [experimental](../development/experimental.md) feature.
2016-02-12 17:19:28 -05:00
2019-04-19 18:52:26 -04:00
Lookups are a concept in Apache Druid (incubating) where dimension values are (optionally) replaced with new values, allowing join-like
2018-02-01 21:30:19 -05:00
functionality. Applying lookups in Druid is similar to joining a dimension table in a data warehouse. See
2019-08-21 00:48:59 -04:00
[dimension specs ](../querying/dimensionspecs.md ) for more information. For the purpose of these documents, a "key"
2018-02-01 21:30:19 -05:00
refers to a dimension value to match, and a "value" refers to its replacement. So if you wanted to map
`appid-12345` to `Super Mega Awesome App` then the key would be `appid-12345` and the value would be
`Super Mega Awesome App` .
2015-06-16 20:17:41 -04:00
2018-02-01 21:30:19 -05:00
It is worth noting that lookups support not just use cases where keys map one-to-one to unique values, such as country
code and country name, but also support use cases where multiple IDs map to the same value, e.g. multiple app-ids
mapping to a single account manager. When lookups are one-to-one, Druid is able to apply additional optimizations at
query time; see [Query execution ](#query-execution ) below for more details.
2015-06-16 20:17:41 -04:00
2019-08-21 00:48:59 -04:00
Lookups do not have history. They always use the current data. This means that if the chief account manager for a
particular app-id changes, and you issue a query with a lookup to store the app-id to account manager relationship,
2015-12-31 19:32:51 -05:00
it will return the current account manager for that app-id REGARDLESS of the time range over which you query.
2015-06-16 20:17:41 -04:00
2019-08-21 00:48:59 -04:00
If you require data time range sensitive lookups, such a use case is not currently supported dynamically at query time,
2015-12-31 19:32:51 -05:00
and such data belongs in the raw denormalized data for use in Druid.
2015-06-16 20:17:41 -04:00
2019-08-21 00:48:59 -04:00
Very small lookups (count of keys on the order of a few dozen to a few hundred) can be passed at query time as a "map"
lookup as per [dimension specs ](../querying/dimensionspecs.md ).
2015-06-16 20:17:41 -04:00
2016-06-07 13:43:35 -04:00
Other lookup types are available as extensions, including:
2016-03-17 20:11:00 -04:00
2019-08-21 00:48:59 -04:00
- Globally cached lookups from local files, remote URIs, or JDBC through [lookups-cached-global ](../development/extensions-core/lookups-cached-global.md ).
- Globally cached lookups from a Kafka topic through [kafka-extraction-namespace ](../development/extensions-core/kafka-extraction-namespace.md ).
2016-03-25 12:57:34 -04:00
2019-05-06 15:31:51 -04:00
Query Syntax
------------
In [Druid SQL ](sql.html ), lookups can be queried using the `LOOKUP` function, for example:
```
SELECT LOOKUP(column_name, 'lookup-name'), COUNT(*) FROM datasource GROUP BY 1
```
In native queries, lookups can be queried with [dimension specs or extraction functions ](dimensionspecs.html ).
2018-02-01 21:30:19 -05:00
Query Execution
---------------
When executing an aggregation query involving lookups, Druid can decide to apply lookups either while scanning and
aggregating rows, or to apply them after aggregation is complete. It is more efficient to apply lookups after
aggregation is complete, so Druid will do this if it can. Druid decides this by checking if the lookup is marked
as "injective" or not. In general, you should set this property for any lookup that is naturally one-to-one, to allow
Druid to run your queries as fast as possible.
Injective lookups should include _all_ possible keys that may show up in your dataset, and should also map all keys to
_unique values_. This matters because non-injective lookups may map different keys to the same value, which must be
accounted for during aggregation, lest query results contain two result values that should have been aggregated into
one.
This lookup is injective (assuming it contains all possible keys from your data):
```
1 -> Foo
2 -> Bar
3 -> Billy
```
But this one is not, since both "2" and "3" map to the same key:
```
1 -> Foo
2 -> Bar
3 -> Bar
```
To tell Druid that your lookup is injective, you must specify `"injective" : true` in the lookup configuration. Druid
will not detect this automatically.
2016-06-07 13:43:35 -04:00
Dynamic Configuration
2016-03-25 12:57:34 -04:00
---------------------
2019-08-21 00:48:59 -04:00
> Dynamic lookup configuration is an [experimental](../development/experimental.md) feature. Static
> configuration is no longer supported.
2019-01-30 22:41:07 -05:00
The following documents the behavior of the cluster-wide config which is accessible through the Coordinator.
2016-03-25 12:57:34 -04:00
The configuration is propagated through the concept of "tier" of servers.
A "tier" is defined as a group of services which should receive a set of lookups.
2019-01-30 22:41:07 -05:00
For example, you might have all Historicals be part of `__default` , and Peons be part of individual tiers for the datasources they are tasked with.
The tiers for lookups are completely independent of Historical tiers.
2016-03-25 12:57:34 -04:00
These configs are accessed using JSON through the following URI template
```
2017-11-09 20:39:53 -05:00
http://< COORDINATOR_IP > :< PORT > /druid/coordinator/v1/lookups/config/{tier}/{id}
2016-03-25 12:57:34 -04:00
```
All URIs below are assumed to have `http://<COORDINATOR_IP>:<PORT>` prepended.
2017-11-09 20:39:53 -05:00
If you have NEVER configured lookups before, you MUST post an empty json object `{}` to `/druid/coordinator/v1/lookups/config` to initialize the configuration.
2016-03-25 12:57:34 -04:00
These endpoints will return one of the following results:
* 404 if the resource is not found
* 400 if there is a problem in the formatting of the request
* 202 if the request was accepted asynchronously (`POST` and `DELETE` )
* 200 if the request succeeded (`GET` only)
## Configuration propagation behavior
2019-01-30 22:41:07 -05:00
The configuration is propagated to the query serving processes (Broker / Router / Peon / Historical) by the Coordinator.
2019-02-28 21:10:39 -05:00
The query serving processes have an internal API for managing lookups on the process and those are used by the Coordinator.
The Coordinator periodically checks if any of the processes need to load/drop lookups and updates them appropriately.
2016-03-25 12:57:34 -04:00
2019-07-29 20:06:33 -04:00
Please note that only 2 simultaneous lookup configuration propagation requests can be concurrently handled by a single query serving process. This limit is applied to prevent lookup handling from consuming too many server HTTP connections.
2019-08-21 00:48:59 -04:00
## API for configuring lookups
2016-03-25 12:57:34 -04:00
2019-08-21 00:48:59 -04:00
### Bulk update
2017-11-09 20:39:53 -05:00
Lookups can be updated in bulk by posting a JSON object to `/druid/coordinator/v1/lookups/config` . The format of the json object is as follows:
2016-03-25 12:57:34 -04:00
```json
{
2017-04-28 09:41:38 -04:00
"< tierName > ": {
"< lookupName > ": {
"version": "< version > ",
"lookupExtractorFactory": {
"type": "< someExtractorFactoryType > ",
"< someExtractorField > ": "< someExtractorValue > "
}
2016-03-25 12:57:34 -04:00
}
}
}
```
2017-04-28 09:41:38 -04:00
Note that "version" is an arbitrary string assigned by the user, when making updates to existing lookup then user would need to specify a lexicographically higher version.
For example, a config might look something like:
2016-06-02 14:36:45 -04:00
2016-03-25 12:57:34 -04:00
```json
{
2017-04-28 09:41:38 -04:00
"__default": {
"country_code": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"77483": "United States"
}
}
},
"site_id": {
"version": "v0",
"lookupExtractorFactory": {
"type": "cachedNamespace",
"extractionNamespace": {
"type": "jdbc",
"connectorConfig": {
"createTables": true,
"connectURI": "jdbc:mysql:\/\/localhost:3306\/druid",
"user": "druid",
"password": "diurd"
2016-06-07 13:42:41 -04:00
},
2017-04-28 09:41:38 -04:00
"table": "lookupTable",
"keyColumn": "country_id",
"valueColumn": "country_name",
"tsColumn": "timeColumn"
2016-03-25 12:57:34 -04:00
},
2017-04-28 09:41:38 -04:00
"firstCacheTimeout": 120000,
"injective": true
}
},
"site_id_customer1": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"847632": "Internal Use Only"
2016-03-25 12:57:34 -04:00
}
2017-04-28 09:41:38 -04:00
}
2016-03-25 12:57:34 -04:00
},
2017-04-28 09:41:38 -04:00
"site_id_customer2": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"AHF77": "Home"
2016-03-25 12:57:34 -04:00
}
2017-04-28 09:41:38 -04:00
}
}
},
"realtime_customer1": {
"country_code": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"77483": "United States"
}
}
2016-03-25 12:57:34 -04:00
},
2017-04-28 09:41:38 -04:00
"site_id_customer1": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"847632": "Internal Use Only"
}
}
}
},
"realtime_customer2": {
"country_code": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"77483": "United States"
}
}
},
"site_id_customer2": {
"version": "v0",
"lookupExtractorFactory": {
"type": "map",
"map": {
"AHF77": "Home"
2016-03-25 12:57:34 -04:00
}
2017-04-28 09:41:38 -04:00
}
2016-03-25 12:57:34 -04:00
}
2017-04-28 09:41:38 -04:00
}
2016-03-25 12:57:34 -04:00
}
```
All entries in the map will UPDATE existing entries. No entries will be deleted.
2019-08-21 00:48:59 -04:00
### Update lookup
2017-11-09 20:39:53 -05:00
A `POST` to a particular lookup extractor factory via `/druid/coordinator/v1/lookups/config/{tier}/{id}` will update that specific extractor factory.
2016-03-25 12:57:34 -04:00
2017-11-09 20:39:53 -05:00
For example, a post to `/druid/coordinator/v1/lookups/config/realtime_customer1/site_id_customer1` might contain the following:
2016-03-25 12:57:34 -04:00
```json
{
2017-04-28 09:41:38 -04:00
"version": "v1",
"lookupExtractorFactory": {
"type": "map",
"map": {
"847632": "Internal Use Only"
}
}
2016-03-25 12:57:34 -04:00
}
```
This will replace the `site_id_customer1` lookup in the `realtime_customer1` with the definition above.
2019-08-21 00:48:59 -04:00
### Get all lookups
2019-02-08 14:05:59 -05:00
A `GET` to `/druid/coordinator/v1/lookups/config/all` will return all known lookup specs for all tiers.
2019-08-21 00:48:59 -04:00
### Get lookup
2019-02-08 14:05:59 -05:00
A `GET` to a particular lookup extractor factory is accomplished via `/druid/coordinator/v1/lookups/config/{tier}/{id}`
2016-03-25 12:57:34 -04:00
2017-11-09 20:39:53 -05:00
Using the prior example, a `GET` to `/druid/coordinator/v1/lookups/config/realtime_customer2/site_id_customer2` should return
2016-03-25 12:57:34 -04:00
```json
{
2017-04-28 09:41:38 -04:00
"version": "v1",
"lookupExtractorFactory": {
"type": "map",
"map": {
"AHF77": "Home"
}
}
2016-03-25 12:57:34 -04:00
}
```
2019-08-21 00:48:59 -04:00
### Delete lookup
2019-06-15 20:55:50 -04:00
A `DELETE` to `/druid/coordinator/v1/lookups/config/{tier}/{id}` will remove that lookup from the cluster. If it was last lookup in the tier, then tier is deleted as well.
2019-08-21 00:48:59 -04:00
### Delete tier
2019-06-15 20:55:50 -04:00
A `DELETE` to `/druid/coordinator/v1/lookups/config/{tier}` will remove that tier from the cluster.
2016-03-25 12:57:34 -04:00
2019-08-21 00:48:59 -04:00
### List tier names
2017-11-09 20:39:53 -05:00
A `GET` to `/druid/coordinator/v1/lookups/config` will return a list of known tier names in the dynamic configuration.
2019-05-14 16:30:51 -04:00
To discover a list of tiers currently active in the cluster in addition to ones known in the dynamic configuration, the parameter `discover=true` can be added as per `/druid/coordinator/v1/lookups/config?discover=true` .
2016-03-25 12:57:34 -04:00
2019-08-21 00:48:59 -04:00
### List lookup names
2017-11-09 20:39:53 -05:00
A `GET` to `/druid/coordinator/v1/lookups/config/{tier}` will return a list of known lookup names for that tier.
2016-03-25 12:57:34 -04:00
2019-02-28 21:10:39 -05:00
These end points can be used to get the propagation status of configured lookups to processes using lookups such as Historicals.
2017-05-04 14:15:30 -04:00
2019-08-21 00:48:59 -04:00
## API for lookup status
### List load status of all lookups
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/status` with optional query parameter `detailed` .
2019-08-21 00:48:59 -04:00
### List load status of lookups in a tier
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/status/{tier}` with optional query parameter `detailed` .
2019-08-21 00:48:59 -04:00
### List load status of single lookup
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/status/{tier}/{lookup}` with optional query parameter `detailed` .
2019-08-21 00:48:59 -04:00
### List lookup state of all processes
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/nodeStatus` with optional query parameter `discover` to discover tiers from zookeeper or configured lookup tiers are listed.
2019-08-21 00:48:59 -04:00
### List lookup state of processes in a tier
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/nodeStatus/{tier}`
2019-08-21 00:48:59 -04:00
### List lookup state of single process
2017-05-04 14:15:30 -04:00
`GET /druid/coordinator/v1/lookups/nodeStatus/{tier}/{host:port}`
2019-08-21 00:48:59 -04:00
## Internal API
2016-03-25 12:57:34 -04:00
2019-02-28 21:10:39 -05:00
The Peon, Router, Broker, and Historical processes all have the ability to consume lookup configuration.
There is an internal API these processes use to list/load/drop their lookups starting at `/druid/listen/v1/lookups` .
2017-04-28 09:41:38 -04:00
These follow the same convention for return values as the cluster wide dynamic configuration. Following endpoints
can be used for debugging purposes but not otherwise.
2016-03-25 12:57:34 -04:00
2019-08-21 00:48:59 -04:00
### Get lookups
2016-03-25 12:57:34 -04:00
2019-02-28 21:10:39 -05:00
A `GET` to the process at `/druid/listen/v1/lookups` will return a json map of all the lookups currently active on the process.
2016-03-25 12:57:34 -04:00
The return value will be a json map of the lookups to their extractor factories.
```json
{
2017-04-28 09:41:38 -04:00
"site_id_customer2": {
"version": "v1",
"lookupExtractorFactory": {
"type": "map",
"map": {
"AHF77": "Home"
}
}
2016-06-07 13:42:41 -04:00
}
2016-03-25 12:57:34 -04:00
}
```
2019-08-21 00:48:59 -04:00
### Get lookup
2016-03-25 12:57:34 -04:00
2019-02-28 21:10:39 -05:00
A `GET` to the process at `/druid/listen/v1/lookups/some_lookup_name` will return the LookupExtractorFactory for the lookup identified by `some_lookup_name` .
2016-03-25 12:57:34 -04:00
The return value will be the json representation of the factory.
```json
{
2017-04-28 09:41:38 -04:00
"version": "v1",
"lookupExtractorFactory": {
2016-06-07 13:42:41 -04:00
"type": "map",
2017-04-28 09:41:38 -04:00
"map": {
"AHF77": "Home"
}
2016-06-07 13:42:41 -04:00
}
2016-03-25 12:57:34 -04:00
}
```
2019-08-21 00:48:59 -04:00
## Configuration
See [Lookups Dynamic Configuration ](../configuration/index.md#lookups-dynamic-configuration ) for Coordinator configuration.
2016-03-25 12:57:34 -04:00
To configure a Broker / Router / Historical / Peon to announce itself as part of a lookup tier, use the `druid.zk.paths.lookupTier` property.
|Property | Description | Default |
|---------|-------------|---------|
2019-02-28 21:10:39 -05:00
|`druid.lookup.lookupTier`| The tier for **lookups** for this process. This is independent of other tiers.|`__default`|
2019-01-30 22:41:07 -05:00
|`druid.lookup.lookupTierIsDatasource`|For some things like indexing service tasks, the datasource is passed in the runtime properties of a task. This option fetches the tierName from the same value as the datasource for the task. It is suggested to only use this as Peon options for the indexing service, if at all. If true, `druid.lookup.lookupTier` MUST NOT be specified|`"false"`|
2016-04-08 11:15:18 -04:00
2019-01-30 22:41:07 -05:00
To configure the behavior of the dynamic configuration manager, use the following properties on the Coordinator:
2016-06-03 16:58:10 -04:00
|Property|Description|Default|
|--------|-----------|-------|
2017-04-28 09:41:38 -04:00
|`druid.manager.lookups.hostTimeout`|Timeout (in ms) PER HOST for processing request|`2000`(2 seconds)|
2019-02-28 21:10:39 -05:00
|`druid.manager.lookups.allHostTimeout`|Timeout (in ms) to finish lookup management on all the processes.|`900000`(15 mins)|
2017-04-28 09:41:38 -04:00
|`druid.manager.lookups.period`|How long to pause between management cycles|`120000`(2 mins)|
2019-02-28 21:10:39 -05:00
|`druid.manager.lookups.threadPoolSize`|Number of service processes that can be managed concurrently|`10`|
2016-06-03 16:58:10 -04:00
2016-04-08 11:15:18 -04:00
## Saving configuration across restarts
2019-02-28 21:10:39 -05:00
It is possible to save the configuration across restarts such that a process will not have to wait for Coordinator action to re-populate its lookups. To do this the following property is set:
2016-04-08 11:15:18 -04:00
|Property|Description|Default|
|--------|-----------|-------|
2017-11-09 00:30:36 -05:00
|`druid.lookup.snapshotWorkingDir`|Working path used to store snapshot of current lookup configuration, leaving this property null will disable snapshot/bootstrap utility|null|
2019-02-28 21:10:39 -05:00
|`druid.lookup.enableLookupSyncOnStartup`|Enable the lookup synchronization process with Coordinator on startup. The queryable processes will fetch and load the lookups from the Coordinator instead of waiting for the Coordinator to load the lookups for them. Users may opt to disable this option if there are no lookups configured in the cluster.|true|
2017-11-09 00:30:36 -05:00
|`druid.lookup.numLookupLoadingThreads`|Number of threads for loading the lookups in parallel on startup. This thread pool is destroyed once startup is done. It is not kept during the lifetime of the JVM|Available Processors / 2|
2019-01-30 22:41:07 -05:00
|`druid.lookup.coordinatorFetchRetries`|How many times to retry to fetch the lookup bean list from Coordinator, during the sync on startup.|3|
2017-11-09 00:30:36 -05:00
|`druid.lookup.lookupStartRetries`|How many times to retry to start each lookup, either during the sync on startup, or during the runtime.|3|
2019-01-30 22:41:07 -05:00
|`druid.lookup.coordinatorRetryDelay`|How long to delay (in millis) between retries to fetch lookup list from the Coordinator during the sync on startup.|60_000|
2016-04-21 13:15:57 -04:00
## Introspect a Lookup
2019-08-21 00:48:59 -04:00
The Broker provides an API for lookup introspection if the lookup type implements a `LookupIntrospectHandler` .
2016-04-21 13:15:57 -04:00
2019-08-21 00:48:59 -04:00
A `GET` request to `/druid/v1/lookups/introspect/{lookupId}` will return the map of complete values.
2018-03-26 20:01:02 -04:00
ex: `GET /druid/v1/lookups/introspect/nato-phonetic`
```
{
"A": "Alfa",
"B": "Bravo",
"C": "Charlie",
...
"Y": "Yankee",
"Z": "Zulu",
"-": "Dash"
}
```
The list of keys can be retrieved via `GET` to `/druid/v1/lookups/introspect/{lookupId}/keys"`
ex: `GET /druid/v1/lookups/introspect/nato-phonetic/keys`
```
[
"A",
"B",
"C",
...
"Y",
"Z",
"-"
]
```
A `GET` request to `/druid/v1/lookups/introspect/{lookupId}/values"` will return the list of values.
ex: `GET /druid/v1/lookups/introspect/nato-phonetic/values`
```
[
"Alfa",
"Bravo",
"Charlie",
...
"Yankee",
"Zulu",
"Dash"
]
```
2019-08-21 00:48:59 -04:00
2017-04-28 09:41:38 -04:00
## Druid version 0.10.0 to 0.10.1 upgrade/downgrade
2019-02-28 21:10:39 -05:00
Overall druid cluster lookups configuration is persisted in metadata store and also individual lookup processes optionally persist a snapshot of loaded lookups on disk.
2017-04-28 09:41:38 -04:00
If upgrading from druid version 0.10.0 to 0.10.1, then migration for all persisted metadata is handled automatically.
2019-01-30 22:41:07 -05:00
If downgrading from 0.10.1 to 0.9.0 then lookups updates done via Coordinator while 0.10.1 was running, would be lost.
2017-04-28 09:41:38 -04:00
2019-08-21 00:48:59 -04:00