import { AnyExpression, Condition, Expression, ToType } from '../expressions'; import { Template } from '../template'; import { BigintType, DoubleType, IntegerArg, IntegerType } from '../types'; export interface WindowBoundConfig { type: 'PRECEDING' | 'UNBOUNDED PRECEDING' | 'CURRENT ROW' | 'FOLLOWING' | 'UNBOUNDED FOLLOWING'; offset?: any; } export interface WindowDefinitionConfig { name?: string; partitionBy?: AnyExpression[]; orderBy?: (AnyExpression | { by: AnyExpression; direction?: 'ASC' | 'DESC'; using?: string; nulls?: 'FIRST' | 'LAST'; })[]; frame?: { type: 'RANGE' | 'ROWS' | 'GROUPS'; start: WindowBoundConfig; end?: WindowBoundConfig; exclude?: 'CURRENT ROW' | 'GROUP' | 'TIES' | 'NO OTHERS'; }; } export declare const stringifyWindowDefinition: (config: WindowDefinitionConfig) => Template; export declare const stringifyFrame: (config: Exclude) => Template; export interface WindowConfig { filterWhere?: Condition; over: WindowDefinitionConfig; } export declare const stringifyWindowConfig: (config?: WindowConfig | undefined) => Template; /** * @description Returns the number of the current row within its partition, counting from 1. * * @signature row_number () → bigint */ export declare function ROW_NUMBER(window: WindowConfig): Expression; /** * @description Returns the rank of the current row, with gaps; that is, the * row_number of the first row in its peer group. * * @signature rank () → bigint */ export declare function RANK(window: WindowConfig): Expression; /** * @description Returns the rank of the current row, without gaps; this function effectively * counts peer groups. * * @signature dense_rank () → bigint */ export declare function DENSE_RANK(window: WindowConfig): Expression; /** * @description Returns the relative rank of the current row, that is (rank - 1) / (total partition rows - 1). * The value thus ranges from 0 to 1 inclusive. * * @signature percent_rank () → double precision */ export declare function PERCENT_RANK(window: WindowConfig): Expression; /** * @description Returns the cumulative distribution, that is * (number of partition rows preceding or peers with current row) / (total partition rows). * The value thus ranges from 1/N to 1. * * @signature cume_dist () → double precision */ export declare function CUME_DIST(window?: WindowConfig): Expression; /** * @description Returns an integer ranging from 1 to the argument value, dividing the * partition as equally as possible. * * @signature ntile ( num_buckets integer ) → integer */ export declare function NTILE(buckets: IntegerArg, window: WindowConfig): Expression; /** * @description Returns value evaluated at the row that is offset rows before the * current row within the partition; if there is no such row, instead * returns default (which must be of the same type as value). Both * offset and default are evaluated with respect to the current row. If * omitted, offset defaults to 1 and default to NULL. * * @signature lag ( value anyelement [, offset integer [, default anyelement ]] ) → anyelement */ export declare function LAG(value: T, window: WindowConfig): Expression>; export declare function LAG(value: T, offset: IntegerArg, window: WindowConfig): Expression>; export declare function LAG(value: T, offset: IntegerArg, def: T, window: WindowConfig): Expression>; /** * @description Returns value evaluated at the row that is offset rows after the * current row within the partition; if there is no such row, instead * returns default (which must be of the same type as value). Both * offset and default are evaluated with respect to the current row. If * omitted, offset defaults to 1 and default to NULL. * * @signature lead ( value anyelement [, offset integer [, default anyelement ]] ) → anyelement */ export declare function LEAD(value: T, window: WindowConfig): Expression>; export declare function LEAD(value: T, offset: IntegerArg, window: WindowConfig): Expression>; export declare function LEAD(value: T, offset: IntegerArg, def: T, window: WindowConfig): Expression>; /** * @description Returns value evaluated at the row that is the first row of * the window frame. * * @signature first_value ( value anyelement ) → anyelement */ export declare function FIRST_VALUE(value: T, window: WindowConfig): Expression>; /** * @description Returns value evaluated at the row that is the last row of * the window frame. * * @signature last_value ( value anyelement ) → anyelement */ export declare function LAST_VALUE(value: T, window: WindowConfig): Expression>; /** * @description Returns value evaluated at the row that is the n'th row of * the window frame (counting from 1); returns NULL if there is no * such row. * * @signature nth_value ( value anyelement, n integer ) → anyelement */ export declare function NTH_VALUE(value: T, n: IntegerArg, window: WindowConfig): Expression>;