Skip to content

Commit 68f9b13

Browse files
committed
Update instructions
1 parent 26ce7e4 commit 68f9b13

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ Full documentation can be found on the Couchbase Developer Portal.
1111
<hr>
1212

1313
## UDF Examples
14+
1415
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 of calculating the distance between two GPS coordinates for the two services.
16+
1517
<hr>
1618

1719
### Query Service UDF using Javascript
1820

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. Here, we create a custom UDF that calculates the distance between two GPS coordinates using the [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).
21+
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. Here, we create a custom UDF that calculates the distance between two GPS coordinates using the [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).
2022

2123
#### Importing the UDF in Couchbase
2224

@@ -27,14 +29,15 @@ Couchbase allows you to create User Defined Functions (UDF) with Javascript to i
2729

2830
- `EXECUTE FUNCTION distance(51.5, 0, 38.8, -77.1)`
2931

30-
- If the UDF is defined properly, there will be an output like the one shown below:
32+
- If the UDF is defined properly, there will be an output like the one shown below:
3133

32-
```sh
33-
[
34-
5918.185064088764
35-
]
36-
```
37-
<hr>
34+
```sh
35+
[
36+
5918.185064088764
37+
]
38+
```
39+
40+
<hr>
3841

3942
### Analytics Service UDF using Python
4043

@@ -44,7 +47,7 @@ Couchbase Analytics supports creating custom User Defined Functions using Python
4447

4548
- Couchbase can be run as a Docker container
4649

47-
> docker run -d -p 8091-8094:8091-8094 -p 11210:11210 --name db couchbase
50+
> docker run -d -p 8091-8096:8091-8096 -p 11210:11210 --name db couchbase
4851
4952
- Setting Up
5053

@@ -67,21 +70,26 @@ Couchbase Analytics supports creating custom User Defined Functions using Python
6770
#### Install requirements
6871

6972
- `$ pip install -r requirements.txt`
70-
73+
7174
### UDF Code
75+
7276
- The UDF code is [here](analytics-udf-python/distance-lib/distance_library.py).
7377

7478
#### Testing the UDF
7579

7680
- Run the test [code](analytics-udf-python/distance-lib/test_distance_library.py).
77-
81+
7882
`$ python test_distance_library.py`
7983

8084
#### Importing the UDF into Couchbase
8185

8286
- The Python module can be packaged including all the dependencies using shiv for any platform. We use Linux here for our container.
8387

84-
> $ shiv -o distance-lib.pyz --site-packages . --platform manylinux2010_x86_64 --python-version 39 --only-binary=:all: geopy
88+
```bash
89+
$ cd distance-lib
90+
91+
$ shiv -o distance-lib.pyz --site-packages . --platform manylinux2010_x86_64 --python-version 39 --only-binary=:all: geopy
92+
```
8593

8694
- Copy the package into the Couchbase Container
8795

0 commit comments

Comments
 (0)