Skip to content

Commit 93275a6

Browse files
authored
Merge pull request #439 from jfontan/improvement/upgrade-bblfshd-client
Improvement/upgrade bblfshd client
2 parents 5bc2e00 + 97d3a2f commit 93275a6

File tree

35 files changed

+1353
-267
lines changed

35 files changed

+1353
-267
lines changed

Gopkg.lock

Lines changed: 182 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
[[constraint]]
5252
name = "gopkg.in/bblfsh/client-go.v2"
53-
version = "2.8.0"
53+
version = "2.8.4"
5454

5555
[[constraint]]
5656
name = "gopkg.in/bblfsh/sdk.v1"

docs/using-gitbase/functions.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
To make some common tasks easier for the user, there are some functions to interact with the aforementioned tables:
66

7-
| Name | Description |
8-
|:-------------|:----------------------------------------------------------------------------------------------------|
9-
|is_remote(reference_name)bool| check if the given reference name is from a remote one |
10-
|is_tag(reference_name)bool| check if the given reference name is a tag |
11-
|language(path, [blob])text| gets the language of a file given its path and the optional content of the file |
12-
|uast(blob, [lang, [xpath]])json_blob| returns an array of UAST nodes as blobs |
13-
|uast_xpath(json_blob, xpath)| performs an XPath query over the given UAST nodes |
7+
| Name | Description |
8+
|:-------------|:-------------------------------------------------------------------------------------------------------------------------------|
9+
|is_remote(reference_name)bool| check if the given reference name is from a remote one |
10+
|is_tag(reference_name)bool| check if the given reference name is a tag |
11+
|language(path, [blob])text| gets the language of a file given its path and the optional content of the file |
12+
|uast(blob, [lang, [xpath]])json_blob| returns an array of UAST nodes as blobs in semantic mode |
13+
|uast_mode(mode, blob, lang)json_blob| returns an array of UAST nodes as blobs specifying its language and mode (semantic, annotated or native) |
14+
|uast_xpath(json_blob, xpath)| performs an XPath query over the given UAST nodes |
1415

1516
## Standard functions
1617

docs/using-gitbase/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
`gitbase` has two optional dependencies that should be running on your system if you're planning on using certain functionality.
66

7-
- [bblfsh](https://github.com/bblfsh/bblfshd) >= 2.5.0 (only if you're planning to use the `UAST` functionality provided in gitbase)
7+
- [bblfsh](https://github.com/bblfsh/bblfshd) >= 2.6.1 (only if you're planning to use the `UAST` functionality provided in gitbase)
88
- [pilosa](https://github.com/pilosa/pilosa) 0.9.0 (only if you're planning on using indexes)
99

1010
## Installing gitbase

integration_test.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,56 @@ func TestIntegration(t *testing.T) {
261261
}
262262

263263
func TestUastQueries(t *testing.T) {
264-
require := require.New(t)
265-
266264
engine, pool, cleanup := setup(t)
267265
defer cleanup()
268266

269-
session := gitbase.NewSession(pool)
270-
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
271-
_, iter, err := engine.Query(ctx, `
272-
SELECT uast_xpath(uast(blob_content, language(tree_entry_name, blob_content)), '//*[@roleIdentifier]') as uast,
267+
testCases := []struct {
268+
query string
269+
rows int
270+
}{
271+
{`SELECT uast_xpath(uast(blob_content, language(tree_entry_name, blob_content)), '//Identifier') as uast,
273272
tree_entry_name
274273
FROM tree_entries te
275274
INNER JOIN blobs b
276275
ON b.blob_hash = te.blob_hash
277-
WHERE te.tree_entry_name = 'crappy.php'`,
278-
)
279-
require.NoError(err)
276+
WHERE te.tree_entry_name = 'example.go'`, 1},
277+
{`SELECT uast_xpath(uast_mode('semantic', blob_content, language(tree_entry_name, blob_content)), '//Identifier') as uast,
278+
tree_entry_name
279+
FROM tree_entries te
280+
INNER JOIN blobs b
281+
ON b.blob_hash = te.blob_hash
282+
WHERE te.tree_entry_name = 'example.go'`, 1},
283+
{`SELECT uast_xpath(uast_mode('annotated', blob_content, language(tree_entry_name, blob_content)), '//*[@roleIdentifier]') as uast,
284+
tree_entry_name
285+
FROM tree_entries te
286+
INNER JOIN blobs b
287+
ON b.blob_hash = te.blob_hash
288+
WHERE te.tree_entry_name = 'example.go'`, 1},
289+
{`SELECT uast_xpath(uast_mode('native', blob_content, language(tree_entry_name, blob_content)), '//*[@ast_type=\'FunctionDef\']') as uast,
290+
tree_entry_name
291+
FROM tree_entries te
292+
INNER JOIN blobs b
293+
ON b.blob_hash = te.blob_hash
294+
WHERE te.tree_entry_name = 'example.go'`, 1},
295+
}
280296

281-
rows, err := sql.RowIterToRows(iter)
282-
require.NoError(err)
283-
require.Len(rows, 1)
297+
_ = testCases
298+
299+
for _, c := range testCases {
300+
t.Run(c.query, func(t *testing.T) {
301+
require := require.New(t)
302+
303+
session := gitbase.NewSession(pool)
304+
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
305+
306+
_, iter, err := engine.Query(ctx, c.query)
307+
require.NoError(err)
308+
309+
rows, err := sql.RowIterToRows(iter)
310+
require.NoError(err)
311+
require.Len(rows, c.rows)
312+
})
313+
}
284314
}
285315

286316
func TestSquashCorrectness(t *testing.T) {

internal/function/registry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ var Functions = sql.Functions{
88
"is_remote": sql.Function1(NewIsRemote),
99
"language": sql.FunctionN(NewLanguage),
1010
"uast": sql.FunctionN(NewUAST),
11+
"uast_mode": sql.Function3(NewUASTMode),
1112
"uast_xpath": sql.Function2(NewUASTXPath),
1213
}

0 commit comments

Comments
 (0)