Skip to content

Commit 3899560

Browse files
authored
Merge pull request #245764 from seesharprun/cosmos-populate-nosql-6
Cosmos DB | Add NoSQL query functions #8
2 parents 3bd41e7 + 0e54b74 commit 3899560

File tree

10 files changed

+256
-408
lines changed

10 files changed

+256
-408
lines changed

articles/cosmos-db/nosql/query/objecttoarray.md

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: nosql
1010
ms.topic: reference
11-
ms.date: 07/01/2023
11+
ms.date: 07/20/2023
1212
ms.custom: query-reference
1313
---
1414

@@ -40,92 +40,35 @@ An array of elements with two fields, either `k` and `v` or custom-named fields.
4040

4141
This example demonstrates converting a static object to an array of field/value pairs using the default `k` and `v` identifiers.
4242

43-
```sql
44-
SELECT VALUE
45-
ObjectToArray({
46-
"a": "12345",
47-
"b": "67890"
48-
})
49-
```
43+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray/query.sql" highlight="2-5":::
5044

51-
```json
52-
[
53-
[
54-
{
55-
"k": "a",
56-
"v": "12345"
57-
},
58-
{
59-
"k": "b",
60-
"v": "67890"
61-
}
62-
]
63-
]
64-
```
45+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray/result.json":::
6546

6647
In this example, the field name is updated to use the `name` identifier.
6748

68-
```sql
69-
SELECT VALUE
70-
ObjectToArray({
71-
"a": "12345",
72-
"b": "67890"
73-
}, "name")
74-
```
49+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-key/query.sql" highlight="2-5":::
7550

76-
```json
77-
[
78-
[
79-
{
80-
"name": "a",
81-
"v": "12345"
82-
},
83-
{
84-
"name": "b",
85-
"v": "67890"
86-
}
87-
]
88-
]
89-
```
51+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-key/result.json":::
9052

9153
In this example, the value name is updated to use the `value` identifier and the field name uses the `key` identifier.
9254

93-
```sql
94-
SELECT VALUE
95-
ObjectToArray({
96-
"a": "12345",
97-
"b": "67890"
98-
}, "key", "value")
99-
```
55+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-key-value/query.sql" highlight="2-5":::
10056

101-
```json
102-
[
103-
[
104-
{
105-
"key": "a",
106-
"value": "12345"
107-
},
108-
{
109-
"key": "b",
110-
"value": "67890"
111-
}
112-
]
113-
]
114-
```
57+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-key-value/result.json":::
11558

11659
This final example uses an item within an existing container that stores data using fields within a JSON object.
11760

118-
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/object-to-array/seed.json":::
61+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-field/seed.json" range="1-2,4-13" highlight="5-10":::
11962

12063
In this example, the function is used to break up the object into an array item for each field/value pair.
12164

122-
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/object-to-array/query.sql":::
65+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-field/query.sql" highlight="3":::
12366

124-
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/object-to-array/result.json":::
67+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/objecttoarray-field/result.json":::
12568

12669
## Remarks
12770

128-
If the input value isn't a valid Object, the result is Undefined\.
71+
- If the input value isn't a valid object, the result is `undefined`.
12972

13073
## See also
13174

articles/cosmos-db/nosql/query/pi.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: nosql
1010
ms.topic: reference
11-
ms.date: 07/01/2023
11+
ms.date: 07/20/2023
1212
ms.custom: query-reference
1313
---
1414

@@ -30,18 +30,11 @@ Returns a numeric expression.
3030

3131
## Examples
3232

33-
The following example returns the constant value of Pi.
33+
The following example returns the constant value of Pi.
3434

35-
```sql
36-
SELECT VALUE
37-
PI()
38-
```
39-
40-
```json
41-
[
42-
3.141592653589793
43-
]
44-
```
35+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/pi/query.sql" highlight="2":::
36+
37+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/pi/result.json":::
4538

4639
## Next steps
4740

articles/cosmos-db/nosql/query/power.md

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: nosql
1010
ms.topic: reference
11-
ms.date: 07/01/2023
11+
ms.date: 07/20/2023
1212
ms.custom: query-reference
1313
---
1414

@@ -39,37 +39,15 @@ Returns a numeric expression.
3939

4040
The following example demonstrates raising a number to various powers.
4141

42-
```sql
43-
SELECT VALUE {
44-
oneFirstPower: POWER(1, 1),
45-
twoSquared: POWER(2, 2),
46-
threeCubed: POWER(3, 3),
47-
fourFourthPower: POWER(4, 4),
48-
fiveFithPower: POWER(5, 5),
49-
zeroSquared: POWER(0, 2),
50-
nullCubed: POWER(null, 3),
51-
twoNullPower: POWER(2, null)
52-
}
53-
```
42+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/power/query.sql" highlight="2-9":::
5443

55-
```json
56-
[
57-
{
58-
"oneFirstPower": 1,
59-
"twoSquared": 4,
60-
"threeCubed": 27,
61-
"fourFourthPower": 256,
62-
"fiveFithPower": 3125,
63-
"zeroSquared": 0
64-
}
65-
]
66-
```
44+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/power/result.json":::
6745

6846
## Remarks
6947

70-
- This system function doesn't utilize the index.
48+
- This function doesn't use the index.
7149

7250
## Next steps
7351

7452
- [System functions Azure Cosmos DB](system-functions.yml)
75-
- [Introduction to Azure Cosmos DB](../../introduction.md)
53+
- [`SQRT`](sqrt.md)
Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
---
2-
title: RAND in Azure Cosmos DB query language
3-
description: Learn about SQL system function RAND in Azure Cosmos DB.
4-
author: ginamr
2+
title: RAND
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a randomly generated numeric value from zero to one.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 09/16/2019
9-
ms.author: girobins
10-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/21/2023
12+
ms.custom: query-reference
1113
---
12-
# RAND (Azure Cosmos DB)
14+
15+
# RAND (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
Returns a randomly generated numeric value from [0,1).
16-
19+
Returns a randomly generated numeric value from zero to one.
20+
1721
## Syntax
18-
22+
1923
```sql
20-
RAND ()
21-
```
24+
RAND()
25+
```
2226

2327
## Return types
2428

25-
Returns a numeric expression.
29+
Returns a numeric expression.
2630

27-
## Remarks
31+
## Examples
2832

29-
`RAND` is a nondeterministic function. Repetitive calls of `RAND` do not return the same results. This system function will not utilize the index.
33+
The following example returns randomly generated numeric values.
3034

35+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/rand/query.novalidate.sql" highlight="2-3":::
3136

32-
## Examples
33-
34-
The following example returns a randomly generated numeric value.
35-
36-
```sql
37-
SELECT RAND() AS rand
38-
```
39-
40-
Here is the result set.
41-
42-
```json
43-
[{"rand": 0.87860053195618093}]
44-
```
37+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/rand/result.novalidate.json":::
38+
39+
## Remarks
40+
41+
- This function doesn't use the index.
42+
- This function is nondeterministic. Repetitive calls of this function don't return the same results.
4543

4644
## Next steps
4745

4846
- [System functions Azure Cosmos DB](system-functions.yml)
49-
- [Introduction to Azure Cosmos DB](../../introduction.md)
47+
- [`IS_NUMBER`](is-number.md)

0 commit comments

Comments
 (0)