You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-14Lines changed: 16 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,31 +11,32 @@ Full documentation can be found on the Couchbase Developer Portal.
11
11
<hr>
12
12
13
13
## UDF Examples
14
-
14
+
We have two different types of UDFs in Couchbase, using Javascript for the Query service and using Python for the Analytics service. Here, we showcase the same UDF functionality for the two services.
15
15
<hr>
16
-
### Javascript UDF
16
+
17
+
### Query Service UDF using Javascript
17
18
18
19
Couchbase allows you to create User Defined Functions (UDF) with Javascript to include custom business logic inside your SQL++ queries while querying the data stored in Couchbase.
19
20
20
21
#### Importing the UDF in Couchbase
21
22
22
23
- The Javascript [code](javascript-udf/distance.js) here can be imported directly using the `add function library` in the Couchbase Query Workbench under the UDF pane as a library.
23
24
- The UDFs can be defined using the `add function` in the Couchbase Query Workbench under the UDF pane as a library.
24
-
<hr>
25
25
26
26
#### Testing the UDF in Couchbase
27
27
28
-
> EXECUTE FUNCTION distance(51.5, 0, 38.8, -77.1)
28
+
-`EXECUTE FUNCTION distance(51.5, 0, 38.8, -77.1)`
29
29
30
-
If the UDF is defined properly, there will be an output like the one shown below:
30
+
-If the UDF is defined properly, there will be an output like the one shown below:
31
31
32
-
```sh
33
-
[
34
-
5918.185064088764
35
-
]
36
-
```
32
+
```sh
33
+
[
34
+
5918.185064088764
35
+
]
36
+
```
37
+
<hr>
37
38
38
-
### Analytics UDF using Python
39
+
### Analytics Service UDF using Python
39
40
40
41
Couchbase Analytics supports creating custom User Defined Functions using Python. Here, we create a custom UDF that calculates the distance between two GPS coordinates using the [Geodesic distance](https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid).
41
42
@@ -65,12 +66,13 @@ Couchbase Analytics supports creating custom User Defined Functions using Python
65
66
66
67
#### Install requirements
67
68
68
-
`$ pip install -r requirements.txt`
69
+
- `$ pip install -r requirements.txt`
69
70
70
71
#### Testing the UDF
71
72
72
-
Run the test [code](analytics-udf/test_distance_library.py).
73
-
`$ python test_distance_library.py`
73
+
- Run the test [code](analytics-udf/test_distance_library.py).
0 commit comments