mirror of https://github.com/apache/druid.git
[Docs] Batch09: only `lookup` (#16878)
* [Docs] Batch09: only `lookup` * slight changes * Apply suggestions from code review Co-authored-by: Katya Macedo <38017980+ektravel@users.noreply.github.com> * applying suggestiontions * Apply suggestions from code review Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com> * otherwise null -> otherwise returns null * updating definition in sql-scalar.md * Apply suggestions from code review Co-authored-by: Charles Smith <techdocsmith@gmail.com> * hoping to re-run web checks * change replaceMissingValueWith -> defaultValue * Update docs/querying/sql-scalar.md Co-authored-by: Katya Macedo <38017980+ektravel@users.noreply.github.com> * acronym_to_name -> airportcode_to_name * shortens `airportcode_to_name` to `code_to_name` --------- Co-authored-by: Katya Macedo <38017980+ektravel@users.noreply.github.com> Co-authored-by: Victoria Lim <vtlim@users.noreply.github.com> Co-authored-by: Charles Smith <techdocsmith@gmail.com>
This commit is contained in:
parent
a83125e4a0
commit
fda2d19b88
|
@ -1546,11 +1546,42 @@ Returns the following:
|
|||
|
||||
## LOOKUP
|
||||
|
||||
`LOOKUP(<CHARACTER>, <CHARACTER>[, <CHARACTER>])`
|
||||
Searches for `expr` in a registered [query-time lookup table](lookups.md) named `lookupName` and returns the mapped value. If `expr` is null or not contained in the lookup, returns `defaultValue` if supplied, otherwise returns null.
|
||||
|
||||
**Function type:** [Scalar, string](sql-scalar.md#string-functions)
|
||||
* **Syntax:** `LOOKUP(expr, lookupName[, defaultValue])`
|
||||
* **Function type:** Scalar, string
|
||||
|
||||
Looks up the expression in a registered query-time lookup table.
|
||||
<details><summary>Example</summary>
|
||||
|
||||
The following example uses a `map` type lookup table named `code_to_name`, which contains the following key-value pairs:
|
||||
|
||||
```json
|
||||
{
|
||||
"SJU": "Luis Munoz Marin International Airport",
|
||||
"IAD": "Dulles International Airport"
|
||||
}
|
||||
```
|
||||
|
||||
The example uses `code_to_name` to map the `Origin` column from the `flight-carriers` datasource to the corresponding full airport name. Returns `key not found` if no matching key exists in the lookup table.
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
"Origin" AS "origin_airport",
|
||||
LOOKUP("Origin", 'code_to_name','key not found') AS "full_airport_name"
|
||||
FROM "flight-carriers"
|
||||
LIMIT 2
|
||||
```
|
||||
|
||||
Returns the following:
|
||||
|
||||
| `origin_airport` | `full_airport_name` |
|
||||
| -- | -- |
|
||||
| `SJU` | `Luis Munoz Marin International Airport` |
|
||||
| `BOS` | `key not found` |
|
||||
|
||||
</details>
|
||||
|
||||
[Learn more](sql-scalar.md#string-functions)
|
||||
|
||||
## LOWER
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ String functions accept strings and return a type appropriate to the function.
|
|||
|`CHAR_LENGTH(expr)`|Alias for `LENGTH`.|
|
||||
|`CHARACTER_LENGTH(expr)`|Alias for `LENGTH`.|
|
||||
|`STRLEN(expr)`|Alias for `LENGTH`.|
|
||||
|`LOOKUP(expr, lookupName[, replaceMissingValueWith])`|Looks up `expr` in an existing [query-time lookup table](lookups.md) that has the name `lookupName`. Returns the optional constant `replaceMissingValueWith` when `expr` is null or when the lookup does not contain a value for `expr`.<br /><br />You can query lookups directly using the [`lookup` schema](sql.md#from).|
|
||||
|`LOOKUP(expr, lookupName[, replaceMissingValueWith])`|Searches for `expr` in a registered [query-time lookup table](lookups.md) named `lookupName` and returns the mapped value. If `expr` is null or not contained in the lookup, returns `replaceMissingValueWith` if supplied, otherwise returns null.<br /><br />You can query lookups directly using the [`lookup` schema](sql.md#from).|
|
||||
|`LOWER(expr)`|Returns `expr` in all lowercase.|
|
||||
|`UPPER(expr)`|Returns `expr` in all uppercase.|
|
||||
|`LPAD(expr, length[, chars])`|Returns a string of `length` from `expr`. If `expr` is shorter than `length`, left pads `expr` with `chars`, which defaults to space characters. If `expr` exceeds `length`, truncates `expr` to equal `length`. If `chars` is an empty string, no padding is added. Returns `null` if either `expr` or `chars` is null.|
|
||||
|
|
Loading…
Reference in New Issue