Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions enginetest/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func WidenRow(t *testing.T, sch sql.Schema, row sql.Row) sql.Row {
widened := make(sql.Row, len(row))
for i, v := range row {
if i < len(sch) && types.IsJSON(sch[i].Type) {
widened[i] = widenJSONValues(v)
widened[i] = widenJSONValues(t.Context(), v)
continue
}

Expand Down Expand Up @@ -893,7 +893,7 @@ func widenValue(t *testing.T, v interface{}) (vw interface{}) {
return vw
}

func widenJSONValues(val interface{}) sql.JSONWrapper {
func widenJSONValues(ctx context.Context, val interface{}) sql.JSONWrapper {
if val == nil {
return nil
}
Expand All @@ -907,7 +907,7 @@ func widenJSONValues(val interface{}) sql.JSONWrapper {
js = types.MustJSON(str)
}

doc, err := js.ToInterface()
doc, err := js.ToInterface(ctx)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions sql/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package sql

import (
"context"
"encoding/json"
"fmt"
trace2 "runtime/trace"
Expand Down Expand Up @@ -324,7 +325,7 @@ func ConvertToBool(ctx *Context, v interface{}) (bool, error) {
}
}

func ConvertToVector(v interface{}) ([]float64, error) {
func ConvertToVector(ctx context.Context, v interface{}) ([]float64, error) {
switch b := v.(type) {
case []float64:
return b, nil
Expand All @@ -336,7 +337,7 @@ func ConvertToVector(v interface{}) ([]float64, error) {
}
return convertJsonInterfaceToVector(val)
case JSONWrapper:
val, err := b.ToInterface()
val, err := b.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/aggregation/json_agg.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (j *jsonObjectBuffer) Update(ctx *sql.Context, row sql.Row) error {
return err
}
if js, ok := val.(sql.JSONWrapper); ok {
val, err = js.ToInterface()
val, err = js.ToInterface(ctx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/aggregation/unary_agg_buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func (j *jsonArrayBuffer) Update(ctx *sql.Context, row sql.Row) error {
return err
}
if js, ok := v.(sql.JSONWrapper); ok {
v, err = js.ToInterface()
v, err = js.ToInterface(ctx)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/aggregation/window_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ func (a *WindowedJSONArrayAgg) aggregateVals(ctx *sql.Context, interval sql.Wind
return nil, err
}
if js, ok := v.(sql.JSONWrapper); ok {
v, err = js.ToInterface()
v, err = js.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1146,7 +1146,7 @@ func (a *WindowedJSONObjectAgg) aggregateVals(ctx *sql.Context, interval sql.Win
return nil, err
}
if js, ok := val.(sql.JSONWrapper); ok {
val, err = js.ToInterface()
val, err = js.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (j *JSONArray) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {

switch v := val.(type) {
case sql.JSONWrapper:
val, err = v.ToInterface()
val, err = v.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_array_append.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (j JSONArrayAppend) Eval(ctx *sql.Context, row sql.Row) (interface{}, error

// Apply the path-value pairs to the document.
for _, pair := range pairs {
doc, _, err = doc.ArrayAppend(pair.path, pair.val)
doc, _, err = doc.ArrayAppend(ctx, pair.path, pair.val)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_array_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (j JSONArrayInsert) Eval(ctx *sql.Context, row sql.Row) (interface{}, error

// Apply the path-value pairs to the document.
for _, pair := range pairs {
doc, _, err = doc.ArrayInsert(pair.path, pair.val)
doc, _, err = doc.ArrayInsert(ctx, pair.path, pair.val)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func MutableJsonDoc(ctx context.Context, wrapper sql.JSONWrapper) (types.Mutable
return mutable, nil
}

val, err := clonedJsonWrapper.ToInterface()
val, err := clonedJsonWrapper.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions sql/expression/function/json/json_contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (j *JSONContains) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
return nil, err
}

extracted, err := types.LookupJSONValue(target, path.(string))
extracted, err := types.LookupJSONValue(ctx, target, path.(string))
if err != nil {
return nil, err
}
Expand All @@ -162,11 +162,11 @@ func (j *JSONContains) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
}

// Now determine whether the candidate value exists in the target
targetVal, err := target.ToInterface()
targetVal, err := target.ToInterface(ctx)
if err != nil {
return nil, err
}
candidateVal, err := candidate.ToInterface()
candidateVal, err := candidate.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_contains_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (j JSONContainsPath) Eval(ctx *sql.Context, row sql.Row) (interface{}, erro
return nil, err
}

result, err := types.LookupJSONValue(target, path.(string))
result, err := types.LookupJSONValue(ctx, target, path.(string))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_depth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (j *JSONDepth) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, nil
}

val, err := doc.ToInterface()
val, err := doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (j *JSONExtract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, nil
}

results[i], err = types.LookupJSONValue(searchable, path.(string))
results[i], err = types.LookupJSONValue(ctx, searchable, path.(string))
if err != nil {
return nil, fmt.Errorf("failed to extract from expression '%s'; %s", j.JSON.String(), err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/json_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (j *JSONKeys) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, nil
}

js, err := types.LookupJSONValue(doc, *path)
js, err := types.LookupJSONValue(ctx, doc, *path)
if err != nil {
if errors.Is(err, jsonpath.ErrKeyError) {
return nil, nil
Expand All @@ -117,7 +117,7 @@ func (j *JSONKeys) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, nil
}

val, err := js.ToInterface()
val, err := js.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/json_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (j *JsonLength) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, strErr
}

res, err := types.LookupJSONValue(doc, path)
res, err := types.LookupJSONValue(ctx, doc, path)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +104,7 @@ func (j *JsonLength) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, nil
}

val, err := res.ToInterface()
val, err := res.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/json_merge_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (j *JSONMergePatch) Eval(ctx *sql.Context, row sql.Row) (interface{}, error
return nil, nil
}

val, err := initDoc.ToInterface()
val, err := initDoc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand All @@ -131,7 +131,7 @@ func (j *JSONMergePatch) Eval(ctx *sql.Context, row sql.Row) (interface{}, error
if doc == nil {
return nil, nil
}
val, err = doc.ToInterface()
val, err = doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/json_merge_preserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (j *JSONMergePreserve) Eval(ctx *sql.Context, row sql.Row) (interface{}, er
return nil, nil
}

val, err := initDoc.ToInterface()
val, err := initDoc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +138,7 @@ func (j *JSONMergePreserve) Eval(ctx *sql.Context, row sql.Row) (interface{}, er
if doc == nil {
return nil, nil
}
val, err = doc.ToInterface()
val, err = doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (j JSONObject) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return nil, err
}
if json, ok := val.(sql.JSONWrapper); ok {
val, err = json.ToInterface()
val, err = json.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/json_overlaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (j *JSONOverlaps) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
if left == nil {
return nil, nil
}
leftVal, err := left.ToInterface()
leftVal, err := left.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand All @@ -202,7 +202,7 @@ func (j *JSONOverlaps) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
if right == nil {
return nil, nil
}
rightVal, err := right.ToInterface()
rightVal, err := right.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (j *JSONPretty) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
if doc == nil {
return nil, nil
}
val, err := doc.ToInterface()
val, err := doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (j *JSONSearch) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}
}

val, err := doc.ToInterface()
val, err := doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/json/json_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (j JSONType) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return comparableDoc.Type(ctx)
}

val, err := doc.ToInterface()
val, err := doc.ToInterface(ctx)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions sql/expression/function/json/json_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (j *JsonValue) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}

// json NULLs also result in sql NULLs.
cmp, err := types.CompareJSON(js, types.JSONDocument{Val: nil})
cmp, err := types.CompareJSON(ctx, js, types.JSONDocument{Val: nil})
if cmp == 0 {
return nil, nil
}
Expand All @@ -111,7 +111,7 @@ func (j *JsonValue) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}

var res interface{}
res, err = types.LookupJSONValue(searchable, path.(string))
res, err = types.LookupJSONValue(ctx, searchable, path.(string))
if err != nil || res == nil {
return nil, err
}
Expand All @@ -120,7 +120,7 @@ func (j *JsonValue) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
// bad lookups on arrays, instead of an error. Note that this will cause lookups that expect [] to return incorrect
// results.
// See https://github.com/dolthub/dolt/issues/7905 for more information.
cmp, err = types.CompareJSON(res, types.JSONDocument{Val: []interface{}{}})
cmp, err = types.CompareJSON(ctx, res, types.JSONDocument{Val: []interface{}{}})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func GetJSONFromWrapperOrCoercibleString(ctx *sql.Context, js interface{}, funct
}
return jsonData, nil
case sql.JSONWrapper:
return jsType.ToInterface()
return jsType.ToInterface(ctx)
default:
return nil, sql.ErrInvalidJSONArgument.New(argumentPosition, functionName)
}
Expand Down
3 changes: 2 additions & 1 deletion sql/expression/function/json/jsontests/json_extract_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package jsontests

import (
"context"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -67,7 +68,7 @@ func JsonExtractTestCases(t *testing.T, prepare prepareJsonValue) []testCase {
}}
// Workaround for https://github.com/dolthub/dolt/issues/7998
// Otherwise, converting this to a string will create invalid JSON
jsonBytes, err := types.MarshallJson(jsonDocument)
jsonBytes, err := types.MarshallJson(context.Background(), jsonDocument)
require.NoError(t, err)
jsonInput := prepare(t, jsonBytes)

Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/json/jsontests/json_function_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var jsonFormatTests = []jsonFormatTest{
prepareFunc: func(t *testing.T, js interface{}) interface{} {
doc, _, err := types.JSON.Convert(sqlCtx, js)
require.NoError(t, err)
val, err := doc.(sql.JSONWrapper).ToInterface()
val, err := doc.(sql.JSONWrapper).ToInterface(t.Context())
require.NoError(t, err)
return types.JSONDocument{Val: val}
},
Expand All @@ -59,7 +59,7 @@ var jsonFormatTests = []jsonFormatTest{
prepareFunc: func(t *testing.T, js interface{}) interface{} {
doc, _, err := types.JSON.Convert(sqlCtx, js)
require.NoError(t, err)
bytes, err := types.MarshallJson(doc.(sql.JSONWrapper))
bytes, err := types.MarshallJson(sqlCtx, doc.(sql.JSONWrapper))
require.NoError(t, err)
return types.NewLazyJSONDocument(bytes)
},
Expand Down
Loading
Loading