@@ -2,9 +2,11 @@ package gitbase_test
22
33import (
44 "context"
5+ "fmt"
56 "io/ioutil"
67 "os"
78 "path/filepath"
9+ "strings"
810 "testing"
911
1012 "github.com/src-d/gitbase/internal/rule"
@@ -610,111 +612,67 @@ func col(t testing.TB, schema sql.Schema, name string) sql.Expression {
610612}
611613
612614type indexData struct {
613- id string
614- expressions []sql.Expression
615- table sql.Table
616- columns []string
615+ id string
616+ table string
617+ exprs []string
617618}
618619
619620func createTestIndexes (t testing.TB , engine * sqle.Engine , ctx * sql.Context ) func () {
620- db , err := engine .Catalog .Database ("foo" )
621- require .NoError (t , err )
622- tables := db .Tables ()
623-
624621 var indexes = []indexData {
625622 {
626- id : "refs_idx" ,
627- table : tables [gitbase .ReferencesTableName ],
628- columns : []string {"ref_name" },
629- expressions : []sql.Expression {
630- col (t , gitbase .RefsSchema , "ref_name" ),
631- },
623+ id : "refs_idx" ,
624+ table : gitbase .ReferencesTableName ,
625+ exprs : []string {"ref_name" },
632626 },
633627 {
634- id : "remotes_idx" ,
635- table : tables [gitbase .RemotesTableName ],
636- columns : []string {"remote_name" },
637- expressions : []sql.Expression {
638- col (t , gitbase .RemotesSchema , "remote_name" ),
639- },
628+ id : "remotes_idx" ,
629+ table : gitbase .RemotesTableName ,
630+ exprs : []string {"remote_name" },
640631 },
641632 {
642- id : "ref_commits_idx" ,
643- table : tables [gitbase .RefCommitsTableName ],
644- columns : []string {"ref_name" },
645- expressions : []sql.Expression {
646- col (t , gitbase .RefCommitsSchema , "ref_name" ),
647- },
633+ id : "ref_commits_idx" ,
634+ table : gitbase .RefCommitsTableName ,
635+ exprs : []string {"ref_name" },
648636 },
649637 {
650- id : "commits_idx" ,
651- table : tables [gitbase .CommitsTableName ],
652- columns : []string {"commit_hash" },
653- expressions : []sql.Expression {
654- col (t , gitbase .CommitsSchema , "commit_hash" ),
655- },
638+ id : "commits_idx" ,
639+ table : gitbase .CommitsTableName ,
640+ exprs : []string {"commit_hash" },
656641 },
657642 {
658- id : "commit_trees_idx" ,
659- table : tables [gitbase .CommitTreesTableName ],
660- columns : []string {"commit_hash" },
661- expressions : []sql.Expression {
662- col (t , gitbase .CommitTreesSchema , "commit_hash" ),
663- },
643+ id : "commit_trees_idx" ,
644+ table : gitbase .CommitTreesTableName ,
645+ exprs : []string {"commit_hash" },
664646 },
665647 {
666- id : "commit_blobs_idx" ,
667- table : tables [gitbase .CommitBlobsTableName ],
668- columns : []string {"commit_hash" },
669- expressions : []sql.Expression {
670- col (t , gitbase .CommitBlobsSchema , "commit_hash" ),
671- },
648+ id : "commit_blobs_idx" ,
649+ table : gitbase .CommitBlobsTableName ,
650+ exprs : []string {"commit_hash" },
672651 },
673652 {
674- id : "tree_entries_idx" ,
675- table : tables [gitbase .TreeEntriesTableName ],
676- columns : []string {"tree_entry_name" },
677- expressions : []sql.Expression {
678- col (t , gitbase .TreeEntriesSchema , "tree_entry_name" ),
679- },
653+ id : "tree_entries_idx" ,
654+ table : gitbase .TreeEntriesTableName ,
655+ exprs : []string {"tree_entry_name" },
680656 },
681657 {
682- id : "blobs_idx" ,
683- table : tables [gitbase .BlobsTableName ],
684- columns : []string {"blob_hash" },
685- expressions : []sql.Expression {
686- col (t , gitbase .BlobsSchema , "blob_hash" ),
687- },
658+ id : "blobs_idx" ,
659+ table : gitbase .BlobsTableName ,
660+ exprs : []string {"blob_hash" },
688661 },
689662 {
690- id : "commit_files_idx" ,
691- table : tables [gitbase .CommitFilesTableName ],
692- columns : []string {"commit_hash" },
693- expressions : []sql.Expression {
694- col (t , gitbase .CommitFilesSchema , "commit_hash" ),
695- },
663+ id : "commit_files_idx" ,
664+ table : gitbase .CommitFilesTableName ,
665+ exprs : []string {"commit_hash" },
696666 },
697667 {
698- id : "files_idx" ,
699- table : tables [gitbase .FilesTableName ],
700- columns : []string {"file_path" },
701- expressions : []sql.Expression {
702- col (t , gitbase .FilesSchema , "file_path" ),
703- },
668+ id : "files_idx" ,
669+ table : gitbase .FilesTableName ,
670+ exprs : []string {"file_path" },
704671 },
705672 {
706- id : "files_lang_idx" ,
707- table : tables [gitbase .FilesTableName ],
708- columns : []string {"file_path" },
709- expressions : []sql.Expression {
710- func () sql.Expression {
711- f , _ := function .NewLanguage (
712- col (t , gitbase .FilesSchema , "file_path" ),
713- col (t , gitbase .FilesSchema , "blob_content" ),
714- )
715- return f
716- }(),
717- },
673+ id : "files_lang_idx" ,
674+ table : gitbase .FilesTableName ,
675+ exprs : []string {"language(file_path, blob_content)" },
718676 },
719677 }
720678
@@ -736,31 +694,14 @@ func createIndex(
736694 ctx * sql.Context ,
737695) {
738696 t .Helper ()
739- require := require .New (t )
740- driver := e .Catalog .IndexDriver (pilosa .DriverID )
741- require .NotNil (driver )
742-
743- var hashes []sql.ExpressionHash
744- for _ , e := range data .expressions {
745- hashes = append (hashes , sql .NewExpressionHash (e ))
746- }
747697
748- idx , err := driver .Create (
749- "foo" , data .table .Name (),
750- data .id , hashes ,
751- make (map [string ]string ),
698+ query := fmt .Sprintf (
699+ `CREATE INDEX %s ON %s (%s) WITH (async = false)` ,
700+ data .id , data .table , strings .Join (data .exprs , ", " ),
752701 )
753- require .NoError (err )
754702
755- done , err := e .Catalog .AddIndex (idx )
756- require .NoError (err )
757-
758- iter , err := data .table .(sql.Indexable ).IndexKeyValueIter (ctx , data .columns )
759- require .NoError (err )
760-
761- require .NoError (driver .Save (sql .NewEmptyContext (), idx , iter ))
762-
763- done <- struct {}{}
703+ _ , _ , err := e .Query (ctx , query )
704+ require .NoError (t , err )
764705}
765706
766707func deleteIndex (
0 commit comments