Skip to content

Commit c399fd9

Browse files
committed
vector.Or: Properly handle nulls values
This commit adjusts the behavior of vector.Or so that null values are properly set.
1 parent 605b4bb commit c399fd9

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

runtime/vam/expr/logic.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,7 @@ func (o *Or) eval(vecs ...vector.Any) vector.Any {
118118
if _, ok := rhs.(*vector.Error); ok {
119119
return o.orError(rhs, lhs)
120120
}
121-
blhs, brhs := toBool(lhs), toBool(rhs)
122-
bits := bitvec.Or(blhs.Bits, brhs.Bits)
123-
if blhs.Nulls.IsZero() && brhs.Nulls.IsZero() {
124-
// Fast path involves no nulls.
125-
return vector.NewBool(bits, bitvec.Zero)
126-
}
127-
nulls := bitvec.Or(blhs.Nulls, brhs.Nulls)
128-
nulls = bitvec.And(bitvec.Not(bits), nulls)
129-
return vector.NewBool(bits, nulls)
121+
return vector.Or(toBool(lhs), toBool(rhs))
130122
}
131123

132124
func (o *Or) orError(err, vec vector.Any) vector.Any {

vector/bool.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ func (b *Bool) Serialize(builder *scode.Builder, slot uint32) {
5151
}
5252
}
5353

54-
// Or is a simple case of logical-or where we don't care about nulls in
55-
// the input (presuming the corresponding bits to be false) and we return
56-
// the or'd result as a boolean vector without nulls.
5754
func Or(a, b *Bool) *Bool {
58-
return NewBool(bitvec.Or(a.Bits, b.Bits), bitvec.Zero)
55+
bits := bitvec.Or(a.Bits, b.Bits)
56+
if a.Nulls.IsZero() && b.Nulls.IsZero() {
57+
// Fast path involves no nulls.
58+
return NewBool(bits, bitvec.Zero)
59+
}
60+
nulls := bitvec.Or(a.Nulls, b.Nulls)
61+
nulls = bitvec.And(bitvec.Not(bits), nulls)
62+
return NewBool(bits, nulls)
5963
}
6064

6165
// BoolValue returns the value of slot in vec if the value is a Boolean. It

0 commit comments

Comments
 (0)