Skip to content

Commit 300fc41

Browse files
authored
Merge pull request #195 from erizocosmico/feature/uast-udf
internal/function: implement uast and uast_xpath functions
2 parents 9cd6912 + cccd2f9 commit 300fc41

File tree

760 files changed

+515454
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

760 files changed

+515454
-10
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
language: go
2+
sudo: required
23

34
go:
45
- 1.9
56
- tip
67

8+
services:
9+
- docker
10+
711
go_import_path: github.com/src-d/gitbase
812

913
matrix:
1014
fast_finish: true
1115
allow_failures:
1216
- go: tip
1317

18+
addons:
19+
apt:
20+
sources:
21+
- ubuntu-toolchain-r-test
22+
packages:
23+
- gcc-6
24+
- g++-6
25+
1426
install:
27+
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
28+
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
29+
- cd ./vendor/gopkg.in/bblfsh/client-go.v2
1530
- make dependencies
31+
- cd ./../../../..
32+
- make dependencies
33+
34+
before_script:
35+
- docker run -d --name bblfshd --privileged -p 9432:9432 -v /var/lib/bblfshd:/var/lib/bblfshd bblfsh/bblfshd
36+
- docker exec -it bblfshd bblfshctl driver install python bblfsh/python-driver
37+
- docker exec -it bblfshd bblfshctl driver install php bblfsh/php-driver
1638

1739
script:
1840
- make test-coverage codecov

Gopkg.lock

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

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
[[constraint]]
4646
name = "gopkg.in/src-d/enry.v1"
4747
version = "1.6.3"
48+
49+
[[constraint]]
50+
name = "gopkg.in/bblfsh/client-go.v2"
51+
version = "2.4.1"

env.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ func getBoolEnv(key string, defaultValue bool) bool {
2525

2626
return defaultValue
2727
}
28+
29+
func getStringEnv(key string, defaultValue string) string {
30+
v, ok := os.LookupEnv(key)
31+
if !ok {
32+
return defaultValue
33+
}
34+
return v
35+
}

integration_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,38 @@ func TestIntegration(t *testing.T) {
157157
t.Run("with squash", runTests)
158158
}
159159

160+
func TestUastQueries(t *testing.T) {
161+
require := require.New(t)
162+
engine := sqle.New()
163+
require.NoError(fixtures.Init())
164+
defer func() {
165+
require.NoError(fixtures.Clean())
166+
}()
167+
168+
pool := gitbase.NewRepositoryPool()
169+
for _, f := range fixtures.ByTag("worktree") {
170+
pool.AddGit(f.Worktree().Root())
171+
}
172+
173+
engine.AddDatabase(gitbase.NewDatabase("foo"))
174+
engine.Catalog.RegisterFunctions(function.Functions)
175+
176+
session := gitbase.NewSession(&pool)
177+
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
178+
_, iter, err := engine.Query(ctx, `
179+
SELECT uast_xpath(uast(content, 'php'), '//*[@roleIdentifier]') as uast, name
180+
FROM tree_entries te
181+
INNER JOIN blobs b
182+
ON b.hash = te.entry_hash
183+
WHERE te.name = 'php/crappy.php'`,
184+
)
185+
require.NoError(err)
186+
187+
rows, err := sql.RowIterToRows(iter)
188+
require.NoError(err)
189+
require.Len(rows, 3)
190+
}
191+
160192
func BenchmarkQueries(b *testing.B) {
161193
queries := []struct {
162194
name string

internal/function/registry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package function
22

33
import "gopkg.in/src-d/go-mysql-server.v0/sql"
44

5+
// Functions for gitbase queries.
56
var Functions = sql.Functions{
67
"is_tag": sql.Function1(NewIsTag),
78
"is_remote": sql.Function1(NewIsRemote),
89
"commit_has_blob": sql.Function2(NewCommitHasBlob),
910
"history_idx": sql.Function2(NewHistoryIdx),
1011
"commit_has_tree": sql.Function2(NewCommitHasTree),
1112
"language": sql.FunctionN(NewLanguage),
13+
"uast": sql.FunctionN(NewUAST),
14+
"uast_xpath": sql.Function2(NewUASTXPath),
1215
}

0 commit comments

Comments
 (0)