Skip to content

Commit d8aebaf

Browse files
committed
Updated README
1 parent d37ec2b commit d8aebaf

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

  • samples/features/sql-clr/TransitiveClosure

samples/features/sql-clr/TransitiveClosure/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This code sample demonstrates how to create CLR User-Defined aggregate that impl
2121

2222
<a name=build-functions></a>
2323

24-
## Build the CLR/RegEx functions
24+
## Build the CLR/TransitiveClosure aggregate
2525

2626
1. Download the source code and open the solution using Visual Studio.
2727
2. Change the password in .pfk file and rebuild the solution in **Release** mode.
@@ -53,13 +53,13 @@ RETURNS NVARCHAR(MAX)
5353
EXTERNAL NAME TransitiveClosure.[TransitiveClosure.Aggregate];
5454
```
5555

56-
This code will import assembly in SQL Database and add three functions that provide clustering functionalities.
56+
This code will import assembly in SQL Database and add an aggregate that provides clustering functionalities.
5757

5858
<a name=test></a>
5959

6060
## Test the function
6161

62-
Once you create the assembly and expose the functions, you can use it to cluster some relational data in T-SQL code:
62+
Once you create the assembly and expose the aggregate, you can use it to cluster some relational data in T-SQL code:
6363

6464
```
6565
declare @edges table(n1 int, n2 int);
@@ -71,6 +71,26 @@ values (1,2),(2,3),(3,4),(4,5),(2,21),(2,22),
7171
select TC.CLUSTERING(n1,n2)
7272
from @edges;
7373
```
74+
The result will be JSON document that groups the numbers that belong to the same cluster.
75+
```javascript
76+
{
77+
"0":[1,2,3,4,5,21,22],
78+
"1":[7,8,9,10]
79+
}
80+
```
81+
You can transform this JSON document into relational formatusing **OPENJSON** function:
82+
```
83+
select cluster = [key], elements = value
84+
from openjson(
85+
       (select TC.CLUSTERING(n1,n2) from @edges)
86+
);
87+
```
88+
The result of this query is:
89+
90+
|cluster|elements|
91+
|----|---|
92+
|0|[1,2,3,4,5,21,22]|
93+
|1|[7,8,9,10]|
7494

7595
<a name=disclaimers></a>
7696

0 commit comments

Comments
 (0)