fixed failing niltable tests

This commit is contained in:
Andy Arthur
2022-01-19 15:50:41 -08:00
parent be7b5440dd
commit c80067d256
6 changed files with 22 additions and 29 deletions

View File

@@ -39,29 +39,16 @@ func TestQueries(t *testing.T) {
}
func TestSingleQuery(t *testing.T) {
t.Skip()
var test enginetest.QueryTest
test = enginetest.QueryTest{
Query: `SELECT
myTable.i,
(SELECT
dolt_commit_diff_mytable.diff_type
FROM
dolt_commit_diff_mytable
WHERE (
dolt_commit_diff_mytable.from_commit = 'abc' AND
dolt_commit_diff_mytable.to_commit = 'abc' AND
dolt_commit_diff_mytable.to_i = myTable.i -- extra filter clause
)) AS diff_type
FROM myTable`,
Expected: []sql.Row{},
Query: "SELECT i FROM niltable WHERE b IS NULL",
Expected: []sql.Row{{int64(1)}, {int64(4)}},
}
harness := newDoltHarness(t)
engine := enginetest.NewEngine(t, harness)
engine.Analyzer.Debug = true
engine.Analyzer.Verbose = true
//engine.Analyzer.Debug = true
//engine.Analyzer.Verbose = true
enginetest.TestQuery(t, harness, engine, test.Query, test.Expected, test.ExpectedColumns, test.Bindings)
}

View File

@@ -426,7 +426,10 @@ func prollyRangeFromSqlRange(sqlRange sql.Range, tb *val.TupleBuilder) (rng prol
startFields = append(startFields, sql.GetRangeCutKey(sc))
}
if !start.Unbound {
start.Key = tupleFromKeys(startFields, tb)
start.Key, err = tupleFromKeys(startFields, tb)
if err != nil {
return prolly.Range{}, err
}
}
stop := prolly.RangeCut{Inclusive: true}
@@ -440,7 +443,10 @@ func prollyRangeFromSqlRange(sqlRange sql.Range, tb *val.TupleBuilder) (rng prol
stopFields = append(stopFields, sql.GetRangeCutKey(sc))
}
if !stop.Unbound {
stop.Key = tupleFromKeys(stopFields, tb)
stop.Key, err = tupleFromKeys(stopFields, tb)
if err != nil {
return prolly.Range{}, err
}
}
return prolly.Range{
@@ -455,9 +461,12 @@ func isBindingCut(cut sql.RangeCut) bool {
return cut != sql.BelowAll{} && cut != sql.AboveAll{}
}
func tupleFromKeys(keys sql.Row, tb *val.TupleBuilder) val.Tuple {
func tupleFromKeys(keys sql.Row, tb *val.TupleBuilder) (val.Tuple, error) {
for i, v := range keys {
if !tb.Desc.Types[i].Nullable && v == nil {
return nil, errors.New("cannot set non-nullable field to NULL")
}
tb.PutField(i, v)
}
return tb.Build(sharePool)
return tb.Build(sharePool), nil
}

View File

@@ -27,8 +27,6 @@ const (
numFieldsSize ByteSize = 2
)
var NULL []byte = nil
// Tuples are byte slices containing field values and a footer. Tuples only
// contain Values for non-NULL Fields. Value i contains the data for ith non-
// NULL Field. Values are packed contiguously from the front of the Tuple. The
@@ -134,7 +132,7 @@ func makeTuple(pool pool.BuffPool, bufSz ByteSize, values, fields int) (tup Tupl
func (tup Tuple) GetField(i int) []byte {
// first check if the field is NULL
if !tup.mask().present(i) {
return NULL
return nil
}
// translate from field index to value

View File

@@ -51,6 +51,9 @@ func (tb *TupleBuilder) Build(pool pool.BuffPool) (tup Tuple) {
// Recycle resets the TupleBuilder so it can build a new Tuple.
func (tb *TupleBuilder) Recycle() {
for i := 0; i < tb.Desc.Count(); i++ {
tb.fields[i] = nil
}
tb.pos = 0
}

View File

@@ -302,7 +302,7 @@ func (td TupleDesc) GetField(i int, tup Tuple) (v interface{}) {
panic("unknown encoding")
}
if !ok {
return NULL
return nil
}
return v
}

View File

@@ -25,10 +25,6 @@ import (
var testPool = pool.NewBuffPool()
func TestNULL(t *testing.T) {
assert.True(t, NULL == nil)
}
func TestNewTuple(t *testing.T) {
t.Run("test tuple round trip", func(t *testing.T) {
roundTripBytes(t)