@@ -2,9 +2,11 @@ package gitbase_test
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"io/ioutil"
6
7
"os"
7
8
"path/filepath"
9
+ "strings"
8
10
"testing"
9
11
10
12
"github.com/src-d/gitbase/internal/rule"
@@ -610,111 +612,67 @@ func col(t testing.TB, schema sql.Schema, name string) sql.Expression {
610
612
}
611
613
612
614
type 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
617
618
}
618
619
619
620
func 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
-
624
621
var indexes = []indexData {
625
622
{
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" },
632
626
},
633
627
{
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" },
640
631
},
641
632
{
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" },
648
636
},
649
637
{
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" },
656
641
},
657
642
{
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" },
664
646
},
665
647
{
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" },
672
651
},
673
652
{
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" },
680
656
},
681
657
{
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" },
688
661
},
689
662
{
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" },
696
666
},
697
667
{
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" },
704
671
},
705
672
{
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)" },
718
676
},
719
677
}
720
678
@@ -736,31 +694,14 @@ func createIndex(
736
694
ctx * sql.Context ,
737
695
) {
738
696
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
- }
747
697
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 , ", " ),
752
701
)
753
- require .NoError (err )
754
702
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 )
764
705
}
765
706
766
707
func deleteIndex (
0 commit comments