Skip to content

Commit 4f0fe29

Browse files
Merge pull request #9 from stackql/feature/postgres-casting
postgres-suffix-casting
2 parents 5cf1612 + c1f8d40 commit 4f0fe29

File tree

6 files changed

+3127
-3019
lines changed

6 files changed

+3127
-3019
lines changed

go/vt/sqlparser/ast.go

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ type (
727727
// ListArg represents a named list argument.
728728
ListArg []byte
729729

730+
// ListArgConcatamer represents a concatamer string of apparent list arguments / postgres cast operators.
731+
ListArgConcatamer []ListArg
732+
730733
// ValTuple represents a tuple of actual values.
731734
ValTuple Exprs
732735

@@ -742,6 +745,12 @@ type (
742745
Expr Expr
743746
}
744747

748+
// UnaryCastConcatamerExpr represents an expression with a casting concatamer suffix.
749+
UnaryCastConcatamerExpr struct {
750+
CastConcatamer ListArgConcatamer
751+
Expr Expr
752+
}
753+
745754
// IntervalExpr represents a date-time INTERVAL expression.
746755
IntervalExpr struct {
747756
Expr Expr
@@ -843,36 +852,37 @@ type (
843852
)
844853

845854
// iExpr ensures that only expressions nodes can be assigned to a Expr
846-
func (*AndExpr) iExpr() {}
847-
func (*OrExpr) iExpr() {}
848-
func (*XorExpr) iExpr() {}
849-
func (*NotExpr) iExpr() {}
850-
func (*ComparisonExpr) iExpr() {}
851-
func (*RangeCond) iExpr() {}
852-
func (*IsExpr) iExpr() {}
853-
func (*ExistsExpr) iExpr() {}
854-
func (*SQLVal) iExpr() {}
855-
func (*NullVal) iExpr() {}
856-
func (BoolVal) iExpr() {}
857-
func (*ColName) iExpr() {}
858-
func (ValTuple) iExpr() {}
859-
func (*Subquery) iExpr() {}
860-
func (ListArg) iExpr() {}
861-
func (*BinaryExpr) iExpr() {}
862-
func (*UnaryExpr) iExpr() {}
863-
func (*IntervalExpr) iExpr() {}
864-
func (*CollateExpr) iExpr() {}
865-
func (*FuncExpr) iExpr() {}
866-
func (*TimestampFuncExpr) iExpr() {}
867-
func (*CurTimeFuncExpr) iExpr() {}
868-
func (*CaseExpr) iExpr() {}
869-
func (*ValuesFuncExpr) iExpr() {}
870-
func (*ConvertExpr) iExpr() {}
871-
func (*SubstrExpr) iExpr() {}
872-
func (*ConvertUsingExpr) iExpr() {}
873-
func (*MatchExpr) iExpr() {}
874-
func (*GroupConcatExpr) iExpr() {}
875-
func (*Default) iExpr() {}
855+
func (*AndExpr) iExpr() {}
856+
func (*OrExpr) iExpr() {}
857+
func (*XorExpr) iExpr() {}
858+
func (*NotExpr) iExpr() {}
859+
func (*ComparisonExpr) iExpr() {}
860+
func (*RangeCond) iExpr() {}
861+
func (*IsExpr) iExpr() {}
862+
func (*ExistsExpr) iExpr() {}
863+
func (*SQLVal) iExpr() {}
864+
func (*NullVal) iExpr() {}
865+
func (BoolVal) iExpr() {}
866+
func (*ColName) iExpr() {}
867+
func (ValTuple) iExpr() {}
868+
func (*Subquery) iExpr() {}
869+
func (ListArg) iExpr() {}
870+
func (*BinaryExpr) iExpr() {}
871+
func (*UnaryExpr) iExpr() {}
872+
func (*UnaryCastConcatamerExpr) iExpr() {}
873+
func (*IntervalExpr) iExpr() {}
874+
func (*CollateExpr) iExpr() {}
875+
func (*FuncExpr) iExpr() {}
876+
func (*TimestampFuncExpr) iExpr() {}
877+
func (*CurTimeFuncExpr) iExpr() {}
878+
func (*CaseExpr) iExpr() {}
879+
func (*ValuesFuncExpr) iExpr() {}
880+
func (*ConvertExpr) iExpr() {}
881+
func (*SubstrExpr) iExpr() {}
882+
func (*ConvertUsingExpr) iExpr() {}
883+
func (*MatchExpr) iExpr() {}
884+
func (*GroupConcatExpr) iExpr() {}
885+
func (*Default) iExpr() {}
876886

877887
// Exprs represents a list of value expressions.
878888
// It's not a valid expression because it's not parenthesized.
@@ -1766,6 +1776,15 @@ func (node *BinaryExpr) Format(buf *TrackedBuffer) {
17661776
buf.astPrintf(node, "%v %s %v", node.Left, node.Operator, node.Right)
17671777
}
17681778

1779+
// Format formats the node.
1780+
func (node *UnaryCastConcatamerExpr) Format(buf *TrackedBuffer) {
1781+
var s string
1782+
for _, n := range node.CastConcatamer {
1783+
s = s + string(n)
1784+
}
1785+
buf.astPrintf(node, "%v%s", node.Expr, s)
1786+
}
1787+
17691788
// Format formats the node.
17701789
func (node *UnaryExpr) Format(buf *TrackedBuffer) {
17711790
if _, unary := node.Expr.(*UnaryExpr); unary {

go/vt/sqlparser/ast_funcs.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ func (node TableName) IsEmpty() bool {
350350
return node.Name.IsEmpty()
351351
}
352352

353+
func (lac ListArgConcatamer) String() string {
354+
var rv string
355+
for _, entry := range lac {
356+
rv = rv + string(entry)
357+
}
358+
return rv
359+
}
360+
353361
// ToViewName returns a TableName acceptable for use as a VIEW. VIEW names are
354362
// always lowercase, so ToViewName lowercasese the name. Databases are case-sensitive
355363
// so Qualifier is left untouched.
@@ -544,7 +552,7 @@ func NewExecVarDef(colIdent ColIdent, val Expr) ExecVarDef {
544552
}
545553
}
546554

547-
//NewSelect is used to create a select statement
555+
// NewSelect is used to create a select statement
548556
func NewSelect(comments Comments, exprs SelectExprs, selectOptions []string, from TableExprs, where *Where, groupBy GroupBy, having *Where) *Select {
549557
var cache *bool
550558
var distinct, straightJoinHint, sqlFoundRows bool
@@ -858,7 +866,7 @@ func (node *Union) SetLock(lock string) {
858866
node.Lock = lock
859867
}
860868

861-
//Unionize returns a UNION, either creating one or adding SELECT to an existing one
869+
// Unionize returns a UNION, either creating one or adding SELECT to an existing one
862870
func Unionize(lhs, rhs SelectStatement, typ string, by OrderBy, limit *Limit, lock string) *Union {
863871
union, isUnion := lhs.(*Union)
864872
if isUnion {

0 commit comments

Comments
 (0)