Skip to content

Commit 5f26811

Browse files
author
James Cor
committed
fix coalesce
1 parent b02d6d5 commit 5f26811

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

sql/expression/function/coalesce_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func TestCoalesce(t *testing.T) {
152152
typ: types.Float64,
153153
nullable: false,
154154
},
155+
{
156+
name: "coalesce(json({'a': 'a \n b'}), '')",
157+
input: []sql.Expression{
158+
expression.NewLiteral("{\"a\": \"one \\n two\"}", types.JSON),
159+
expression.NewLiteral("", types.LongText),
160+
},
161+
expected: "{\"a\": \"one \\n two\"}",
162+
typ: types.LongText,
163+
nullable: false,
164+
},
155165
{
156166
name: "coalesce(sysInt, sysInt)",
157167
input: []sql.Expression{

sql/types/json_value.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func JsonToMySqlString(jsonWrapper sql.JSONWrapper) (string, error) {
4343
return marshalToMySqlString(val)
4444
}
4545

46-
// JsonToMySqlString generates a byte slice representation of a sql.JSONWrapper that is compatible with MySQL's JSON output, including spaces.
46+
// JsonToMySqlBytes generates a byte slice representation of a sql.JSONWrapper that is compatible with MySQL's JSON output, including spaces.
4747
func JsonToMySqlBytes(jsonWrapper sql.JSONWrapper) ([]byte, error) {
4848
val, err := jsonWrapper.ToInterface()
4949
if err != nil {
@@ -630,8 +630,8 @@ func compareJSONArray(a JsonArray, b interface{}) (int, error) {
630630
func compareJSONObject(a JsonObject, b interface{}) (int, error) {
631631
switch b := b.(type) {
632632
case
633-
bool,
634-
JsonArray:
633+
bool,
634+
JsonArray:
635635
// a is lower precedence
636636
return -1, nil
637637

@@ -662,9 +662,9 @@ func compareJSONObject(a JsonObject, b interface{}) (int, error) {
662662
func compareJSONString(a string, b interface{}) (int, error) {
663663
switch b := b.(type) {
664664
case
665-
bool,
666-
JsonArray,
667-
JsonObject:
665+
bool,
666+
JsonArray,
667+
JsonObject:
668668
// a is lower precedence
669669
return -1, nil
670670

@@ -680,10 +680,10 @@ func compareJSONString(a string, b interface{}) (int, error) {
680680
func compareJSONNumber(a float64, b interface{}) (int, error) {
681681
switch b := b.(type) {
682682
case
683-
bool,
684-
JsonArray,
685-
JsonObject,
686-
string:
683+
bool,
684+
JsonArray,
685+
JsonObject,
686+
string:
687687
// a is lower precedence
688688
return -1, nil
689689
case int:

sql/types/strings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/shopspring/decimal"
3030
"gopkg.in/src-d/go-errors.v1"
3131

32-
"github.com/dolthub/go-mysql-server/internal/strings"
3332
"github.com/dolthub/go-mysql-server/sql"
3433
"github.com/dolthub/go-mysql-server/sql/encodings"
3534
)
@@ -416,7 +415,8 @@ func ConvertToBytes(ctx context.Context, v interface{}, t sql.StringType, dest [
416415
if err != nil {
417416
return nil, err
418417
}
419-
val, err = strings.UnquoteBytes(val)
418+
// TODO: why do we do this?
419+
//val, err = strings.UnquoteBytes(val)
420420
if err != nil {
421421
return nil, err
422422
}

0 commit comments

Comments
 (0)