Skip to content

Commit

Permalink
Fixing issue with IndexedDoltTable not fully implementing the interfa…
Browse files Browse the repository at this point in the history
…ce of DoltTable (inconsistent with WritableIndexedDoltTable)
  • Loading branch information
fulghum committed Feb 14, 2024
1 parent 02e9f99 commit b368470
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
45 changes: 45 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,51 @@ var DoltScripts = []queries.ScriptTest{
},
},
},
{
Name: "test AS OF indexed queries (https://github.com/dolthub/dolt/issues/7488)",
SetUpScript: []string{
"create table indexedTable (pk int primary key, c0 int, c1 varchar(255), key c1_idx(c1));",
"insert into indexedTable (pk, c1) values (1, 'one');",
"call dolt_commit('-Am', 'adding table t with index');",
"SET @commit1 = hashof('HEAD');",

"update indexedTable set c1='two';",
"call dolt_commit('-am', 'updating one to two');",
"SET @commit2 = hashof('HEAD');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT c1 from indexedTable;",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable where c1 > 'o';",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{"c1_idx"},
},
{
Query: "SELECT c1 from indexedTable as of @commit2;",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable as of @commit2 where c1 > 'o';",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{"c1_idx"},
},
{
Query: "SELECT c1 from indexedTable as of @commit1;",
Expected: []sql.Row{{"one"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable as of @commit1 where c1 > 'o';",
Expected: []sql.Row{{"one"}},
ExpectedIndexes: []string{"c1_idx"},
},
},
},
{
Name: "test as of indexed join (https://github.com/dolthub/dolt/issues/2189)",
SetUpScript: []string{
Expand Down
42 changes: 7 additions & 35 deletions go/libraries/doltcore/sqle/indexed_dolt_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// DoltTable, but its RowIter function returns values that match a sql.Range, instead of all
// rows. It's returned by the DoltTable.IndexedAccess function.
type IndexedDoltTable struct {
table *DoltTable
*DoltTable
idx index.DoltIndex
lb index.LookupBuilder
isDoltFormat bool
Expand All @@ -36,7 +36,7 @@ type IndexedDoltTable struct {

func NewIndexedDoltTable(t *DoltTable, idx index.DoltIndex) *IndexedDoltTable {
return &IndexedDoltTable{
table: t,
DoltTable: t,
idx: idx,
isDoltFormat: types.IsFormat_DOLT(t.Format()),
mu: &sync.Mutex{},
Expand All @@ -46,32 +46,8 @@ func NewIndexedDoltTable(t *DoltTable, idx index.DoltIndex) *IndexedDoltTable {
var _ sql.IndexedTable = (*IndexedDoltTable)(nil)
var _ sql.CommentedTable = (*IndexedDoltTable)(nil)

func (idt *IndexedDoltTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
return idt.table.GetIndexes(ctx)
}

func (idt *IndexedDoltTable) Name() string {
return idt.table.Name()
}

func (idt *IndexedDoltTable) String() string {
return idt.table.String()
}

func (idt *IndexedDoltTable) Schema() sql.Schema {
return idt.table.Schema()
}

func (idt *IndexedDoltTable) Collation() sql.CollationID {
return sql.CollationID(idt.table.sch.GetCollation())
}

func (idt *IndexedDoltTable) Comment() string {
return idt.table.Comment()
}

func (idt *IndexedDoltTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLookup) (sql.PartitionIter, error) {
return index.NewRangePartitionIter(ctx, idt.table, lookup, idt.isDoltFormat)
return index.NewRangePartitionIter(ctx, idt.DoltTable, lookup, idt.isDoltFormat)
}

func (idt *IndexedDoltTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
Expand All @@ -81,13 +57,13 @@ func (idt *IndexedDoltTable) Partitions(ctx *sql.Context) (sql.PartitionIter, er
func (idt *IndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
idt.mu.Lock()
defer idt.mu.Unlock()
key, canCache, err := idt.table.DataCacheKey(ctx)
key, canCache, err := idt.DoltTable.DataCacheKey(ctx)
if err != nil {
return nil, err
}

if idt.lb == nil || !canCache || idt.lb.Key() != key {
idt.lb, err = index.NewLookupBuilder(ctx, idt.table, idt.idx, key, idt.table.projectedCols, idt.table.sqlSch, idt.isDoltFormat)
idt.lb, err = index.NewLookupBuilder(ctx, idt.DoltTable, idt.idx, key, idt.DoltTable.projectedCols, idt.DoltTable.sqlSch, idt.isDoltFormat)
if err != nil {
return nil, err
}
Expand All @@ -99,12 +75,12 @@ func (idt *IndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition)
func (idt *IndexedDoltTable) PartitionRows2(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
idt.mu.Lock()
defer idt.mu.Unlock()
key, canCache, err := idt.table.DataCacheKey(ctx)
key, canCache, err := idt.DoltTable.DataCacheKey(ctx)
if err != nil {
return nil, err
}
if idt.lb == nil || !canCache || idt.lb.Key() != key {
idt.lb, err = index.NewLookupBuilder(ctx, idt.table, idt.idx, key, idt.table.projectedCols, idt.table.sqlSch, idt.isDoltFormat)
idt.lb, err = index.NewLookupBuilder(ctx, idt.DoltTable, idt.idx, key, idt.DoltTable.projectedCols, idt.DoltTable.sqlSch, idt.isDoltFormat)
if err != nil {
return nil, err
}
Expand All @@ -113,10 +89,6 @@ func (idt *IndexedDoltTable) PartitionRows2(ctx *sql.Context, part sql.Partition
return idt.lb.NewRowIter(ctx, part)
}

func (idt *IndexedDoltTable) IsTemporary() bool {
return idt.table.IsTemporary()
}

var _ sql.IndexedTable = (*WritableIndexedDoltTable)(nil)
var _ sql.UpdatableTable = (*WritableIndexedDoltTable)(nil)
var _ sql.DeletableTable = (*WritableIndexedDoltTable)(nil)
Expand Down

0 comments on commit b368470

Please sign in to comment.