53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const assert = require('assert');
|
|
|
|
// Analytic
|
|
// -------
|
|
|
|
// The "Analytic" is an object holding any necessary info about a analytic function
|
|
// e.g row_number, rank, dense_rank,
|
|
class Analytic {
|
|
constructor(method, schema, alias, orderBy, partitions) {
|
|
this.schema = schema;
|
|
this.type = 'analytic';
|
|
this.method = method;
|
|
this.order = orderBy || [];
|
|
this.partitions = partitions || [];
|
|
this.alias = alias;
|
|
this.and = this;
|
|
|
|
this.grouping = 'columns';
|
|
}
|
|
|
|
partitionBy(column, direction) {
|
|
assert(
|
|
Array.isArray(column) || typeof column === 'string',
|
|
`The argument to an analytic partitionBy function must be either a string
|
|
or an array of string.`
|
|
);
|
|
|
|
if (Array.isArray(column)) {
|
|
this.partitions = this.partitions.concat(column);
|
|
} else {
|
|
this.partitions.push({ column: column, order: direction });
|
|
}
|
|
return this;
|
|
}
|
|
|
|
orderBy(column, direction) {
|
|
assert(
|
|
Array.isArray(column) || typeof column === 'string',
|
|
`The argument to an analytic orderBy function must be either a string
|
|
or an array of string.`
|
|
);
|
|
|
|
if (Array.isArray(column)) {
|
|
this.order = this.order.concat(column);
|
|
} else {
|
|
this.order.push({ column: column, order: direction });
|
|
}
|
|
return this;
|
|
}
|
|
}
|
|
|
|
module.exports = Analytic;
|