validate spatial indexes

This commit is contained in:
James Cor
2023-02-21 01:07:39 -08:00
parent 13efc85013
commit ba03677a5f

View File

@@ -17,10 +17,12 @@ package enginetest
import (
"context"
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/index"
"io"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/mysql_db"
sqltypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
@@ -144,7 +146,7 @@ func validateIndexConsistency(
// TODO: the descriptors in the primary key are different
// than the ones in the secondary key; this test assumes
// they're the same
if len(def.PrefixLengths()) > 0 || def.IsSpatial() {
if len(def.PrefixLengths()) > 0 {
return nil
}
@@ -179,7 +181,16 @@ func validateKeylessIndex(ctx context.Context, sch schema.Schema, def schema.Ind
for i := range mapping {
j := mapping.MapOrdinal(i)
// first field in |value| is cardinality
builder.PutRaw(i, value.GetField(j+1))
field := value.GetField(j+1)
if def.IsSpatial() {
geom, err := sqltypes.GeometryType{}.Convert(field[:len(field)-1])
if err != nil {
panic(err)
}
cell := index.ZCell(geom.(sqltypes.GeometryValue))
field = cell[:]
}
builder.PutRaw(i, field)
}
builder.PutRaw(idxDesc.Count()-1, hashId.GetField(0))
k := builder.Build(primary.Pool())
@@ -222,7 +233,16 @@ func validatePkIndex(ctx context.Context, sch schema.Schema, def schema.Index, p
if j < pkSize {
builder.PutRaw(i, key.GetField(j))
} else {
builder.PutRaw(i, value.GetField(j-pkSize))
field := value.GetField(j-pkSize)
if def.IsSpatial() {
geom, err := sqltypes.GeometryType{}.Convert(field[:len(field)-1])
if err != nil {
panic(err)
}
cell := index.ZCell(geom.(sqltypes.GeometryValue))
field = cell[:]
}
builder.PutRaw(i, field)
}
}
k := builder.Build(primary.Pool())