MCPcopy Create free account
hub / github.com/dolthub/doltgresql / nodeWindowDef

Function nodeWindowDef

server/ast/window.go:42–111  ·  view source on GitHub ↗

nodeWindowDef handles *tree.WindowDef nodes.

(ctx *Context, node *tree.WindowDef)

Source from the content-addressed store, hash-verified

40
41// nodeWindowDef handles *tree.WindowDef nodes.
42func nodeWindowDef(ctx *Context, node *tree.WindowDef) (*vitess.WindowDef, error) {
43 if node == nil {
44 return nil, nil
45 }
46 partitionBy, err := nodeExprs(ctx, node.Partitions)
47 if err != nil {
48 return nil, err
49 }
50 orderBy, err := nodeOrderBy(ctx, node.OrderBy)
51 if err != nil {
52 return nil, err
53 }
54 var frame *vitess.Frame
55 if node.Frame != nil {
56 var unit vitess.FrameUnit
57 switch node.Frame.Mode {
58 case tree.RANGE:
59 unit = vitess.RangeUnit
60 case tree.ROWS:
61 unit = vitess.RowsUnit
62 case tree.GROUPS:
63 return nil, errors.Errorf("GROUPS is not yet supported")
64 default:
65 return nil, errors.Errorf("unknown window frame mode")
66 }
67 var bounds [2]*vitess.FrameBound
68 for i, bound := range []*tree.WindowFrameBound{node.Frame.Bounds.StartBound, node.Frame.Bounds.EndBound} {
69 if bound == nil {
70 continue
71 }
72 var boundType vitess.BoundType
73 switch bound.BoundType {
74 case tree.UnboundedPreceding:
75 boundType = vitess.UnboundedPreceding
76 case tree.OffsetPreceding:
77 boundType = vitess.ExprPreceding
78 case tree.CurrentRow:
79 boundType = vitess.CurrentRow
80 case tree.OffsetFollowing:
81 boundType = vitess.ExprFollowing
82 case tree.UnboundedFollowing:
83 boundType = vitess.UnboundedFollowing
84 default:
85 return nil, errors.Errorf("unknown window frame bound type")
86 }
87 boundExpr, err := nodeExpr(ctx, bound.OffsetExpr)
88 if err != nil {
89 return nil, err
90 }
91 bounds[i] = &vitess.FrameBound{
92 Expr: boundExpr,
93 Type: boundType,
94 }
95 }
96 frame = &vitess.Frame{
97 Unit: unit,
98 Extent: &vitess.FrameExtent{
99 Start: bounds[0],

Callers 2

nodeWindowFunction · 0.85
nodeFuncExprFunction · 0.85

Calls 4

nodeExprsFunction · 0.85
nodeOrderByFunction · 0.85
nodeExprFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected