squirreling 0.12.6 → 0.12.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squirreling",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "description": "Squirreling Async SQL Engine",
5
5
  "author": "Hyperparam",
6
6
  "homepage": "https://hyperparam.app",
@@ -448,11 +448,25 @@ function executeProject(plan, context) {
448
448
  // Common case: simple identifier. Avoid evaluateExpr overhead by
449
449
  // directly mapping to the child's cell, relying on the planner to
450
450
  // have normalized the identifier to match the child's column layout.
451
+ // If the identifier didn't normalize to a child cell key (e.g. the
452
+ // name refers to a table alias that produced no matching column),
453
+ // fall through to the evaluator so suffix-search and the proper
454
+ // ColumnNotFoundError apply instead of emitting an undefined cell.
451
455
  const id = col.expr
452
456
  const sourceName = id.prefix ? `${id.prefix}.${id.name}` : id.name
453
- cells[columns[colIdx]] = row.cells[sourceName]
454
- if (resolved && source) resolved[columns[colIdx]] = source[sourceName]
455
- colIdx++
457
+ const alias = columns[colIdx++]
458
+ if (sourceName in row.cells) {
459
+ cells[alias] = row.cells[sourceName]
460
+ if (resolved && source) resolved[alias] = source[sourceName]
461
+ } else {
462
+ const { expr } = col
463
+ cells[alias] = () => evaluateExpr({
464
+ node: expr,
465
+ row,
466
+ rowIndex: currentRowIndex,
467
+ context,
468
+ })
469
+ }
456
470
  } else {
457
471
  const alias = columns[colIdx++]
458
472
  cells[alias] = () => evaluateExpr({
@@ -14,8 +14,13 @@ import { ParseError } from './parseErrors.js'
14
14
  */
15
15
  export function findAggregate(expr) {
16
16
  if (!expr) return undefined
17
- if (expr.type === 'function' && isAggregateFunc(expr.funcName.toUpperCase())) {
18
- return expr
17
+ if (expr.type === 'function') {
18
+ if (isAggregateFunc(expr.funcName.toUpperCase())) return expr
19
+ for (const arg of expr.args) {
20
+ const found = findAggregate(arg)
21
+ if (found) return found
22
+ }
23
+ return undefined
19
24
  }
20
25
  if (expr.type === 'binary') {
21
26
  return findAggregate(expr.left) || findAggregate(expr.right)