github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/window_frame.go (about) 1 package plan 2 3 import ( 4 "fmt" 5 6 "github.com/dolthub/go-mysql-server/sql" 7 ) 8 9 //go:generate go run ../../optgen/cmd/optgen/main.go -out window_frame.og.go -pkg plan frame window_frame.go 10 11 // windowFrameBase maintains window frame bounds if 12 // set for a plan.Window's over clause. 13 // If no bounds set, plan.Window uses a nil windowFrameBase. 14 // We assume the parser errors for bound pairings that 15 // violate PRECEDING < CURRENT ROW < FOLLOWING ordering, 16 // and only a valid subset of fields will be set. 17 type windowFrameBase struct { 18 isRows bool 19 isRange bool 20 21 unboundedFollowing bool 22 unboundedPreceding bool 23 startCurrentRow bool 24 endCurrentRow bool 25 startNPreceding sql.Expression 26 startNFollowing sql.Expression 27 endNPreceding sql.Expression 28 endNFollowing sql.Expression 29 } 30 31 func (f *windowFrameBase) String() string { 32 if f == nil { 33 return "" 34 } 35 36 var boundType string 37 if f.isRange { 38 boundType = "RANGE" 39 } else { 40 boundType = "ROWS" 41 } 42 43 var startExtent string 44 switch { 45 case f.unboundedPreceding: 46 startExtent = "UNBOUNDED PRECEDING" 47 case f.startCurrentRow: 48 startExtent = "CURRENT ROW" 49 case f.startNFollowing != nil: 50 startExtent = fmt.Sprintf("%s FOLLOWING", f.startNFollowing.String()) 51 case f.startNPreceding != nil: 52 startExtent = fmt.Sprintf("%s PRECEDING", f.startNPreceding.String()) 53 default: 54 } 55 56 var endExtent string 57 switch { 58 case f.unboundedPreceding: 59 endExtent = "UNBOUNDED FOLLOWING" 60 case f.endCurrentRow: 61 endExtent = "CURRENT ROW" 62 case f.endNFollowing != nil: 63 endExtent = fmt.Sprintf("%s FOLLOWING", f.endNFollowing.String()) 64 case f.endNPreceding != nil: 65 endExtent = fmt.Sprintf("%s PRECEDING", f.endNPreceding.String()) 66 default: 67 } 68 69 if endExtent != "" { 70 return fmt.Sprintf("%s BETWEEN %s AND %s", boundType, startExtent, endExtent) 71 } else { 72 return fmt.Sprintf("%s %s", boundType, startExtent) 73 } 74 } 75 76 func (f *windowFrameBase) DebugString() string { 77 if f == nil { 78 return "" 79 } 80 return f.String() 81 }