Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix null value bug in engine #1375

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions node/engine/interpreter/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ func init() {
valueMapping{
KwilType: types.NumericArrayType,
ZeroValue: func(t *types.DataType) (value, error) {
if !t.HasMetadata() {
return nil, fmt.Errorf("cannot create zero value of decimal type with zero precision and scale")
}

prec := t.Metadata[0]
scale := t.Metadata[1]

Expand All @@ -213,10 +209,6 @@ func init() {
return arr, nil
},
NullValue: func(t *types.DataType) (value, error) {
if !t.HasMetadata() {
return nil, fmt.Errorf("cannot create null value of decimal array type with zero precision and scale")
}

prec := t.Metadata[0]
scale := t.Metadata[1]

Expand Down Expand Up @@ -384,14 +376,22 @@ func newValue(v any) (value, error) {
}
return makeBlob(*v), nil
case *types.UUID:
if v == nil {
return makeNull(types.UUIDType)
}
return makeUUID(v), nil
case types.UUID:
return makeUUID(&v), nil
case *types.Decimal:
// makeDecimal accounts for nil, so we can pass it directly
return makeDecimal(v), nil
case types.Decimal:
return makeDecimal(&v), nil
case []int64:
if v == nil {
return makeNull(types.IntArrayType)
}

pgInts := make([]pgtype.Int8, len(v))
for i, val := range v {
pgInts[i].Int64 = val
Expand All @@ -402,6 +402,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgInts),
}, nil
case []*int64:
if v == nil {
return makeNull(types.IntArrayType)
}

pgInts := make([]pgtype.Int8, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -415,6 +419,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgInts),
}, nil
case []int:
if v == nil {
return makeNull(types.IntArrayType)
}

pgInts := make([]pgtype.Int8, len(v))
for i, val := range v {
pgInts[i].Int64 = int64(val)
Expand All @@ -425,6 +433,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgInts),
}, nil
case []*int:
if v == nil {
return makeNull(types.IntArrayType)
}

pgInts := make([]pgtype.Int8, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -438,6 +450,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgInts),
}, nil
case []string:
if v == nil {
return makeNull(types.TextArrayType)
}

pgTexts := make([]pgtype.Text, len(v))
for i, val := range v {
pgTexts[i].String = val
Expand All @@ -448,6 +464,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgTexts),
}, nil
case []*string:
if v == nil {
return makeNull(types.TextArrayType)
}

pgTexts := make([]pgtype.Text, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -462,6 +482,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgTexts),
}, nil
case []bool:
if v == nil {
return makeNull(types.BoolArrayType)
}

pgBools := make([]pgtype.Bool, len(v))
for i, val := range v {
pgBools[i].Bool = val
Expand All @@ -472,6 +496,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgBools),
}, nil
case []*bool:
if v == nil {
return makeNull(types.BoolArrayType)
}

pgBools := make([]pgtype.Bool, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -486,6 +514,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgBools),
}, nil
case [][]byte:
if v == nil {
return makeNull(types.ByteaArrayType)
}

pgBlobs := make([]blobValue, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -499,6 +531,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgBlobs),
}, nil
case []*[]byte:
if v == nil {
return makeNull(types.ByteaArrayType)
}

pgBlobs := make([]blobValue, len(v))
for i, val := range v {
if val == nil {
Expand All @@ -512,6 +548,10 @@ func newValue(v any) (value, error) {
singleDimArray: newValidArr(pgBlobs),
}, nil
case []*types.Decimal:
if v == nil {
return makeNull(types.NumericArrayType)
}

pgDecs := make([]pgtype.Numeric, len(v))
var firstNonNilDecimal *types.Decimal
for i, val := range v {
Expand All @@ -533,6 +573,10 @@ func newValue(v any) (value, error) {
metadata: metadata,
}, nil
case []*types.UUID:
if v == nil {
return makeNull(types.UUIDArrayType)
}

pgUUIDs := make([]pgtype.UUID, len(v))
for i, val := range v {
if val == nil {
Expand Down
Loading