data-finder-ts 0.1.3 → 0.1.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/README.md +17 -55
- package/dist/{chunk-V647VNMY.js → chunk-4JVW4TAB.js} +59 -14
- package/dist/chunk-4JVW4TAB.js.map +1 -0
- package/dist/{chunk-5K2Z3YDY.js → chunk-4LNZV6EN.js} +138 -31
- package/dist/chunk-4LNZV6EN.js.map +1 -0
- package/dist/{chunk-6QTCGJWX.js → chunk-FJYA2ASS.js} +46 -8
- package/dist/chunk-FJYA2ASS.js.map +1 -0
- package/dist/{chunk-DFYZVBII.js → chunk-MH4XMYVB.js} +186 -142
- package/dist/chunk-MH4XMYVB.js.map +1 -0
- package/dist/{chunk-EYXBYV2X.js → chunk-PMPLCEWQ.js} +2 -2
- package/dist/{chunk-3SSWFES4.js → chunk-UYMOE6YU.js} +64 -3
- package/dist/chunk-UYMOE6YU.js.map +1 -0
- package/dist/datafinder/attribute.cjs +64 -13
- package/dist/datafinder/attribute.cjs.map +1 -1
- package/dist/datafinder/attribute.d.cts +48 -7
- package/dist/datafinder/attribute.d.ts +48 -7
- package/dist/datafinder/attribute.js +2 -2
- package/dist/datafinder/runner.cjs +389 -140
- package/dist/datafinder/runner.cjs.map +1 -1
- package/dist/datafinder/runner.d.cts +14 -3
- package/dist/datafinder/runner.d.ts +14 -3
- package/dist/datafinder/runner.js +12 -6
- package/dist/datafinder/sql-generator.cjs +344 -138
- package/dist/datafinder/sql-generator.cjs.map +1 -1
- package/dist/datafinder/sql-generator.d.cts +4 -13
- package/dist/datafinder/sql-generator.d.ts +4 -13
- package/dist/datafinder/sql-generator.js +5 -7
- package/dist/datafinder/typed-attributes.cjs +199 -41
- package/dist/datafinder/typed-attributes.cjs.map +1 -1
- package/dist/datafinder/typed-attributes.d.cts +120 -13
- package/dist/datafinder/typed-attributes.d.ts +120 -13
- package/dist/datafinder/typed-attributes.js +3 -3
- package/dist/index.cjs +507 -176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -15
- package/dist/index.d.ts +16 -15
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/dist/model/milestoning.cjs.map +1 -1
- package/dist/model/milestoning.js +2 -2
- package/dist/model/relational.cjs +66 -1
- package/dist/model/relational.cjs.map +1 -1
- package/dist/model/relational.d.cts +47 -2
- package/dist/model/relational.d.ts +47 -2
- package/dist/model/relational.js +9 -1
- package/package.json +4 -2
- package/dist/chunk-3SSWFES4.js.map +0 -1
- package/dist/chunk-5K2Z3YDY.js.map +0 -1
- package/dist/chunk-6QTCGJWX.js.map +0 -1
- package/dist/chunk-DFYZVBII.js.map +0 -1
- package/dist/chunk-V647VNMY.js.map +0 -1
- /package/dist/{chunk-EYXBYV2X.js.map → chunk-PMPLCEWQ.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/datafinder/sql-generator.ts"],"sourcesContent":["import { Attribute } from './attribute';\nimport {\n RelationalOperationElement,\n Operation,\n NoOperation,\n ConstantOperation,\n StringConstantOperation,\n IntegerConstantOperation,\n FloatConstantOperation,\n DateConstantOperation,\n DateTimeConstantOperation,\n BooleanConstantOperation,\n DecimalConstantOperation,\n LogicalOperation,\n LogicalOperator,\n ComparisonOperation,\n ComparisonOperator,\n IsNullOperation,\n IsNotNullOperation,\n AggregateOperation,\n AggregateOperator,\n ScalarFunctionOperation,\n ScalarFunction,\n DateExtractOperation,\n DateArithmeticOperation,\n DateDiffOperation,\n WindowFunction,\n WindowFunctionOperation,\n WindowSpecification,\n Column,\n ColumnWithJoin,\n Table,\n JoinOperation,\n JoinTreeNodeOperation,\n SortOperation,\n SortDirection,\n CountAllOperation,\n UnaryOperation,\n Alias,\n ExistsOperation,\n NotExistsOperation,\n SelectOperation,\n} from '../model/relational';\nimport {\n MilestonedTable,\n BiTemporalColumns,\n BusinessDateAndProcessingTemporalColumns,\n ProcessingTemporalColumns,\n SingleBusinessDateColumn,\n} from '../model/milestoning';\nimport { DateAttribute, DateTimeAttribute } from './typed-attributes';\n\nclass TableAlias {\n constructor(readonly table: string, readonly alias: string) {}\n}\n\nclass TableAliasColumn extends RelationalOperationElement {\n constructor(readonly column: Column, readonly tableAlias: TableAlias) { super(); }\n}\n\nclass Join {\n constructor(\n readonly source: TableAliasColumn,\n readonly target: TableAliasColumn,\n readonly filterOp?: RelationalOperationElement,\n ) {}\n}\n\nfunction sqlFormatDatetime(value: Date): string {\n const pad = (n: number, w = 2) => String(n).padStart(w, '0');\n return `'${value.getUTCFullYear()}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())} ${pad(value.getUTCHours())}:${pad(value.getUTCMinutes())}:${pad(value.getUTCSeconds())}'`;\n}\n\nfunction sqlFormatDate(value: Date): string {\n const pad = (n: number) => String(n).padStart(2, '0');\n return `'${value.getUTCFullYear()}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())}'`;\n}\n\nconst LOGICAL_OPERATOR_STR: Record<LogicalOperator, string> = {\n [LogicalOperator.AND]: ' AND ',\n [LogicalOperator.OR]: ' OR ',\n};\n\nconst COMPARISON_OPERATOR_STR: Record<ComparisonOperator, string> = {\n [ComparisonOperator.EQUAL]: ' = ',\n [ComparisonOperator.NOT_EQUAL]: ' <> ',\n [ComparisonOperator.LESS_THAN]: ' < ',\n [ComparisonOperator.GREATER_THAN]: ' > ',\n [ComparisonOperator.LESS_THAN_OR_EQUAL_TO]: ' <= ',\n [ComparisonOperator.GREATER_THAN_OR_EQUAL_TO]: ' >= ',\n [ComparisonOperator.LIKE]: ' LIKE ',\n [ComparisonOperator.NOT_LIKE]: ' NOT LIKE ',\n};\n\nconst AGGREGATE_SQL_NAMES: Partial<Record<AggregateOperator, string>> = {\n [AggregateOperator.AVERAGE]: 'AVG',\n};\n\nconst WINDOW_SQL_NAMES: Record<WindowFunction, string> = {\n [WindowFunction.ROW_NUMBER]: 'ROW_NUMBER',\n [WindowFunction.RANK]: 'RANK',\n [WindowFunction.DENSE_RANK]: 'DENSE_RANK',\n [WindowFunction.NTILE]: 'NTILE',\n [WindowFunction.LAG]: 'LAG',\n [WindowFunction.LEAD]: 'LEAD',\n [WindowFunction.FIRST_VALUE]: 'FIRST_VALUE',\n [WindowFunction.LAST_VALUE]: 'LAST_VALUE',\n [WindowFunction.CUME_DIST]: 'CUME_DIST',\n [WindowFunction.PERCENT_RANK]: 'PERCENT_RANK',\n};\n\nconst SCALAR_SQL_NAMES: Record<ScalarFunction, string> = {\n [ScalarFunction.ABS]: 'ABS',\n [ScalarFunction.CEILING]: 'CEILING',\n [ScalarFunction.FLOOR]: 'FLOOR',\n [ScalarFunction.MOD]: 'MOD',\n [ScalarFunction.POWER]: 'POWER',\n [ScalarFunction.SQRT]: 'SQRT',\n [ScalarFunction.ROUND]: 'ROUND',\n [ScalarFunction.UPPER]: 'UPPER',\n [ScalarFunction.LOWER]: 'LOWER',\n [ScalarFunction.TRIM]: 'TRIM',\n [ScalarFunction.LTRIM]: 'LTRIM',\n [ScalarFunction.RTRIM]: 'RTRIM',\n [ScalarFunction.LENGTH]: 'LENGTH',\n [ScalarFunction.REVERSE]: 'REVERSE',\n [ScalarFunction.LEFT]: 'LEFT',\n [ScalarFunction.RIGHT]: 'RIGHT',\n [ScalarFunction.REPEAT]: 'REPEAT',\n [ScalarFunction.REPLACE]: 'REPLACE',\n [ScalarFunction.SUBSTRING]: 'SUBSTRING',\n};\n\nfunction constantValueString(op: ConstantOperation): string {\n if (op instanceof StringConstantOperation) return \"'\" + op.value + \"'\";\n if (op instanceof DateConstantOperation) return sqlFormatDate(op.value);\n if (op instanceof DateTimeConstantOperation) return sqlFormatDatetime(op.value);\n if (op instanceof IntegerConstantOperation) return String(op.value);\n if (op instanceof FloatConstantOperation) return String(op.value);\n if (op instanceof BooleanConstantOperation) return op.value ? 'TRUE' : 'FALSE';\n if (op instanceof DecimalConstantOperation) return String(op.value);\n throw new Error('Unknown constant operation');\n}\n\nfunction windowSpecToString(window: WindowSpecification): string {\n const parts: string[] = [];\n if (window.partitionBy.length > 0) {\n parts.push('PARTITION BY ' + window.partitionBy.map(p => sqlOperationToString(p)).join(', '));\n }\n if (window.orderBy.length > 0) {\n parts.push('ORDER BY ' + window.orderBy.map(s =>\n sqlOperationToString(s.column) + (s.direction === SortDirection.ASC ? ' ASC' : ' DESC'),\n ).join(', '));\n }\n return 'OVER (' + parts.join(' ') + ')';\n}\n\nfunction sqlOperationToString(operation: RelationalOperationElement): string {\n if (operation instanceof TableAliasColumn) {\n return operation.tableAlias.alias + '.' + operation.column.name;\n }\n if (operation instanceof WindowFunctionOperation) {\n const fn = WINDOW_SQL_NAMES[operation.func];\n const parts: string[] = [];\n if (operation.element !== null && operation.element !== undefined) {\n parts.push(sqlOperationToString(operation.element));\n }\n if (operation.secondArg !== undefined) parts.push(String(operation.secondArg));\n for (const arg of operation.extraArgs) {\n parts.push(typeof arg === 'string' ? \"'\" + arg + \"'\" : String(arg));\n }\n const sql = fn + '(' + parts.join(', ') + ')';\n return sql + (operation.window !== undefined ? ' ' + windowSpecToString(operation.window) : ' OVER ()');\n }\n if (operation instanceof AggregateOperation) {\n const fn = AGGREGATE_SQL_NAMES[operation.operator] ?? operation.operator;\n let sql = fn + '(' + sqlOperationToString(operation.element) + ')';\n if (operation.window !== undefined) {\n sql += ' ' + windowSpecToString(operation.window);\n }\n return sql;\n }\n if (operation instanceof ScalarFunctionOperation) {\n const fn = SCALAR_SQL_NAMES[operation.func];\n const parts: string[] = [sqlOperationToString(operation.element)];\n if (operation.secondArg !== undefined) parts.push(String(operation.secondArg));\n for (const arg of operation.extraArgs) {\n parts.push(typeof arg === 'string' ? \"'\" + arg + \"'\" : String(arg));\n }\n return fn + '(' + parts.join(', ') + ')';\n }\n if (operation instanceof DateExtractOperation) {\n return 'EXTRACT(' + operation.part + ' FROM ' + sqlOperationToString(operation.element) + ')';\n }\n if (operation instanceof DateArithmeticOperation) {\n const op = operation.isAdd ? '+' : '-';\n return sqlOperationToString(operation.element) + ' ' + op + ' INTERVAL ' + operation.n + ' ' + operation.unit;\n }\n if (operation instanceof DateDiffOperation) {\n const otherSql = sqlFormatDatetime(operation.other);\n return \"DATE_DIFF('\" + operation.unit.toLowerCase() + \"', \" + sqlOperationToString(operation.element) + ', ' + otherSql + ')';\n }\n if (operation instanceof CountAllOperation) return 'COUNT(*)';\n if (operation instanceof Alias) {\n return sqlOperationToString(operation.element) + ' AS \"' + operation.name + '\"';\n }\n throw new TypeError('Unknown operation in sqlOperationToString: ' + operation.constructor.name);\n}\n\nfunction embeddedOf(ref: Attribute | ColumnWithJoin): Attribute | ColumnWithJoin | undefined {\n return ref instanceof Attribute ? ref.embedded() : ref.embedded;\n}\n\nfunction findColumn(operation: RelationalOperationElement): ColumnWithJoin {\n if (operation instanceof UnaryOperation) return findColumn(operation.element);\n if (operation instanceof ColumnWithJoin) return operation;\n throw new TypeError('Cannot find ColumnWithJoin in: ' + operation.constructor.name);\n}\n\nfunction openEndClause(\n endAttr: DateTimeAttribute | DateAttribute,\n value: Date,\n infiniteDatetime?: string,\n): Operation {\n const gtOp = endAttr instanceof DateTimeAttribute ? endAttr.gt(value) : endAttr.gt(value);\n if (infiniteDatetime === undefined) {\n const colRef = new ColumnWithJoin(endAttr.column(), endAttr.parent());\n return new LogicalOperation(gtOp, LogicalOperator.OR, new IsNullOperation(colRef));\n }\n return gtOp;\n}\n\nfunction buildMilestoningFilterOperation(\n businessDate: Date | null,\n processingDatetime: Date | null,\n table: MilestonedTable,\n joinNode?: JoinTreeNodeOperation,\n): Operation | null {\n const mc = table.milestoningColumns;\n const ops: Operation[] = [];\n\n if (mc instanceof BiTemporalColumns) {\n if (businessDate !== null) {\n const dateFrom = new DateAttribute('business_date_from', mc.businessDateFromColumn.name, mc.businessDateFromColumn.type, mc.businessDateFromColumn.table!.qualifiedName, joinNode);\n const dateTo = new DateAttribute('business_date_to', mc.businessDateToColumn.name, mc.businessDateToColumn.type, mc.businessDateToColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(dateFrom.lte(businessDate), LogicalOperator.AND, openEndClause(dateTo, businessDate, mc.infiniteDatetime)));\n }\n if (processingDatetime !== null) {\n const startAt = new DateTimeAttribute('start_at', mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table!.qualifiedName, joinNode);\n const endAt = new DateTimeAttribute('end_at', mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(startAt.lte(processingDatetime), LogicalOperator.AND, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));\n }\n } else if (mc instanceof BusinessDateAndProcessingTemporalColumns) {\n if (businessDate !== null) {\n const businessAtt = new DateAttribute('business_date', mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table!.qualifiedName, joinNode);\n ops.push(businessAtt.eq(businessDate));\n }\n if (processingDatetime !== null) {\n const startAt = new DateTimeAttribute('start_at', mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table!.qualifiedName, joinNode);\n const endAt = new DateTimeAttribute('end_at', mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(startAt.lte(processingDatetime), LogicalOperator.AND, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));\n }\n } else if (mc instanceof ProcessingTemporalColumns && processingDatetime !== null) {\n const startAt = new DateTimeAttribute('start_at', mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table!.qualifiedName, joinNode);\n const endAt = new DateTimeAttribute('end_at', mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(startAt.lte(processingDatetime), LogicalOperator.AND, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));\n } else if (mc instanceof SingleBusinessDateColumn && businessDate !== null) {\n const businessAtt = new DateAttribute('business_date', mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table!.qualifiedName, joinNode);\n ops.push(businessAtt.eq(businessDate));\n }\n\n if (ops.length === 0) return null;\n if (ops.length === 1) return ops[0];\n return new LogicalOperation(ops[0], LogicalOperator.AND, ops[1]);\n}\n\n/**\n * Like buildMilestoningFilterOperation but applies a business-date range filter.\n *\n * Bitemporal tables use interval overlap:\n * business_date_from_col <= businessDateTo AND business_date_to_col > businessDateFrom\n * Single-date tables:\n * business_date >= businessDateFrom AND business_date <= businessDateTo\n * Processing-date filtering is point-in-time, as in the normal path.\n */\nfunction buildMilestoningFilterOperationForDateRange(\n businessDateFrom: Date | null,\n businessDateTo: Date | null,\n processingDatetime: Date | null,\n table: MilestonedTable,\n joinNode?: JoinTreeNodeOperation,\n): Operation | null {\n const mc = table.milestoningColumns;\n const ops: Operation[] = [];\n const hasRange = businessDateFrom !== null && businessDateTo !== null;\n\n const processingOp = (m: BiTemporalColumns | BusinessDateAndProcessingTemporalColumns | ProcessingTemporalColumns): Operation => {\n const startAt = new DateTimeAttribute('start_at', m.startAtColumn.name, m.startAtColumn.type, m.startAtColumn.table!.qualifiedName, joinNode);\n const endAt = new DateTimeAttribute('end_at', m.endAtColumn.name, m.endAtColumn.type, m.endAtColumn.table!.qualifiedName, joinNode);\n return new LogicalOperation(startAt.lte(processingDatetime!), LogicalOperator.AND, openEndClause(endAt, processingDatetime!, m.infiniteDatetime));\n };\n\n if (mc instanceof BiTemporalColumns) {\n if (hasRange) {\n const dateFrom = new DateAttribute('business_date_from', mc.businessDateFromColumn.name, mc.businessDateFromColumn.type, mc.businessDateFromColumn.table!.qualifiedName, joinNode);\n const dateTo = new DateAttribute('business_date_to', mc.businessDateToColumn.name, mc.businessDateToColumn.type, mc.businessDateToColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(dateFrom.lte(businessDateTo!), LogicalOperator.AND, openEndClause(dateTo, businessDateFrom!, mc.infiniteDatetime)));\n }\n if (processingDatetime !== null) ops.push(processingOp(mc));\n } else if (mc instanceof BusinessDateAndProcessingTemporalColumns) {\n if (hasRange) {\n const businessAtt = new DateAttribute('business_date', mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(businessAtt.gte(businessDateFrom!), LogicalOperator.AND, businessAtt.lte(businessDateTo!)));\n }\n if (processingDatetime !== null) ops.push(processingOp(mc));\n } else if (mc instanceof ProcessingTemporalColumns) {\n if (processingDatetime !== null) ops.push(processingOp(mc));\n } else if (mc instanceof SingleBusinessDateColumn && hasRange) {\n const businessAtt = new DateAttribute('business_date', mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table!.qualifiedName, joinNode);\n ops.push(new LogicalOperation(businessAtt.gte(businessDateFrom!), LogicalOperator.AND, businessAtt.lte(businessDateTo!)));\n }\n\n if (ops.length === 0) return null;\n if (ops.length === 1) return ops[0];\n return new LogicalOperation(ops[0], LogicalOperator.AND, ops[1]);\n}\n\ntype RefVisitor = (ref: Attribute | ColumnWithJoin) => void;\n\ntype NodeVisitor = (node: JoinTreeNodeOperation) => void;\n\n/**\n * Call `visit` for every Attribute/ColumnWithJoin referenced anywhere in `op`, and `visitExists` for the\n * join node of every exists()/notExists(). The latter are not attribute references, so they don't count\n * against whether other references to the same node can be satisfied by an embedded alternate.\n */\nfunction walkRefs(\n op: RelationalOperationElement | null | undefined,\n visit: RefVisitor,\n visitExists?: NodeVisitor,\n): void {\n if (op === null || op === undefined) return;\n if (op instanceof Attribute || op instanceof ColumnWithJoin) {\n visit(op);\n } else if (op instanceof ExistsOperation || op instanceof NotExistsOperation) {\n visitExists?.(op.node);\n } else if (op instanceof AggregateOperation) {\n walkRefs(op.element, visit, visitExists);\n if (op.window) walkWindowSpec(op.window, visit, visitExists);\n } else if (op instanceof WindowFunctionOperation) {\n if (op.element) walkRefs(op.element, visit, visitExists);\n if (op.window) walkWindowSpec(op.window, visit, visitExists);\n } else if (op instanceof ScalarFunctionOperation || op instanceof DateExtractOperation ||\n op instanceof DateArithmeticOperation || op instanceof DateDiffOperation ||\n op instanceof IsNullOperation || op instanceof IsNotNullOperation) {\n walkRefs((op as UnaryOperation).element, visit, visitExists);\n } else if (op instanceof SortOperation) {\n walkRefs(op.column, visit, visitExists);\n } else if (op instanceof LogicalOperation || op instanceof ComparisonOperation) {\n walkRefs((op as any).left, visit, visitExists);\n walkRefs((op as any).right, visit, visitExists);\n }\n}\n\nfunction walkWindowSpec(window: WindowSpecification, visit: RefVisitor, visitExists?: NodeVisitor): void {\n for (const p of window.partitionBy) walkRefs(p, visit, visitExists);\n for (const s of window.orderBy) walkRefs(s.column, visit, visitExists);\n}\n\n/**\n * Translate property-equality filters given to a related finder (e.g. `ef.projects({ code: 'ALPHA' })`)\n * into a relational filter on the join node. `columnMap` maps property ids to [column, type, table].\n */\nfunction buildJoinFilterFromProperties(\n node: JoinTreeNodeOperation,\n filter: Record<string, unknown>,\n columnMap: Record<string, [string, string, string]>,\n): Operation {\n const ops: Operation[] = [];\n for (const [key, value] of Object.entries(filter)) {\n const entry = columnMap[key];\n if (entry === undefined) {\n throw new Error(`Unknown property '${key}' — valid properties are: ${Object.keys(columnMap).sort().join(', ')}`);\n }\n const [name, type, table] = entry;\n const col = new ColumnWithJoin(new Column(name, type, table), node);\n let constant: ConstantOperation;\n if (typeof value === 'boolean') constant = new BooleanConstantOperation(value);\n else if (typeof value === 'number') constant = Number.isInteger(value) ? new IntegerConstantOperation(value) : new FloatConstantOperation(value);\n else if (value instanceof Date) constant = type.toUpperCase() === 'DATE' ? new DateConstantOperation(value) : new DateTimeConstantOperation(value);\n else constant = new StringConstantOperation(String(value));\n ops.push(new ComparisonOperation(col, ComparisonOperator.EQUAL, constant));\n }\n return ops.reduce((acc, op) => new LogicalOperation(acc, LogicalOperator.AND, op));\n}\n\n/**\n * The nodes plus every ancestor, each once, ancestors first. The SQL generator joins a node's\n * ancestors whenever it joins the node, so each of them needs its join filter set too, not only the\n * nodes an expression refers to directly.\n */\nfunction withAncestors(nodes: Iterable<JoinTreeNodeOperation>): JoinTreeNodeOperation[] {\n const ordered = new Set<JoinTreeNodeOperation>();\n const add = (node: JoinTreeNodeOperation): void => {\n if (ordered.has(node)) return;\n if (node.parent !== undefined) add(node.parent);\n ordered.add(node);\n };\n for (const node of nodes) add(node);\n return [...ordered];\n}\n\nfunction buildQueryOperation(\n businessDate: Date | null,\n processingDatetime: Date | null,\n columns: (Attribute | RelationalOperationElement)[],\n table: Table,\n op: RelationalOperationElement,\n orderBy: SortOperation[] = [],\n groupBy: Attribute[] = [],\n limit?: number,\n businessDateTo: Date | null = null,\n): SelectOperation {\n let filter = op;\n const milestoningFor = (t: MilestonedTable, node?: JoinTreeNodeOperation) =>\n businessDateTo !== null\n ? buildMilestoningFilterOperationForDateRange(businessDate, businessDateTo, processingDatetime, t, node)\n : buildMilestoningFilterOperation(businessDate, processingDatetime, t, node);\n\n if (table instanceof MilestonedTable) {\n const milestonedOp = milestoningFor(table);\n if (milestonedOp !== null) {\n filter = filter instanceof NoOperation\n ? milestonedOp\n : new LogicalOperation(filter, LogicalOperator.AND, milestonedOp);\n }\n }\n\n const requiredJoins = new Set<JoinTreeNodeOperation>();\n const collect: RefVisitor = ref => {\n const parent = ref instanceof Attribute ? ref.parent() : ref.parent;\n if (parent !== undefined) requiredJoins.add(parent);\n };\n const collectNode: NodeVisitor = node => requiredJoins.add(node);\n for (const col of columns) walkRefs(col, collect, collectNode);\n for (const expr of groupBy) walkRefs(expr, collect, collectNode);\n for (const sort of orderBy) walkRefs(sort, collect, collectNode);\n walkRefs(op, collect, collectNode);\n\n const joinFilters = new Map<JoinTreeNodeOperation, Operation>();\n for (const node of withAncestors(requiredJoins)) {\n let combined: Operation | undefined;\n if (Object.keys(node.join.filterKwargs).length > 0) {\n combined = buildJoinFilterFromProperties(node, node.join.filterKwargs, node.join.filterColumnMap);\n }\n if (node.join.target instanceof MilestonedTable) {\n const milestonedOp = milestoningFor(node.join.target, node);\n if (milestonedOp !== null) {\n combined = combined === undefined ? milestonedOp : new LogicalOperation(combined, LogicalOperator.AND, milestonedOp);\n }\n }\n if (combined !== undefined) joinFilters.set(node, combined);\n }\n\n return new SelectOperation(columns, filter, orderBy, groupBy, limit, table, joinFilters);\n}\n\nclass SQLQueryGenerator {\n private _select: Alias[] = [];\n private _from: Set<TableAlias> = new Set();\n private _join: Join[] = [];\n private _groupByParts: string[] = [];\n private _orderByParts: string[] = [];\n private _where = '';\n private _limit?: number;\n private _tableAliasIncr = 0;\n private _tableAliasesByTable = new Map<unknown, TableAlias>();\n private _addedJoinIds = new Set<JoinTreeNodeOperation>();\n private _rootTable?: Table;\n private _elidableNodes = new Set<JoinTreeNodeOperation>();\n private _joinFilters: ReadonlyMap<JoinTreeNodeOperation, Operation> = new Map();\n\n generate(select: SelectOperation): void {\n this._rootTable = select.table;\n this._elidableNodes = this._computeElidableNodes(select);\n this._joinFilters = select.joinFilters;\n if (this._rootTable !== undefined) {\n this._from.add(this._tableAliasForTable(this._rootTable.qualifiedName, this._rootTable.qualifiedName));\n }\n this.processSelect(select.display);\n this._where = this.buildFilter(select.filter);\n const groupByJoins = new Map<JoinTreeNodeOperation, JoinTreeNodeOperation>();\n for (const expr of select.groupBy) {\n this._collectRequiredJoins(expr, groupByJoins);\n }\n for (const node of groupByJoins.values()) {\n this._addJoin(node);\n }\n this._groupByParts = select.groupBy.map(a => this._attrToColString(a as Attribute));\n this._orderByParts = select.orderBy.map(s =>\n this.buildFilter(s.column) + (s.direction === SortDirection.ASC ? ' ASC' : ' DESC'),\n );\n this._limit = select.limit;\n }\n\n private _attrToColString(attr: Attribute): string {\n const { column, parent } = this._resolve(attr);\n const ta = this._tableAliasForTable(column.owner!, parent ?? column.owner!);\n return ta.alias + '.' + column.name;\n }\n\n private _collectRequiredJoins(op: RelationalOperationElement | null | undefined, out: Map<JoinTreeNodeOperation, JoinTreeNodeOperation>): void {\n walkRefs(op, ref => {\n const { parent } = this._resolve(ref);\n if (parent !== undefined) out.set(parent, parent);\n });\n }\n\n /**\n * Determine upfront which join nodes can be satisfied entirely by embedded (join-less) alternates:\n * a node is elidable when every reference to it has an embedded alternate. A reference without one\n * (e.g. a milestoning column) keeps the join for every reference to that node.\n */\n private _computeElidableNodes(select: SelectOperation): Set<JoinTreeNodeOperation> {\n const refsByNode = new Map<JoinTreeNodeOperation, (Attribute | ColumnWithJoin)[]>();\n const record = (ref: Attribute | ColumnWithJoin) => {\n const parent = ref instanceof Attribute ? ref.parent() : ref.parent;\n if (parent === undefined) return;\n const refs = refsByNode.get(parent);\n if (refs) refs.push(ref); else refsByNode.set(parent, [ref]);\n };\n for (const col of select.display) walkRefs(col, record);\n for (const expr of select.groupBy) walkRefs(expr, record);\n for (const sort of select.orderBy) walkRefs(sort, record);\n walkRefs(select.filter, record);\n\n const elidable = new Set<JoinTreeNodeOperation>();\n for (const [node, refs] of refsByNode) {\n if (refs.every(ref => embeddedOf(ref) !== undefined)) elidable.add(node);\n }\n return elidable;\n }\n\n /** The (column, parent) a reference should resolve to, substituting its embedded alternate when its join is elided. */\n private _resolve(ref: Attribute | ColumnWithJoin): { column: Column; parent?: JoinTreeNodeOperation } {\n const column = ref instanceof Attribute ? ref.column() : ref.column;\n const parent = ref instanceof Attribute ? ref.parent() : ref.parent;\n if (parent !== undefined && this._elidableNodes.has(parent)) {\n const embedded = embeddedOf(ref);\n if (embedded !== undefined) return this._resolve(embedded);\n }\n return { column, parent };\n }\n\n private _rewriteWindowSpec(window: WindowSpecification): WindowSpecification {\n const partitionBy = window.partitionBy.map(p => this._rewriteOperation(p));\n const orderBy = window.orderBy.map(s => new SortOperation(this._rewriteOperation(s.column) as ColumnWithJoin, s.direction));\n return new WindowSpecification(partitionBy, orderBy);\n }\n\n private _rewriteOperation(op: RelationalOperationElement): RelationalOperationElement {\n if (op instanceof Attribute || op instanceof ColumnWithJoin) {\n const { column, parent } = this._resolve(op);\n return new TableAliasColumn(column, this._tableAliasForTable(column.owner!, parent ?? column.owner!));\n }\n if (op instanceof Column) {\n const ta = this._tableAliasForTable(op.owner!, op.owner!);\n return new TableAliasColumn(op, ta);\n }\n if (op instanceof AggregateOperation) {\n return new AggregateOperation(\n this._rewriteOperation(op.element), op.operator, op.displayName,\n op.window ? this._rewriteWindowSpec(op.window) : undefined,\n );\n }\n if (op instanceof WindowFunctionOperation) {\n const el = op.element ? this._rewriteOperation(op.element) : null;\n return new WindowFunctionOperation(el, op.func, op.displayName, op.secondArg, [...op.extraArgs],\n op.window ? this._rewriteWindowSpec(op.window) : undefined);\n }\n if (op instanceof ScalarFunctionOperation) {\n return new ScalarFunctionOperation(this._rewriteOperation(op.element), op.func, op.displayName, op.secondArg, op.extraArgs);\n }\n if (op instanceof DateExtractOperation) {\n return new DateExtractOperation(this._rewriteOperation(op.element), op.part, op.displayName);\n }\n if (op instanceof DateArithmeticOperation) {\n return new DateArithmeticOperation(this._rewriteOperation(op.element), op.n, op.unit, op.isAdd, op.displayName);\n }\n if (op instanceof DateDiffOperation) {\n return new DateDiffOperation(this._rewriteOperation(op.element), (op as DateDiffOperation).other, (op as DateDiffOperation).unit, op.displayName);\n }\n return op;\n }\n\n private processSelect(cols: (Attribute | RelationalOperationElement)[]): void {\n const requiredJoins = new Map<JoinTreeNodeOperation, JoinTreeNodeOperation>();\n\n for (const col of cols) {\n this._collectRequiredJoins(col, requiredJoins);\n }\n for (const node of requiredJoins.values()) {\n this._addJoin(node);\n }\n\n for (const col of cols) {\n if (col instanceof Attribute) {\n const { column, parent: node } = this._resolve(col);\n let ta: TableAlias;\n if (node !== undefined) {\n ta = this._tableAliasForTable(column.owner!, node);\n } else {\n ta = this._tableAliasForTable(column.owner!, column.owner!);\n this._from.add(ta);\n }\n this._select.push(new Alias(new TableAliasColumn(column, ta), col.displayName()));\n } else if (col instanceof WindowFunctionOperation) {\n const rewritten = this._rewriteOperation(col) as WindowFunctionOperation;\n let alias: string;\n if (col.displayName) {\n alias = col.displayName;\n } else if ([WindowFunction.ROW_NUMBER, WindowFunction.RANK, WindowFunction.DENSE_RANK].includes(col.func)) {\n alias = col.func.replace(/_/g, ' ').replace(/\\b\\w/g, c => c.toUpperCase());\n } else if (col.element) {\n alias = col.func + ' ' + findColumn(col).column.name;\n } else {\n alias = col.func;\n }\n this._select.push(new Alias(rewritten, alias));\n } else if (col instanceof AggregateOperation) {\n const colNested = this._resolve(findColumn(col));\n const node = colNested.parent;\n let ta: TableAlias;\n if (node !== undefined) {\n ta = this._tableAliasForTable(colNested.column.owner!, node);\n } else {\n ta = this._tableAliasForTable(colNested.column.owner!, colNested.column.owner!);\n this._from.add(ta);\n }\n const alias = col.displayName ?? col.operator + ' ' + findColumn(col).column.name;\n const rewrittenAgg = new AggregateOperation(\n new TableAliasColumn(colNested.column, ta), col.operator, undefined,\n col.window ? this._rewriteWindowSpec(col.window) : undefined,\n );\n this._select.push(new Alias(rewrittenAgg, alias));\n } else if (col instanceof ScalarFunctionOperation) {\n const colNested = this._resolve(findColumn(col));\n const node = colNested.parent;\n let ta: TableAlias;\n if (node !== undefined) {\n ta = this._tableAliasForTable(colNested.column.owner!, node);\n } else {\n ta = this._tableAliasForTable(colNested.column.owner!, colNested.column.owner!);\n this._from.add(ta);\n }\n const alias = col.displayName ?? col.func + ' ' + findColumn(col).column.name;\n this._select.push(new Alias(\n new ScalarFunctionOperation(new TableAliasColumn(colNested.column, ta), col.func, undefined, col.secondArg, col.extraArgs),\n alias,\n ));\n } else if (col instanceof DateExtractOperation || col instanceof DateArithmeticOperation || col instanceof DateDiffOperation) {\n const colNested = this._resolve(findColumn(col as RelationalOperationElement));\n const node = colNested.parent;\n let ta: TableAlias;\n if (node !== undefined) {\n ta = this._tableAliasForTable(colNested.column.owner!, node);\n } else {\n ta = this._tableAliasForTable(colNested.column.owner!, colNested.column.owner!);\n this._from.add(ta);\n }\n const alias = (col as DateExtractOperation).displayName ?? findColumn(col as RelationalOperationElement).column.name;\n let aliasedOp: RelationalOperationElement;\n if (col instanceof DateExtractOperation) {\n aliasedOp = new DateExtractOperation(new TableAliasColumn(colNested.column, ta), col.part);\n } else if (col instanceof DateArithmeticOperation) {\n aliasedOp = new DateArithmeticOperation(new TableAliasColumn(colNested.column, ta), col.n, col.unit, col.isAdd);\n } else {\n aliasedOp = new DateDiffOperation(new TableAliasColumn(colNested.column, ta), (col as DateDiffOperation).other, (col as DateDiffOperation).unit);\n }\n this._select.push(new Alias(aliasedOp, alias));\n } else if (col instanceof CountAllOperation) {\n const ta = this._tableAliasForTable(col.table, col.table);\n this._from.add(ta);\n this._select.push(new Alias(col, 'Count'));\n }\n }\n }\n\n private _addJoin(node: JoinTreeNodeOperation): void {\n if (this._addedJoinIds.has(node)) return;\n if (node.parent !== undefined) this._addJoin(node.parent);\n this._addedJoinIds.add(node);\n\n const join = node.join;\n const left = join.left;\n const srcTa = this._tableAliasForTable(left.owner!, node.parent ?? left.owner!);\n if (node.parent === undefined) this._from.add(srcTa);\n const sc = new TableAliasColumn(left, srcTa);\n const right = join.right;\n const tc = new TableAliasColumn(right, this._tableAliasForTable(right.owner!, node));\n const queryFilter = this._joinFilters.get(node);\n const filterOp = join.filter !== undefined && queryFilter !== undefined\n ? new LogicalOperation(join.filter as Operation, LogicalOperator.AND, queryFilter)\n : join.filter ?? queryFilter;\n this._join.push(new Join(sc, tc, filterOp));\n }\n\n buildFilter(op: RelationalOperationElement): string {\n if (op instanceof NoOperation) return '';\n if (op instanceof ExistsOperation) {\n const col = op.node.join.right;\n return this.buildFilter(new ColumnWithJoin(col, op.node)) + ' IS NOT NULL';\n }\n if (op instanceof NotExistsOperation) {\n const col = op.node.join.right;\n return this.buildFilter(new ColumnWithJoin(col, op.node)) + ' IS NULL';\n }\n if (op instanceof IsNotNullOperation) return this.buildFilter(op.element) + ' IS NOT NULL';\n if (op instanceof IsNullOperation) return this.buildFilter(op.element) + ' IS NULL';\n if (op instanceof LogicalOperation) {\n let left = this.buildFilter(op.left);\n let right = this.buildFilter(op.right);\n if (op.left instanceof LogicalOperation) left = '(' + left + ')';\n if (op.right instanceof LogicalOperation) right = '(' + right + ')';\n return left + LOGICAL_OPERATOR_STR[op.operator] + right;\n }\n if (op instanceof ComparisonOperation) {\n return this.buildFilter(op.left) + COMPARISON_OPERATOR_STR[op.operator] + this.buildFilter(op.right);\n }\n if (op instanceof ConstantOperation) return constantValueString(op);\n if (op instanceof ColumnWithJoin) {\n const { column, parent: node } = this._resolve(op);\n let ta: TableAlias;\n if (node !== undefined) {\n ta = this._tableAliasForTable(column.owner!, node);\n this._addJoin(node);\n } else {\n ta = this._tableAliasForTable(column.owner!, column.owner!);\n }\n return ta.alias + '.' + column.name;\n }\n if (op instanceof Column) {\n const ta = this._tableAliasForTable(op.owner!, op.owner!);\n return ta.alias + '.' + op.name;\n }\n throw new Error('Unknown operation in buildFilter: ' + op.constructor.name);\n }\n\n private _tableAliasForTable(table: string, key: unknown): TableAlias {\n if (this._tableAliasesByTable.has(key)) {\n return this._tableAliasesByTable.get(key)!;\n }\n const ta = new TableAlias(table, 't' + this._tableAliasIncr++);\n this._tableAliasesByTable.set(key, ta);\n return ta;\n }\n\n buildQueryString(): string {\n const joins = this._join.map(j =>\n ' LEFT OUTER JOIN ' + j.target.tableAlias.table + ' AS ' + j.target.tableAlias.alias +\n ' ON ' + j.source.tableAlias.alias + '.' + j.source.column.name +\n ' = ' + j.target.tableAlias.alias + '.' + j.target.column.name +\n (j.filterOp ? ' AND ' + this.buildFilter(j.filterOp) : ''),\n );\n\n return 'SELECT ' + this._select.map(ca => sqlOperationToString(ca)).join(',') +\n ' FROM ' + Array.from(this._from).map(ta => ta.table + ' AS ' + ta.alias).join(',') +\n joins.join('') +\n this._buildWhere() +\n this._buildGroupBy() +\n this._buildOrderBy() +\n this._buildLimit();\n }\n\n private _buildWhere(): string {\n return this._where.length > 0 ? ' WHERE ' + this._where : '';\n }\n private _buildGroupBy(): string {\n return this._groupByParts.length > 0 ? ' GROUP BY ' + this._groupByParts.join(', ') : '';\n }\n private _buildOrderBy(): string {\n return this._orderByParts.length > 0 ? ' ORDER BY ' + this._orderByParts.join(', ') : '';\n }\n private _buildLimit(): string {\n return this._limit !== undefined ? ' LIMIT ' + this._limit : '';\n }\n}\n\nexport function selectSqlToString(selectOperation: SelectOperation): string {\n const qg = new SQLQueryGenerator();\n qg.generate(selectOperation);\n return qg.buildQueryString();\n}\n\nexport function toSql(\n businessDate: Date | null,\n processingDatetime: Date | null,\n columns: (Attribute | RelationalOperationElement)[],\n table: Table,\n op: RelationalOperationElement,\n orderBy: SortOperation[] = [],\n groupBy: Attribute[] = [],\n limit?: number,\n businessDateTo: Date | null = null,\n): string {\n const selectOp = buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy, groupBy, limit, businessDateTo);\n return selectSqlToString(selectOp);\n}\n\nexport { buildQueryOperation };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,IAAM,aAAN,MAAiB;AAAA,EACf,YAAqB,OAAwB,OAAe;AAAvC;AAAwB;AAAA,EAAgB;AAAA,EAAxC;AAAA,EAAwB;AAC/C;AAEA,IAAM,mBAAN,cAA+B,2BAA2B;AAAA,EACxD,YAAqB,QAAyB,YAAwB;AAAE,UAAM;AAAzD;AAAyB;AAAA,EAAmC;AAAA,EAA5D;AAAA,EAAyB;AAChD;AAEA,IAAM,OAAN,MAAW;AAAA,EACT,YACW,QACA,QACA,UACT;AAHS;AACA;AACA;AAAA,EACR;AAAA,EAHQ;AAAA,EACA;AAAA,EACA;AAEb;AAEA,SAAS,kBAAkB,OAAqB;AAC9C,QAAM,MAAM,CAAC,GAAW,IAAI,MAAM,OAAO,CAAC,EAAE,SAAS,GAAG,GAAG;AAC3D,SAAO,IAAI,MAAM,eAAe,CAAC,IAAI,IAAI,MAAM,YAAY,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,WAAW,CAAC,CAAC,IAAI,IAAI,MAAM,YAAY,CAAC,CAAC,IAAI,IAAI,MAAM,cAAc,CAAC,CAAC,IAAI,IAAI,MAAM,cAAc,CAAC,CAAC;AACtL;AAEA,SAAS,cAAc,OAAqB;A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|
2
2
|
Table
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UYMOE6YU.js";
|
|
4
4
|
|
|
5
5
|
// src/model/milestoning.ts
|
|
6
6
|
var MilestoningColumns = class {
|
|
@@ -87,4 +87,4 @@ export {
|
|
|
87
87
|
BiTemporalColumns,
|
|
88
88
|
MilestonedTable
|
|
89
89
|
};
|
|
90
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-PMPLCEWQ.js.map
|
|
@@ -366,6 +366,10 @@ var JoinOperation = class {
|
|
|
366
366
|
left;
|
|
367
367
|
right;
|
|
368
368
|
filter;
|
|
369
|
+
/** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */
|
|
370
|
+
filterKwargs = {};
|
|
371
|
+
/** Maps property ids to [column, type, table] for `filterKwargs`. */
|
|
372
|
+
filterColumnMap = {};
|
|
369
373
|
};
|
|
370
374
|
var JoinTreeNodeOperation = class {
|
|
371
375
|
constructor(join, parent) {
|
|
@@ -376,13 +380,19 @@ var JoinTreeNodeOperation = class {
|
|
|
376
380
|
parent;
|
|
377
381
|
};
|
|
378
382
|
var ColumnWithJoin = class extends RelationalOperationElement {
|
|
379
|
-
|
|
383
|
+
/**
|
|
384
|
+
* `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
|
|
385
|
+
* holds the same value without the join; the SQL generator uses it when the join can be elided.
|
|
386
|
+
*/
|
|
387
|
+
constructor(column, parent, embedded) {
|
|
380
388
|
super();
|
|
381
389
|
this.column = column;
|
|
382
390
|
this.parent = parent;
|
|
391
|
+
this.embedded = embedded;
|
|
383
392
|
}
|
|
384
393
|
column;
|
|
385
394
|
parent;
|
|
395
|
+
embedded;
|
|
386
396
|
};
|
|
387
397
|
var SortOperation = class {
|
|
388
398
|
constructor(column, direction) {
|
|
@@ -399,6 +409,53 @@ var CountAllOperation = class extends RelationalOperationElement {
|
|
|
399
409
|
}
|
|
400
410
|
table;
|
|
401
411
|
};
|
|
412
|
+
var Alias = class extends RelationalOperationElement {
|
|
413
|
+
constructor(element, name) {
|
|
414
|
+
super();
|
|
415
|
+
this.element = element;
|
|
416
|
+
this.name = name;
|
|
417
|
+
}
|
|
418
|
+
element;
|
|
419
|
+
name;
|
|
420
|
+
};
|
|
421
|
+
var ExistsOperation = class extends RelationalOperationElement {
|
|
422
|
+
constructor(node) {
|
|
423
|
+
super();
|
|
424
|
+
this.node = node;
|
|
425
|
+
}
|
|
426
|
+
node;
|
|
427
|
+
andOp(other) {
|
|
428
|
+
return new LogicalOperation(this, "AND" /* AND */, other);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var NotExistsOperation = class extends RelationalOperationElement {
|
|
432
|
+
constructor(node) {
|
|
433
|
+
super();
|
|
434
|
+
this.node = node;
|
|
435
|
+
}
|
|
436
|
+
node;
|
|
437
|
+
andOp(other) {
|
|
438
|
+
return new LogicalOperation(this, "AND" /* AND */, other);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
var SelectOperation = class {
|
|
442
|
+
constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map()) {
|
|
443
|
+
this.display = display;
|
|
444
|
+
this.filter = filter;
|
|
445
|
+
this.orderBy = orderBy;
|
|
446
|
+
this.groupBy = groupBy;
|
|
447
|
+
this.limit = limit;
|
|
448
|
+
this.table = table;
|
|
449
|
+
this.joinFilters = joinFilters;
|
|
450
|
+
}
|
|
451
|
+
display;
|
|
452
|
+
filter;
|
|
453
|
+
orderBy;
|
|
454
|
+
groupBy;
|
|
455
|
+
limit;
|
|
456
|
+
table;
|
|
457
|
+
joinFilters;
|
|
458
|
+
};
|
|
402
459
|
|
|
403
460
|
export {
|
|
404
461
|
ComparisonOperator,
|
|
@@ -443,6 +500,10 @@ export {
|
|
|
443
500
|
JoinTreeNodeOperation,
|
|
444
501
|
ColumnWithJoin,
|
|
445
502
|
SortOperation,
|
|
446
|
-
CountAllOperation
|
|
503
|
+
CountAllOperation,
|
|
504
|
+
Alias,
|
|
505
|
+
ExistsOperation,
|
|
506
|
+
NotExistsOperation,
|
|
507
|
+
SelectOperation
|
|
447
508
|
};
|
|
448
|
-
//# sourceMappingURL=chunk-
|
|
509
|
+
//# sourceMappingURL=chunk-UYMOE6YU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/model/relational.ts"],"sourcesContent":["export enum ComparisonOperator {\n EQUAL = 'EQUAL',\n NOT_EQUAL = 'NOT_EQUAL',\n LESS_THAN = 'LESS_THAN',\n GREATER_THAN = 'GREATER_THAN',\n LESS_THAN_OR_EQUAL_TO = 'LESS_THAN_OR_EQUAL_TO',\n GREATER_THAN_OR_EQUAL_TO = 'GREATER_THAN_OR_EQUAL_TO',\n LIKE = 'LIKE',\n NOT_LIKE = 'NOT_LIKE',\n}\n\nexport enum LogicalOperator {\n AND = 'AND',\n OR = 'OR',\n}\n\nexport enum AggregateOperator {\n COUNT = 'COUNT',\n SUM = 'SUM',\n MIN = 'MIN',\n MAX = 'MAX',\n AVERAGE = 'AVERAGE',\n}\n\nexport enum ScalarFunction {\n ABS = 'ABS',\n CEILING = 'CEILING',\n FLOOR = 'FLOOR',\n MOD = 'MOD',\n POWER = 'POWER',\n SQRT = 'SQRT',\n ROUND = 'ROUND',\n UPPER = 'UPPER',\n LOWER = 'LOWER',\n TRIM = 'TRIM',\n LTRIM = 'LTRIM',\n RTRIM = 'RTRIM',\n LENGTH = 'LENGTH',\n REVERSE = 'REVERSE',\n LEFT = 'LEFT',\n RIGHT = 'RIGHT',\n REPEAT = 'REPEAT',\n REPLACE = 'REPLACE',\n SUBSTRING = 'SUBSTRING',\n}\n\nexport enum DatePart {\n YEAR = 'YEAR',\n MONTH = 'MONTH',\n DAY = 'DAY',\n HOUR = 'HOUR',\n MINUTE = 'MINUTE',\n SECOND = 'SECOND',\n QUARTER = 'QUARTER',\n WEEK = 'WEEK',\n DOW = 'DOW',\n}\n\nexport enum SortDirection {\n ASC = 'ASC',\n DESC = 'DESC',\n}\n\nexport abstract class RelationalOperationElement {}\n\nexport abstract class Operation extends RelationalOperationElement {\n andOp(other: RelationalOperationElement): Operation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\nexport class NoOperation extends Operation {\n andOp(other: RelationalOperationElement): Operation {\n return other as Operation;\n }\n}\n\nexport abstract class ConstantOperation extends RelationalOperationElement {}\n\nexport class IntegerConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class FloatConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class StringConstantOperation extends ConstantOperation {\n constructor(readonly value: string) { super(); }\n}\n\nexport class DateConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DateTimeConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DecimalConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class BooleanConstantOperation extends ConstantOperation {\n constructor(readonly value: boolean) { super(); }\n}\n\nexport abstract class UnaryOperation extends Operation {\n constructor(readonly element: RelationalOperationElement) { super(); }\n}\n\nexport abstract class BinaryOperation extends Operation {\n constructor(\n readonly left: RelationalOperationElement,\n readonly right: RelationalOperationElement,\n ) { super(); }\n}\n\nexport class IsNullOperation extends UnaryOperation {}\n\nexport class IsNotNullOperation extends UnaryOperation {}\n\nexport class ComparisonOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: ComparisonOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class LogicalOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: LogicalOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class WindowSpecification {\n constructor(\n readonly partitionBy: RelationalOperationElement[] = [],\n readonly orderBy: SortOperation[] = [],\n ) {}\n}\n\nexport class AggregateOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly operator: AggregateOperator,\n readonly displayName?: string,\n readonly window?: WindowSpecification,\n ) { super(element); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): AggregateOperation {\n return new AggregateOperation(this.element, this.operator, this.displayName,\n new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport enum WindowFunction {\n ROW_NUMBER = 'ROW_NUMBER',\n RANK = 'RANK',\n DENSE_RANK = 'DENSE_RANK',\n NTILE = 'NTILE',\n LAG = 'LAG',\n LEAD = 'LEAD',\n FIRST_VALUE = 'FIRST_VALUE',\n LAST_VALUE = 'LAST_VALUE',\n CUME_DIST = 'CUME_DIST',\n PERCENT_RANK = 'PERCENT_RANK',\n}\n\nexport class WindowFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement | null,\n readonly func: WindowFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n readonly window?: WindowSpecification,\n ) { super(element as RelationalOperationElement); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): WindowFunctionOperation {\n return new WindowFunctionOperation(this.element, this.func, this.displayName, this.secondArg,\n [...this.extraArgs], new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport class ScalarFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly func: ScalarFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n ) { super(element); }\n}\n\nexport class DateExtractOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly part: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateArithmeticOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly n: number,\n readonly unit: DatePart,\n readonly isAdd: boolean = true,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateDiffOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly other: Date,\n readonly unit: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class Column extends RelationalOperationElement {\n table?: Table;\n\n constructor(\n readonly name: string,\n readonly type: string,\n readonly owner?: string,\n readonly primaryKey: boolean = false,\n ) { super(); }\n}\n\nexport class ForeignKey {\n constructor(readonly column: Column, readonly references: Column) {}\n}\n\nexport abstract class DataStore {\n readonly schemas: Schema[] = [];\n\n constructor(readonly name: string) {}\n\n abstract namespace(schemaName: string): string;\n}\n\nexport class Database extends DataStore {\n constructor(name: string, readonly location?: string) { super(name); }\n\n namespace(schemaName: string): string { return schemaName; }\n}\n\nexport class DataCatalog extends DataStore {\n constructor(name: string) { super(name); }\n\n namespace(schemaName: string): string { return `${this.name}.${schemaName}`; }\n}\n\nexport class Schema {\n readonly tables: Table[] = [];\n\n constructor(readonly name: string, readonly datastore?: DataStore) {\n datastore?.schemas.push(this);\n }\n}\n\nexport class Table {\n private readonly _columnsByName: Map<string, Column> = new Map();\n readonly foreignKeys: ForeignKey[] = [];\n\n constructor(readonly name: string, columns: Column[], readonly schema?: Schema) {\n for (const col of columns) {\n if (this._columnsByName.has(col.name)) {\n throw new Error(`Duplicate column name '${col.name}' in table '${name}'`);\n }\n this._columnsByName.set(col.name, col);\n col.table = this;\n }\n schema?.tables.push(this);\n }\n\n get columns(): Column[] {\n return Array.from(this._columnsByName.values());\n }\n\n get qualifiedName(): string {\n if (!this.schema) return this.name;\n if (!this.schema.datastore) return `${this.schema.name}.${this.name}`;\n return `${this.schema.datastore.namespace(this.schema.name)}.${this.name}`;\n }\n}\n\nexport class JoinOperation {\n filter?: RelationalOperationElement;\n /** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */\n filterKwargs: Record<string, unknown> = {};\n /** Maps property ids to [column, type, table] for `filterKwargs`. */\n filterColumnMap: Record<string, [string, string, string]> = {};\n\n constructor(\n readonly name: string,\n readonly target: Table,\n readonly left: Column,\n readonly right: Column,\n filter?: RelationalOperationElement,\n ) {\n this.filter = filter;\n }\n}\n\nexport class JoinTreeNodeOperation {\n constructor(\n readonly join: JoinOperation,\n readonly parent?: JoinTreeNodeOperation,\n ) {}\n}\n\nexport class ColumnWithJoin extends RelationalOperationElement {\n /**\n * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that\n * holds the same value without the join; the SQL generator uses it when the join can be elided.\n */\n constructor(\n readonly column: Column,\n readonly parent?: JoinTreeNodeOperation,\n readonly embedded?: ColumnWithJoin,\n ) { super(); }\n}\n\nexport class SortOperation {\n constructor(\n readonly column: ColumnWithJoin,\n readonly direction: SortDirection,\n ) {}\n}\n\nexport class CountAllOperation extends RelationalOperationElement {\n constructor(readonly table: string) { super(); }\n}\n\nexport class Alias extends RelationalOperationElement {\n constructor(readonly element: RelationalOperationElement, readonly name: string) { super(); }\n}\n\n/** Returned by `RelatedFinder.exists()`. A backend translates it to a join-presence check. */\nexport class ExistsOperation extends RelationalOperationElement {\n constructor(readonly node: JoinTreeNodeOperation) { super(); }\n\n andOp(other: RelationalOperationElement): LogicalOperation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\n/** Returned by `RelatedFinder.notExists()`. A backend translates it to a join-absence check. */\nexport class NotExistsOperation extends RelationalOperationElement {\n constructor(readonly node: JoinTreeNodeOperation) { super(); }\n\n andOp(other: RelationalOperationElement): LogicalOperation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\nexport class SelectOperation {\n constructor(\n readonly display: RelationalOperationElement[],\n readonly filter: RelationalOperationElement,\n readonly orderBy: SortOperation[] = [],\n readonly groupBy: RelationalOperationElement[] = [],\n readonly limit?: number,\n readonly table?: Table,\n /**\n * Extra ON conditions for this query's joins (milestoning and property filters), keyed by join node.\n * Held here rather than on the shared JoinOperation, so queries that use the same node can't affect each other.\n */\n readonly joinFilters: ReadonlyMap<JoinTreeNodeOperation, Operation> = new Map(),\n ) {}\n}\n"],"mappings":";AAAO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,WAAQ;AACR,EAAAA,oBAAA,eAAY;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Ae;AAAE,UAAM;AAAvB;AAAA,EAA0B;AAAA,EAA1B;AACvB;AAEO,IAAM,QAAN,cAAoB,2BAA2B;AAAA,EACpD,YAAqB,SAA8C,MAAc;AAAE,UAAM;AAApE;AAA8C;AAAA,EAAyB;AAAA,EAAvE;AAAA,EAA8C;AACrE;AAGO,IAAM,kBAAN,cAA8B,2BAA2B;AAAA,EAC9D,YAAqB,MAA6B;AAAE,UAAM;AAArC;AAAA,EAAwC;AAAA,EAAxC;AAAA,EAErB,MAAM,OAAqD;AACzD,WAAO,IAAI,iBAAiB,MAAM,iBAAqB,KAAK;AAAA,EAC9D;AACF;AAGO,IAAM,qBAAN,cAAiC,2BAA2B;AAAA,EACjE,YAAqB,MAA6B;AAAE,UAAM;AAArC;AAAA,EAAwC;AAAA,EAAxC;AAAA,EAErB,MAAM,OAAqD;AACzD,WAAO,IAAI,iBAAiB,MAAM,iBAAqB,KAAK;AAAA,EAC9D;AACF;AAEO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YACW,SACA,QACA,UAA2B,CAAC,GAC5B,UAAwC,CAAC,GACzC,OACA,OAKA,cAA6D,oBAAI,IAAI,GAC9E;AAXS;AACA;AACA;AACA;AACA;AACA;AAKA;AAAA,EACR;AAAA,EAXQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAKA;AAEb;","names":["ComparisonOperator","LogicalOperator","AggregateOperator","ScalarFunction","DatePart","SortDirection","WindowFunction"]}
|
|
@@ -126,13 +126,19 @@ var Column = class extends RelationalOperationElement {
|
|
|
126
126
|
table;
|
|
127
127
|
};
|
|
128
128
|
var ColumnWithJoin = class extends RelationalOperationElement {
|
|
129
|
-
|
|
129
|
+
/**
|
|
130
|
+
* `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
|
|
131
|
+
* holds the same value without the join; the SQL generator uses it when the join can be elided.
|
|
132
|
+
*/
|
|
133
|
+
constructor(column, parent, embedded) {
|
|
130
134
|
super();
|
|
131
135
|
this.column = column;
|
|
132
136
|
this.parent = parent;
|
|
137
|
+
this.embedded = embedded;
|
|
133
138
|
}
|
|
134
139
|
column;
|
|
135
140
|
parent;
|
|
141
|
+
embedded;
|
|
136
142
|
};
|
|
137
143
|
var SortOperation = class {
|
|
138
144
|
constructor(column, direction) {
|
|
@@ -144,16 +150,18 @@ var SortOperation = class {
|
|
|
144
150
|
};
|
|
145
151
|
|
|
146
152
|
// src/datafinder/attribute.ts
|
|
147
|
-
var Attribute = class {
|
|
153
|
+
var Attribute = class _Attribute {
|
|
148
154
|
_displayName;
|
|
149
155
|
_column;
|
|
150
156
|
_owner;
|
|
151
157
|
_parent;
|
|
152
|
-
|
|
158
|
+
_embedded;
|
|
159
|
+
constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
|
|
153
160
|
this._displayName = displayName;
|
|
154
161
|
this._column = new Column(columnName, columnDbType, owner);
|
|
155
162
|
this._owner = owner;
|
|
156
163
|
this._parent = parent;
|
|
164
|
+
this._embedded = embedded;
|
|
157
165
|
}
|
|
158
166
|
column() {
|
|
159
167
|
return this._column;
|
|
@@ -167,33 +175,58 @@ var Attribute = class {
|
|
|
167
175
|
displayName() {
|
|
168
176
|
return this._displayName;
|
|
169
177
|
}
|
|
178
|
+
/** Alternate attribute on a flat column of the owning table, used in place of this one when its join is elided. */
|
|
179
|
+
embedded() {
|
|
180
|
+
return this._embedded;
|
|
181
|
+
}
|
|
170
182
|
cwj() {
|
|
171
|
-
return new ColumnWithJoin(this._column, this._parent);
|
|
183
|
+
return new ColumnWithJoin(this._column, this._parent, this._embedded?.cwj());
|
|
172
184
|
}
|
|
185
|
+
/** Count the number of non-null values. Use in a projection with `groupByOp` to aggregate per group. */
|
|
173
186
|
count() {
|
|
174
187
|
return new AggregateOperation(
|
|
175
|
-
|
|
188
|
+
this.cwj(),
|
|
176
189
|
"COUNT" /* COUNT */,
|
|
177
190
|
this._displayName + " Count"
|
|
178
191
|
);
|
|
179
192
|
}
|
|
193
|
+
/** Sort this attribute in ascending order. Pass to `orderByOp` or a window function's `orderBy`. */
|
|
180
194
|
ascending() {
|
|
181
|
-
return new SortOperation(
|
|
195
|
+
return new SortOperation(this.cwj(), "ASC" /* ASC */);
|
|
182
196
|
}
|
|
197
|
+
/** Sort this attribute in descending order. Pass to `orderByOp` or a window function's `orderBy`. */
|
|
183
198
|
descending() {
|
|
184
|
-
return new SortOperation(
|
|
199
|
+
return new SortOperation(this.cwj(), "DESC" /* DESC */);
|
|
185
200
|
}
|
|
201
|
+
/** Filter to rows where this attribute has no value. */
|
|
186
202
|
isNull() {
|
|
187
|
-
return new IsNullOperation(
|
|
203
|
+
return new IsNullOperation(this.cwj());
|
|
188
204
|
}
|
|
205
|
+
/** Filter to rows where this attribute has a value. */
|
|
189
206
|
isNotNull() {
|
|
190
|
-
return new IsNotNullOperation(
|
|
207
|
+
return new IsNotNullOperation(this.cwj());
|
|
191
208
|
}
|
|
192
209
|
_windowSpec(partitionBy, orderBy) {
|
|
193
|
-
const
|
|
210
|
+
const pbArr = partitionBy === void 0 ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];
|
|
211
|
+
const pb = pbArr.map((x) => x instanceof _Attribute ? x.cwj() : x);
|
|
194
212
|
const ob = orderBy === void 0 ? [] : Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
195
213
|
return new WindowSpecification(pb, ob);
|
|
196
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Assign a rank to each row within the ordered window, following pandas `Series.rank` conventions.
|
|
217
|
+
*
|
|
218
|
+
* `method` controls tie-breaking (default `'min'`):
|
|
219
|
+
* - `'min'` — tied rows share the lowest rank; the next rank skips.
|
|
220
|
+
* - `'dense'` — like `'min'` but ranks are contiguous (no gaps).
|
|
221
|
+
* - `'first'` — each row gets a unique sequential integer (no ties).
|
|
222
|
+
* - `'max'` — only meaningful with `pct: true` (see below).
|
|
223
|
+
*
|
|
224
|
+
* When `pct: true` the result is a relative rank between 0 and 1:
|
|
225
|
+
* - `method: 'min'` (default) → fraction of values strictly below this row (PERCENT_RANK).
|
|
226
|
+
* - `method: 'max'` → fraction of values at or below this row (cumulative distribution).
|
|
227
|
+
*
|
|
228
|
+
* `partitionBy` restarts the ranking within each group of distinct values.
|
|
229
|
+
*/
|
|
197
230
|
rank(opts = {}) {
|
|
198
231
|
const { method = "min", pct = false, partitionBy, orderBy } = opts;
|
|
199
232
|
let func;
|
|
@@ -218,6 +251,11 @@ var Attribute = class {
|
|
|
218
251
|
}
|
|
219
252
|
return new WindowFunctionOperation(null, func, name, void 0, [], this._windowSpec(partitionBy, orderBy));
|
|
220
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Split rows into `buckets` equal-sized quantile bins ordered by `orderBy`.
|
|
256
|
+
* Each row receives a bucket number from 1 (lowest) to `buckets` (highest).
|
|
257
|
+
* Named after `pandas.qcut`.
|
|
258
|
+
*/
|
|
221
259
|
qcut(buckets, opts = {}) {
|
|
222
260
|
return new WindowFunctionOperation(
|
|
223
261
|
null,
|
|
@@ -228,12 +266,17 @@ var Attribute = class {
|
|
|
228
266
|
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
229
267
|
);
|
|
230
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Return the value of this attribute from `periods` rows earlier (positive) or later (negative)
|
|
271
|
+
* within the ordered window, following `pandas.Series.shift`.
|
|
272
|
+
* Rows with no neighbour at the given offset return `null` (or `fillValue` if provided).
|
|
273
|
+
*/
|
|
231
274
|
shift(periods = 1, opts = {}) {
|
|
232
275
|
const extraArgs = opts.fillValue !== void 0 ? [opts.fillValue] : [];
|
|
233
276
|
const func = periods >= 0 ? "LAG" /* LAG */ : "LEAD" /* LEAD */;
|
|
234
277
|
const label = periods >= 0 ? "Lag" : "Lead";
|
|
235
278
|
return new WindowFunctionOperation(
|
|
236
|
-
|
|
279
|
+
this.cwj(),
|
|
237
280
|
func,
|
|
238
281
|
label + " " + this._displayName,
|
|
239
282
|
Math.abs(periods),
|
|
@@ -241,9 +284,13 @@ var Attribute = class {
|
|
|
241
284
|
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
242
285
|
);
|
|
243
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Return the first value of this attribute in the window frame.
|
|
289
|
+
* Use `partitionBy` to restart the frame for each group.
|
|
290
|
+
*/
|
|
244
291
|
first(opts = {}) {
|
|
245
292
|
return new WindowFunctionOperation(
|
|
246
|
-
|
|
293
|
+
this.cwj(),
|
|
247
294
|
"FIRST_VALUE" /* FIRST_VALUE */,
|
|
248
295
|
"First " + this._displayName,
|
|
249
296
|
void 0,
|
|
@@ -251,9 +298,13 @@ var Attribute = class {
|
|
|
251
298
|
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
252
299
|
);
|
|
253
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Return the last value of this attribute in the window frame.
|
|
303
|
+
* Use `partitionBy` to restart the frame for each group.
|
|
304
|
+
*/
|
|
254
305
|
last(opts = {}) {
|
|
255
306
|
return new WindowFunctionOperation(
|
|
256
|
-
|
|
307
|
+
this.cwj(),
|
|
257
308
|
"LAST_VALUE" /* LAST_VALUE */,
|
|
258
309
|
"Last " + this._displayName,
|
|
259
310
|
void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/datafinder/attribute.ts","../../src/model/relational.ts"],"sourcesContent":["import {\n Column,\n AggregateOperation,\n AggregateOperator,\n ColumnWithJoin,\n SortOperation,\n SortDirection,\n IsNullOperation,\n IsNotNullOperation,\n JoinTreeNodeOperation,\n WindowFunction,\n WindowFunctionOperation,\n WindowSpecification,\n} from '../model/relational';\n\nexport abstract class Attribute {\n private readonly _displayName: string;\n private readonly _column: Column;\n private readonly _owner: string;\n private readonly _parent?: JoinTreeNodeOperation;\n\n constructor(\n displayName: string,\n columnName: string,\n columnDbType: string,\n owner: string,\n parent?: JoinTreeNodeOperation,\n ) {\n this._displayName = displayName;\n this._column = new Column(columnName, columnDbType, owner);\n this._owner = owner;\n this._parent = parent;\n }\n\n column(): Column { return this._column; }\n owner(): string { return this._owner; }\n parent(): JoinTreeNodeOperation | undefined { return this._parent; }\n displayName(): string { return this._displayName; }\n\n cwj(): ColumnWithJoin {\n return new ColumnWithJoin(this._column, this._parent);\n }\n\n count(): AggregateOperation {\n return new AggregateOperation(\n new ColumnWithJoin(this._column, this._parent),\n AggregateOperator.COUNT,\n this._displayName + ' Count',\n );\n }\n\n ascending(): SortOperation {\n return new SortOperation(new ColumnWithJoin(this._column, this._parent), SortDirection.ASC);\n }\n\n descending(): SortOperation {\n return new SortOperation(new ColumnWithJoin(this._column, this._parent), SortDirection.DESC);\n }\n\n isNull(): IsNullOperation {\n return new IsNullOperation(new ColumnWithJoin(this._column, this._parent));\n }\n\n isNotNull(): IsNotNullOperation {\n return new IsNotNullOperation(new ColumnWithJoin(this._column, this._parent));\n }\n\n private _windowSpec(\n partitionBy?: ColumnWithJoin | ColumnWithJoin[],\n orderBy?: SortOperation | SortOperation[],\n ): WindowSpecification {\n const pb = partitionBy === undefined ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];\n const ob = orderBy === undefined ? [] : Array.isArray(orderBy) ? orderBy : [orderBy];\n return new WindowSpecification(pb, ob);\n }\n\n rank(opts: {\n method?: 'min' | 'dense' | 'first';\n pct?: boolean;\n partitionBy?: ColumnWithJoin | ColumnWithJoin[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n const { method = 'min', pct = false, partitionBy, orderBy } = opts;\n let func: WindowFunction;\n let name: string;\n if (pct) {\n if (method === 'max' as string) { func = WindowFunction.CUME_DIST; name = 'Cume Dist'; }\n else { func = WindowFunction.PERCENT_RANK; name = 'Percent Rank'; }\n } else if (method === 'first') { func = WindowFunction.ROW_NUMBER; name = 'Row Number'; }\n else if (method === 'dense') { func = WindowFunction.DENSE_RANK; name = 'Dense Rank'; }\n else { func = WindowFunction.RANK; name = 'Rank'; }\n return new WindowFunctionOperation(null, func, name, undefined, [], this._windowSpec(partitionBy, orderBy));\n }\n\n qcut(buckets: number, opts: {\n partitionBy?: ColumnWithJoin | ColumnWithJoin[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(null, WindowFunction.NTILE, 'Quantile', buckets, [],\n this._windowSpec(opts.partitionBy, opts.orderBy));\n }\n\n shift(periods = 1, opts: {\n fillValue?: string | number;\n partitionBy?: ColumnWithJoin | ColumnWithJoin[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n const extraArgs: (string | number)[] = opts.fillValue !== undefined ? [opts.fillValue] : [];\n const func = periods >= 0 ? WindowFunction.LAG : WindowFunction.LEAD;\n const label = periods >= 0 ? 'Lag' : 'Lead';\n return new WindowFunctionOperation(\n new ColumnWithJoin(this._column, this._parent),\n func,\n label + ' ' + this._displayName,\n Math.abs(periods),\n extraArgs,\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n\n first(opts: {\n partitionBy?: ColumnWithJoin | ColumnWithJoin[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(\n new ColumnWithJoin(this._column, this._parent),\n WindowFunction.FIRST_VALUE,\n 'First ' + this._displayName,\n undefined, [],\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n\n last(opts: {\n partitionBy?: ColumnWithJoin | ColumnWithJoin[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(\n new ColumnWithJoin(this._column, this._parent),\n WindowFunction.LAST_VALUE,\n 'Last ' + this._displayName,\n undefined, [],\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n}\n","export enum ComparisonOperator {\n EQUAL = 'EQUAL',\n NOT_EQUAL = 'NOT_EQUAL',\n LESS_THAN = 'LESS_THAN',\n GREATER_THAN = 'GREATER_THAN',\n LESS_THAN_OR_EQUAL_TO = 'LESS_THAN_OR_EQUAL_TO',\n GREATER_THAN_OR_EQUAL_TO = 'GREATER_THAN_OR_EQUAL_TO',\n LIKE = 'LIKE',\n NOT_LIKE = 'NOT_LIKE',\n}\n\nexport enum LogicalOperator {\n AND = 'AND',\n OR = 'OR',\n}\n\nexport enum AggregateOperator {\n COUNT = 'COUNT',\n SUM = 'SUM',\n MIN = 'MIN',\n MAX = 'MAX',\n AVERAGE = 'AVERAGE',\n}\n\nexport enum ScalarFunction {\n ABS = 'ABS',\n CEILING = 'CEILING',\n FLOOR = 'FLOOR',\n MOD = 'MOD',\n POWER = 'POWER',\n SQRT = 'SQRT',\n ROUND = 'ROUND',\n UPPER = 'UPPER',\n LOWER = 'LOWER',\n TRIM = 'TRIM',\n LTRIM = 'LTRIM',\n RTRIM = 'RTRIM',\n LENGTH = 'LENGTH',\n REVERSE = 'REVERSE',\n LEFT = 'LEFT',\n RIGHT = 'RIGHT',\n REPEAT = 'REPEAT',\n REPLACE = 'REPLACE',\n SUBSTRING = 'SUBSTRING',\n}\n\nexport enum DatePart {\n YEAR = 'YEAR',\n MONTH = 'MONTH',\n DAY = 'DAY',\n HOUR = 'HOUR',\n MINUTE = 'MINUTE',\n SECOND = 'SECOND',\n QUARTER = 'QUARTER',\n WEEK = 'WEEK',\n DOW = 'DOW',\n}\n\nexport enum SortDirection {\n ASC = 'ASC',\n DESC = 'DESC',\n}\n\nexport abstract class RelationalOperationElement {}\n\nexport abstract class Operation extends RelationalOperationElement {\n andOp(other: RelationalOperationElement): Operation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\nexport class NoOperation extends Operation {\n andOp(other: RelationalOperationElement): Operation {\n return other as Operation;\n }\n}\n\nexport abstract class ConstantOperation extends RelationalOperationElement {}\n\nexport class IntegerConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class FloatConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class StringConstantOperation extends ConstantOperation {\n constructor(readonly value: string) { super(); }\n}\n\nexport class DateConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DateTimeConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DecimalConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class BooleanConstantOperation extends ConstantOperation {\n constructor(readonly value: boolean) { super(); }\n}\n\nexport abstract class UnaryOperation extends Operation {\n constructor(readonly element: RelationalOperationElement) { super(); }\n}\n\nexport abstract class BinaryOperation extends Operation {\n constructor(\n readonly left: RelationalOperationElement,\n readonly right: RelationalOperationElement,\n ) { super(); }\n}\n\nexport class IsNullOperation extends UnaryOperation {}\n\nexport class IsNotNullOperation extends UnaryOperation {}\n\nexport class ComparisonOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: ComparisonOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class LogicalOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: LogicalOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class WindowSpecification {\n constructor(\n readonly partitionBy: RelationalOperationElement[] = [],\n readonly orderBy: SortOperation[] = [],\n ) {}\n}\n\nexport class AggregateOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly operator: AggregateOperator,\n readonly displayName?: string,\n readonly window?: WindowSpecification,\n ) { super(element); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): AggregateOperation {\n return new AggregateOperation(this.element, this.operator, this.displayName,\n new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport enum WindowFunction {\n ROW_NUMBER = 'ROW_NUMBER',\n RANK = 'RANK',\n DENSE_RANK = 'DENSE_RANK',\n NTILE = 'NTILE',\n LAG = 'LAG',\n LEAD = 'LEAD',\n FIRST_VALUE = 'FIRST_VALUE',\n LAST_VALUE = 'LAST_VALUE',\n CUME_DIST = 'CUME_DIST',\n PERCENT_RANK = 'PERCENT_RANK',\n}\n\nexport class WindowFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement | null,\n readonly func: WindowFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n readonly window?: WindowSpecification,\n ) { super(element as RelationalOperationElement); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): WindowFunctionOperation {\n return new WindowFunctionOperation(this.element, this.func, this.displayName, this.secondArg,\n [...this.extraArgs], new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport class ScalarFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly func: ScalarFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n ) { super(element); }\n}\n\nexport class DateExtractOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly part: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateArithmeticOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly n: number,\n readonly unit: DatePart,\n readonly isAdd: boolean = true,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateDiffOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly other: Date,\n readonly unit: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class Column extends RelationalOperationElement {\n table?: Table;\n\n constructor(\n readonly name: string,\n readonly type: string,\n readonly owner?: string,\n readonly primaryKey: boolean = false,\n ) { super(); }\n}\n\nexport class ForeignKey {\n constructor(readonly column: Column, readonly references: Column) {}\n}\n\nexport abstract class DataStore {\n readonly schemas: Schema[] = [];\n\n constructor(readonly name: string) {}\n\n abstract namespace(schemaName: string): string;\n}\n\nexport class Database extends DataStore {\n constructor(name: string, readonly location?: string) { super(name); }\n\n namespace(schemaName: string): string { return schemaName; }\n}\n\nexport class DataCatalog extends DataStore {\n constructor(name: string) { super(name); }\n\n namespace(schemaName: string): string { return `${this.name}.${schemaName}`; }\n}\n\nexport class Schema {\n readonly tables: Table[] = [];\n\n constructor(readonly name: string, readonly datastore?: DataStore) {\n datastore?.schemas.push(this);\n }\n}\n\nexport class Table {\n private readonly _columnsByName: Map<string, Column> = new Map();\n readonly foreignKeys: ForeignKey[] = [];\n\n constructor(readonly name: string, columns: Column[], readonly schema?: Schema) {\n for (const col of columns) {\n if (this._columnsByName.has(col.name)) {\n throw new Error(`Duplicate column name '${col.name}' in table '${name}'`);\n }\n this._columnsByName.set(col.name, col);\n col.table = this;\n }\n schema?.tables.push(this);\n }\n\n get columns(): Column[] {\n return Array.from(this._columnsByName.values());\n }\n\n get qualifiedName(): string {\n if (!this.schema) return this.name;\n if (!this.schema.datastore) return `${this.schema.name}.${this.name}`;\n return `${this.schema.datastore.namespace(this.schema.name)}.${this.name}`;\n }\n}\n\nexport class JoinOperation {\n filter?: RelationalOperationElement;\n\n constructor(\n readonly name: string,\n readonly target: Table,\n readonly left: Column,\n readonly right: Column,\n filter?: RelationalOperationElement,\n ) {\n this.filter = filter;\n }\n}\n\nexport class JoinTreeNodeOperation {\n constructor(\n readonly join: JoinOperation,\n readonly parent?: JoinTreeNodeOperation,\n ) {}\n}\n\nexport class ColumnWithJoin extends RelationalOperationElement {\n constructor(\n readonly column: Column,\n readonly parent?: JoinTreeNodeOperation,\n ) { super(); }\n}\n\nexport class SortOperation {\n constructor(\n readonly column: ColumnWithJoin,\n readonly direction: SortDirection,\n ) {}\n}\n\nexport class CountAllOperation extends RelationalOperationElement {\n constructor(readonly table: string) { super(); }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+DO,IAAe,6BAAf,MAA0C;AAAC;AAE3C,IAAe,YAAf,cAAiC,2BAA2B;AAAA,EACjE,MAAM,OAA8C;AAClD,WAAO,IAAI,iBAAiB,MAAM,iBAAqB,KAAK;AAAA,EAC9D;AACF;AAsCO,IAAe,iBAAf,cAAsC,UAAU;AAAA,EACrD,YAAqB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KAAK,YAAY,KAAK,aAAa,KAAK,OAAO;AAAA,IAAC;AAAA,EACpD;AAAA,EAEA,MAAM,UAAU,GAAG,OAIf,CAAC,GAA4B;AAC/B,UAAM,YAAiC,KAAK,cAAc,SAAY,CAAC,KAAK,SAAS,IAAI,CAAC;AAC1F,UAAM,OAAO,WAAW;AACxB,UAAM,QAAQ,WAAW,IAAI,QAAQ;AACrC,WAAO,IAAI;AAAA,MACT,IAAI,eAAe,KAAK,SAAS,KAAK,OAAO;AAAA,MAC7C;AAAA,MACA,QAAQ,MAAM,KAAK;AAAA,MACnB,KAAK,IAAI,OAAO;AAAA,MAChB;AAAA,MACA,KAAK,YAAY,KAAK,aAAa,KAAK,OAAO;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,MAAM,OAGF,CAAC,GAA4B;AAC/B,WAAO,IAAI;AAAA,MACT,IAAI,eAAe,KAAK,SAAS,KAAK,OAAO;AAAA;AAAA,MAE7C,WAAW,KAAK;AAAA,MAChB;AAAA,MAAW,CAAC;AAAA,MACZ,KAAK,YAAY,KAAK,aAAa,KAAK,OAAO;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,KAAK,OAGD,CAAC,GAA4B;AAC/B,WAAO,IAAI;AAAA,MACT,IAAI,eAAe,KAAK,SAAS,KAAK,OAAO;AAAA;AAAA,MAE7C,UAAU,KAAK;AAAA,MACf;AAAA,MAAW,CAAC;AAAA,MACZ,KAAK,YAAY,KAAK,aAAa,KAAK,OAAO;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/datafinder/attribute.ts","../../src/model/relational.ts"],"sourcesContent":["import {\n Column,\n AggregateOperation,\n AggregateOperator,\n ColumnWithJoin,\n SortOperation,\n SortDirection,\n IsNullOperation,\n IsNotNullOperation,\n JoinTreeNodeOperation,\n WindowFunction,\n WindowFunctionOperation,\n WindowSpecification,\n} from '../model/relational';\n\nexport abstract class Attribute {\n private readonly _displayName: string;\n private readonly _column: Column;\n private readonly _owner: string;\n private readonly _parent?: JoinTreeNodeOperation;\n private readonly _embedded?: Attribute;\n\n constructor(\n displayName: string,\n columnName: string,\n columnDbType: string,\n owner: string,\n parent?: JoinTreeNodeOperation,\n embedded?: Attribute,\n ) {\n this._displayName = displayName;\n this._column = new Column(columnName, columnDbType, owner);\n this._owner = owner;\n this._parent = parent;\n this._embedded = embedded;\n }\n\n column(): Column { return this._column; }\n owner(): string { return this._owner; }\n parent(): JoinTreeNodeOperation | undefined { return this._parent; }\n displayName(): string { return this._displayName; }\n\n /** Alternate attribute on a flat column of the owning table, used in place of this one when its join is elided. */\n embedded(): Attribute | undefined { return this._embedded; }\n\n cwj(): ColumnWithJoin {\n return new ColumnWithJoin(this._column, this._parent, this._embedded?.cwj());\n }\n\n /** Count the number of non-null values. Use in a projection with `groupByOp` to aggregate per group. */\n count(): AggregateOperation {\n return new AggregateOperation(\n this.cwj(),\n AggregateOperator.COUNT,\n this._displayName + ' Count',\n );\n }\n\n /** Sort this attribute in ascending order. Pass to `orderByOp` or a window function's `orderBy`. */\n ascending(): SortOperation {\n return new SortOperation(this.cwj(), SortDirection.ASC);\n }\n\n /** Sort this attribute in descending order. Pass to `orderByOp` or a window function's `orderBy`. */\n descending(): SortOperation {\n return new SortOperation(this.cwj(), SortDirection.DESC);\n }\n\n /** Filter to rows where this attribute has no value. */\n isNull(): IsNullOperation {\n return new IsNullOperation(this.cwj());\n }\n\n /** Filter to rows where this attribute has a value. */\n isNotNull(): IsNotNullOperation {\n return new IsNotNullOperation(this.cwj());\n }\n\n private _windowSpec(\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[],\n orderBy?: SortOperation | SortOperation[],\n ): WindowSpecification {\n const pbArr = partitionBy === undefined ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];\n const pb = pbArr.map(x => x instanceof Attribute ? x.cwj() : x);\n const ob = orderBy === undefined ? [] : Array.isArray(orderBy) ? orderBy : [orderBy];\n return new WindowSpecification(pb, ob);\n }\n\n /**\n * Assign a rank to each row within the ordered window, following pandas `Series.rank` conventions.\n *\n * `method` controls tie-breaking (default `'min'`):\n * - `'min'` — tied rows share the lowest rank; the next rank skips.\n * - `'dense'` — like `'min'` but ranks are contiguous (no gaps).\n * - `'first'` — each row gets a unique sequential integer (no ties).\n * - `'max'` — only meaningful with `pct: true` (see below).\n *\n * When `pct: true` the result is a relative rank between 0 and 1:\n * - `method: 'min'` (default) → fraction of values strictly below this row (PERCENT_RANK).\n * - `method: 'max'` → fraction of values at or below this row (cumulative distribution).\n *\n * `partitionBy` restarts the ranking within each group of distinct values.\n */\n rank(opts: {\n method?: 'min' | 'dense' | 'first' | 'max';\n pct?: boolean;\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n const { method = 'min', pct = false, partitionBy, orderBy } = opts;\n let func: WindowFunction;\n let name: string;\n if (pct) {\n if (method === 'max') { func = WindowFunction.CUME_DIST; name = 'Cume Dist'; }\n else { func = WindowFunction.PERCENT_RANK; name = 'Percent Rank'; }\n } else if (method === 'first') { func = WindowFunction.ROW_NUMBER; name = 'Row Number'; }\n else if (method === 'dense') { func = WindowFunction.DENSE_RANK; name = 'Dense Rank'; }\n else { func = WindowFunction.RANK; name = 'Rank'; }\n return new WindowFunctionOperation(null, func, name, undefined, [], this._windowSpec(partitionBy, orderBy));\n }\n\n /**\n * Split rows into `buckets` equal-sized quantile bins ordered by `orderBy`.\n * Each row receives a bucket number from 1 (lowest) to `buckets` (highest).\n * Named after `pandas.qcut`.\n */\n qcut(buckets: number, opts: {\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(null, WindowFunction.NTILE, 'Quantile', buckets, [],\n this._windowSpec(opts.partitionBy, opts.orderBy));\n }\n\n /**\n * Return the value of this attribute from `periods` rows earlier (positive) or later (negative)\n * within the ordered window, following `pandas.Series.shift`.\n * Rows with no neighbour at the given offset return `null` (or `fillValue` if provided).\n */\n shift(periods = 1, opts: {\n fillValue?: string | number;\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n const extraArgs: (string | number)[] = opts.fillValue !== undefined ? [opts.fillValue] : [];\n const func = periods >= 0 ? WindowFunction.LAG : WindowFunction.LEAD;\n const label = periods >= 0 ? 'Lag' : 'Lead';\n return new WindowFunctionOperation(\n this.cwj(),\n func,\n label + ' ' + this._displayName,\n Math.abs(periods),\n extraArgs,\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n\n /**\n * Return the first value of this attribute in the window frame.\n * Use `partitionBy` to restart the frame for each group.\n */\n first(opts: {\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(\n this.cwj(),\n WindowFunction.FIRST_VALUE,\n 'First ' + this._displayName,\n undefined, [],\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n\n /**\n * Return the last value of this attribute in the window frame.\n * Use `partitionBy` to restart the frame for each group.\n */\n last(opts: {\n partitionBy?: Attribute | ColumnWithJoin | (Attribute | ColumnWithJoin)[];\n orderBy?: SortOperation | SortOperation[];\n } = {}): WindowFunctionOperation {\n return new WindowFunctionOperation(\n this.cwj(),\n WindowFunction.LAST_VALUE,\n 'Last ' + this._displayName,\n undefined, [],\n this._windowSpec(opts.partitionBy, opts.orderBy),\n );\n }\n}\n","export enum ComparisonOperator {\n EQUAL = 'EQUAL',\n NOT_EQUAL = 'NOT_EQUAL',\n LESS_THAN = 'LESS_THAN',\n GREATER_THAN = 'GREATER_THAN',\n LESS_THAN_OR_EQUAL_TO = 'LESS_THAN_OR_EQUAL_TO',\n GREATER_THAN_OR_EQUAL_TO = 'GREATER_THAN_OR_EQUAL_TO',\n LIKE = 'LIKE',\n NOT_LIKE = 'NOT_LIKE',\n}\n\nexport enum LogicalOperator {\n AND = 'AND',\n OR = 'OR',\n}\n\nexport enum AggregateOperator {\n COUNT = 'COUNT',\n SUM = 'SUM',\n MIN = 'MIN',\n MAX = 'MAX',\n AVERAGE = 'AVERAGE',\n}\n\nexport enum ScalarFunction {\n ABS = 'ABS',\n CEILING = 'CEILING',\n FLOOR = 'FLOOR',\n MOD = 'MOD',\n POWER = 'POWER',\n SQRT = 'SQRT',\n ROUND = 'ROUND',\n UPPER = 'UPPER',\n LOWER = 'LOWER',\n TRIM = 'TRIM',\n LTRIM = 'LTRIM',\n RTRIM = 'RTRIM',\n LENGTH = 'LENGTH',\n REVERSE = 'REVERSE',\n LEFT = 'LEFT',\n RIGHT = 'RIGHT',\n REPEAT = 'REPEAT',\n REPLACE = 'REPLACE',\n SUBSTRING = 'SUBSTRING',\n}\n\nexport enum DatePart {\n YEAR = 'YEAR',\n MONTH = 'MONTH',\n DAY = 'DAY',\n HOUR = 'HOUR',\n MINUTE = 'MINUTE',\n SECOND = 'SECOND',\n QUARTER = 'QUARTER',\n WEEK = 'WEEK',\n DOW = 'DOW',\n}\n\nexport enum SortDirection {\n ASC = 'ASC',\n DESC = 'DESC',\n}\n\nexport abstract class RelationalOperationElement {}\n\nexport abstract class Operation extends RelationalOperationElement {\n andOp(other: RelationalOperationElement): Operation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\nexport class NoOperation extends Operation {\n andOp(other: RelationalOperationElement): Operation {\n return other as Operation;\n }\n}\n\nexport abstract class ConstantOperation extends RelationalOperationElement {}\n\nexport class IntegerConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class FloatConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class StringConstantOperation extends ConstantOperation {\n constructor(readonly value: string) { super(); }\n}\n\nexport class DateConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DateTimeConstantOperation extends ConstantOperation {\n constructor(readonly value: Date) { super(); }\n}\n\nexport class DecimalConstantOperation extends ConstantOperation {\n constructor(readonly value: number) { super(); }\n}\n\nexport class BooleanConstantOperation extends ConstantOperation {\n constructor(readonly value: boolean) { super(); }\n}\n\nexport abstract class UnaryOperation extends Operation {\n constructor(readonly element: RelationalOperationElement) { super(); }\n}\n\nexport abstract class BinaryOperation extends Operation {\n constructor(\n readonly left: RelationalOperationElement,\n readonly right: RelationalOperationElement,\n ) { super(); }\n}\n\nexport class IsNullOperation extends UnaryOperation {}\n\nexport class IsNotNullOperation extends UnaryOperation {}\n\nexport class ComparisonOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: ComparisonOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class LogicalOperation extends BinaryOperation {\n constructor(\n left: RelationalOperationElement,\n readonly operator: LogicalOperator,\n right: RelationalOperationElement,\n ) { super(left, right); }\n}\n\nexport class WindowSpecification {\n constructor(\n readonly partitionBy: RelationalOperationElement[] = [],\n readonly orderBy: SortOperation[] = [],\n ) {}\n}\n\nexport class AggregateOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly operator: AggregateOperator,\n readonly displayName?: string,\n readonly window?: WindowSpecification,\n ) { super(element); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): AggregateOperation {\n return new AggregateOperation(this.element, this.operator, this.displayName,\n new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport enum WindowFunction {\n ROW_NUMBER = 'ROW_NUMBER',\n RANK = 'RANK',\n DENSE_RANK = 'DENSE_RANK',\n NTILE = 'NTILE',\n LAG = 'LAG',\n LEAD = 'LEAD',\n FIRST_VALUE = 'FIRST_VALUE',\n LAST_VALUE = 'LAST_VALUE',\n CUME_DIST = 'CUME_DIST',\n PERCENT_RANK = 'PERCENT_RANK',\n}\n\nexport class WindowFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement | null,\n readonly func: WindowFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n readonly window?: WindowSpecification,\n ) { super(element as RelationalOperationElement); }\n\n over(partitionBy?: RelationalOperationElement[], orderBy?: SortOperation[]): WindowFunctionOperation {\n return new WindowFunctionOperation(this.element, this.func, this.displayName, this.secondArg,\n [...this.extraArgs], new WindowSpecification(partitionBy ?? [], orderBy ?? []));\n }\n}\n\nexport class ScalarFunctionOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly func: ScalarFunction,\n readonly displayName?: string,\n readonly secondArg?: number,\n readonly extraArgs: (string | number)[] = [],\n ) { super(element); }\n}\n\nexport class DateExtractOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly part: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateArithmeticOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly n: number,\n readonly unit: DatePart,\n readonly isAdd: boolean = true,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class DateDiffOperation extends UnaryOperation {\n constructor(\n element: RelationalOperationElement,\n readonly other: Date,\n readonly unit: DatePart,\n readonly displayName?: string,\n ) { super(element); }\n}\n\nexport class Column extends RelationalOperationElement {\n table?: Table;\n\n constructor(\n readonly name: string,\n readonly type: string,\n readonly owner?: string,\n readonly primaryKey: boolean = false,\n ) { super(); }\n}\n\nexport class ForeignKey {\n constructor(readonly column: Column, readonly references: Column) {}\n}\n\nexport abstract class DataStore {\n readonly schemas: Schema[] = [];\n\n constructor(readonly name: string) {}\n\n abstract namespace(schemaName: string): string;\n}\n\nexport class Database extends DataStore {\n constructor(name: string, readonly location?: string) { super(name); }\n\n namespace(schemaName: string): string { return schemaName; }\n}\n\nexport class DataCatalog extends DataStore {\n constructor(name: string) { super(name); }\n\n namespace(schemaName: string): string { return `${this.name}.${schemaName}`; }\n}\n\nexport class Schema {\n readonly tables: Table[] = [];\n\n constructor(readonly name: string, readonly datastore?: DataStore) {\n datastore?.schemas.push(this);\n }\n}\n\nexport class Table {\n private readonly _columnsByName: Map<string, Column> = new Map();\n readonly foreignKeys: ForeignKey[] = [];\n\n constructor(readonly name: string, columns: Column[], readonly schema?: Schema) {\n for (const col of columns) {\n if (this._columnsByName.has(col.name)) {\n throw new Error(`Duplicate column name '${col.name}' in table '${name}'`);\n }\n this._columnsByName.set(col.name, col);\n col.table = this;\n }\n schema?.tables.push(this);\n }\n\n get columns(): Column[] {\n return Array.from(this._columnsByName.values());\n }\n\n get qualifiedName(): string {\n if (!this.schema) return this.name;\n if (!this.schema.datastore) return `${this.schema.name}.${this.name}`;\n return `${this.schema.datastore.namespace(this.schema.name)}.${this.name}`;\n }\n}\n\nexport class JoinOperation {\n filter?: RelationalOperationElement;\n /** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */\n filterKwargs: Record<string, unknown> = {};\n /** Maps property ids to [column, type, table] for `filterKwargs`. */\n filterColumnMap: Record<string, [string, string, string]> = {};\n\n constructor(\n readonly name: string,\n readonly target: Table,\n readonly left: Column,\n readonly right: Column,\n filter?: RelationalOperationElement,\n ) {\n this.filter = filter;\n }\n}\n\nexport class JoinTreeNodeOperation {\n constructor(\n readonly join: JoinOperation,\n readonly parent?: JoinTreeNodeOperation,\n ) {}\n}\n\nexport class ColumnWithJoin extends RelationalOperationElement {\n /**\n * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that\n * holds the same value without the join; the SQL generator uses it when the join can be elided.\n */\n constructor(\n readonly column: Column,\n readonly parent?: JoinTreeNodeOperation,\n readonly embedded?: ColumnWithJoin,\n ) { super(); }\n}\n\nexport class SortOperation {\n constructor(\n readonly column: ColumnWithJoin,\n readonly direction: SortDirection,\n ) {}\n}\n\nexport class CountAllOperation extends RelationalOperationElement {\n constructor(readonly table: string) { super(); }\n}\n\nexport class Alias extends RelationalOperationElement {\n constructor(readonly element: RelationalOperationElement, readonly name: string) { super(); }\n}\n\n/** Returned by `RelatedFinder.exists()`. A backend translates it to a join-presence check. */\nexport class ExistsOperation extends RelationalOperationElement {\n constructor(readonly node: JoinTreeNodeOperation) { super(); }\n\n andOp(other: RelationalOperationElement): LogicalOperation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\n/** Returned by `RelatedFinder.notExists()`. A backend translates it to a join-absence check. */\nexport class NotExistsOperation extends RelationalOperationElement {\n constructor(readonly node: JoinTreeNodeOperation) { super(); }\n\n andOp(other: RelationalOperationElement): LogicalOperation {\n return new LogicalOperation(this, LogicalOperator.AND, other);\n }\n}\n\nexport class SelectOperation {\n constructor(\n readonly display: RelationalOperationElement[],\n readonly filter: RelationalOperationElement,\n readonly orderBy: SortOperation[] = [],\n readonly groupBy: RelationalOperationElement[] = [],\n readonly limit?: number,\n readonly table?: Table,\n /**\n * Extra ON conditions for this query's joins (milestoning and property filters), keyed by join node.\n * Held here rather than on the shared JoinOperation, so queries that use the same node can't affect each other.\n */\n readonly joinFilters: ReadonlyMap<JoinTreeNodeOperation, Operation> = new Map(),\n ) {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+DO,IAAe,6BAAf,MAA0C;AAAC;AAE3C,IAAe,YAAf,cAAiC,2BAA2B;AAAA,EACjE,MAAM,OAA8C;AAClD,WAAO,IAAI,iBAAiB,MAAM,iBAAqB,KAAK;AAAA,EAC9D;AACF;AAsCO,IAAe,iBAAf,cAAsC,UAAU;AAAA,EACrD,YAAqB,SAAqC;AAAE,UAAM;AAA7C;AAAA,EAAgD;AAAA,EAAhD;AACvB;AAEO,IAAe,kBAAf,cAAuC,UAAU;AAAA,EACtD,YACW,MACA,OACT;AAAE,UAAM;AAFC;AACA;AAAA,EACE;AAAA,EAFF;AAAA,EACA;AAEb;AAEO,IAAM,kBAAN,cAA8B,eAAe;AAAC;AAE9C,IAAM,qBAAN,cAAiC,eAAe;AAAC;AAUjD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