Skip to content

Commit c2493a7

Browse files
authored
Merge branch 'master' into meyskens-patch-1
2 parents 92999b4 + cf34387 commit c2493a7

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

docs/using-gitbase/examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ or through a specific property:
181181
SELECT file_path, uast_extract(uast(blob_content, language(file_path), "//FuncLit"), "internalRole") FROM files;
182182
```
183183

184-
As result, you will get an array of arrays showing a list of the retrieved information for each of the given nodes:
184+
As result, you will get an array showing a list of the retrieved information. Each element in the list matches a node in the given sequence of nodes having a value for that property. It means that the length of the properties list may not be equal to the length of the given sequence of nodes:
185185

186186
```sh
187187
+-------------------+------------------------------------------------------------------------------------------------+
188188
| file_path | uast_extract(uast(files.blob_content, language(files.file_path), "//FuncLit"), "internalRole") |
189189
+-------------------+------------------------------------------------------------------------------------------------+
190-
| benchmark_test.go | [["Args"],["Args"],["Args"],["Args"],["Args"],["Args"],["Args"]] |
190+
| benchmark_test.go | ["Args","Args","Args","Args","Args","Args","Args"] |
191191
+-------------------+------------------------------------------------------------------------------------------------+
192192
```
193193

docs/using-gitbase/functions.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ To make some common tasks easier for the user, there are some functions to inter
1111
|language(path, [blob])text| gets the language of a file given its path and the optional content of the file |
1212
|uast(blob, [lang, [xpath]]) blob| returns a sequence of serialized UAST nodes in semantic mode |
1313
|uast_mode(mode, blob, lang) blob| returns a sequence of serialized UAST nodes specifying its language and mode (semantic, annotated or native) |
14-
|uast_xpath(blob, xpath)| performs an XPath query over the given UAST nodes |
15-
|uast_extract(blob, key)| extracts information identified by the given key from the uast nodes |
16-
|uast_children(blob)| returns a flattened array of the children UAST nodes from each one of the UAST nodes in the given sequence |
14+
|uast_xpath(blob, xpath) blob| performs an XPath query over the given UAST nodes |
15+
|uast_extract(blob, key) text array| extracts information identified by the given key from the uast nodes |
16+
|uast_children(blob) blob| returns a flattened array of the children UAST nodes from each one of the UAST nodes in the given sequence |
1717

1818

19-
## Note about uast and uast_mode functions
19+
## Note about uast, uast_mode, uast_xpath and uast_children functions
2020

2121
The data returned by these functions are a list of UAST nodes serialized as explained below.
2222

@@ -30,6 +30,34 @@ BigEndianInt32(len(marhsal(node))+marshal(node)+
3030
...
3131
```
3232

33+
## How to formulate XPath queries when use uast and uast_xpath functions
34+
35+
Have a look at the [bblfsh docs](https://docs.sourced.tech/babelfish/using-babelfish/uast-querying) to query UASTs with XPath.
36+
37+
## How to use uast_extract
38+
39+
Check out the [UAST specification](https://docs.sourced.tech/babelfish/uast/uast-specification) to know what an UAST node represents.
40+
41+
`uast_extracts` accepts special selectors to match common node properties:
42+
43+
- `@type`
44+
- `@token`
45+
- `@role`
46+
- `@startpos`
47+
- `@endpos`
48+
49+
Using these selectors as in,
50+
51+
> uast_extract(nodes_column, @common_selector)
52+
53+
you will extract the value of that property for each node.
54+
55+
Nodes that have no value for the requested property will not be present in any way in the final array. That is, having a sequence of nodes `[node-1, node-2, node-3]` and knowing that node-2 doesn't have a value for the requested property, the returned array will be `[prop-1, prop-3]`.
56+
57+
Also, if you want to retrieve values from a non common property, you can pass it directly
58+
59+
> uast_extract(nodes_column, 'some-property')
60+
3361
## Standard functions
3462

3563
You can check standard functions in [`go-mysql-server` documentation](https://github.com/src-d/go-mysql-server/tree/679d33772845593ce5fdf17925f49f2335bc8356#custom-functions).

0 commit comments

Comments
 (0)