diff --git a/pkg/sql/parser/parse.go b/pkg/sql/parser/parse.go index 2540bcaf9b57..cb9a17d26207 100644 --- a/pkg/sql/parser/parse.go +++ b/pkg/sql/parser/parse.go @@ -21,6 +21,7 @@ package parser import ( "fmt" + "go/constant" "strings" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" @@ -30,6 +31,11 @@ import ( "github.com/cockroachdb/errors" ) +func init() { + NewNumValFn = func(a constant.Value, s string, b bool) interface{} { return tree.NewNumVal(a, s, b) } + NewPlaceholderFn = func(s string) (interface{}, error) { return tree.NewPlaceholder(s) } +} + // Statement is the result of parsing a single statement. It contains the AST // node along with other information. type Statement struct { diff --git a/pkg/sql/parser/scan.go b/pkg/sql/parser/scan.go index a8826fbc90dd..e23c814d354a 100644 --- a/pkg/sql/parser/scan.go +++ b/pkg/sql/parser/scan.go @@ -20,7 +20,6 @@ import ( "unsafe" "github.com/cockroachdb/cockroach/pkg/sql/lexbase" - "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" ) const eof = -1 @@ -30,6 +29,17 @@ const errInvalidHexNumeric = "invalid hexadecimal numeric literal" const singleQuote = '\'' const identQuote = '"' +// NewNumValFn allows us to use tree.NewNumVal without a dependency on tree. +var NewNumValFn = func(constant.Value, string, bool) interface{} { + return struct{}{} +} + +// NewPlaceholderFn allows us to use tree.NewPlaceholder without a dependency on +// tree. +var NewPlaceholderFn = func(string) (interface{}, error) { + return struct{}{}, nil +} + // scanner lexes SQL statements. type scanner struct { in string @@ -655,7 +665,7 @@ func (s *scanner) scanNumber(lval *sqlSymType, ch int) { lval.str = fmt.Sprintf("could not make constant float from literal %q", lval.str) return } - lval.union.val = tree.NewNumVal(floatConst, lval.str, false /* negative */) + lval.union.val = NewNumValFn(floatConst, lval.str, false /* negative */) } else { if isHex && s.pos == start+2 { lval.id = ERROR @@ -680,7 +690,7 @@ func (s *scanner) scanNumber(lval *sqlSymType, ch int) { lval.str = fmt.Sprintf("could not make constant int from literal %q", lval.str) return } - lval.union.val = tree.NewNumVal(intConst, lval.str, false /* negative */) + lval.union.val = NewNumValFn(intConst, lval.str, false /* negative */) } } @@ -691,7 +701,7 @@ func (s *scanner) scanPlaceholder(lval *sqlSymType) { } lval.str = s.in[start:s.pos] - placeholder, err := tree.NewPlaceholder(lval.str) + placeholder, err := NewPlaceholderFn(lval.str) if err != nil { lval.id = ERROR lval.str = err.Error()