All files / src/abap/2_statements/expressions sql_over.ts

100% Statements 30/30
100% Branches 1/1
100% Functions 1/1
100% Lines 30/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 311x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {Version} from "../../../version";
import {ParenLeftW, WParenRightW, WParenRight} from "../../1_lexer/tokens";
import {Expression, ver, seq, tok, altPrio, optPrio, plus, opt} from "../combi";
import {IStatementRunnable} from "../statement_runnable";
import {SQLFunctionInput} from "./sql_function_input";
import {SQLSource} from "./sql_source";
import {SQLOrderBy} from "./sql_order_by";
 
const lparen = tok(ParenLeftW);
const rparen = altPrio(tok(WParenRightW), tok(WParenRight));
 
export class SQLOver extends Expression {
  public getRunnable(): IStatementRunnable {
    const partitionBy = seq("PARTITION", "BY", plus(seq(SQLFunctionInput, opt(","))));
 
    const unboundedPreceding = seq("UNBOUNDED", "PRECEDING");
    const unboundedFollowing = seq("UNBOUNDED", "FOLLOWING");
    const currentRow = seq("CURRENT", "ROW");
    const numBound = seq(SQLSource, altPrio("PRECEDING", "FOLLOWING"));
    const bound = altPrio(unboundedPreceding, unboundedFollowing, currentRow, numBound);
    const windowFrameSpec = ver(Version.v757, seq("ROWS", "BETWEEN", bound, "AND", bound));
 
    return ver(Version.v757,
               seq("OVER", lparen,
                   optPrio(partitionBy),
                   optPrio(SQLOrderBy),
                   optPrio(windowFrameSpec),
                   rparen));
  }
}