Skip to content

Commit 07f286f

Browse files
committed
added
1 parent 09ceab2 commit 07f286f

File tree

7 files changed

+195
-0
lines changed

7 files changed

+195
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: MAP_FILTER
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Filters key-value pairs from a map using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md) to define the condition.
9+
10+
## Syntax
11+
12+
```sql
13+
MAP_FILTER(<map>, (<key>, <value>) -> <condition>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a map that includes only the key-value pairs meeting the condition specified by the lambda expression.
19+
20+
## Examples
21+
22+
This example returns a map containing only the products with stock quantities below 10:
23+
24+
```sql
25+
SELECT MAP_FILTER({101:15, 102:8, 103:12, 104:5}, (product_id, stock) -> (stock < 10)) AS low_stock_products;
26+
27+
┌────────────────────┐
28+
│ low_stock_products │
29+
├────────────────────┤
30+
│ {102:8,104:5} │
31+
└────────────────────┘
32+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: MAP_TRANSFORM_KEYS
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Applies a transformation to each key in a map using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md).
9+
10+
## Syntax
11+
12+
```sql
13+
MAP_TRANSFORM_KEYS(<map>, (<key>, <value>) -> <key_transformation>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a map with the same values as the input map but with keys modified according to the specified lambda transformation.
19+
20+
## Examples
21+
22+
This example adds 1,000 to each product ID, creating a new map with updated keys while keeping the associated prices the same:
23+
24+
```sql
25+
SELECT MAP_TRANSFORM_KEYS({101: 29.99, 102: 45.50, 103: 15.00}, (product_id, price) -> product_id + 1000) AS updated_product_ids;
26+
27+
┌────────────────────────────────────┐
28+
│ updated_product_ids │
29+
├────────────────────────────────────┤
30+
│ {1101:29.99,1102:45.50,1103:15.00} │
31+
└────────────────────────────────────┘
32+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: MAP_TRANSFORM_VALUES
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Applies a transformation to each value in a map using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md).
9+
10+
## Syntax
11+
12+
```sql
13+
MAP_TRANSFORM_VALUES(<map>, (<key>, <value>) -> <value_transformation>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a map with the same keys as the input map but with values modified according to the specified lambda transformation.
19+
20+
## Examples
21+
22+
This example reduces each product's price by 10%, while the product IDs (keys) remain unchanged:
23+
24+
```sql
25+
SELECT MAP_TRANSFORM_VALUES({101: 100.0, 102: 150.0, 103: 200.0}, (product_id, price) -> price * 0.9) AS discounted_prices;
26+
27+
┌───────────────────────────────────┐
28+
│ discounted_prices │
29+
├───────────────────────────────────┤
30+
│ {101:90.00,102:135.00,103:180.00} │
31+
└───────────────────────────────────┘
32+
```

docs/en/sql-reference/20-sql-functions/10-semi-structured-functions/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ This section provides reference information for the semi-structured data functio
4545
- [JSON_ARRAY_MAP](json-array-map.md)
4646
- [JSON_ARRAY_FILTER](json-array-filter.md)
4747
- [JSON_ARRAY_REDUCE](json-array-reduce.md)
48+
- [JSON_MAP_FILTER](json-map-filter.md)
49+
- [JSON_MAP_TRANSFORM_KEYS](json-map-transform-keys.md)
50+
- [JSON_MAP_TRANSFORM_VALUES](json-map-transform-values.md)
4851

4952
## Object Operations:
5053
- [GET](get.md)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: JSON_MAP_FILTER
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Filters key-value pairs in a JSON object based on a specified condition, defined using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md).
9+
10+
## Syntax
11+
12+
```sql
13+
JSON_MAP_FILTER(<json_object>, (<key>, <value>) -> <condition>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a JSON object with only the key-value pairs that satisfy the specified condition.
19+
20+
## Examples
21+
22+
This example extracts only the `"status": "active"` key-value pair from the JSON object, filtering out the other fields.
23+
24+
```sql
25+
SELECT JSON_MAP_FILTER('{"status":"active", "user":"admin", "time":"2024-11-01"}'::VARIANT, (k, v) -> k = 'status') AS filtered_metadata;
26+
27+
┌─────────────────────┐
28+
│ filtered_metadata │
29+
├─────────────────────┤
30+
│ {"status":"active"} │
31+
└─────────────────────┘
32+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: JSON_MAP_TRANSFORM_KEYS
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Applies a transformation to each key in a JSON object using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md).
9+
10+
## Syntax
11+
12+
```sql
13+
JSON_MAP_TRANSFORM_KEYS(<json_object>, (<key>, <value>) -> <key_transformation>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a JSON object with the same values as the input JSON object, but with keys modified according to the specified lambda transformation.
19+
20+
## Examples
21+
22+
This example appends "_v1" to each key, creating a new JSON object with modified keys:
23+
24+
```sql
25+
SELECT JSON_MAP_TRANSFORM_KEYS('{"name":"John", "role":"admin"}'::VARIANT, (k, v) -> CONCAT(k, '_v1')) AS versioned_metadata;
26+
27+
┌──────────────────────────────────────┐
28+
│ versioned_metadata │
29+
├──────────────────────────────────────┤
30+
│ {"name_v1":"John","role_v1":"admin"} │
31+
└──────────────────────────────────────┘
32+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: JSON_MAP_TRANSFORM_VALUES
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.652"/>
7+
8+
Applies a transformation to each value in a JSON object using a [lambda expression](../../00-sql-reference/42-lambda-expressions.md).
9+
10+
## Syntax
11+
12+
```sql
13+
JSON_MAP_TRANSFORM_VALUES(<json_object>, (<key>, <value>) -> <value_transformation>)
14+
```
15+
16+
## Return Type
17+
18+
Returns a JSON object with the same keys as the input JSON object, but with values modified according to the specified lambda transformation.
19+
20+
## Examples
21+
22+
This example appends " - Special Offer" to each product description:
23+
24+
```sql
25+
SELECT JSON_MAP_TRANSFORM_VALUES('{"product1":"laptop", "product2":"phone"}'::VARIANT, (k, v) -> CONCAT(v, ' - Special Offer')) AS promo_descriptions;
26+
27+
┌──────────────────────────────────────────────────────────────────────────┐
28+
│ promo_descriptions │
29+
├──────────────────────────────────────────────────────────────────────────┤
30+
│ {"product1":"laptop - Special Offer","product2":"phone - Special Offer"} │
31+
└──────────────────────────────────────────────────────────────────────────┘
32+
```

0 commit comments

Comments
 (0)