Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestSingleScript(t *testing.T) {

for _, test := range scripts {
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, true, nil)
harness.UseServer()
//harness.UseServer()
engine, err := harness.NewEngine(t)
if err != nil {
panic(err)
Expand Down
29 changes: 29 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8684,6 +8684,35 @@ where
},
},
},
{
// This is a script test here because every table in the harness setup data is in all lowercase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what this comment is saying or what it means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, bad copy paste; will remove

Name: "substring function tests with wrappers",
Dialect: "mysql",
SetUpScript: []string{
"create table tbl (t text);",
"insert into tbl values ('abcdef');",
},
Assertions: []ScriptTestAssertion{
{
Query: "select left(t, 3) from tbl;",
Expected: []sql.Row{
{"abc"},
},
},
{
Query: "select right(t, 3) from tbl;",
Expected: []sql.Row{
{"def"},
},
},
{
Query: "select instr(t, 'bcd') from tbl;",
Expected: []sql.Row{
{2},
},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
38 changes: 37 additions & 1 deletion sql/expression/function/substring.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,20 @@ func (l Left) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
switch str := str.(type) {
case string:
text = []rune(str)
case sql.StringWrapper:
s, err := str.Unwrap(ctx)
if err != nil {
return nil, err
}
text = []rune(s)
case []byte:
text = []rune(string(str))
case sql.BytesWrapper:
b, err := str.Unwrap(ctx)
if err != nil {
return nil, err
}
text = []rune(string(b))
case nil:
return nil, nil
default:
Expand Down Expand Up @@ -583,8 +595,20 @@ func (i Instr) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
switch str := str.(type) {
case string:
text = []rune(str)
case sql.StringWrapper:
s, err := str.Unwrap(ctx)
if err != nil {
return nil, err
}
text = []rune(s)
case []byte:
text = []rune(string(str))
case sql.BytesWrapper:
s, err := str.Unwrap(ctx)
if err != nil {
return nil, err
}
text = []rune(string(s))
case nil:
return nil, nil
default:
Expand All @@ -600,8 +624,20 @@ func (i Instr) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
switch substr := substr.(type) {
case string:
subtext = []rune(substr)
case sql.StringWrapper:
s, err := substr.Unwrap(ctx)
if err != nil {
return nil, err
}
text = []rune(s)
case []byte:
subtext = []rune(string(subtext))
subtext = []rune(string(substr))
case sql.BytesWrapper:
s, err := substr.Unwrap(ctx)
if err != nil {
return nil, err
}
subtext = []rune(string(s))
case nil:
return nil, nil
default:
Expand Down