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