Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Substring function is not parsed correctly #532

Closed
theodesp opened this issue Nov 5, 2018 · 4 comments
Closed

Substring function is not parsed correctly #532

theodesp opened this issue Nov 5, 2018 · 4 comments
Assignees
Labels
3rd-party Third party compatibility bug Something isn't working

Comments

@theodesp
Copy link
Contributor

theodesp commented Nov 5, 2018

I'm trying to implement #483 but it looks like we broke substring. The unit tests run fine but when we login into a console it doesn't work.

mysql> select SUBSTRING("foo", 2, 2);
ERROR 1105 (HY000): unknown error: syntax error at position 23 near 'foo'
mysql> select substring("foobar", 1, 2);
ERROR 1105 (HY000): unknown error: syntax error at position 26 near 'foobar'
mysql> select SUBSTRING("foo", 1, 2);
ERROR 1105 (HY000): unknown error: syntax error at position 23 near 'foo'
@erizocosmico erizocosmico changed the title Substring function is broken Substring function is not parsed correctly Nov 5, 2018
@erizocosmico erizocosmico added the bug Something isn't working label Nov 5, 2018
@erizocosmico
Copy link
Contributor

This is probably an issue with vitess, because afaik we don't parse substring manually.

@kuba-- kuba-- self-assigned this Nov 6, 2018
@kuba--
Copy link
Contributor

kuba-- commented Nov 6, 2018

It will require fix in vitess. So far, we get from vitess:

	// INVALID_ARGUMENT indicates client specified an invalid argument.
	// Note that this differs from FAILED_PRECONDITION. It indicates arguments
	// that are problematic regardless of the state of the system
	// (e.g., a malformed file name).
	Code_INVALID_ARGUMENT Code = 3

@kuba--
Copy link
Contributor

kuba-- commented Nov 6, 2018

Looks that vitess doesn't support SubstrExpr for static strings (only column names), so the fix is not super trivial just by updating vitess lexer but it will require changes in ast (by adding a new StaticSubstrExpr type or by extending current one SubstrExpr), then update lexer generator after that implement it in go-mysql-server parser.

@kuba-- kuba-- added the 3rd-party Third party compatibility label Nov 7, 2018
@kuba--
Copy link
Contributor

kuba-- commented Nov 8, 2018

PR: vitessio/vitess#4350
But it will also require changes in /go-mysql-server.v0/sql/parse/parse.go by adding to func exprToExpression(e sqlparser.Expr):

	case *sqlparser.SubstrExpr:
		var (
			name sql.Expression
			err  error
		)
		if v.Name != nil {
			name, err = exprToExpression(v.Name)
		} else {
			name, err = exprToExpression(v.StrVal)
		}
//...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd-party Third party compatibility bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants