Skip to content

gitbase: create sync indexes instead of using low level calls #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[constraint]]
name = "gopkg.in/src-d/go-mysql-server.v0"
revision = "e03c0c8264d306f683a8c1e7933c5d2f4b200a5b"
revision = "9c3b77f244b0909fed15a669be2cdeb355462a7d"

[[constraint]]
name = "github.com/jessevdk/go-flags"
Expand Down
2 changes: 1 addition & 1 deletion docs/using-gitbase/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ To make some common tasks easier for the user, there are some functions to inter

## Standard functions

You can check standard functions in [`go-mysql-server` documentation](https://github.com/src-d/go-mysql-server/tree/e03c0c8264d306f683a8c1e7933c5d2f4b200a5b#custom-functions).
You can check standard functions in [`go-mysql-server` documentation](https://github.com/src-d/go-mysql-server/tree/9c3b77f244b0909fed15a669be2cdeb355462a7d#custom-functions).
2 changes: 1 addition & 1 deletion docs/using-gitbase/indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Note that you can create an index either **on one or more columns** or **on a si

You can find some more examples in the [examples](./examples.md#create-an-index-for-columns-on-a-table) section.

See [go-mysql-server](https://github.com/src-d/go-mysql-server/tree/e03c0c8264d306f683a8c1e7933c5d2f4b200a5b#indexes) documentation for more details
See [go-mysql-server](https://github.com/src-d/go-mysql-server/tree/9c3b77f244b0909fed15a669be2cdeb355462a7d#indexes) documentation for more details
2 changes: 1 addition & 1 deletion docs/using-gitbase/supported-syntax.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Supported syntax

To see the SQL subset currently supported take a look at [this list](https://github.com/src-d/go-mysql-server/blob/e03c0c8264d306f683a8c1e7933c5d2f4b200a5b/SUPPORTED.md) from [src-d/go-mysql-server](https://github.com/src-d/go-mysql-server).
To see the SQL subset currently supported take a look at [this list](https://github.com/src-d/go-mysql-server/blob/9c3b77f244b0909fed15a669be2cdeb355462a7d/SUPPORTED.md) from [src-d/go-mysql-server](https://github.com/src-d/go-mysql-server).
145 changes: 43 additions & 102 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package gitbase_test

import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/src-d/gitbase/internal/rule"
Expand Down Expand Up @@ -610,111 +612,67 @@ func col(t testing.TB, schema sql.Schema, name string) sql.Expression {
}

type indexData struct {
id string
expressions []sql.Expression
table sql.Table
columns []string
id string
table string
exprs []string
}

func createTestIndexes(t testing.TB, engine *sqle.Engine, ctx *sql.Context) func() {
db, err := engine.Catalog.Database("foo")
require.NoError(t, err)
tables := db.Tables()

var indexes = []indexData{
{
id: "refs_idx",
table: tables[gitbase.ReferencesTableName],
columns: []string{"ref_name"},
expressions: []sql.Expression{
col(t, gitbase.RefsSchema, "ref_name"),
},
id: "refs_idx",
table: gitbase.ReferencesTableName,
exprs: []string{"ref_name"},
},
{
id: "remotes_idx",
table: tables[gitbase.RemotesTableName],
columns: []string{"remote_name"},
expressions: []sql.Expression{
col(t, gitbase.RemotesSchema, "remote_name"),
},
id: "remotes_idx",
table: gitbase.RemotesTableName,
exprs: []string{"remote_name"},
},
{
id: "ref_commits_idx",
table: tables[gitbase.RefCommitsTableName],
columns: []string{"ref_name"},
expressions: []sql.Expression{
col(t, gitbase.RefCommitsSchema, "ref_name"),
},
id: "ref_commits_idx",
table: gitbase.RefCommitsTableName,
exprs: []string{"ref_name"},
},
{
id: "commits_idx",
table: tables[gitbase.CommitsTableName],
columns: []string{"commit_hash"},
expressions: []sql.Expression{
col(t, gitbase.CommitsSchema, "commit_hash"),
},
id: "commits_idx",
table: gitbase.CommitsTableName,
exprs: []string{"commit_hash"},
},
{
id: "commit_trees_idx",
table: tables[gitbase.CommitTreesTableName],
columns: []string{"commit_hash"},
expressions: []sql.Expression{
col(t, gitbase.CommitTreesSchema, "commit_hash"),
},
id: "commit_trees_idx",
table: gitbase.CommitTreesTableName,
exprs: []string{"commit_hash"},
},
{
id: "commit_blobs_idx",
table: tables[gitbase.CommitBlobsTableName],
columns: []string{"commit_hash"},
expressions: []sql.Expression{
col(t, gitbase.CommitBlobsSchema, "commit_hash"),
},
id: "commit_blobs_idx",
table: gitbase.CommitBlobsTableName,
exprs: []string{"commit_hash"},
},
{
id: "tree_entries_idx",
table: tables[gitbase.TreeEntriesTableName],
columns: []string{"tree_entry_name"},
expressions: []sql.Expression{
col(t, gitbase.TreeEntriesSchema, "tree_entry_name"),
},
id: "tree_entries_idx",
table: gitbase.TreeEntriesTableName,
exprs: []string{"tree_entry_name"},
},
{
id: "blobs_idx",
table: tables[gitbase.BlobsTableName],
columns: []string{"blob_hash"},
expressions: []sql.Expression{
col(t, gitbase.BlobsSchema, "blob_hash"),
},
id: "blobs_idx",
table: gitbase.BlobsTableName,
exprs: []string{"blob_hash"},
},
{
id: "commit_files_idx",
table: tables[gitbase.CommitFilesTableName],
columns: []string{"commit_hash"},
expressions: []sql.Expression{
col(t, gitbase.CommitFilesSchema, "commit_hash"),
},
id: "commit_files_idx",
table: gitbase.CommitFilesTableName,
exprs: []string{"commit_hash"},
},
{
id: "files_idx",
table: tables[gitbase.FilesTableName],
columns: []string{"file_path"},
expressions: []sql.Expression{
col(t, gitbase.FilesSchema, "file_path"),
},
id: "files_idx",
table: gitbase.FilesTableName,
exprs: []string{"file_path"},
},
{
id: "files_lang_idx",
table: tables[gitbase.FilesTableName],
columns: []string{"file_path"},
expressions: []sql.Expression{
func() sql.Expression {
f, _ := function.NewLanguage(
col(t, gitbase.FilesSchema, "file_path"),
col(t, gitbase.FilesSchema, "blob_content"),
)
return f
}(),
},
id: "files_lang_idx",
table: gitbase.FilesTableName,
exprs: []string{"language(file_path, blob_content)"},
},
}

Expand All @@ -736,31 +694,14 @@ func createIndex(
ctx *sql.Context,
) {
t.Helper()
require := require.New(t)
driver := e.Catalog.IndexDriver(pilosa.DriverID)
require.NotNil(driver)

var hashes []sql.ExpressionHash
for _, e := range data.expressions {
hashes = append(hashes, sql.NewExpressionHash(e))
}

idx, err := driver.Create(
"foo", data.table.Name(),
data.id, hashes,
make(map[string]string),
query := fmt.Sprintf(
`CREATE INDEX %s ON %s (%s) WITH (async = false)`,
data.id, data.table, strings.Join(data.exprs, ", "),
)
require.NoError(err)

done, err := e.Catalog.AddIndex(idx)
require.NoError(err)

iter, err := data.table.(sql.Indexable).IndexKeyValueIter(ctx, data.columns)
require.NoError(err)

require.NoError(driver.Save(sql.NewEmptyContext(), idx, iter))

done <- struct{}{}
_, _, err := e.Query(ctx, query)
require.NoError(t, err)
}

func deleteIndex(
Expand Down
11 changes: 11 additions & 0 deletions vendor/gopkg.in/src-d/go-mysql-server.v0/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 2 additions & 19 deletions vendor/gopkg.in/src-d/go-mysql-server.v0/engine_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading