@dbsp/nql 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isRankingWindowFunction } from '@dbsp/types';
1
2
  import { createToken, Lexer, CstParser } from 'chevrotain';
2
3
 
3
4
  // src/errors/types.ts
@@ -1008,7 +1009,6 @@ function compileMembership(expr, ctx, fns, aliasContext, outerAliases) {
1008
1009
  const result2 = {
1009
1010
  kind: "in",
1010
1011
  field,
1011
- values: [],
1012
1012
  subquery
1013
1013
  };
1014
1014
  if (inExpr.negated) {
@@ -1451,8 +1451,9 @@ function resolveBindingsInWhere(where, bindings) {
1451
1451
  if (!bindings || bindings.size === 0) return where;
1452
1452
  if (where.kind === "in") {
1453
1453
  const inWhere = where;
1454
- if (inWhere.values && inWhere.values.length === 1) {
1455
- const val = inWhere.values[0];
1454
+ const inValues = inWhere.subquery ? void 0 : inWhere.values;
1455
+ if (inValues && inValues.length === 1) {
1456
+ const val = inValues[0];
1456
1457
  if (val && typeof val === "object" && "$ref" in val) {
1457
1458
  const ref = val.$ref;
1458
1459
  if (bindings.has(ref)) {
@@ -1472,7 +1473,6 @@ function resolveBindingsInWhere(where, bindings) {
1472
1473
  return {
1473
1474
  kind: "in",
1474
1475
  field: inWhere.field,
1475
- values: [],
1476
1476
  subquery: cteRef
1477
1477
  };
1478
1478
  }
@@ -1507,8 +1507,6 @@ function extractBindName(stmt) {
1507
1507
  }
1508
1508
  return void 0;
1509
1509
  }
1510
-
1511
- // src/compiler/compile-select.ts
1512
1510
  function compileSelectClause(clause, ctx, fns) {
1513
1511
  if (clause.items.length === 1 && clause.items[0]?.type === "star") {
1514
1512
  return { type: "all" };
@@ -1633,17 +1631,36 @@ function compileSelectExpression(item, ctx, fns) {
1633
1631
  }
1634
1632
  return { field: f, direction: o.direction };
1635
1633
  }) : void 0;
1634
+ const over = {
1635
+ ...partitionBy && { partitionBy },
1636
+ ...orderBy && { orderBy }
1637
+ };
1638
+ const alias = exprItem.alias ?? fn;
1639
+ if (isRankingWindowFunction(fn)) {
1640
+ return {
1641
+ kind: "window",
1642
+ function: fn,
1643
+ alias,
1644
+ over
1645
+ };
1646
+ }
1647
+ if (fn === "lag" || fn === "lead") {
1648
+ return {
1649
+ kind: "window",
1650
+ function: fn,
1651
+ field: field ?? "",
1652
+ alias,
1653
+ ...offset !== void 0 && { offset },
1654
+ ...defaultValue !== void 0 && { defaultValue },
1655
+ over
1656
+ };
1657
+ }
1636
1658
  return {
1637
1659
  kind: "window",
1638
1660
  function: fn,
1639
1661
  ...field !== void 0 && { field },
1640
- alias: exprItem.alias ?? fn,
1641
- ...offset !== void 0 && { offset },
1642
- ...defaultValue !== void 0 && { defaultValue },
1643
- over: {
1644
- ...partitionBy && { partitionBy },
1645
- ...orderBy && { orderBy }
1646
- }
1662
+ alias,
1663
+ over
1647
1664
  };
1648
1665
  }
1649
1666
  if (expr.type === "subquery") {