Skip to content

Commit a3bdbd6

Browse files
authored
Merge pull request #2980 from dolthub/nicktobey/unwrap3
Unwrap inputs to JSON_OBJECT.
2 parents 2f1ae3d + d500d0c commit a3bdbd6

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

enginetest/enginetests.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ func TestComplexIndexQueriesPrepared(t *testing.T, harness Harness) {
19071907
}
19081908

19091909
func TestJsonScriptsPrepared(t *testing.T, harness Harness, skippedTests []string) {
1910-
harness.Setup(setup.MydbData)
1910+
harness.Setup(setup.MydbData, setup.BlobData)
19111911
for _, script := range queries.JsonScripts {
19121912
for _, skippedTest := range skippedTests {
19131913
if strings.Contains(script.Name, skippedTest) {
@@ -5154,6 +5154,7 @@ func TestNullRanges(t *testing.T, harness Harness) {
51545154
}
51555155

51565156
func TestJsonScripts(t *testing.T, harness Harness, skippedTests []string) {
5157+
harness.Setup(setup.MydbData, setup.BlobData)
51575158
for _, script := range queries.JsonScripts {
51585159
for _, skippedTest := range skippedTests {
51595160
if strings.Contains(script.Name, skippedTest) {

enginetest/queries/json_scripts.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ var JsonScripts = []ScriptTest{
126126
},
127127
},
128128
},
129+
{
130+
Name: "json_object works on text values from tables",
131+
Assertions: []ScriptTestAssertion{
132+
{
133+
Query: `select JSON_OBJECT(t, t) FROM textt where i = 1;`,
134+
Expected: []sql.Row{
135+
{types.MustJSON("{\"first row\": \"first row\"}")},
136+
},
137+
},
138+
},
139+
},
129140
{
130141
Name: "types survive round-trip into tables",
131142
SetUpScript: []string{

sql/expression/function/json/json_object.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,19 @@ func (j JSONObject) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
102102
return nil, err
103103
}
104104
if i%2 == 0 {
105-
val, _, err := types.LongText.Convert(ctx, val)
105+
val, _, err = types.LongText.Convert(ctx, val)
106+
if err != nil {
107+
return nil, err
108+
}
109+
key, _, err = sql.Unwrap[string](ctx, val)
106110
if err != nil {
107111
return nil, err
108112
}
109-
key = val.(string)
110113
} else {
114+
val, err = sql.UnwrapAny(ctx, val)
115+
if err != nil {
116+
return nil, err
117+
}
111118
if json, ok := val.(sql.JSONWrapper); ok {
112119
val, err = json.ToInterface()
113120
if err != nil {

0 commit comments

Comments
 (0)