github.com/dolthub/go-mysql-server@v0.18.0/sql/planbuilder/window_frame_factory.go (about)

     1  package planbuilder
     2  
     3  import (
     4  	ast "github.com/dolthub/vitess/go/vt/sqlparser"
     5  
     6  	"github.com/dolthub/go-mysql-server/sql"
     7  )
     8  
     9  //go:generate go run ../../optgen/cmd/optgen/main.go -out window_frame_factory.og.go -pkg planbuilder frameFactory window_frame_factory.go
    10  
    11  func (b *Builder) getFrameStartNPreceding(inScope *scope, frame *ast.Frame) sql.Expression {
    12  	if frame == nil || frame.Extent.Start.Type != ast.ExprPreceding {
    13  		return nil
    14  	}
    15  	return b.buildScalar(inScope, frame.Extent.Start.Expr)
    16  }
    17  
    18  func (b *Builder) getFrameEndNPreceding(inScope *scope, frame *ast.Frame) sql.Expression {
    19  	if frame == nil || frame.Extent.End == nil || frame.Extent.End.Type != ast.ExprPreceding {
    20  		return nil
    21  	}
    22  	return b.buildScalar(inScope, frame.Extent.End.Expr)
    23  }
    24  
    25  func (b *Builder) getFrameStartNFollowing(inScope *scope, frame *ast.Frame) sql.Expression {
    26  	if frame == nil || frame.Extent.Start.Type != ast.ExprFollowing {
    27  		return nil
    28  	}
    29  	return b.buildScalar(inScope, frame.Extent.Start.Expr)
    30  }
    31  
    32  func (b *Builder) getFrameEndNFollowing(inScope *scope, frame *ast.Frame) sql.Expression {
    33  	if frame == nil || frame.Extent.End == nil || frame.Extent.End.Type != ast.ExprFollowing {
    34  		return nil
    35  	}
    36  	return b.buildScalar(inScope, frame.Extent.End.Expr)
    37  }
    38  
    39  func (b *Builder) getFrameStartCurrentRow(_ *scope, frame *ast.Frame) bool {
    40  	return frame != nil && frame.Extent.Start.Type == ast.CurrentRow
    41  }
    42  
    43  func (b *Builder) getFrameEndCurrentRow(_ *scope, frame *ast.Frame) bool {
    44  	if frame == nil {
    45  		return false
    46  	}
    47  	if frame.Extent.End == nil {
    48  		// if a frame is not null and only specifies start, default to current row
    49  		return true
    50  	}
    51  	return frame != nil && frame.Extent.End != nil && frame.Extent.End.Type == ast.CurrentRow
    52  }
    53  
    54  func (b *Builder) getFrameUnboundedPreceding(_ *scope, frame *ast.Frame) bool {
    55  	return frame != nil &&
    56  		frame.Extent.Start != nil && frame.Extent.Start.Type == ast.UnboundedPreceding ||
    57  		frame.Extent.End != nil && frame.Extent.End.Type == ast.UnboundedPreceding
    58  }
    59  
    60  func (b *Builder) getFrameUnboundedFollowing(_ *scope, frame *ast.Frame) bool {
    61  	return frame != nil &&
    62  		frame.Extent.Start != nil && frame.Extent.Start.Type == ast.UnboundedFollowing ||
    63  		frame.Extent.End != nil && frame.Extent.End.Type == ast.UnboundedFollowing
    64  }