diff --git a/.changeset/vquery-parameterized-dialects.md b/.changeset/vquery-parameterized-dialects.md new file mode 100644 index 0000000000..c7975c7aba --- /dev/null +++ b/.changeset/vquery-parameterized-dialects.md @@ -0,0 +1,9 @@ +--- +'@visactor/vquery': patch +--- + +Expose parameterized `compileQuery` with MySQL as the default dialect and explicit `convertDSLToMysql` / `convertDSLToDuckDB` helpers, replacing `convertDSLToSQL`. Keep dataset queries on the DuckDB strategy. + +Align MySQL and DuckDB aggregation, date grouping, string matching, NULL ordering, and median/quantile behavior. Add a shared real-schema DSL catalog that snapshots both dialects without database test dependencies. + +Default browser and Node dataset storage to memory. Keep separate Node and browser strategy entrypoints with shared constructor option types, and enable IndexedDB persistence only with `new VQuery({ enableIndexedDB: true })`. diff --git a/apps/website/docs/zh-CN/vquery/development/tests.md b/apps/website/docs/zh-CN/vquery/development/tests.md index c735efedd1..487ff5e482 100644 --- a/apps/website/docs/zh-CN/vquery/development/tests.md +++ b/apps/website/docs/zh-CN/vquery/development/tests.md @@ -3,25 +3,70 @@ VQuery 使用 `rstest` 框架进行测试。**所有命令需在根目录执行。** ## 测试机制 -VQuery 的测试覆盖了: -- **Unit**: 工具函数与编译器逻辑。 -- **examples**: 完整的 SQL 生成与数据查询流程。 + +- **Unit**:工具函数、编译器逻辑与内存查询引擎。 +- **examples**:SQL 生成与内存数据查询流程。 +- **dialects**:共用一套 DSL,快照校验 MySQL 和 DuckDB 的 SQL 生成结果,不连接数据库。 ## 常用命令 ### 运行所有测试 + ```bash -pnpm --filter=@visactor/vquery run test +pnpm --filter @visactor/vquery run test ``` ### 更新快照 -如果 SQL 生成逻辑变更符合预期,需更新快照: + +确认 SQL 变化符合预期后更新快照,并审阅生成的差异: + ```bash -pnpm --filter=@visactor/vquery run test:update +pnpm --filter @visactor/vquery run test:update ``` ### 覆盖率报告 -生成并查看测试覆盖率: + +```bash +pnpm --filter @visactor/vquery run test:coverage +``` + +## 方言 SQL 快照 + +方言测试只有一套共享用例和一份快照: + +- `tests/dialects/queries.json`:以 `supermarket` 为查询表,保存真实 CSV 的完整 20 字段逻辑 schema 和共享 DSL 用例。`source` 指向仓库已有的 `tests/unit/assets/supermarket.csv`;该文件与本次提供的 CSV 内容一致,测试无需访问用户的 Downloads 目录。每条用例用唯一且稳定的 `name` 标识,可附 `description` 解释业务场景。 +- `tests/dialects/compile.test.ts`:每条 DSL 分别调用 MySQL、DuckDB 的 `compileQuery`,将两种方言的 `{ sql, parameters }` 一起核对快照。 +- `tests/dialects/__snapshots__/compile.test.ts.snap`:按用例保存两种方言的 SQL 和参数;通过快照差异审阅编译逻辑变化。 + +测试纳入现有的 `test`、`test:update`、`test:coverage`,无需专用配置、数据库服务、CLI 或连接凭据。新增方言时复用同一套 DSL,增加对应编译结果即可。 + +CSV 中 `id`、`sales`、`amount`、`discount`、`profit` 使用 number,`order_date`、`delivery_date` 使用 date,其余列使用 string。日期样例按 SQL DATE 格式表示为 `YYYY-MM-DD`。用例涵盖销售利润、商品层级、省市地域、客户贡献、折扣亏损与配送分析,使用真实字段和业务值;不在业务用例中改写 schema 或虚构源字段。 + +测试将 schema 字段与 CSV 表头逐一比较,并逐条检查 SELECT、WHERE、HAVING 的源字段;GROUP BY、ORDER BY 可以引用真实字段或 SELECT 输出别名。聚合查询中的维度必须参与分组,聚合结果别名不能作为分组键。别名是输出名称,不视为新的源字段。 + +只运行方言快照测试: + ```bash -pnpm --filter=@visactor/vquery run test:coverage +pnpm --filter @visactor/vquery exec rstest --include 'tests/dialects/**/*.test.ts' --coverage.enabled=false ``` + +覆盖率沿用包现有的四项 100% 门槛,非法 DSL 的拒绝分支由 Unit 测试覆盖,不维护另一套方言覆盖率配置。 + +## 功能与组合覆盖 + +源码覆盖率 100% 不等于所有 DSL 组合都被验证。嵌套层数、条件数量和参数值没有有限的穷举集合;用例库持续积累实际场景和历史回归,不以数量代替覆盖范围。 + +共享 JSON 用例库持续扩充,测试同时检查以下明确的组合要求,删除必要用例会失败。功能与操作符清单通过 DSL 类型约束;现有 `typecheck` 同时检查源码和测试,新增功能时需要同步补充清单与用例。 + +| 范围 | 覆盖要求 | +| --- | --- | +| SELECT | 11 种基础聚合、8 种日期聚合,以及字段、别名与全部字段投影 | +| HAVING | 11 种基础聚合 × 12 种比较操作符,共 132 种组合 | +| 日期分组 | 8 种日期聚合 × 11 种基础聚合,共 88 种组合 | +| 排序 | 11 种基础聚合 × 升降序 × 默认/first/last NULL 位置,共 66 种组合 | +| WHERE | 16 种操作符分别位于 AND、OR 嵌套树中,共 32 种组合 | +| 完整查询 | SELECT、WHERE、GROUP BY、HAVING、ORDER BY、limit 同时出现 | + +另包含商品名称 MIN/MAX 的 HAVING、下单日与配送日分组、多日期多字段分组、销售与利润跨字段统计、未投影 HAVING、别名冲突、2/4/8 层嵌套等回归场景。这些场景不代表任意组合均已穷尽。 + +追加场景时,直接在 `queries.json` 的 `queries` 数组中增加基于这份 schema 的完整 DSL,用 `description` 说明触发条件或历史问题,再运行 `test:update` 并审阅两种方言的 SQL 差异。不要复制方言专属用例或加入随机生成步骤。无 schema、特殊标识符、JS `Date`、`Infinity` 等编译器边界由 Unit 测试维护。 diff --git a/apps/website/docs/zh-CN/vquery/index.md b/apps/website/docs/zh-CN/vquery/index.md index e3ef1adeff..922548beee 100644 --- a/apps/website/docs/zh-CN/vquery/index.md +++ b/apps/website/docs/zh-CN/vquery/index.md @@ -1,5 +1,21 @@ # VQuery -:::info In Development -Coming Soon -::: +VQuery 在 Node.js 和浏览器中默认使用内存查询与存储 adapter,无需 IndexedDB。每个实例独立管理自己的数据集。 + +```ts +import { VQuery } from '@visactor/vquery' + +const vquery = new VQuery() +``` + +默认存储的数据只在当前实例生命周期内有效,关闭实例或刷新页面后不保留。 + +## 启用 IndexedDB + +需要跨会话保存数据集 schema 和数据源时,显式开启 `enableIndexedDB`: + +```ts +const vquery = new VQuery({ enableIndexedDB: true }) +``` + +开启后使用 IndexedDB 存储 adapter,运行环境需要支持 IndexedDB;查询仍通过内存查询 adapter 执行。省略此选项、传入空 options 或设置为 `false` 时,均使用内存存储,无需 IndexedDB API。 diff --git a/packages/vquery/README.md b/packages/vquery/README.md index 362511d7f8..19dfc75920 100644 --- a/packages/vquery/README.md +++ b/packages/vquery/README.md @@ -1 +1,17 @@ # VQuery + +Node.js and browser entrypoints use in-memory query and storage adapters by default. No IndexedDB API is required, and each VQuery instance owns its datasets. + +```ts +import { VQuery } from '@visactor/vquery' + +const vquery = new VQuery() +``` + +Enable IndexedDB explicitly to persist dataset schemas and sources between sessions: + +```ts +const vquery = new VQuery({ enableIndexedDB: true }) +``` + +The runtime must support IndexedDB when this option is enabled. Queries still run in memory. With the default storage, closing the instance or reloading the page discards its datasets. diff --git a/packages/vquery/rstest.config.ts b/packages/vquery/rstest.config.ts index 8faaf18345..3fb7565358 100644 --- a/packages/vquery/rstest.config.ts +++ b/packages/vquery/rstest.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ globals: true, testEnvironment: 'node', includeSource: ['src/**/*.{js,ts}'], - exclude: ['src/browser.ts', 'src/vquery-browser.ts'], + exclude: ['src/browser.ts'], setupFiles: ['./tests/setup.ts'], coverage: { enabled: true, @@ -12,9 +12,8 @@ export default defineConfig({ exclude: [ '**/node_modules/**', '**/dist/**', - // rstest can't run browser entrypoints. + // Export barrels have no runtime logic; both entrypoints are exercised by unit tests. 'src/browser.ts', - 'src/vquery-browser.ts', ], include: ['src/**'], reporters: ['html', ['text', { skipFull: true }], 'json', 'json-summary'], diff --git a/packages/vquery/scripts/build-tests.js b/packages/vquery/scripts/build-tests.js index e1f3fd49a0..8faebda2b0 100644 --- a/packages/vquery/scripts/build-tests.js +++ b/packages/vquery/scripts/build-tests.js @@ -34,7 +34,7 @@ function generateTest(jsonPath) { const testPath = path.join(path.dirname(jsonPath), testFileName) const template = `import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './${jsonFileName}' describe('${description}', () => { @@ -52,7 +52,7 @@ describe('${description}', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot() diff --git a/packages/vquery/src/browser.ts b/packages/vquery/src/browser.ts index 5612752b58..6188837426 100644 --- a/packages/vquery/src/browser.ts +++ b/packages/vquery/src/browser.ts @@ -1,4 +1,5 @@ -export { convertDSLToSQL, Dataset } from './dataset' +export { Dataset } from './dataset' +export * from './sql-builder' export { DatasetSourceBuilder } from './data-source-builder/dataSourceBuilder' export * from './utils' export * from './types' diff --git a/packages/vquery/src/dataset/dataset.ts b/packages/vquery/src/dataset/dataset.ts index b10957314c..e0201278fc 100644 --- a/packages/vquery/src/dataset/dataset.ts +++ b/packages/vquery/src/dataset/dataset.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, DatasetSource, QueryDSL, QueryAdapter, StorageAdapter, VQueryDSL } from '../types' -import { convertDSLToSQL } from '../sql-builder' +import { convertDSLToDuckDB } from '../sql-builder' export class Dataset { private queryAdapter: QueryAdapter @@ -38,7 +38,7 @@ export class Dataset { } public async query>(queryDSL: QueryDSL | VQueryDSL) { - const sql = convertDSLToSQL(queryDSL, this.datasetId) + const sql = convertDSLToDuckDB(queryDSL, this.datasetId) return this.queryBySQL(sql) } diff --git a/packages/vquery/src/dataset/index.ts b/packages/vquery/src/dataset/index.ts index e56401a20a..126e036ab4 100644 --- a/packages/vquery/src/dataset/index.ts +++ b/packages/vquery/src/dataset/index.ts @@ -1,2 +1 @@ export { Dataset } from './dataset' -export { convertDSLToSQL } from '../sql-builder' diff --git a/packages/vquery/src/node.ts b/packages/vquery/src/node.ts index a9f145156f..91f18b3137 100644 --- a/packages/vquery/src/node.ts +++ b/packages/vquery/src/node.ts @@ -1,4 +1,5 @@ -export { convertDSLToSQL, Dataset } from './dataset' +export { Dataset } from './dataset' +export * from './sql-builder' export { DatasetSourceBuilder } from './data-source-builder/dataSourceBuilder' export * from './utils' export * from './types' diff --git a/packages/vquery/src/query-engine/sql.ts b/packages/vquery/src/query-engine/sql.ts index 36eb3ca0e9..d84159b0e0 100644 --- a/packages/vquery/src/query-engine/sql.ts +++ b/packages/vquery/src/query-engine/sql.ts @@ -29,7 +29,7 @@ type Predicate = | { type: 'truthy'; value: Expression } type SelectItem = { expression: Expression; alias?: string } -type OrderItem = { expression: Expression; direction: 'asc' | 'desc' } +type OrderItem = { expression: Expression; direction: 'asc' | 'desc'; nulls: 'first' | 'last' } export type SelectQuery = { table?: string @@ -263,7 +263,12 @@ class Parser { if (this.match('like') || this.match('ilike')) { const matchedOperator = this.tokens[this.index - 1].value.toLowerCase() as 'like' | 'ilike' const operator: LikeOperator = negated ? `not ${matchedOperator}` : matchedOperator - return { type: 'comparison', operator, left, right: this.scalar() } + const right = this.scalar() + if (this.match('escape')) { + const escape = this.scalar() + if (escape.type !== 'literal' || escape.value !== '') throw new Error('Only empty LIKE escape is supported') + } + return { type: 'comparison', operator, left, right } } if (negated) throw new Error('Expected IN, BETWEEN, LIKE, or ILIKE after NOT') const token = this.current() @@ -299,7 +304,12 @@ class Parser { do { const expression = this.scalar() const direction = this.match('desc') ? 'desc' : (this.match('asc'), 'asc') - result.orderBy.push({ expression, direction }) + let nulls: 'first' | 'last' = 'last' + if (this.match('nulls')) { + if (this.match('first')) nulls = 'first' + else this.expect('last') + } + result.orderBy.push({ expression, direction, nulls }) } while (this.match(',')) } else if (this.match('limit')) { const token = this.current() @@ -358,10 +368,8 @@ const compareText = (left: string, right: string): number => { return leftCodePoints.length - rightCodePoints.length } -const compare = (left: unknown, right: unknown): number => { +const compareNonNull = (left: unknown, right: unknown): number => { if (left === right) return 0 - if (left === null || left === undefined) return 1 - if (right === null || right === undefined) return -1 if (typeof left === 'number' && typeof right === 'number') return left - right return compareText(String(left), String(right)) } @@ -411,8 +419,10 @@ const aggregate = (expression: Extract, rows: Data const numbers = numericValues(argument, rows) return numbers.length ? numbers.reduce((sum, value) => sum + value, 0) / numbers.length : null } - if (expression.name === 'min') return values.length ? values.reduce((a, b) => (compare(a, b) <= 0 ? a : b)) : null - if (expression.name === 'max') return values.length ? values.reduce((a, b) => (compare(a, b) >= 0 ? a : b)) : null + if (expression.name === 'min') + return values.length ? values.reduce((a, b) => (compareNonNull(a, b) <= 0 ? a : b)) : null + if (expression.name === 'max') + return values.length ? values.reduce((a, b) => (compareNonNull(a, b) >= 0 ? a : b)) : null const numbers = numericValues(argument, rows).sort((a, b) => a - b) if (!numbers.length) return null if (expression.name === 'median') { @@ -426,10 +436,8 @@ const aggregate = (expression: Extract, rows: Data if (value === null || value === undefined || !Number.isFinite(quantile) || quantile < -1 || quantile > 1) { throw new Error('QUANTILE parameter must be a number in the range [-1, 1]') } - const index = - quantile < 0 - ? Math.min(numbers.length + Math.floor(quantile * numbers.length), numbers.length - 1) - : Math.max(Math.ceil(quantile * numbers.length) - 1, 0) + const position = Math.max(numbers.length - Math.floor(numbers.length - numbers.length * Math.abs(quantile)), 1) + const index = quantile < 0 ? numbers.length - position : position - 1 return numbers[index] } const average = numbers.reduce((sum, value) => sum + value, 0) / numbers.length @@ -513,7 +521,7 @@ const evaluatePredicate = (predicate: Predicate, row: DataRow, rows: DataRow[]): if (predicate.operator === 'in' || predicate.operator === 'not in') { const values = predicate.values.map((value) => evaluate(value, row, rows)) if (left === null || left === undefined) return null - const found = values.some((value) => value !== null && value !== undefined && compare(left, value) === 0) + const found = values.some((value) => value !== null && value !== undefined && compareNonNull(left, value) === 0) if (found) return predicate.operator === 'in' if (values.some((value) => value === null || value === undefined)) return null return predicate.operator === 'not in' @@ -522,7 +530,7 @@ const evaluatePredicate = (predicate: Predicate, row: DataRow, rows: DataRow[]): const values = predicate.values.map((value) => evaluate(value, row, rows)) if (left === null || left === undefined || values.some((value) => value === null || value === undefined)) return null - const found = compare(left, values[0]) >= 0 && compare(left, values[1]) <= 0 + const found = compareNonNull(left, values[0]) >= 0 && compareNonNull(left, values[1]) <= 0 return predicate.operator === 'between' ? found : !found } const operator = predicate.operator @@ -533,7 +541,7 @@ const evaluatePredicate = (predicate: Predicate, row: DataRow, rows: DataRow[]): return operator.startsWith('not ') ? !result : result } if (left === null || left === undefined || right === null || right === undefined) return null - const comparison = compare(left, right) + const comparison = compareNonNull(left, right) if (operator === '=') return comparison === 0 if (operator === '!=' || operator === '<>') return comparison !== 0 if (operator === '>') return comparison > 0 @@ -607,7 +615,13 @@ export const executeSQL = (query: SelectQuery, tableRows: DataRow[]): DataRow[] fieldName && Object.hasOwn(right.output, fieldName) ? right.output[fieldName] : evaluate(order.expression, right.row, right.rows) - const result = compare(leftValue, rightValue) + const leftNull = leftValue === null || leftValue === undefined + const rightNull = rightValue === null || rightValue === undefined + if (leftNull || rightNull) { + if (leftNull !== rightNull) return (leftNull ? 1 : -1) * (order.nulls === 'first' ? -1 : 1) + continue + } + const result = compareNonNull(leftValue, rightValue) if (result !== 0) return order.direction === 'desc' ? -result : result } if (!query.groupBy.length || !query.orderBy.length) return 0 diff --git a/packages/vquery/src/sql-builder/builders/having.ts b/packages/vquery/src/sql-builder/builders/having.ts index 9a213898f6..0d014c9b03 100644 --- a/packages/vquery/src/sql-builder/builders/having.ts +++ b/packages/vquery/src/sql-builder/builders/having.ts @@ -2,45 +2,12 @@ import type { RawBuilder, SelectQueryBuilder } from 'kysely' import type { Having, HavingAggregation, HavingClause } from '../../types' import { sql } from 'kysely' import { toSqlOperator } from '../utils' - -const AGGREGATE_FUNCTIONS = [ - 'sum', - 'avg', - 'count', - 'count_distinct', - 'min', - 'max', - 'variance', - 'variance_pop', - 'stddev', - 'median', - 'quantile', -] as const - -const isAggregateFunction = (func: string): boolean => { - return AGGREGATE_FUNCTIONS.includes(func as (typeof AGGREGATE_FUNCTIONS)[number]) -} - -const toAggregateExpression = (func: string, field: string, aggr?: HavingAggregation): RawBuilder => { - switch (func) { - case 'count': - return sql`count(${sql.ref(field)})` - case 'count_distinct': - return sql`count(distinct ${sql.ref(field)})` - case 'variance': - return sql`var_samp(${sql.ref(field)})` - case 'variance_pop': - return sql`var_pop(${sql.ref(field)})` - case 'quantile': - return sql`quantile(${sql.ref(field)}, ${aggr?.quantile ?? 0.5})` - default: - return sql`${sql.raw(func)}(${sql.ref(field)})` - } -} +import type { SQLStrategy } from '../types' export const applyHaving = ( qb: SelectQueryBuilder, - having?: Having | HavingClause, + having: Having | HavingClause | undefined, + strategy: SQLStrategy, ): SelectQueryBuilder => { if (!having) { return qb @@ -48,6 +15,7 @@ export const applyHaving = ( const toRaw = (h: Having | HavingClause): RawBuilder => { if ('op' in h && 'conditions' in h) { + if (h.conditions.length === 0) return h.op === 'and' ? sql`1=1` : sql`0=1` const parts: RawBuilder[] = (h.conditions as Array>).map((c) => toRaw(c)) const sep: RawBuilder = sql` ${sql.raw(h.op)} ` return sql`(${sql.join(parts, sep)})` @@ -60,11 +28,8 @@ export const applyHaving = ( } const field = leaf.field const value = leaf.value - if (!leaf.aggr?.func || !isAggregateFunction(leaf.aggr.func)) { - throw new Error(`Invalid having clause for field "${String(field)}": aggr.func is required`) - } const compareOp = toSqlOperator(leaf.op.trim().toLowerCase()) - const leftExpr: RawBuilder = toAggregateExpression(leaf.aggr.func, field, leaf.aggr) + const leftExpr: RawBuilder = strategy.aggregate(field, leaf.aggr) switch (compareOp) { case 'is null': @@ -73,22 +38,22 @@ export const applyHaving = ( return sql`${leftExpr} is not null` case 'in': { const items = Array.isArray(value) ? (value as unknown[]) : [value] - return sql`${leftExpr} in (${sql.join(items.map((v) => sql.val(v)))})` + return sql`${leftExpr} in (${sql.join(items.map((v) => strategy.value(v)))})` } case 'not in': { const items = Array.isArray(value) ? (value as unknown[]) : [value] - return sql`not ${leftExpr} in (${sql.join(items.map((v) => sql.val(v)))})` + return sql`not ${leftExpr} in (${sql.join(items.map((v) => strategy.value(v)))})` } case 'between': { const [a, b] = value as [unknown, unknown] - return sql`${leftExpr} between ${sql.val(a)} and ${sql.val(b)}` + return sql`${leftExpr} between ${strategy.value(a)} and ${strategy.value(b)}` } case 'not between': { const [a, b] = value as [unknown, unknown] - return sql`${leftExpr} not between ${sql.val(a)} and ${sql.val(b)}` + return sql`${leftExpr} not between ${strategy.value(a)} and ${strategy.value(b)}` } default: - return sql`${leftExpr} ${sql.raw(compareOp)} ${sql.val(value)}` + return sql`${leftExpr} ${sql.raw(compareOp)} ${strategy.value(value)}` } } return qb.having(toRaw(having)) diff --git a/packages/vquery/src/sql-builder/builders/limit.ts b/packages/vquery/src/sql-builder/builders/limit.ts index 87f3b02d18..b3d559029b 100644 --- a/packages/vquery/src/sql-builder/builders/limit.ts +++ b/packages/vquery/src/sql-builder/builders/limit.ts @@ -1,8 +1,13 @@ import type { SelectQueryBuilder } from 'kysely' +import type { SQLStrategy } from '../types' -export const applyLimit = (qb: SelectQueryBuilder, limit?: number) => { - if (limit && typeof limit === 'number') { - qb = qb.limit(limit) +export const applyLimit = ( + qb: SelectQueryBuilder, + limit: number | undefined, + strategy: SQLStrategy, +) => { + if (limit !== undefined) { + qb = qb.limit(strategy.limit(limit)) } return qb } diff --git a/packages/vquery/src/sql-builder/builders/order.ts b/packages/vquery/src/sql-builder/builders/order.ts index e7f2c2c3b4..7008ab7888 100644 --- a/packages/vquery/src/sql-builder/builders/order.ts +++ b/packages/vquery/src/sql-builder/builders/order.ts @@ -1,19 +1,16 @@ import type { SelectQueryBuilder } from 'kysely' - -type OrderByItem = { - field: string - order?: 'asc' | 'desc' -} +import type { OrderBy } from '../../types' +import type { SQLStrategy } from '../types' export const applyOrder = ( qb: SelectQueryBuilder, - orderBy?: Array, + orderBy: OrderBy | undefined, + strategy: SQLStrategy, ) => { - if (orderBy && orderBy.length > 0) { - orderBy.forEach((o) => { - // @ts-expect-error - Kysely orderBy type complexity - qb = qb.orderBy(o.field, o.order ?? 'asc') - }) + for (const item of orderBy ?? []) { + for (const expression of strategy.order(item.field as string, item.order ?? 'asc', item.nulls ?? 'last')) { + qb = qb.orderBy(expression) + } } return qb } diff --git a/packages/vquery/src/sql-builder/builders/select.ts b/packages/vquery/src/sql-builder/builders/select.ts index fbc6ab1eb1..190f753c2a 100644 --- a/packages/vquery/src/sql-builder/builders/select.ts +++ b/packages/vquery/src/sql-builder/builders/select.ts @@ -2,64 +2,20 @@ import type { SelectItem } from '../../types/dsl/Select' import { isSelectItem } from '../utils' import { sql } from 'kysely' import type { SelectQueryBuilder } from 'kysely' - -const DATE_FORMAT_MAP: Record = { - year: '%Y', - month: '%Y-%m', - day: '%Y-%m-%d', - week: '%Y-W%W', - hour: '%Y-%m-%d %H', - minute: '%Y-%m-%d %H:%M', - second: '%Y-%m-%d %H:%M:%S', -} +import type { SQLStrategy } from '../types' export const applySelect = ( qb: SelectQueryBuilder, - select?: Array>, + select: Array>, + strategy: SQLStrategy, ) => { - if (select && select.length > 0) { - return qb.select((eb) => - select.map((item) => { - if (isSelectItem(item)) { - const field = item.field as Extract - const expression = eb.ref(field as any) - // 优先使用用户提供的 alias,其次使用 field,保证唯一性 - const alias = item.alias ?? field - - if (item.aggr) { - const { func } = item.aggr - if (['avg', 'sum', 'min', 'max', 'variance', 'variance_pop', 'stddev', 'median'].includes(func)) { - if (func === 'variance') { - return sql`var_samp(${expression})`.as(alias) - } - if (func === 'variance_pop') { - return sql`var_pop(${expression})`.as(alias) - } - return sql`${sql.raw(func)}(${expression})`.as(alias) - } else if (func === 'count') { - return sql`CAST(count(${expression}) AS INTEGER)`.as(alias) - } else if (func === 'quantile') { - const q = item.aggr.quantile ?? 0.5 - return sql`quantile(${expression}, ${q})`.as(alias) - } else if (func === 'count_distinct') { - return sql`CAST(count(distinct ${expression}) AS INTEGER)`.as(alias) - } - const dateTrunc = func.replace('to_', '') - const format = DATE_FORMAT_MAP[dateTrunc] - if (format) { - return sql`strftime(CAST(${expression} AS TIMESTAMP), ${format})`.as(alias) - } - return sql`strftime(CAST(${expression} AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST(${expression} AS TIMESTAMP))`.as( - alias, - ) - } - // 优先使用用户提供的 alias,其次使用 field - return expression.as(alias) - } - return item as any - }), - ) - } else { - return qb.selectAll() - } + if (select.length === 0) return qb.selectAll() + return qb.select(() => + select.map((item) => { + if (!isSelectItem(item)) return item as any + const field = item.field as string + const expression = sql.ref(field) + return (item.aggr ? strategy.aggregate(field, item.aggr) : expression).as(item.alias ?? field) + }), + ) } diff --git a/packages/vquery/src/sql-builder/builders/where.ts b/packages/vquery/src/sql-builder/builders/where.ts index 12793f150b..7e96ccf802 100644 --- a/packages/vquery/src/sql-builder/builders/where.ts +++ b/packages/vquery/src/sql-builder/builders/where.ts @@ -2,10 +2,12 @@ import type { Where, WhereClause } from '../../types' import { sql } from 'kysely' import type { RawBuilder, SelectQueryBuilder } from 'kysely' import { toSqlOperator } from '../utils' +import type { SQLStrategy } from '../types' export const applyWhere = ( qb: SelectQueryBuilder, - where?: Where | WhereClause, + where: Where | WhereClause | undefined, + strategy: SQLStrategy, ): SelectQueryBuilder => { if (!where) { return qb @@ -13,6 +15,7 @@ export const applyWhere = ( const toRaw = (w: Where | WhereClause): RawBuilder => { if ('op' in w && 'conditions' in w) { + if (w.conditions.length === 0) return w.op === 'and' ? sql`1=1` : sql`0=1` const parts: RawBuilder[] = (w.conditions as Array>).map((c) => toRaw(c)) const sep: RawBuilder = sql` ${sql.raw(w.op)} ` return sql`(${sql.join(parts, sep)})` @@ -22,28 +25,33 @@ export const applyWhere = ( const value = leaf.value const sqlOp = toSqlOperator(leaf.op) switch (leaf.op) { + case 'like': + case 'not like': + case 'ilike': + case 'not ilike': + return strategy.like(sql.ref(field), value, leaf.op.startsWith('not '), leaf.op.includes('ilike')) case 'is null': return sql`${sql.ref(field)} is null` case 'is not null': return sql`${sql.ref(field)} is not null` case 'in': { const items = Array.isArray(value) ? (value as unknown[]) : [value] - return sql`${sql.ref(field)} in (${sql.join(items.map((v) => sql.val(v)))})` + return sql`${sql.ref(field)} in (${sql.join(items.map((v) => strategy.value(v)))})` } case 'not in': { const items = Array.isArray(value) ? (value as unknown[]) : [value] - return sql`not ${sql.ref(field)} in (${sql.join(items.map((v) => sql.val(v)))})` + return sql`not ${sql.ref(field)} in (${sql.join(items.map((v) => strategy.value(v)))})` } case 'between': { const [a, b] = value as [unknown, unknown] - return sql`${sql.ref(field)} between ${sql.val(a)} and ${sql.val(b)}` + return sql`${sql.ref(field)} between ${strategy.value(a)} and ${strategy.value(b)}` } case 'not between': { const [a, b] = value as [unknown, unknown] - return sql`${sql.ref(field)} not between ${sql.val(a)} and ${sql.val(b)}` + return sql`${sql.ref(field)} not between ${strategy.value(a)} and ${strategy.value(b)}` } default: - return sql`${sql.ref(field)} ${sql.raw(sqlOp)} ${sql.val(value)}` + return sql`${sql.ref(field)} ${sql.raw(sqlOp)} ${strategy.value(value)}` } } return qb.where(toRaw(where)) diff --git a/packages/vquery/src/sql-builder/compile/inlineParameters.ts b/packages/vquery/src/sql-builder/compile/inlineParameters.ts index aff9bf0b60..216ec911fc 100644 --- a/packages/vquery/src/sql-builder/compile/inlineParameters.ts +++ b/packages/vquery/src/sql-builder/compile/inlineParameters.ts @@ -1,20 +1,14 @@ import { escapeValue } from '../utils' +import type { QueryDialect } from '../types' -export const inlineParameters = (sql: string, params: readonly unknown[]): string => { +export const inlineParameters = (sql: string, params: readonly unknown[], dialect: QueryDialect = 'duckdb'): string => { if (params.length === 0) return sql - if (sql.includes('?')) { - let out = sql - for (const p of params) { - out = out.replace(/\?/, escapeValue(p)) - } - return out - } - if (/\$\d+/.test(sql)) { - return sql.replace(/\$(\d+)/g, (_, idx) => { - const i = Number(idx) - 1 - const v = params[i] - return escapeValue(v) - }) - } - return sql + let index = 0 + // Match quoted SQL first, and substitute each placeholder only once. Parameter + // values containing '?' or '$1' must never become new placeholders. + return sql.replace(/("(?:[^"]|"")*"|'(?:[^']|'')*'|`(?:[^`]|``)*`)|\$(\d+)|\?/g, (match, quoted, numbered) => { + if (quoted) return match + const value = params[numbered ? Number(numbered) - 1 : index++] + return escapeValue(dialect === 'mysql' && typeof value === 'string' ? value.replaceAll('\\', '\\\\') : value) + }) } diff --git a/packages/vquery/src/sql-builder/compileQuery.ts b/packages/vquery/src/sql-builder/compileQuery.ts new file mode 100644 index 0000000000..2998c6a36a --- /dev/null +++ b/packages/vquery/src/sql-builder/compileQuery.ts @@ -0,0 +1,27 @@ +import { Kysely } from 'kysely' +import type { QueryDSL } from '../types' +import type { CompileQueryOptions, CompiledQuery, SQLStrategy } from './types' +import { mysqlStrategy, duckdbStrategy } from './dialect' +import { applyWhere, applyGroupBy, applyHaving, applyLimit, applyOrder, applySelect } from './builders' +import { validateQuery } from './validateQuery' + +const strategies = { mysql: mysqlStrategy, duckdb: duckdbStrategy } + +export const compileQuery = (dsl: QueryDSL, options: CompileQueryOptions): CompiledQuery => { + const dialect = options.dialect ?? 'mysql' + if (!Object.hasOwn(strategies, dialect)) throw new Error(`Unsupported query dialect: ${dialect}`) + const strategy: SQLStrategy = strategies[dialect] + validateQuery(dsl, options.columns) + const db = new Kysely>({ dialect: strategy.dialect }) + let qb = strategy.source(db, options.table, options.columns ?? []) + qb = applyWhere(qb, dsl.where, strategy) + const prepared = strategy.prepare(qb, dsl, db, options.columns ?? []) + const preparedStrategy = { ...strategy, aggregate: prepared.aggregate } + qb = applySelect(prepared.query, dsl.select, preparedStrategy) + qb = applyGroupBy(qb, dsl.groupBy as string[] | undefined) + qb = applyHaving(qb, dsl.having, preparedStrategy) + qb = applyOrder(qb, dsl.orderBy, strategy) + qb = applyLimit(qb, dsl.limit, strategy) + const { sql, parameters } = qb.compile() + return { sql, parameters } +} diff --git a/packages/vquery/src/sql-builder/convertDSLToDuckDB.ts b/packages/vquery/src/sql-builder/convertDSLToDuckDB.ts new file mode 100644 index 0000000000..5b85a4adb9 --- /dev/null +++ b/packages/vquery/src/sql-builder/convertDSLToDuckDB.ts @@ -0,0 +1,13 @@ +import type { QueryDSL } from '../types' +import type { QueryTable, CompileQueryOptions } from './types' +import { compileQuery } from './compileQuery' +import { inlineParameters } from './compile' + +export const convertDSLToDuckDB = ( + dsl: QueryDSL, + table: TableName, + options: Omit = {}, +): string => { + const { sql, parameters } = compileQuery(dsl, { ...options, table, dialect: 'duckdb' }) + return inlineParameters(sql, parameters) +} diff --git a/packages/vquery/src/sql-builder/convertDSLToMysql.ts b/packages/vquery/src/sql-builder/convertDSLToMysql.ts new file mode 100644 index 0000000000..9f30492f82 --- /dev/null +++ b/packages/vquery/src/sql-builder/convertDSLToMysql.ts @@ -0,0 +1,13 @@ +import type { QueryDSL } from '../types' +import type { QueryTable, CompileQueryOptions } from './types' +import { compileQuery } from './compileQuery' +import { inlineParameters } from './compile' + +export const convertDSLToMysql = ( + dsl: QueryDSL, + table: TableName, + options: Omit = {}, +): string => { + const { sql, parameters } = compileQuery(dsl, { ...options, table, dialect: 'mysql' }) + return inlineParameters(sql, parameters, 'mysql') +} diff --git a/packages/vquery/src/sql-builder/dialect/compilationDialect.ts b/packages/vquery/src/sql-builder/dialect/compilationDialect.ts new file mode 100644 index 0000000000..68414d4daf --- /dev/null +++ b/packages/vquery/src/sql-builder/dialect/compilationDialect.ts @@ -0,0 +1,14 @@ +import { DummyDriver } from 'kysely' +import type { Dialect, DialectAdapter, QueryCompiler } from 'kysely' + +// Compilation never opens a database connection or introspects a live schema. +export const compilationDialect = (compiler: QueryCompiler, adapter: DialectAdapter): Dialect => ({ + createDriver: () => new DummyDriver(), + createQueryCompiler: () => compiler, + createAdapter: () => adapter, + createIntrospector: () => ({ + getSchemas: async () => [], + getTables: async () => [], + getMetadata: async () => ({ tables: [] }), + }), +}) diff --git a/packages/vquery/src/sql-builder/dialect/duckdb.ts b/packages/vquery/src/sql-builder/dialect/duckdb.ts new file mode 100644 index 0000000000..8cacd61f31 --- /dev/null +++ b/packages/vquery/src/sql-builder/dialect/duckdb.ts @@ -0,0 +1,46 @@ +import { PostgresAdapter, PostgresQueryCompiler, sql } from 'kysely' +import { compilationDialect } from './compilationDialect' +import type { SQLStrategy } from '../types' +import { createSource, normalizeValue } from './source' + +const formats: Record = { + to_year: '%Y', + to_month: '%Y-%m', + to_day: '%Y-%m-%d', + to_week: '%Y-W%W', + to_hour: '%Y-%m-%d %H', + to_minute: '%Y-%m-%d %H:%M', + to_second: '%Y-%m-%d %H:%M:%S', +} + +export const duckdbStrategy: SQLStrategy = { + dialect: compilationDialect(new PostgresQueryCompiler(), new PostgresAdapter()), + source: (db, table, columns) => createSource(db, table, columns, (field) => sql`${field} collate "binary"`), + prepare: (query) => ({ query, aggregate: duckdbStrategy.aggregate }), + value: (value) => sql.val(normalizeValue(value)), + limit: (value) => value, + aggregate: (name, aggr) => { + const field = sql.ref(name) + const { func } = aggr + if (formats[func]) return sql`strftime(CAST(${field} AS TIMESTAMP), ${formats[func]})` + switch (func) { + case 'to_quarter': + return sql`strftime(CAST(${field} AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST(${field} AS TIMESTAMP))` + case 'count': + return sql`count(${field})` + case 'count_distinct': + return sql`count(distinct ${field})` + case 'variance': + return sql`var_samp(${field})` + case 'variance_pop': + return sql`var_pop(${field})` + case 'quantile': + return sql`quantile(${field}, CAST(${aggr.quantile ?? 0.5} AS DOUBLE))` + default: + return sql`${sql.raw(func)}(${field})` + } + }, + like: (field, value, negated, insensitive) => + sql`${field} ${sql.raw(`${negated ? 'not ' : ''}${insensitive ? 'ilike' : 'like'}`)} ${sql.val(normalizeValue(value))} escape ''`, + order: (field, direction, nulls) => [sql`${sql.ref(field)} ${sql.raw(direction)} nulls ${sql.raw(nulls)}`], +} diff --git a/packages/vquery/src/sql-builder/dialect/index.ts b/packages/vquery/src/sql-builder/dialect/index.ts index 9ce5bf1fac..5b505d37c2 100644 --- a/packages/vquery/src/sql-builder/dialect/index.ts +++ b/packages/vquery/src/sql-builder/dialect/index.ts @@ -1 +1,2 @@ -export { PostgresDialect } from './postgresDialect' +export { mysqlStrategy } from './mysql' +export { duckdbStrategy } from './duckdb' diff --git a/packages/vquery/src/sql-builder/dialect/mysql.ts b/packages/vquery/src/sql-builder/dialect/mysql.ts new file mode 100644 index 0000000000..81fb56fecf --- /dev/null +++ b/packages/vquery/src/sql-builder/dialect/mysql.ts @@ -0,0 +1,62 @@ +import { MysqlAdapter, MysqlQueryCompiler, sql } from 'kysely' +import { compilationDialect } from './compilationDialect' +import type { SQLStrategy } from '../types' +import { createSource, normalizeValue } from './source' +import { prepareMysqlStatistics } from './mysqlStatistics' + +const text = (field: ReturnType) => sql`convert(${field} using utf8mb4) collate utf8mb4_0900_bin` + +const formats: Record = { + to_year: '%Y', + to_month: '%Y-%m', + to_day: '%Y-%m-%d', + to_hour: '%Y-%m-%d %H', + to_minute: '%Y-%m-%d %H:%i', + to_second: '%Y-%m-%d %H:%i:%s', +} + +export const mysqlStrategy: SQLStrategy = { + dialect: compilationDialect(new MysqlQueryCompiler(), new MysqlAdapter()), + source: (db, table, columns) => createSource(db, table, columns, text), + prepare: (query, dsl, db, columns) => prepareMysqlStatistics(query, dsl, db, mysqlStrategy, columns), + value: (value) => { + const normalized = normalizeValue(value) + return typeof normalized === 'string' ? text(sql.val(normalized)) : sql.val(normalized) + }, + // mysql2 encodes JS numbers as DOUBLE, which some MySQL versions reject + // for LIMIT placeholders. validateQuery has already checked this integer. + limit: (value) => sql.lit(value), + aggregate: (name, aggr) => { + const field = sql.ref(name) + const { func } = aggr + if (formats[func]) return sql`date_format(${field}, ${formats[func]})` + switch (func) { + case 'to_week': + return sql`concat(date_format(${field}, '%Y-W'), lpad(week(${field}, 5), 2, '0'))` + case 'to_quarter': + return sql`concat(date_format(${field}, '%Y'), '-Q', quarter(${field}))` + case 'count_distinct': + return sql`count(distinct ${field})` + case 'variance': + return sql`var_samp(${field})` + case 'variance_pop': + return sql`var_pop(${field})` + case 'stddev': + return sql`stddev_samp(${field})` + case 'median': + case 'quantile': + throw new Error('Statistical aggregates cannot be used as grouping keys') + default: + return sql`${sql.raw(func)}(${field})` + } + }, + like: (field, value, negated, insensitive) => { + const left = text(field), + right = text(sql.val(normalizeValue(value))) + return sql`${insensitive ? sql`lower(${left})` : left} ${sql.raw(negated ? 'not like' : 'like')} ${insensitive ? sql`lower(${right})` : right} escape ''` + }, + order: (field, direction, nulls) => [ + sql`${sql.ref(field)} is null ${sql.raw(nulls === 'last' ? 'asc' : 'desc')}`, + sql`${sql.ref(field)} ${sql.raw(direction)}`, + ], +} diff --git a/packages/vquery/src/sql-builder/dialect/mysqlStatistics.ts b/packages/vquery/src/sql-builder/dialect/mysqlStatistics.ts new file mode 100644 index 0000000000..a2c3a62787 --- /dev/null +++ b/packages/vquery/src/sql-builder/dialect/mysqlStatistics.ts @@ -0,0 +1,83 @@ +import { sql } from 'kysely' +import type { Kysely, SelectExpression } from 'kysely' +import type { DatasetColumn, QueryDSL } from '../../types' +import type { AggregateBuilder, QueryBuilder, SQLStrategy } from '../types' + +export function prepareMysqlStatistics( + query: QueryBuilder, + dsl: QueryDSL>, + db: Kysely, + strategy: SQLStrategy, + columns: DatasetColumn[], +) { + const fields = new Set() + const statistical = new Set() + const used = new Set() + const selectItems = dsl.select.map((item) => (typeof item === 'string' ? { field: item } : item)) + for (const item of selectItems) { + fields.add(item.field) + used.add(item.alias ?? item.field) + if (item.aggr?.func === 'median' || item.aggr?.func === 'quantile') statistical.add(item.field) + } + const visit = (node: any) => { + if ('conditions' in node) node.conditions.forEach(visit) + else { + fields.add(node.field) + if (node.aggr?.func === 'median' || node.aggr?.func === 'quantile') statistical.add(node.field) + } + } + if (dsl.having) visit(dsl.having) + if (!statistical.size) return { query, aggregate: strategy.aggregate } + + const aliases = new Map(selectItems.map((item) => [item.alias ?? item.field, item])) + const sourceNames = new Set([...fields, ...columns.map((column) => column.name)]) + const groups = (dsl.groupBy ?? []).map((name) => { + // Both engines resolve source columns before SELECT aliases in GROUP BY. + const item = sourceNames.has(name) ? undefined : aliases.get(name) + const field = item?.field ?? name + fields.add(field) + return item?.aggr ? strategy.aggregate(field, item.aggr) : sql.ref(field) + }) + for (const item of dsl.orderBy ?? []) { + if (!aliases.has(item.field)) fields.add(item.field) + } + for (const field of fields) used.add(field) + let serial = 0 + const unique = () => { + let name: string + do name = `__vquery_stat_${serial++}` + while (used.has(name)) + used.add(name) + return name + } + const partition = groups.length ? sql`partition by ${sql.join(groups)}` : sql`` + const windows = new Map() + const projections: SelectExpression[] = [...fields] + for (const field of statistical) { + const rank = unique(), + count = unique() + windows.set(field, { rank, count }) + projections.push( + sql`row_number() over (${partition} order by ${sql.ref(field)} is null, ${sql.ref(field)})`.as(rank), + sql`count(${sql.ref(field)}) over (${partition})`.as(count), + ) + } + const ranked = query.select(projections).as('__vquery_ranked') + const aggregate: AggregateBuilder = (field, aggr) => { + if (aggr.func !== 'median' && aggr.func !== 'quantile') return strategy.aggregate(field, aggr) + const names = windows.get(field)! + const rank = sql.ref(names.rank), + count = sql.ref(names.count), + value = sql.ref(field) + if (aggr.func === 'median') { + return sql`avg(case when ${rank} in (floor((${count} + 1) / 2), floor((${count} + 2) / 2)) then ${value} end)` + } + const quantile = aggr.quantile ?? 0.5 + // Match DuckDB's DOUBLE discrete-quantile index, including rounding at + // integer boundaries: n - floor(n - n*q), rather than ceil(n*q). + const position = sql`greatest(${count} - floor(${count} - ${count} * CAST(${Math.abs(quantile)} AS DOUBLE)), 1)` + const target = quantile < 0 ? sql`${count} + 1 - ${position}` : position + return sql`max(case when ${rank} = ${target} then ${value} end)` + } + return { query: db.selectFrom(ranked), aggregate } +} diff --git a/packages/vquery/src/sql-builder/dialect/postgresDialect.ts b/packages/vquery/src/sql-builder/dialect/postgresDialect.ts deleted file mode 100644 index 4e09c12085..0000000000 --- a/packages/vquery/src/sql-builder/dialect/postgresDialect.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { DummyDriver } from 'kysely' -import { PostgresQueryCompiler } from 'kysely' -import { PostgresAdapter } from 'kysely' -import type { Kysely } from 'kysely' -import type { - DatabaseIntrospector, - SchemaMetadata, - TableMetadata, - DatabaseMetadata, - DatabaseMetadataOptions, - Dialect, -} from 'kysely' - -export class PostgresDialect implements Dialect { - createDriver() { - return new DummyDriver() - } - createQueryCompiler() { - return new PostgresQueryCompiler() - } - createAdapter() { - return new PostgresAdapter() - } - createIntrospector(db: Kysely): DatabaseIntrospector { - void db - class NullIntrospector implements DatabaseIntrospector { - async getSchemas(): Promise { - return [] - } - async getTables(options?: DatabaseMetadataOptions): Promise { - void options?.withInternalKyselyTables - return [] - } - async getMetadata(options?: DatabaseMetadataOptions): Promise { - void options?.withInternalKyselyTables - return { tables: [] } - } - } - return new NullIntrospector() - } -} diff --git a/packages/vquery/src/sql-builder/dialect/source.ts b/packages/vquery/src/sql-builder/dialect/source.ts new file mode 100644 index 0000000000..50bf5c4837 --- /dev/null +++ b/packages/vquery/src/sql-builder/dialect/source.ts @@ -0,0 +1,27 @@ +import { sql } from 'kysely' +import type { Kysely, RawBuilder } from 'kysely' +import type { DatasetColumn } from '../../types' +import type { QueryTable } from '../types' + +export const createSource = ( + db: Kysely, + table: QueryTable, + columns: DatasetColumn[], + text: (field: RawBuilder) => RawBuilder, +) => { + const query = typeof table === 'string' ? db.selectFrom(table) : db.withSchema(table.database).selectFrom(table.name) + if (!columns.some((column) => column.type === 'string')) return query + // Collation is part of the logical string type, not a database/table default. + const source = query + .select( + columns.map((column) => { + const field = sql.ref(column.name) + return (column.type === 'string' ? text(field) : field).as(column.name) + }), + ) + .as('__vquery_source') + return db.selectFrom(source) +} + +export const normalizeValue = (value: unknown): unknown => + value instanceof Date ? value.toISOString().slice(0, 23).replace('T', ' ') : value diff --git a/packages/vquery/src/sql-builder/dslToSQL.ts b/packages/vquery/src/sql-builder/dslToSQL.ts deleted file mode 100644 index f79a5ccea5..0000000000 --- a/packages/vquery/src/sql-builder/dslToSQL.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { QueryDSL, VQueryDSL } from '../types' -import { Kysely } from 'kysely' -import { PostgresDialect } from './dialect' -import { inlineParameters } from './compile' -import { applyWhere, applyGroupBy, applyHaving, applyLimit, applyOrder, applySelect } from './builders' - -export const convertDSLToSQL = ( - dsl: QueryDSL | VQueryDSL, - tableName: TableName, -): string => { - const db = new Kysely>({ - dialect: new PostgresDialect(), - }) - - let qb = db.selectFrom(tableName) - - qb = applySelect(qb, dsl.select) - qb = applyWhere(qb, dsl.where) - qb = applyGroupBy(qb, dsl.groupBy as string[] | undefined) - qb = applyHaving(qb, dsl.having) - qb = applyOrder(qb, dsl.orderBy as Array<{ field: string; order?: 'asc' | 'desc' }> | undefined) - qb = applyLimit(qb, dsl.limit) - - const { sql, parameters } = qb.compile() - return inlineParameters(sql, parameters) -} diff --git a/packages/vquery/src/sql-builder/index.ts b/packages/vquery/src/sql-builder/index.ts index 39b51dbea4..7a20b4802c 100644 --- a/packages/vquery/src/sql-builder/index.ts +++ b/packages/vquery/src/sql-builder/index.ts @@ -1 +1,4 @@ -export { convertDSLToSQL } from './dslToSQL' +export { compileQuery } from './compileQuery' +export { convertDSLToMysql } from './convertDSLToMysql' +export { convertDSLToDuckDB } from './convertDSLToDuckDB' +export type { CompileQueryOptions, CompiledQuery, QueryDialect, QueryTable } from './types' diff --git a/packages/vquery/src/sql-builder/types.ts b/packages/vquery/src/sql-builder/types.ts new file mode 100644 index 0000000000..dff8a87512 --- /dev/null +++ b/packages/vquery/src/sql-builder/types.ts @@ -0,0 +1,36 @@ +import type { Dialect, RawBuilder, Kysely, SelectQueryBuilder } from 'kysely' +import type { DatasetColumn, QueryDSL } from '../types' +import type { SelectItem } from '../types/dsl/Select' + +export type QueryDialect = 'mysql' | 'duckdb' +export type QueryTable = string | { database: string; name: string } +export type QueryBuilder = SelectQueryBuilder +export type AggregateBuilder = (field: string, aggr: NonNullable['aggr']>) => RawBuilder + +export interface CompileQueryOptions { + table: QueryTable + dialect?: QueryDialect + /** Full logical source schema, used to align string collations across engines. */ + columns?: DatasetColumn[] +} + +export interface CompiledQuery { + sql: string + parameters: readonly unknown[] +} + +export interface SQLStrategy { + dialect: Dialect + source: (db: Kysely, table: QueryTable, columns: DatasetColumn[]) => QueryBuilder + prepare: ( + query: QueryBuilder, + dsl: QueryDSL, + db: Kysely, + columns: DatasetColumn[], + ) => { query: QueryBuilder; aggregate: AggregateBuilder } + limit: (value: number) => number | RawBuilder + aggregate: AggregateBuilder + value: (value: unknown) => RawBuilder + like: (field: RawBuilder, value: unknown, negated: boolean, insensitive: boolean) => RawBuilder + order: (field: string, direction: 'asc' | 'desc', nulls: 'first' | 'last') => RawBuilder[] +} diff --git a/packages/vquery/src/sql-builder/validateQuery.ts b/packages/vquery/src/sql-builder/validateQuery.ts new file mode 100644 index 0000000000..50b50e3c17 --- /dev/null +++ b/packages/vquery/src/sql-builder/validateQuery.ts @@ -0,0 +1,176 @@ +import type { DatasetColumn } from '../types' +import { toSqlOperator } from './utils' + +const aggregates = [ + 'count', + 'count_distinct', + 'sum', + 'avg', + 'min', + 'max', + 'variance', + 'variance_pop', + 'stddev', + 'median', + 'quantile', +] +const dates = ['to_year', 'to_quarter', 'to_month', 'to_week', 'to_day', 'to_hour', 'to_minute', 'to_second'] +const operators = [ + '=', + '!=', + '>', + '>=', + '<', + '<=', + 'like', + 'not like', + 'ilike', + 'not ilike', + 'in', + 'not in', + 'between', + 'not between', + 'is null', + 'is not null', +] + +function assert(ok: unknown, message: string): asserts ok { + if (!ok) throw new Error(message) +} +const object = (value: unknown): value is Record => + value !== null && typeof value === 'object' && !Array.isArray(value) +const name = (value: unknown) => typeof value === 'string' && value.length > 0 +const scalar = (value: unknown) => + (value instanceof Date && Number.isFinite(value.getTime())) || + value === null || + typeof value === 'string' || + typeof value === 'boolean' || + (typeof value === 'number' && Number.isFinite(value)) + +function aggregate(value: unknown, allowDates: boolean) { + assert(object(value), 'Invalid aggregate') + assert(aggregates.includes(value.func) || (allowDates && dates.includes(value.func)), 'Unsupported aggregate') + assert( + Object.keys(value).every((key) => key === 'func' || key === 'quantile'), + 'Unsupported aggregate property', + ) + if (value.quantile !== undefined) { + assert( + value.func === 'quantile' && + typeof value.quantile === 'number' && + Number.isFinite(value.quantile) && + value.quantile >= -1 && + value.quantile <= 1, + 'Invalid quantile', + ) + } +} + +function predicate(node: unknown, having: boolean) { + assert(object(node), 'Invalid filter') + if ('conditions' in node) { + assert((node.op === 'and' || node.op === 'or') && Array.isArray(node.conditions), 'Invalid filter group') + node.conditions.forEach((child: unknown) => predicate(child, having)) + return + } + assert(name(node.field), 'Invalid filter field') + if (having) { + assert( + object(node.aggr) && aggregates.includes(node.aggr.func), + `Invalid having clause for field "${node.field}": aggr.func is required`, + ) + aggregate(node.aggr, false) + } + assert(typeof node.op === 'string', 'Invalid filter operator') + const op = toSqlOperator(having ? node.op.trim().toLowerCase() : node.op) + assert(operators.includes(op) && (!having || !op.includes('like')), 'Unsupported filter operator') + if (op === 'is null' || op === 'is not null') return + if (op === 'in' || op === 'not in') { + assert( + Array.isArray(node.value) ? node.value.length > 0 && node.value.every(scalar) : scalar(node.value), + 'Invalid IN values', + ) + } else if (op === 'between' || op === 'not between') { + assert(Array.isArray(node.value) && node.value.length === 2 && node.value.every(scalar), 'Invalid range') + } else assert(scalar(node.value), 'Invalid filter value') +} + +export function validateQuery(dsl: unknown, columns: DatasetColumn[] = []) { + assert(object(dsl), 'Expected query DSL') + assert( + Object.keys(dsl).every((key) => ['select', 'where', 'groupBy', 'having', 'orderBy', 'limit'].includes(key)), + 'Unsupported query property', + ) + const numeric = ['sum', 'avg', 'variance', 'variance_pop', 'stddev', 'median', 'quantile'] + const columnTypes = new Map(columns.map((column) => [column.name, column.type])) + const checkType = (field: string, aggr: { func: string }) => { + if (columns.length && numeric.includes(aggr.func)) { + assert(columnTypes.get(field) === 'number', `${aggr.func} requires a number column: ${field}`) + } + } + const checkValues = (node: any, having: boolean) => { + if ('conditions' in node) { + node.conditions.forEach((child: unknown) => checkValues(child, having)) + return + } + const fieldType = columnTypes.get(node.field) + const type = having && node.aggr.func !== 'min' && node.aggr.func !== 'max' ? 'number' : fieldType + const op = node.op.trim().toLowerCase() + if (op.includes('like')) + assert(node.value === null || typeof node.value === 'string', 'LIKE requires a string pattern') + if (columns.length && op.includes('like')) assert(type === 'string', `LIKE requires a string column: ${node.field}`) + if (!columns.length || !type || op.includes('like') || op === 'is null' || op === 'is not null') return + const values = Array.isArray(node.value) ? node.value : [node.value] + assert( + values.every( + (value: unknown) => + value === null || + (type === 'number' + ? typeof value === 'number' + : type === 'string' + ? typeof value === 'string' + : typeof value === 'string' || value instanceof Date), + ), + `Filter value does not match ${type} column: ${node.field}`, + ) + } + assert(Array.isArray(dsl.select), 'Invalid select') + for (const item of dsl.select) { + if (typeof item === 'string') assert(name(item), 'Invalid select field') + else { + assert(object(item) && name(item.field), 'Invalid select item') + assert(item.alias === undefined || name(item.alias), 'Invalid select alias') + if (item.aggr !== undefined) { + aggregate(item.aggr, true) + checkType(item.field, item.aggr) + } + } + } + if (dsl.where !== undefined) { + predicate(dsl.where, false) + checkValues(dsl.where, false) + } + if (dsl.having !== undefined) { + predicate(dsl.having, true) + checkValues(dsl.having, true) + const checkHaving = (node: any) => { + if ('conditions' in node) node.conditions.forEach(checkHaving) + else checkType(node.field, node.aggr) + } + checkHaving(dsl.having) + } + if (dsl.groupBy !== undefined) assert(Array.isArray(dsl.groupBy) && dsl.groupBy.every(name), 'Invalid groupBy') + if (dsl.orderBy !== undefined) + assert( + Array.isArray(dsl.orderBy) && + dsl.orderBy.every( + (item: unknown) => + object(item) && + name(item.field) && + (item.order === undefined || item.order === 'asc' || item.order === 'desc') && + (item.nulls === undefined || item.nulls === 'first' || item.nulls === 'last'), + ), + 'Invalid orderBy', + ) + if (dsl.limit !== undefined) assert(Number.isSafeInteger(dsl.limit) && dsl.limit >= 0, 'Invalid limit') +} diff --git a/packages/vquery/src/types/VQueryOptions.ts b/packages/vquery/src/types/VQueryOptions.ts new file mode 100644 index 0000000000..ef65f6e570 --- /dev/null +++ b/packages/vquery/src/types/VQueryOptions.ts @@ -0,0 +1,4 @@ +export interface VQueryOptions { + /** Persist datasets in IndexedDB. Defaults to false; requires IndexedDB support. */ + enableIndexedDB?: boolean +} diff --git a/packages/vquery/src/types/dsl/OrderBy.ts b/packages/vquery/src/types/dsl/OrderBy.ts index e71646f8d3..96df7ca6f3 100644 --- a/packages/vquery/src/types/dsl/OrderBy.ts +++ b/packages/vquery/src/types/dsl/OrderBy.ts @@ -1,4 +1,6 @@ export type OrderBy = Array<{ field: string | keyof T order?: 'asc' | 'desc' + /** NULL values sort last by default, independent of direction. */ + nulls?: 'first' | 'last' }> diff --git a/packages/vquery/src/types/index.ts b/packages/vquery/src/types/index.ts index 6acecc8732..34f3ee1f4f 100644 --- a/packages/vquery/src/types/index.ts +++ b/packages/vquery/src/types/index.ts @@ -3,3 +3,4 @@ export * from './DataSource' export * from './QueryResult' export * from './dsl' export * from './adapters' +export * from './VQueryOptions' diff --git a/packages/vquery/src/vquery-browser.ts b/packages/vquery/src/vquery-browser.ts index 2c2c483ed3..833cad1130 100644 --- a/packages/vquery/src/vquery-browser.ts +++ b/packages/vquery/src/vquery-browser.ts @@ -1,9 +1,10 @@ -import { IndexedDBAdapter } from './adapters' +import { IndexedDBAdapter, InMemoryAdapter } from './adapters' import { InMemoryQueryAdapter } from './adapters/query-adapter/inMemoryQueryAdapter' import { VQuery as VQueryCore } from './VQuery' +import type { VQueryOptions } from './types' export class VQuery extends VQueryCore { - constructor() { - super(new InMemoryQueryAdapter(), new IndexedDBAdapter()) + constructor({ enableIndexedDB = false }: VQueryOptions = {}) { + super(new InMemoryQueryAdapter(), enableIndexedDB ? new IndexedDBAdapter() : new InMemoryAdapter()) } } diff --git a/packages/vquery/src/vquery-node.ts b/packages/vquery/src/vquery-node.ts index 0f1d9160b9..833cad1130 100644 --- a/packages/vquery/src/vquery-node.ts +++ b/packages/vquery/src/vquery-node.ts @@ -1,9 +1,10 @@ -import { InMemoryAdapter } from './adapters' +import { IndexedDBAdapter, InMemoryAdapter } from './adapters' import { InMemoryQueryAdapter } from './adapters/query-adapter/inMemoryQueryAdapter' import { VQuery as VQueryCore } from './VQuery' +import type { VQueryOptions } from './types' export class VQuery extends VQueryCore { - constructor() { - super(new InMemoryQueryAdapter(), new InMemoryAdapter()) + constructor({ enableIndexedDB = false }: VQueryOptions = {}) { + super(new InMemoryQueryAdapter(), enableIndexedDB ? new IndexedDBAdapter() : new InMemoryAdapter()) } } diff --git a/packages/vquery/tests/dialects/__snapshots__/compile.test.ts.snap b/packages/vquery/tests/dialects/__snapshots__/compile.test.ts.snap new file mode 100644 index 0000000000..41ab3b0fcb --- /dev/null +++ b/packages/vquery/tests/dialects/__snapshots__/compile.test.ts.snap @@ -0,0 +1,10946 @@ +// Rstest Snapshot v1 + +exports[`DSL to SQL snapshots > GROUP BY source takes precedence over a colliding alias 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select sum("profit") as "product_type", median("sales") as "median" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_type"", + }, + "mysql": { + "parameters": [], + "sql": "select sum(\`profit\`) as \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\` from (select \`profit\`, \`sales\`, \`product_type\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`product_type\`", + }, +} +`; + +exports[`DSL to SQL snapshots > GROUP BY source takes precedence over a selected aggregate without alias 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select sum("profit") as "profit", median("sales") as "median" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "profit"", + }, + "mysql": { + "parameters": [], + "sql": "select sum(\`profit\`) as \`profit\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\` from (select \`profit\`, \`sales\`, row_number() over (partition by \`profit\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`profit\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`profit\`", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING between 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 4, + ], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (sum("sales") between $1 and $2)", + }, + "mysql": { + "parameters": [ + 1, + 4, + ], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (sum(\`sales\`) between ? and ?)", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING is not null 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (sum("sales") is not null)", + }, + "mysql": { + "parameters": [], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (sum(\`sales\`) is not null)", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING is null 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (sum("sales") is null)", + }, + "mysql": { + "parameters": [], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (sum(\`sales\`) is null)", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (avg("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (avg(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix avg not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not avg("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not avg(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not count("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not count(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (count(distinct "sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (count(distinct \`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix count_distinct not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not count(distinct "sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not count(distinct \`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (max("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (max(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix max not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not max("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not max(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (median("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix median not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not median("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (not avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (min("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (min(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix min not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not min("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not min(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile != 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) != $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile < 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) < $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile <= 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) <= $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile = 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) = $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile > 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) > $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile >= 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) >= $8 or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile between 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) between $8 and $9 or (count("id") > $10 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $11", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) in ($8, $9, $10) or (count("id") > $11 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) is not null or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile is null 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) is null or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile not between 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (quantile("sales", CAST($7 AS DOUBLE)) not between $8 and $9 or (count("id") > $10 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $11", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix quantile not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $2 and $3 or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (not quantile("sales", CAST($7 AS DOUBLE)) in ($8, $9, $10) or (count("id") > $11 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + 0.5, + -1, + 1, + 1, + "技术", + "家具", + 0.5, + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (not max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (stddev("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (stddev_samp(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix stddev not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not stddev("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not stddev_samp(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (sum(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix sum not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not sum("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not sum(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_samp("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_samp(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not var_samp("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not var_samp(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop != 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") != $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) != ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop < 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") < $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) < ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop <= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") <= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) <= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop = 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") = $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) = ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop > 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") > $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) > ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop >= 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") >= $6 or (count("id") > $7 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) >= ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") is not null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) is not null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop is null 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") is null or (count("id") > $6 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) is null or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (var_pop("sales") not between $6 and $7 or (count("id") > $8 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + -10, + 100, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (var_pop(\`sales\`) not between ? and ? or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING matrix variance_pop not in 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + 50, + ], + "sql": "select "product_type", "product_name", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (not var_pop("sales") in ($6, $7, $8) or (count("id") > $9 and max("profit") is not null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + -1, + 1, + 1, + "技术", + "家具", + 0, + 10, + null, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`product_type\`, \`product_name\` having (not var_pop(\`sales\`) in (?, ?, ?) or (count(\`id\`) > ? and max(\`profit\`) is not null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING not between 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 4, + ], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (sum("sales") not between $1 and $2)", + }, + "mysql": { + "parameters": [ + 1, + 4, + ], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (sum(\`sales\`) not between ? and ?)", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING only median and nested count 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + 1, + ], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having ((median("sales") > $1) and count("id") >= $2)", + }, + "mysql": { + "parameters": [ + 0, + 1, + ], + "sql": "select count(\`id\`) as \`id\` from (select \`id\`, \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` having ((avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) > ?) and count(\`id\`) >= ?)", + }, +} +`; + +exports[`DSL to SQL snapshots > HAVING statistics absent from projection 1`] = ` +{ + "duckdb": { + "parameters": [ + 2.5, + -0.5, + 5, + ], + "sql": "select "product_type", sum("sales") as "sum" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_type" having (median("sales") >= $1 or quantile("profit", CAST($2 AS DOUBLE)) > $3) order by "product_type" asc nulls last", + }, + "mysql": { + "parameters": [ + 2.5, + 0.5, + 5, + ], + "sql": "select \`product_type\`, sum(\`sales\`) as \`sum\` from (select \`product_type\`, \`sales\`, \`profit\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\`, row_number() over (partition by \`product_type\` order by \`profit\` is null, \`profit\`) as \`__vquery_stat_2\`, count(\`profit\`) over (partition by \`product_type\`) as \`__vquery_stat_3\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? or max(case when \`__vquery_stat_2\` = \`__vquery_stat_3\` + 1 - greatest(\`__vquery_stat_3\` - floor(\`__vquery_stat_3\` - \`__vquery_stat_3\` * CAST(? AS DOUBLE)), 1) then \`profit\` end) > ?) order by \`product_type\` is null asc, \`product_type\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > LIKE NULL 1`] = ` +{ + "duckdb": { + "parameters": [ + null, + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" like $1 escape '')", + }, + "mysql": { + "parameters": [ + null, + ], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '')", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering asc default 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" asc nulls last, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null asc, \`sales\` asc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering asc first 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" asc nulls first, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null desc, \`sales\` asc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering asc last 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" asc nulls last, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null asc, \`sales\` asc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering desc default 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" desc nulls last, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null asc, \`sales\` desc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering desc first 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" desc nulls first, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null desc, \`sales\` desc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > NULL ordering desc last 1`] = ` +{ + "duckdb": { + "parameters": [ + 8, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "sales" desc nulls last, "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`sales\` is null asc, \`sales\` desc, \`id\` is null asc, \`id\` asc limit 8", + }, +} +`; + +exports[`DSL to SQL snapshots > all fields and zero limit 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + ], + "sql": "select * from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select * from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` limit 0", + }, +} +`; + +exports[`DSL to SQL snapshots > all-column detail with nested filters and no limit 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars%", + 1, + "技术", + "家具", + ], + "sql": "select * from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) order by "order_date" desc nulls first, "id" desc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars%", + 1, + "技术", + "家具", + ], + "sql": "select * from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) order by \`order_date\` is null desc, \`order_date\` desc, \`id\` is null asc, \`id\` desc", + }, +} +`; + +exports[`DSL to SQL snapshots > array HAVING in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 2, + ], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (sum("sales") in ($1, $2))", + }, + "mysql": { + "parameters": [ + 1, + 2, + ], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (sum(\`sales\`) in (?, ?))", + }, +} +`; + +exports[`DSL to SQL snapshots > array HAVING not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 2, + ], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (not sum("sales") in ($1, $2))", + }, + "mysql": { + "parameters": [ + 1, + 2, + ], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (not sum(\`sales\`) in (?, ?))", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "%Y-%m-%d", + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + 0.5, + "%Y-%m-%d", + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_day variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "%Y-%m-%d %H", + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + 0.5, + "%Y-%m-%d %H", + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_hour variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "%Y-%m-%d %H:%i", + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + 0.5, + "%Y-%m-%d %H:%i", + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_minute variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "%Y-%m", + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y-%m", + 0.5, + "%Y-%m", + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_month variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (avg("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter count 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (count("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (count(distinct "sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter max 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (max("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter median 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (median("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter min 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (min("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (quantile("sales", CAST($8 AS DOUBLE)) >= $9 and (count("id") > $10 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $11", + }, + "mysql": { + "parameters": [ + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (stddev("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (sum("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (var_samp("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_quarter variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("sales" >= $3 and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6)))) group by "order_period", "product_type" having (var_pop("sales") >= $7 and (count("id") > $8 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "%Y-%m-%d %H:%i:%s", + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + 0.5, + "%Y-%m-%d %H:%i:%s", + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_second variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_week variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" desc nulls first, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null desc, \`sales_metric\` desc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year avg 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", avg("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (avg("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (avg(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year count 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", count(distinct "sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (count(distinct "sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, count(distinct \`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (count(distinct \`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year max 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", max("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (max("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (max(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year median 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (median("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "%Y", + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year min 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", min("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (min("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, min(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (min(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + 0.5, + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", quantile("sales", CAST($2 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and (("sales" >= $5 and "profit" is null) or ("id" >= $6 and not "product_type" in ($7, $8)))) group by "order_period", "product_type" having (quantile("sales", CAST($9 AS DOUBLE)) >= $10 and (count("id") > $11 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $12", + }, + "mysql": { + "parameters": [ + "%Y", + 0.5, + "%Y", + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 0.5, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`id\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))))) as \`__vquery_ranked\` group by \`order_period\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year stddev 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", stddev("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (stddev("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, stddev_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (stddev_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year sum 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (sum("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, sum(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (sum(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year variance 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_samp("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_samp("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_samp(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_samp(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date aggregate matrix to_year variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + 25, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", "product_type", var_pop("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and (("sales" >= $4 and "profit" is null) or ("id" >= $5 and not "product_type" in ($6, $7)))) group by "order_period", "product_type" having (var_pop("sales") >= $8 and (count("id") > $9 or min("profit") is null)) order by "sales_metric" asc nulls last, "order_period" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%Y", + "2016-01-01", + "2019-12-30", + -10, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, \`product_type\`, var_pop(\`sales\`) as \`sales_metric\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) group by \`order_period\`, \`product_type\` having (var_pop(\`sales\`) >= ? and (count(\`id\`) > ? or min(\`profit\`) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` asc, \`order_period\` is null asc, \`order_period\` asc limit 25", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_day 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_hour 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_minute 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_month 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y-%m", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_quarter 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("order_date" AS TIMESTAMP)) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select concat(date_format(\`order_date\`, '%Y'), '-Q', quarter(\`order_date\`)) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_second 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d %H:%M:%S", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d %H:%i:%s", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_week 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-W%W", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select concat(date_format(\`order_date\`, '%Y-W'), lpad(week(\`order_date\`, 5), 2, '0')) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping to_year 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_period", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_period" order by "order_period" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_period\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`order_period\` order by \`order_period\` is null asc, \`order_period\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > date grouping with statistical HAVING 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_year", median("sales") as "median" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "order_year" having (median("sales") is not null) order by "order_year" asc nulls last", + }, + "mysql": { + "parameters": [ + "%Y", + "%Y", + "%Y", + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_year\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\` from (select \`order_date\`, \`sales\`, row_number() over (partition by date_format(\`order_date\`, ?) order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?)) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`order_year\` having (avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is not null) order by \`order_year\` is null asc, \`order_year\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > deep mixed WHERE HAVING depth 2 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" between $2 and $3 or "product_type" = $4) and "product_name" like $5 escape '') group by "product_type", "product_name" having ((quantile("sales", CAST($6 AS DOUBLE)) between $7 and $8 or sum("sales") <= $9) and median("sales") >= $10) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $11", + }, + "mysql": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` between ? and ? or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '')) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having ((max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) between ? and ? or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > deep mixed WHERE HAVING depth 4 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (((("sales" between $2 and $3 or "product_type" = $4) and "product_name" like $5 escape '') or "product_type" = $6) and "product_name" like $7 escape '') group by "product_type", "product_name" having ((((quantile("sales", CAST($8 AS DOUBLE)) between $9 and $10 or sum("sales") <= $11) and median("sales") >= $12) or sum("sales") <= $13) and median("sales") >= $14) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $15", + }, + "mysql": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((((\`sales\` between ? and ? or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '')) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having ((((max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) between ? and ? or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > deep mixed WHERE HAVING depth 8 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (((((((("sales" between $2 and $3 or "product_type" = $4) and "product_name" like $5 escape '') or "product_type" = $6) and "product_name" like $7 escape '') or "product_type" = $8) and "product_name" like $9 escape '') or "product_type" = $10) and "product_name" like $11 escape '') group by "product_type", "product_name" having ((((((((quantile("sales", CAST($12 AS DOUBLE)) between $13 and $14 or sum("sales") <= $15) and median("sales") >= $16) or sum("sales") <= $17) and median("sales") >= $18) or sum("sales") <= $19) and median("sales") >= $20) or sum("sales") <= $21) and median("sales") >= $22) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $23", + }, + "mysql": { + "parameters": [ + 0.5, + -10000000000, + 10000000000, + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + "办公用品", + "%剪刀%", + 0.5, + -10, + 100, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((((((((\`sales\` between ? and ? or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') or \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) and convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '')) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having ((((((((max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) between ? and ? or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) or sum(\`sales\`) <= ?) and avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) >= ?) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile -0.01 1`] = ` +{ + "duckdb": { + "parameters": [ + -0.01, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.01, + ], + "sql": "select max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile -0.5 1`] = ` +{ + "duckdb": { + "parameters": [ + -0.5, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.5, + ], + "sql": "select max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile -0.9 1`] = ` +{ + "duckdb": { + "parameters": [ + -0.9, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.9, + ], + "sql": "select max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile -1 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 1, + ], + "sql": "select max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile 0 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile 0.01 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.01, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.01, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile 0.5 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.5, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile 0.9 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.9, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.9, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > discrete quantile 1 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "result" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 1, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`result\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > empty and group 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where 1=1 order by "id" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where 1=1 order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > empty grouping and ordering 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` limit 0", + }, +} +`; + +exports[`DSL to SQL snapshots > empty groups embedded in complete statistical query 1`] = ` +{ + "duckdb": { + "parameters": [ + 50, + ], + "sql": "select "product_type", "product_name", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (0=1 and 1=1) group by "product_type", "product_name" having (1=1 or 0=1) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`product_type\`, \`product_name\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (0=1 and 1=1)) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (1=1 or 0=1) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > empty having and 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having 1=1", + }, + "mysql": { + "parameters": [], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having 1=1", + }, +} +`; + +exports[`DSL to SQL snapshots > empty having or 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having 0=1", + }, + "mysql": { + "parameters": [], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having 0=1", + }, +} +`; + +exports[`DSL to SQL snapshots > empty or group 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where 0=1 order by "id" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where 0=1 order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > empty where and 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where 1=1", + }, + "mysql": { + "parameters": [], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where 1=1", + }, +} +`; + +exports[`DSL to SQL snapshots > empty where or 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where 0=1", + }, + "mysql": { + "parameters": [], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where 0=1", + }, +} +`; + +exports[`DSL to SQL snapshots > filter before ranking and limit after aggregation 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.9, + 2, + 2, + ], + "sql": "select "product_type", median("sales") as "median", quantile("sales", CAST($1 AS DOUBLE)) as "q90" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("id" >= $2) group by "product_type" order by "median" desc nulls last, "product_type" asc nulls last limit $3", + }, + "mysql": { + "parameters": [ + 0.9, + 2, + ], + "sql": "select \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`q90\` from (select \`product_type\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`id\` >= ?)) as \`__vquery_ranked\` group by \`product_type\` order by \`median\` is null asc, \`median\` desc, \`product_type\` is null asc, \`product_type\` asc limit 2", + }, +} +`; + +exports[`DSL to SQL snapshots > filtered statistical aggregates 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + 0, + ], + "sql": "select median("sales") as "median", quantile("sales", CAST($1 AS DOUBLE)) as "quantile", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("id" < $2)", + }, + "mysql": { + "parameters": [ + 0.5, + 0, + ], + "sql": "select avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`quantile\`, count(\`sales\`) as \`count\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`id\` < ?)) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > grouped statistics over multiple fields 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + -0.5, + ], + "sql": "select "product_type", median("sales") as "median", quantile("sales", CAST($1 AS DOUBLE)) as "quantile", quantile("sales", CAST($2 AS DOUBLE)) as "negative_quantile", median("profit") as "median_profit", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_type" order by "product_type" asc nulls last", + }, + "mysql": { + "parameters": [ + 0.5, + 0.5, + ], + "sql": "select \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`quantile\`, max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`negative_quantile\`, avg(case when \`__vquery_stat_2\` in (floor((\`__vquery_stat_3\` + 1) / 2), floor((\`__vquery_stat_3\` + 2) / 2)) then \`profit\` end) as \`median_profit\`, count(\`sales\`) as \`count\` from (select \`product_type\`, \`sales\`, \`profit\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\`, row_number() over (partition by \`product_type\` order by \`profit\` is null, \`profit\`) as \`__vquery_stat_2\`, count(\`profit\`) over (partition by \`product_type\`) as \`__vquery_stat_3\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`product_type\` order by \`product_type\` is null asc, \`product_type\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > internal statistical alias collision 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select median("sales") as "__vquery_stat_0" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select avg(case when \`__vquery_stat_1\` in (floor((\`__vquery_stat_2\` + 1) / 2), floor((\`__vquery_stat_2\` + 2) / 2)) then \`sales\` end) as \`__vquery_stat_0\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_1\`, count(\`sales\`) over () as \`__vquery_stat_2\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > multiple date grouping aliases with multiple statistical fields 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y", + "%Y-%m", + 0.9, + -0.1, + "2016-01-01", + "2019-12-30", + 1, + "技术", + "家具", + 0.1, + 1, + 1, + 1, + 100, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_year", strftime(CAST("order_date" AS TIMESTAMP), $2) as "order_month", "product_type", median("sales") as "median_value", quantile("sales", CAST($3 AS DOUBLE)) as "q90", quantile("profit", CAST($4 AS DOUBLE)) as "q10_profit", sum("profit") as "total" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("order_date" between $5 and $6 or "profit" is null) and ("id" >= $7 and not "product_type" in ($8, $9))) group by "order_year", "order_month", "product_type" having (quantile("sales", CAST($10 AS DOUBLE)) > $11 or (median("profit") >= $12 and var_samp("sales") > $13)) order by "order_year" asc nulls last, "order_month" asc nulls last, "q90" desc nulls first limit $14", + }, + "mysql": { + "parameters": [ + "%Y", + "%Y-%m", + 0.9, + 0.1, + "%Y", + "%Y-%m", + "%Y", + "%Y-%m", + "%Y", + "%Y-%m", + "%Y", + "%Y-%m", + "2016-01-01", + "2019-12-30", + 1, + "技术", + "家具", + 0.1, + 1, + 1, + 1, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_year\`, date_format(\`order_date\`, ?) as \`order_month\`, \`product_type\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median_value\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`q90\`, max(case when \`__vquery_stat_2\` = \`__vquery_stat_3\` + 1 - greatest(\`__vquery_stat_3\` - floor(\`__vquery_stat_3\` - \`__vquery_stat_3\` * CAST(? AS DOUBLE)), 1) then \`profit\` end) as \`q10_profit\`, sum(\`profit\`) as \`total\` from (select \`order_date\`, \`product_type\`, \`sales\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), date_format(\`order_date\`, ?), \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_1\`, row_number() over (partition by date_format(\`order_date\`, ?), date_format(\`order_date\`, ?), \`product_type\` order by \`profit\` is null, \`profit\`) as \`__vquery_stat_2\`, count(\`profit\`) over (partition by date_format(\`order_date\`, ?), date_format(\`order_date\`, ?), \`product_type\`) as \`__vquery_stat_3\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`order_year\`, \`order_month\`, \`product_type\` having (max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ? or (avg(case when \`__vquery_stat_2\` in (floor((\`__vquery_stat_3\` + 1) / 2), floor((\`__vquery_stat_3\` + 2) / 2)) then \`profit\` end) >= ? and var_samp(\`sales\`) > ?)) order by \`order_year\` is null asc, \`order_year\` asc, \`order_month\` is null asc, \`order_month\` asc, \`q90\` is null desc, \`q90\` desc limit 100", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and != 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" != $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` != ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and < 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" < $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` < ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and <= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" <= $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` <= ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and = 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" = $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` = ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and > 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" > $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` > ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and >= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" >= $1 or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` >= ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") > $6 and (count("id") > $7 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and ilike 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" in ($1, $2, $3) or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (sum("sales") > $7 and (count("id") > $8 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` in (?, ?, ?) or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" is not null or "profit" is null) and ("id" >= $1 and not "product_type" in ($2, $3))) group by "product_type", "product_name" having (sum("sales") > $4 and (count("id") > $5 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $6", + }, + "mysql": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` is not null or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and is null 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" is null or "profit" is null) and ("id" >= $1 and not "product_type" in ($2, $3))) group by "product_type", "product_name" having (sum("sales") > $4 and (count("id") > $5 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $6", + }, + "mysql": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` is null or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and like 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" like $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") > $6 and (count("id") > $7 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and not ilike 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ((not "sales" in ($1, $2, $3) or "profit" is null) and ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (sum("sales") > $7 and (count("id") > $8 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((not \`sales\` in (?, ?, ?) or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix and not like 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not like $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or != 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" != $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` != ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or < 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" < $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` < ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or <= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" <= $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` <= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or = 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" = $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` = ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or > 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" > $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` > ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or >= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" >= $1 and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 2, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` >= ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" between $1 and $2 and "profit" is null) or ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") > $6 and (count("id") > $7 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` between ? and ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or ilike 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" ilike $1 escape '' and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" in ($1, $2, $3) and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (sum("sales") > $7 and (count("id") > $8 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` in (?, ?, ?) and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" is not null and "profit" is null) or ("id" >= $1 and not "product_type" in ($2, $3))) group by "product_type", "product_name" having (sum("sales") > $4 and (count("id") > $5 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $6", + }, + "mysql": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` is not null and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or is null 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" is null and "profit" is null) or ("id" >= $1 and not "product_type" in ($2, $3))) group by "product_type", "product_name" having (sum("sales") > $4 and (count("id") > $5 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $6", + }, + "mysql": { + "parameters": [ + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` is null and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or like 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" like $1 escape '' and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '' and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or not between 1`] = ` +{ + "duckdb": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" not between $1 and $2 and "profit" is null) or ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "product_name" having (sum("sales") > $6 and (count("id") > $7 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + -1, + 100, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` not between ? and ? and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or not ilike 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ((not "sales" in ($1, $2, $3) and "profit" is null) or ("id" >= $4 and not "product_type" in ($5, $6))) group by "product_type", "product_name" having (sum("sales") > $7 and (count("id") > $8 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0, + 1, + null, + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((not \`sales\` in (?, ?, ?) and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > nested WHERE matrix or not like 1`] = ` +{ + "duckdb": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + 50, + ], + "sql": "select "product_type", "product_name", sum("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not like $1 escape '' and "profit" is null) or ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type", "product_name" having (sum("sales") > $5 and (count("id") > $6 or median("sales") is null)) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%打印机%", + 1, + "技术", + "家具", + 1, + 1, + ], + "sql": "select \`product_type\`, \`product_name\`, sum(\`sales\`) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, \`id\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '' and \`profit\` is null) or (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (sum(\`sales\`) > ? and (count(\`id\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) is null)) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric aggregates 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + ], + "sql": "select sum("sales") as "sum", avg("sales") as "avg", min("sales") as "min", max("sales") as "max", count("sales") as "count", count(distinct "sales") as "count_distinct", var_samp("sales") as "variance", var_pop("sales") as "variance_pop", stddev("sales") as "stddev", median("sales") as "median", quantile("sales", CAST($1 AS DOUBLE)) as "quantile" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.5, + ], + "sql": "select sum(\`sales\`) as \`sum\`, avg(\`sales\`) as \`avg\`, min(\`sales\`) as \`min\`, max(\`sales\`) as \`max\`, count(\`sales\`) as \`count\`, count(distinct \`sales\`) as \`count_distinct\`, var_samp(\`sales\`) as \`variance\`, var_pop(\`sales\`) as \`variance_pop\`, stddev_samp(\`sales\`) as \`stddev\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`quantile\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter != 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" != $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` != ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter < 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" < $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` < ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter <= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" <= $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` <= ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter = 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" = $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` = ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter > 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" > $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` > ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter >= 1`] = ` +{ + "duckdb": { + "parameters": [ + 2, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" >= $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 2, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` >= ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter between 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 4, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" between $1 and $2) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 1, + 4, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` between ? and ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + null, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" in ($1, $2)) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 1, + null, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` in (?, ?)) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter is not null 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" is not null) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` is not null) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter is null 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" is null) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` is null) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter not between 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + 4, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("sales" not between $1 and $2) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 1, + 4, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`sales\` not between ? and ?) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > numeric filter not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + null, + ], + "sql": "select "id", "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (not "sales" in ($1, $2)) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + 1, + null, + ], + "sql": "select \`id\`, \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (not \`sales\` in (?, ?)) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > order date ISO parameter 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-04-27", + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" >= $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "2019-04-27", + ], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` >= convert(? using utf8mb4) collate utf8mb4_0900_bin) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name BETWEEN uses codepoint order 1`] = ` +{ + "duckdb": { + "parameters": [ + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" between $1 and $2) order by "product_name" asc nulls last", + }, + "mysql": { + "parameters": [ + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`product_name\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin) order by \`product_name\` is null asc, \`product_name\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name IN is exact 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars 剪刀, 蓝色", + "柯尼卡 打印机, 红色", + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" in ($1, $2)) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars 剪刀, 蓝色", + "柯尼卡 打印机, 红色", + ], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`product_name\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name comparison is exact 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars 剪刀, 蓝色", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" = $1) order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars 剪刀, 蓝色", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`product_name\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name distinct and extrema 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count(distinct "product_name") as "distinct_product_names", min("product_name") as "first_product_name", max("product_name") as "last_product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select count(distinct \`product_name\`) as \`distinct_product_names\`, min(\`product_name\`) as \`first_product_name\`, max(\`product_name\`) as \`last_product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > product name grouping 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "product_name", count("sales") as "count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_name" order by "product_name" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`product_name\`, count(\`sales\`) as \`count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` group by \`product_name\` order by \`product_name\` is null asc, \`product_name\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name ilike %信封% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%信封%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%信封%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name ilike %孔加固材料% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name ilike Fiskars% 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name ilike 柯尼卡% 1`] = ` +{ + "duckdb": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name like %信封% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%信封%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%信封%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name like %孔加固材料% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name like Fiskars% 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name like 柯尼卡% 1`] = ` +{ + "duckdb": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not ilike %信封% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%信封%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%信封%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not ilike %孔加固材料% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not ilike Fiskars% 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not ilike 柯尼卡% 1`] = ` +{ + "duckdb": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not ilike $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not like %信封% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%信封%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%信封%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not like %孔加固材料% 1`] = ` +{ + "duckdb": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "%孔加固材料%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not like Fiskars% 1`] = ` +{ + "duckdb": { + "parameters": [ + "Fiskars%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "Fiskars%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > product name not like 柯尼卡% 1`] = ` +{ + "duckdb": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select "id", "product_name" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("product_name" not like $1 escape '') order by "id" asc nulls last", + }, + "mysql": { + "parameters": [ + "柯尼卡%", + ], + "sql": "select \`id\`, \`product_name\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin not like convert(? using utf8mb4) collate utf8mb4_0900_bin escape '') order by \`id\` is null asc, \`id\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > projection without alias 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + ], + "sql": "select "sales" as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" order by "id" asc nulls last limit $1", + }, + "mysql": { + "parameters": [], + "sql": "select \`sales\` as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` order by \`id\` is null asc, \`id\` asc limit 1", + }, +} +`; + +exports[`DSL to SQL snapshots > raw grouping alias 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select "product_type" as "product_category", median("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_category" order by "product_category" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select \`product_type\` as \`product_category\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales\` from (select \`product_type\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`product_category\` order by \`product_category\` is null asc, \`product_category\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > signed fractional and scientific notation parameters with zero result limit 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + 0, + 0.125, + -123.456, + 1e-12, + 1000000000000, + null, + 1, + "技术", + "家具", + -0.14, + -1000000, + 1000000, + 0, + ], + "sql": "select "product_type", "product_name", quantile("sales", CAST($1 AS DOUBLE)) as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" in ($2, $3, $4, $5, $6, $7) or "profit" is null) and ("id" >= $8 and not "product_type" in ($9, $10))) group by "product_type", "product_name" having (quantile("sales", CAST($11 AS DOUBLE)) between $12 and $13) order by "sales_metric" desc nulls last, "product_type" asc nulls last limit $14", + }, + "mysql": { + "parameters": [ + 0.5, + 0, + 0.125, + -123.456, + 1e-12, + 1000000000000, + null, + 1, + "技术", + "家具", + 0.14, + -1000000, + 1000000, + ], + "sql": "select \`product_type\`, \`product_name\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` in (?, ?, ?, ?, ?, ?) or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`product_name\` having (max(case when \`__vquery_stat_0\` = \`__vquery_stat_1\` + 1 - greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) between ? and ?) order by \`sales_metric\` is null asc, \`sales_metric\` desc, \`product_type\` is null asc, \`product_type\` asc limit 0", + }, +} +`; + +exports[`DSL to SQL snapshots > single HAVING in 1`] = ` +{ + "duckdb": { + "parameters": [ + 10, + ], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (count("id") in ($1))", + }, + "mysql": { + "parameters": [ + 10, + ], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (count(\`id\`) in (?))", + }, +} +`; + +exports[`DSL to SQL snapshots > single HAVING not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 10, + ], + "sql": "select count("id") as "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" having (not count("id") in ($1))", + }, + "mysql": { + "parameters": [ + 10, + ], + "sql": "select count(\`id\`) as \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` having (not count(\`id\`) in (?))", + }, +} +`; + +exports[`DSL to SQL snapshots > single WHERE in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("id" in ($1))", + }, + "mysql": { + "parameters": [ + 1, + ], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`id\` in (?))", + }, +} +`; + +exports[`DSL to SQL snapshots > single WHERE not in 1`] = ` +{ + "duckdb": { + "parameters": [ + 1, + ], + "sql": "select "id" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (not "id" in ($1))", + }, + "mysql": { + "parameters": [ + 1, + ], + "sql": "select \`id\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (not \`id\` in (?))", + }, +} +`; + +exports[`DSL to SQL snapshots > statistical aliases collide with internal rank names and source names 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.9, + 0, + 1, + "技术", + "家具", + 1, + 0.5, + 1, + 5, + ], + "sql": "select "product_type", sum("profit") as "sales", median("sales") as "__vquery_stat_0", quantile("profit", CAST($1 AS DOUBLE)) as "__vquery_stat_1" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("sales" >= $2 or "profit" is null) and ("id" >= $3 and not "product_type" in ($4, $5))) group by "product_type", "sales" having (median("sales") >= $6 and quantile("profit", CAST($7 AS DOUBLE)) <= $8) order by "__vquery_stat_0" desc nulls last, "product_type" asc nulls last limit $9", + }, + "mysql": { + "parameters": [ + 0.9, + 0, + 1, + "技术", + "家具", + 1, + 0.5, + 1, + ], + "sql": "select \`product_type\`, sum(\`profit\`) as \`sales\`, avg(case when \`__vquery_stat_2\` in (floor((\`__vquery_stat_3\` + 1) / 2), floor((\`__vquery_stat_3\` + 2) / 2)) then \`sales\` end) as \`__vquery_stat_0\`, max(case when \`__vquery_stat_4\` = greatest(\`__vquery_stat_5\` - floor(\`__vquery_stat_5\` - \`__vquery_stat_5\` * CAST(? AS DOUBLE)), 1) then \`profit\` end) as \`__vquery_stat_1\` from (select \`product_type\`, \`profit\`, \`sales\`, row_number() over (partition by \`product_type\`, \`sales\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_2\`, count(\`sales\`) over (partition by \`product_type\`, \`sales\`) as \`__vquery_stat_3\`, row_number() over (partition by \`product_type\`, \`sales\` order by \`profit\` is null, \`profit\`) as \`__vquery_stat_4\`, count(\`profit\`) over (partition by \`product_type\`, \`sales\`) as \`__vquery_stat_5\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((\`sales\` >= ? or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\`, \`sales\` having (avg(case when \`__vquery_stat_2\` in (floor((\`__vquery_stat_3\` + 1) / 2), floor((\`__vquery_stat_3\` + 2) / 2)) then \`sales\` end) >= ? and max(case when \`__vquery_stat_4\` = greatest(\`__vquery_stat_5\` - floor(\`__vquery_stat_5\` - \`__vquery_stat_5\` * CAST(? AS DOUBLE)), 1) then \`profit\` end) <= ?) order by \`__vquery_stat_0\` is null asc, \`__vquery_stat_0\` desc, \`product_type\` is null asc, \`product_type\` asc limit 5", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max != 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") != $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) != convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max < 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") < $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) < convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max <= 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") <= $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) <= convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max = 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") = $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) = convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max > 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") > $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) > convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max >= 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") >= $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) >= convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max between 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") between $5 and $6 or quantile("sales", CAST($7 AS DOUBLE)) > $8) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max in 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") in ($5, $6, $7) or quantile("sales", CAST($8 AS DOUBLE)) > $9) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin, ?) or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") is not null or quantile("sales", CAST($5 AS DOUBLE)) > $6) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) is not null or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max is null 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") is null or quantile("sales", CAST($5 AS DOUBLE)) > $6) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) is null or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max not between 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (max("product_name") not between $5 and $6 or quantile("sales", CAST($7 AS DOUBLE)) > $8) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (max(\`product_name\`) not between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix max not in 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + 10, + ], + "sql": "select "product_type", max("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (not max("product_name") in ($5, $6, $7) or quantile("sales", CAST($8 AS DOUBLE)) > $9) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + ], + "sql": "select \`product_type\`, max(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (not max(\`product_name\`) in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin, ?) or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min != 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") != $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) != convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min < 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") < $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) < convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min <= 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") <= $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) <= convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min = 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") = $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) = convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min > 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") > $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) > convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min >= 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") >= $5 or quantile("sales", CAST($6 AS DOUBLE)) > $7) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) >= convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min between 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") between $5 and $6 or quantile("sales", CAST($7 AS DOUBLE)) > $8) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min in 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") in ($5, $6, $7) or quantile("sales", CAST($8 AS DOUBLE)) > $9) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin, ?) or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min is not null 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") is not null or quantile("sales", CAST($5 AS DOUBLE)) > $6) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) is not null or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min is null 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") is null or quantile("sales", CAST($5 AS DOUBLE)) > $6) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) is null or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min not between 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (min("product_name") not between $5 and $6 or quantile("sales", CAST($7 AS DOUBLE)) > $8) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $9", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Acco 孔加固材料, 回收", + "贝尔金 鼠标, 耐用", + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (min(\`product_name\`) not between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > string HAVING matrix min not in 1`] = ` +{ + "duckdb": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + 10, + ], + "sql": "select "product_type", min("product_name") as "product_name_boundary", median("sales") as "sales_metric" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where (("product_name" not ilike $1 escape '' or "profit" is null) and ("id" >= $2 and not "product_type" in ($3, $4))) group by "product_type" having (not min("product_name") in ($5, $6, $7) or quantile("sales", CAST($8 AS DOUBLE)) > $9) order by "product_name_boundary" asc nulls last, "sales_metric" desc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "%开信刀%", + 1, + "技术", + "家具", + "Fiskars 剪刀, 蓝色", + "GlobeWeis 搭扣信封, 红色", + null, + 0.5, + 1, + ], + "sql": "select \`product_type\`, min(\`product_name\`) as \`product_name_boundary\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales_metric\` from (select \`product_type\`, \`product_name\`, \`sales\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where ((lower(convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin) not like lower(convert(? using utf8mb4) collate utf8mb4_0900_bin) escape '' or \`profit\` is null) and (\`id\` >= ? and not \`product_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)))) as \`__vquery_ranked\` group by \`product_type\` having (not min(\`product_name\`) in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin, ?) or max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) > ?) order by \`product_name_boundary\` is null asc, \`product_name_boundary\` asc, \`sales_metric\` is null asc, \`sales_metric\` desc limit 10", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased avg 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select avg("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select avg(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased count 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select count(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased count_distinct 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select count(distinct "sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select count(distinct \`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased max 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select max("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select max(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased median 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select median("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased min 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select min("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select min(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased quantile 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.5, + ], + "sql": "select quantile("sales", CAST($1 AS DOUBLE)) as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [ + 0.5, + ], + "sql": "select max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales\` from (select \`sales\`, row_number() over ( order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over () as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased stddev 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select stddev("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select stddev_samp(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased sum 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select sum("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select sum(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased variance 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select var_samp("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select var_samp(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unaliased variance_pop 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select var_pop("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source"", + }, + "mysql": { + "parameters": [], + "sql": "select var_pop(\`sales\`) as \`sales\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`", + }, +} +`; + +exports[`DSL to SQL snapshots > unprojected grouping and sorting 1`] = ` +{ + "duckdb": { + "parameters": [], + "sql": "select median("sales") as "sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" group by "product_type" order by "product_type" asc nulls last", + }, + "mysql": { + "parameters": [], + "sql": "select avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`sales\` from (select \`sales\`, \`product_type\`, row_number() over (partition by \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\`) as \`__vquery_ranked\` group by \`product_type\` order by \`product_type\` is null asc, \`product_type\` asc", + }, +} +`; + +exports[`DSL to SQL snapshots > 下单日和配送日双日期分组 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m-%d", + "%Y-%m-%d", + "2019-01-01", + "2019-12-30", + "当日", + 500, + 0, + 100, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_day", strftime(CAST("delivery_date" AS TIMESTAMP), $2) as "delivery_day", "delivery_method", sum("sales") as "total_sales", median("profit") as "median_profit" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $3 and $4 and "delivery_method" = $5) group by "order_day", "delivery_day", "delivery_method" having (sum("sales") > $6 or median("profit") < $7) order by "order_day" asc nulls last, "delivery_day" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%Y-%m-%d", + "%Y-%m-%d", + "%Y-%m-%d", + "%Y-%m-%d", + "%Y-%m-%d", + "%Y-%m-%d", + "2019-01-01", + "2019-12-30", + "当日", + 500, + 0, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_day\`, date_format(\`delivery_date\`, ?) as \`delivery_day\`, \`delivery_method\`, sum(\`sales\`) as \`total_sales\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`profit\` end) as \`median_profit\` from (select \`order_date\`, \`delivery_date\`, \`delivery_method\`, \`sales\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), date_format(\`delivery_date\`, ?), \`delivery_method\` order by \`profit\` is null, \`profit\`) as \`__vquery_stat_0\`, count(\`profit\`) over (partition by date_format(\`order_date\`, ?), date_format(\`delivery_date\`, ?), \`delivery_method\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`delivery_method\` = convert(? using utf8mb4) collate utf8mb4_0900_bin)) as \`__vquery_ranked\` group by \`order_day\`, \`delivery_day\`, \`delivery_method\` having (sum(\`sales\`) > ? or avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`profit\` end) < ?) order by \`order_day\` is null asc, \`order_day\` asc, \`delivery_day\` is null asc, \`delivery_day\` asc limit 100", + }, +} +`; + +exports[`DSL to SQL snapshots > 全部真实字段的订单明细 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "浙江", + "四川", + 100, + ], + "sql": "select "id", "order_id", "order_date", "delivery_date", "delivery_method", "customer_id", "customer_name", "customer_type", "city", "province", "country_or_region", "area", "product_id", "product_type", "product_sub_type", "product_name", "sales", "amount", "discount", "profit" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and ("province" = $3 or "province" = $4)) order by "order_date" desc nulls last, "id" desc nulls last limit $5", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "浙江", + "四川", + ], + "sql": "select \`id\`, \`order_id\`, \`order_date\`, \`delivery_date\`, \`delivery_method\`, \`customer_id\`, \`customer_name\`, \`customer_type\`, \`city\`, \`province\`, \`country_or_region\`, \`area\`, \`product_id\`, \`product_type\`, \`product_sub_type\`, \`product_name\`, \`sales\`, \`amount\`, \`discount\`, \`profit\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and (\`province\` = convert(? using utf8mb4) collate utf8mb4_0900_bin or \`province\` = convert(? using utf8mb4) collate utf8mb4_0900_bin)) order by \`order_date\` is null asc, \`order_date\` desc, \`id\` is null asc, \`id\` desc limit 100", + }, +} +`; + +exports[`DSL to SQL snapshots > 商品层级利润与销售分位数 1`] = ` +{ + "duckdb": { + "parameters": [ + 0.9, + "2019-01-01", + "2019-12-30", + "办公用品", + "%打印机%", + 10, + 50, + ], + "sql": "select "product_type", "product_sub_type", "product_id", "product_name", sum("profit") as "total_profit", quantile("sales", CAST($1 AS DOUBLE)) as "sales_q90", sum("amount") as "total_amount", avg("discount") as "average_discount" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and ("product_type" = $4 or "product_name" like $5 escape '')) group by "product_type", "product_sub_type", "product_id", "product_name" having (sum("amount") >= $6) order by "total_profit" desc nulls last, "product_id" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + 0.9, + "2019-01-01", + "2019-12-30", + "办公用品", + "%打印机%", + 10, + ], + "sql": "select \`product_type\`, \`product_sub_type\`, \`product_id\`, \`product_name\`, sum(\`profit\`) as \`total_profit\`, max(case when \`__vquery_stat_0\` = greatest(\`__vquery_stat_1\` - floor(\`__vquery_stat_1\` - \`__vquery_stat_1\` * CAST(? AS DOUBLE)), 1) then \`sales\` end) as \`sales_q90\`, sum(\`amount\`) as \`total_amount\`, avg(\`discount\`) as \`average_discount\` from (select \`product_type\`, \`product_sub_type\`, \`product_id\`, \`product_name\`, \`profit\`, \`sales\`, \`amount\`, \`discount\`, row_number() over (partition by \`product_type\`, \`product_sub_type\`, \`product_id\`, \`product_name\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by \`product_type\`, \`product_sub_type\`, \`product_id\`, \`product_name\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and (\`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin or convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin like convert(? using utf8mb4) collate utf8mb4_0900_bin escape ''))) as \`__vquery_ranked\` group by \`product_type\`, \`product_sub_type\`, \`product_id\`, \`product_name\` having (sum(\`amount\`) >= ?) order by \`total_profit\` is null asc, \`total_profit\` desc, \`product_id\` is null asc, \`product_id\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > 客户商品地域交叉销售分析 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "公司", + "技术", + "消费者", + "家具", + 1000, + 0, + 5, + 50, + ], + "sql": "select "customer_type", "product_type", "area", sum("sales") as "total_sales", sum("profit") as "total_profit", count(distinct "order_id") as "order_count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and (("customer_type" = $3 and "product_type" = $4) or ("customer_type" = $5 and "product_type" = $6))) group by "customer_type", "product_type", "area" having (sum("sales") >= $7 and (sum("profit") > $8 or count(distinct "order_id") > $9)) order by "total_sales" desc nulls last, "area" asc nulls last limit $10", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "公司", + "技术", + "消费者", + "家具", + 1000, + 0, + 5, + ], + "sql": "select \`customer_type\`, \`product_type\`, \`area\`, sum(\`sales\`) as \`total_sales\`, sum(\`profit\`) as \`total_profit\`, count(distinct \`order_id\`) as \`order_count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and ((\`customer_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin and \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin) or (\`customer_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin and \`product_type\` = convert(? using utf8mb4) collate utf8mb4_0900_bin))) group by \`customer_type\`, \`product_type\`, \`area\` having (sum(\`sales\`) >= ? and (sum(\`profit\`) > ? or count(distinct \`order_id\`) > ?)) order by \`total_sales\` is null asc, \`total_sales\` desc, \`area\` is null asc, \`area\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > 客户类型与复购客户贡献 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "公司", + "消费者", + "小型企业", + 1, + 50, + ], + "sql": "select "customer_type", "customer_id", "customer_name", count(distinct "order_id") as "order_count", sum("sales") as "total_sales", sum("profit") as "total_profit" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and "customer_type" in ($3, $4, $5)) group by "customer_type", "customer_id", "customer_name" having (count(distinct "order_id") > $6) order by "total_sales" desc nulls last, "customer_id" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "公司", + "消费者", + "小型企业", + 1, + ], + "sql": "select \`customer_type\`, \`customer_id\`, \`customer_name\`, count(distinct \`order_id\`) as \`order_count\`, sum(\`sales\`) as \`total_sales\`, sum(\`profit\`) as \`total_profit\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`customer_type\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)) group by \`customer_type\`, \`customer_id\`, \`customer_name\` having (count(distinct \`order_id\`) > ?) order by \`total_sales\` is null asc, \`total_sales\` desc, \`customer_id\` is null asc, \`customer_id\` asc limit 50", + }, +} +`; + +exports[`DSL to SQL snapshots > 折扣亏损商品在地域中的分布 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + 0, + 0, + 0, + 100, + ], + "sql": "select "country_or_region", "area", "province", "product_type", sum("profit") as "total_loss", sum("sales") as "total_sales", avg("discount") as "average_discount" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and "profit" < $3 and "discount" > $4) group by "country_or_region", "area", "province", "product_type" having (sum("profit") < $5) order by "total_loss" asc nulls last, "province" asc nulls last limit $6", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + 0, + 0, + 0, + ], + "sql": "select \`country_or_region\`, \`area\`, \`province\`, \`product_type\`, sum(\`profit\`) as \`total_loss\`, sum(\`sales\`) as \`total_sales\`, avg(\`discount\`) as \`average_discount\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`profit\` < ? and \`discount\` > ?) group by \`country_or_region\`, \`area\`, \`province\`, \`product_type\` having (sum(\`profit\`) < ?) order by \`total_loss\` is null asc, \`total_loss\` asc, \`province\` is null asc, \`province\` asc limit 100", + }, +} +`; + +exports[`DSL to SQL snapshots > 按月份省份和商品类别比较销售利润 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2019-01-01", + "2019-12-30", + "华东", + "中南", + 1000, + 0, + 100, + ], + "sql": "select strftime(CAST("order_date" AS TIMESTAMP), $1) as "order_month", "province", "product_type", sum("sales") as "total_sales", sum("profit") as "total_profit", median("sales") as "median_sales" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and "area" in ($4, $5)) group by "order_month", "province", "product_type" having (sum("sales") >= $6 and sum("profit") > $7) order by "order_month" asc nulls last, "total_sales" desc nulls last, "province" asc nulls last limit $8", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "%Y-%m", + "%Y-%m", + "2019-01-01", + "2019-12-30", + "华东", + "中南", + 1000, + 0, + ], + "sql": "select date_format(\`order_date\`, ?) as \`order_month\`, \`province\`, \`product_type\`, sum(\`sales\`) as \`total_sales\`, sum(\`profit\`) as \`total_profit\`, avg(case when \`__vquery_stat_0\` in (floor((\`__vquery_stat_1\` + 1) / 2), floor((\`__vquery_stat_1\` + 2) / 2)) then \`sales\` end) as \`median_sales\` from (select \`order_date\`, \`province\`, \`product_type\`, \`sales\`, \`profit\`, row_number() over (partition by date_format(\`order_date\`, ?), \`province\`, \`product_type\` order by \`sales\` is null, \`sales\`) as \`__vquery_stat_0\`, count(\`sales\`) over (partition by date_format(\`order_date\`, ?), \`province\`, \`product_type\`) as \`__vquery_stat_1\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`area\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin))) as \`__vquery_ranked\` group by \`order_month\`, \`province\`, \`product_type\` having (sum(\`sales\`) >= ? and sum(\`profit\`) > ?) order by \`order_month\` is null asc, \`order_month\` asc, \`total_sales\` is null asc, \`total_sales\` desc, \`province\` is null asc, \`province\` asc limit 100", + }, +} +`; + +exports[`DSL to SQL snapshots > 浙江城市销售排行榜 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "浙江", + "标准级", + "二级", + 5, + 20, + ], + "sql": "select "province", "city", sum("sales") as "total_sales", count(distinct "order_id") as "order_count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2 and "province" = $3 and "delivery_method" in ($4, $5)) group by "province", "city" having (count(distinct "order_id") >= $6) order by "total_sales" desc nulls last, "city" asc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + "浙江", + "标准级", + "二级", + 5, + ], + "sql": "select \`province\`, \`city\`, sum(\`sales\`) as \`total_sales\`, count(distinct \`order_id\`) as \`order_count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`province\` = convert(? using utf8mb4) collate utf8mb4_0900_bin and \`delivery_method\` in (convert(? using utf8mb4) collate utf8mb4_0900_bin, convert(? using utf8mb4) collate utf8mb4_0900_bin)) group by \`province\`, \`city\` having (count(distinct \`order_id\`) >= ?) order by \`total_sales\` is null asc, \`total_sales\` desc, \`city\` is null asc, \`city\` asc limit 20", + }, +} +`; + +exports[`DSL to SQL snapshots > 超市全年经营汇总 1`] = ` +{ + "duckdb": { + "parameters": [ + "2019-01-01", + "2019-12-30", + ], + "sql": "select count(distinct "order_id") as "order_count", count(distinct "customer_id") as "customer_count", count(distinct "product_id") as "product_count", sum("sales") as "total_sales", sum("profit") as "total_profit", sum("amount") as "total_amount", avg("discount") as "average_discount" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $1 and $2)", + }, + "mysql": { + "parameters": [ + "2019-01-01", + "2019-12-30", + ], + "sql": "select count(distinct \`order_id\`) as \`order_count\`, count(distinct \`customer_id\`) as \`customer_count\`, count(distinct \`product_id\`) as \`product_count\`, sum(\`sales\`) as \`total_sales\`, sum(\`profit\`) as \`total_profit\`, sum(\`amount\`) as \`total_amount\`, avg(\`discount\`) as \`average_discount\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin)", + }, +} +`; + +exports[`DSL to SQL snapshots > 配送月份与配送方式销售构成 1`] = ` +{ + "duckdb": { + "parameters": [ + "%Y-%m", + "2019-01-01", + "2019-12-30", + "2019-01-01", + "2020-01-10", + 0, + 100, + ], + "sql": "select strftime(CAST("delivery_date" AS TIMESTAMP), $1) as "delivery_month", "delivery_method", sum("sales") as "total_sales", count(distinct "order_id") as "order_count" from (select "id" as "id", "order_id" collate "binary" as "order_id", "order_date" as "order_date", "delivery_date" as "delivery_date", "delivery_method" collate "binary" as "delivery_method", "customer_id" collate "binary" as "customer_id", "customer_name" collate "binary" as "customer_name", "customer_type" collate "binary" as "customer_type", "city" collate "binary" as "city", "province" collate "binary" as "province", "country_or_region" collate "binary" as "country_or_region", "area" collate "binary" as "area", "product_id" collate "binary" as "product_id", "product_type" collate "binary" as "product_type", "product_sub_type" collate "binary" as "product_sub_type", "product_name" collate "binary" as "product_name", "sales" as "sales", "amount" as "amount", "discount" as "discount", "profit" as "profit" from "supermarket") as "__vquery_source" where ("order_date" between $2 and $3 and "delivery_date" between $4 and $5) group by "delivery_month", "delivery_method" having (sum("sales") > $6) order by "delivery_month" asc nulls last, "total_sales" desc nulls last limit $7", + }, + "mysql": { + "parameters": [ + "%Y-%m", + "2019-01-01", + "2019-12-30", + "2019-01-01", + "2020-01-10", + 0, + ], + "sql": "select date_format(\`delivery_date\`, ?) as \`delivery_month\`, \`delivery_method\`, sum(\`sales\`) as \`total_sales\`, count(distinct \`order_id\`) as \`order_count\` from (select \`id\` as \`id\`, convert(\`order_id\` using utf8mb4) collate utf8mb4_0900_bin as \`order_id\`, \`order_date\` as \`order_date\`, \`delivery_date\` as \`delivery_date\`, convert(\`delivery_method\` using utf8mb4) collate utf8mb4_0900_bin as \`delivery_method\`, convert(\`customer_id\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_id\`, convert(\`customer_name\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_name\`, convert(\`customer_type\` using utf8mb4) collate utf8mb4_0900_bin as \`customer_type\`, convert(\`city\` using utf8mb4) collate utf8mb4_0900_bin as \`city\`, convert(\`province\` using utf8mb4) collate utf8mb4_0900_bin as \`province\`, convert(\`country_or_region\` using utf8mb4) collate utf8mb4_0900_bin as \`country_or_region\`, convert(\`area\` using utf8mb4) collate utf8mb4_0900_bin as \`area\`, convert(\`product_id\` using utf8mb4) collate utf8mb4_0900_bin as \`product_id\`, convert(\`product_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_type\`, convert(\`product_sub_type\` using utf8mb4) collate utf8mb4_0900_bin as \`product_sub_type\`, convert(\`product_name\` using utf8mb4) collate utf8mb4_0900_bin as \`product_name\`, \`sales\` as \`sales\`, \`amount\` as \`amount\`, \`discount\` as \`discount\`, \`profit\` as \`profit\` from \`supermarket\`) as \`__vquery_source\` where (\`order_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin and \`delivery_date\` between convert(? using utf8mb4) collate utf8mb4_0900_bin and convert(? using utf8mb4) collate utf8mb4_0900_bin) group by \`delivery_month\`, \`delivery_method\` having (sum(\`sales\`) > ?) order by \`delivery_month\` is null asc, \`delivery_month\` asc, \`total_sales\` is null asc, \`total_sales\` desc limit 100", + }, +} +`; diff --git a/packages/vquery/tests/dialects/compile.test.ts b/packages/vquery/tests/dialects/compile.test.ts new file mode 100644 index 0000000000..91f5a97bb4 --- /dev/null +++ b/packages/vquery/tests/dialects/compile.test.ts @@ -0,0 +1,167 @@ +import { compileQuery } from '@visactor/vquery' +import { readFileSync } from 'node:fs' +import { resolve } from 'node:path' +import type { DatasetColumn, HavingOperator, VQueryDSL, WhereLeaf } from '@visactor/vquery' +import type { BaseAggregateFunction, DateAggregateFunction } from '../../src/types/dsl/Select' +import catalog from './queries.json' + +type QueryCase = { + name: string + description?: string + dsl: VQueryDSL +} +const { source, table, columns, queries } = catalog as { + source: string + table: string + columns: DatasetColumn[] + queries: QueryCase[] +} + +// Exhaustive records make new DSL functions/operators require fixture updates. +const aggregateFunctions: Record = { + count: true, + count_distinct: true, + sum: true, + avg: true, + min: true, + max: true, + variance: true, + variance_pop: true, + stddev: true, + median: true, + quantile: true, +} +const dateFunctions: Record = { + to_year: true, + to_quarter: true, + to_month: true, + to_week: true, + to_day: true, + to_hour: true, + to_minute: true, + to_second: true, +} +const whereOperators: Record>['op'], true> = { + '=': true, + '!=': true, + '>': true, + '>=': true, + '<': true, + '<=': true, + in: true, + 'not in': true, + between: true, + 'not between': true, + 'is null': true, + 'is not null': true, + like: true, + 'not like': true, + ilike: true, + 'not ilike': true, +} +const havingOperators: Record = { + '=': true, + '!=': true, + '>': true, + '>=': true, + '<': true, + '<=': true, + in: true, + 'not in': true, + between: true, + 'not between': true, + 'is null': true, + 'is not null': true, +} +type FilterNode = { field?: string; op: string; aggr?: { func: string }; conditions?: FilterNode[] } +function leaves(node?: FilterNode): FilterNode[] { + if (!node) return [] + return node.conditions ? node.conditions.flatMap((child) => leaves(child)) : [node] +} + +it('uses the real supermarket CSV schema', () => { + const header = readFileSync(resolve(__dirname, '../..', source), 'utf8') + .split(/\r?\n/, 1)[0] + .replace(/^\uFEFF/, '') + .split(',') + expect(table).toBe('supermarket') + expect(columns.map((column) => column.name)).toEqual(header) +}) + +it('keeps fixture names unique and covers the declared DSL feature combinations', () => { + expect(new Set(queries.map((entry) => entry.name)).size).toBe(queries.length) + const selected = new Set() + const where = new Set() + const having = new Set() + const dates = new Set() + const ordering = new Set() + for (const { dsl } of queries) { + const aggregates = dsl.select.flatMap((item) => + typeof item === 'string' || !item.aggr ? [] : [{ ...item, aggr: item.aggr }], + ) + for (const item of aggregates) { + const func = item.aggr.func + selected.add(func) + const sort = dsl.orderBy?.find((sort) => sort.field === (item.alias ?? item.field)) + if (sort) ordering.add(`${func}:${sort.order ?? 'asc'}:${sort.nulls ?? 'default'}`) + } + if (dsl.where?.conditions?.some((child) => 'conditions' in child)) + for (const leaf of leaves(dsl.where)) where.add(`${dsl.where.op}:${leaf.op}`) + for (const leaf of leaves(dsl.having)) having.add(`${leaf.aggr!.func}:${leaf.op}`) + for (const date of aggregates.filter( + (item) => item.aggr.func.startsWith('to_') && dsl.groupBy?.includes(item.alias ?? item.field), + )) + for (const numeric of aggregates.filter((item) => !item.aggr.func.startsWith('to_'))) + dates.add(`${date.aggr.func}:${numeric.aggr.func}`) + } + expect(selected).toEqual(new Set([...Object.keys(aggregateFunctions), ...Object.keys(dateFunctions)])) + expect(queries.some(({ dsl }) => dsl.select.length === 0)).toBe(true) + expect(queries.some(({ dsl }) => dsl.select.some((item) => typeof item === 'string'))).toBe(true) + expect( + queries.some(({ dsl }) => dsl.select.some((item) => typeof item !== 'string' && item.alias && !item.aggr)), + ).toBe(true) + for (const func of Object.keys(aggregateFunctions)) { + for (const op of Object.keys(havingOperators)) expect([...having]).toContain(`${func}:${op}`) + for (const date of Object.keys(dateFunctions)) expect([...dates]).toContain(`${date}:${func}`) + for (const order of ['asc', 'desc']) + for (const nulls of ['default', 'first', 'last']) expect([...ordering]).toContain(`${func}:${order}:${nulls}`) + } + for (const op of Object.keys(whereOperators)) + for (const root of ['and', 'or']) expect([...where]).toContain(`${root}:${op}`) + expect( + queries.some(({ dsl }) => + ['select', 'where', 'groupBy', 'having', 'orderBy', 'limit'].every((clause) => clause in dsl), + ), + ).toBe(true) +}) + +describe('DSL to SQL snapshots', () => { + for (const entry of queries) + it(entry.name, () => { + const { dsl } = entry + const fields = columns.map((column) => column.name) + const selected = dsl.select.map((item) => (typeof item === 'string' ? { field: item } : item)) + const aliases = new Map(selected.map((item) => [item.alias ?? item.field, item])) + for (const item of selected) expect(fields).toContain(item.field) + for (const item of [...leaves(dsl.where), ...leaves(dsl.having)]) expect(fields).toContain(item.field) + for (const field of [...(dsl.groupBy ?? []), ...(dsl.orderBy ?? []).map((item) => item.field)]) + expect([...fields, ...aliases.keys()]).toContain(field) + for (const field of dsl.groupBy ?? []) { + const item = aliases.get(field) + if (!fields.includes(field) && item?.aggr) expect(item.aggr.func.startsWith('to_')).toBe(true) + } + const grouped = + selected.some((item) => item.aggr && !item.aggr.func.startsWith('to_')) || leaves(dsl.having).length + if (grouped) { + for (const item of selected.filter((item) => !item.aggr || item.aggr.func.startsWith('to_'))) + expect( + (dsl.groupBy ?? []).includes(item.field) || (dsl.groupBy ?? []).includes(item.alias ?? item.field), + ).toBe(true) + } + expect( + Object.fromEntries( + (['mysql', 'duckdb'] as const).map((dialect) => [dialect, compileQuery(dsl, { table, columns, dialect })]), + ), + ).toMatchSnapshot() + }) +}) diff --git a/packages/vquery/tests/dialects/queries.json b/packages/vquery/tests/dialects/queries.json new file mode 100644 index 0000000000..40d6133f06 --- /dev/null +++ b/packages/vquery/tests/dialects/queries.json @@ -0,0 +1,31566 @@ +{ + "source": "tests/unit/assets/supermarket.csv", + "table": "supermarket", + "columns": [ + { + "name": "id", + "type": "number" + }, + { + "name": "order_id", + "type": "string" + }, + { + "name": "order_date", + "type": "date" + }, + { + "name": "delivery_date", + "type": "date" + }, + { + "name": "delivery_method", + "type": "string" + }, + { + "name": "customer_id", + "type": "string" + }, + { + "name": "customer_name", + "type": "string" + }, + { + "name": "customer_type", + "type": "string" + }, + { + "name": "city", + "type": "string" + }, + { + "name": "province", + "type": "string" + }, + { + "name": "country_or_region", + "type": "string" + }, + { + "name": "area", + "type": "string" + }, + { + "name": "product_id", + "type": "string" + }, + { + "name": "product_type", + "type": "string" + }, + { + "name": "product_sub_type", + "type": "string" + }, + { + "name": "product_name", + "type": "string" + }, + { + "name": "sales", + "type": "number" + }, + { + "name": "amount", + "type": "number" + }, + { + "name": "discount", + "type": "number" + }, + { + "name": "profit", + "type": "number" + } + ], + "queries": [ + { + "name": "numeric aggregates", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "sum", + "aggr": { + "func": "sum" + } + }, + { + "field": "sales", + "alias": "avg", + "aggr": { + "func": "avg" + } + }, + { + "field": "sales", + "alias": "min", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "max", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + }, + { + "field": "sales", + "alias": "count_distinct", + "aggr": { + "func": "count_distinct" + } + }, + { + "field": "sales", + "alias": "variance", + "aggr": { + "func": "variance" + } + }, + { + "field": "sales", + "alias": "variance_pop", + "aggr": { + "func": "variance_pop" + } + }, + { + "field": "sales", + "alias": "stddev", + "aggr": { + "func": "stddev" + } + }, + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "quantile", + "aggr": { + "func": "quantile" + } + } + ] + } + }, + { + "name": "grouped statistics over multiple fields", + "dsl": { + "select": [ + "product_type", + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "quantile", + "aggr": { + "func": "quantile" + } + }, + { + "field": "sales", + "alias": "negative_quantile", + "aggr": { + "func": "quantile", + "quantile": -0.5 + } + }, + { + "field": "profit", + "alias": "median_profit", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["product_type"], + "orderBy": [ + { + "field": "product_type" + } + ] + } + }, + { + "name": "filter before ranking and limit after aggregation", + "dsl": { + "select": [ + "product_type", + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "q90", + "aggr": { + "func": "quantile", + "quantile": 0.9 + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 2 + } + ] + }, + "groupBy": ["product_type"], + "orderBy": [ + { + "field": "median", + "order": "desc" + }, + { + "field": "product_type" + } + ], + "limit": 2 + } + }, + { + "name": "HAVING statistics absent from projection", + "dsl": { + "select": [ + "product_type", + { + "field": "sales", + "alias": "sum", + "aggr": { + "func": "sum" + } + } + ], + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 2.5 + }, + { + "field": "profit", + "aggr": { + "func": "quantile", + "quantile": -0.5 + }, + "op": ">", + "value": 5 + } + ] + }, + "orderBy": [ + { + "field": "product_type" + } + ] + } + }, + { + "name": "filtered statistical aggregates", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "quantile", + "aggr": { + "func": "quantile" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "id", + "op": "<", + "value": 0 + } + ] + } + } + }, + { + "name": "product name distinct and extrema", + "dsl": { + "select": [ + { + "field": "product_name", + "alias": "distinct_product_names", + "aggr": { + "func": "count_distinct" + } + }, + { + "field": "product_name", + "alias": "first_product_name", + "aggr": { + "func": "min" + } + }, + { + "field": "product_name", + "alias": "last_product_name", + "aggr": { + "func": "max" + } + } + ] + } + }, + { + "name": "product name grouping", + "dsl": { + "select": [ + "product_name", + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["product_name"], + "orderBy": [ + { + "field": "product_name" + } + ] + } + }, + { + "name": "product name comparison is exact", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "=", + "value": "Fiskars 剪刀, 蓝色" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name IN is exact", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "in", + "value": ["Fiskars 剪刀, 蓝色", "柯尼卡 打印机, 红色"] + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name BETWEEN uses codepoint order", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "between", + "value": ["Acco 孔加固材料, 回收", "贝尔金 鼠标, 耐用"] + } + ] + }, + "orderBy": [ + { + "field": "product_name" + } + ] + } + }, + { + "name": "order date ISO parameter", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": ">=", + "value": "2019-04-27" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "date grouping with statistical HAVING", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_year", + "aggr": { + "func": "to_year" + } + }, + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + } + ], + "groupBy": ["order_year"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is not null" + } + ] + }, + "orderBy": [ + { + "field": "order_year" + } + ] + } + }, + { + "name": "discrete quantile -1", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": -1 + } + } + ] + } + }, + { + "name": "discrete quantile -0.9", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": -0.9 + } + } + ] + } + }, + { + "name": "discrete quantile -0.5", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": -0.5 + } + } + ] + } + }, + { + "name": "discrete quantile -0.01", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": -0.01 + } + } + ] + } + }, + { + "name": "discrete quantile 0", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": 0 + } + } + ] + } + }, + { + "name": "discrete quantile 0.01", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": 0.01 + } + } + ] + } + }, + { + "name": "discrete quantile 0.5", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": 0.5 + } + } + ] + } + }, + { + "name": "discrete quantile 0.9", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": 0.9 + } + } + ] + } + }, + { + "name": "discrete quantile 1", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "result", + "aggr": { + "func": "quantile", + "quantile": 1 + } + } + ] + } + }, + { + "name": "date grouping to_year", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_quarter", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_month", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_week", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_day", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_hour", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_minute", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "date grouping to_second", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + { + "field": "sales", + "alias": "count", + "aggr": { + "func": "count" + } + } + ], + "groupBy": ["order_period"], + "orderBy": [ + { + "field": "order_period" + } + ] + } + }, + { + "name": "product name like Fiskars%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "Fiskars%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name like %孔加固材料%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "%孔加固材料%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name like %信封%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "%信封%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name like 柯尼卡%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "柯尼卡%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not like Fiskars%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "Fiskars%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not like %孔加固材料%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "%孔加固材料%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not like %信封%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "%信封%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not like 柯尼卡%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "柯尼卡%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name ilike Fiskars%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "Fiskars%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name ilike %孔加固材料%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "%孔加固材料%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name ilike %信封%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "%信封%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name ilike 柯尼卡%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "柯尼卡%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not ilike Fiskars%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "Fiskars%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not ilike %孔加固材料%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%孔加固材料%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not ilike %信封%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%信封%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "product name not ilike 柯尼卡%", + "dsl": { + "select": ["id", "product_name"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "柯尼卡%" + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "NULL ordering asc default", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "asc" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "NULL ordering asc first", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "asc", + "nulls": "first" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "NULL ordering asc last", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "asc", + "nulls": "last" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "NULL ordering desc default", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "desc" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "NULL ordering desc first", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "desc", + "nulls": "first" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "NULL ordering desc last", + "dsl": { + "select": ["id", "sales"], + "orderBy": [ + { + "field": "sales", + "order": "desc", + "nulls": "last" + }, + { + "field": "id" + } + ], + "limit": 8 + } + }, + { + "name": "numeric filter =", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "=", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter !=", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "!=", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter >", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter >=", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter <", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "<", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter <=", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "<=", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter in", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "in", + "value": [1, null] + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter not in", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "not in", + "value": [1, null] + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter between", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [1, 4] + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter not between", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [1, 4] + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter is null", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "is null", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "numeric filter is not null", + "dsl": { + "select": ["id", "sales"], + "where": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "is not null", + "value": 2 + } + ] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "empty and group", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "empty or group", + "dsl": { + "select": ["id"], + "where": { + "op": "or", + "conditions": [] + }, + "orderBy": [ + { + "field": "id" + } + ] + } + }, + { + "name": "internal statistical alias collision", + "dsl": { + "select": [ + { + "field": "sales", + "alias": "__vquery_stat_0", + "aggr": { + "func": "median" + } + } + ] + } + }, + { + "name": "GROUP BY source takes precedence over a selected aggregate without alias", + "dsl": { + "select": [ + { + "field": "profit", + "alias": "profit", + "aggr": { + "func": "sum" + } + }, + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + } + ], + "groupBy": ["profit"] + } + }, + { + "name": "GROUP BY source takes precedence over a colliding alias", + "dsl": { + "select": [ + { + "field": "profit", + "alias": "product_type", + "aggr": { + "func": "sum" + } + }, + { + "field": "sales", + "alias": "median", + "aggr": { + "func": "median" + } + } + ], + "groupBy": ["product_type"] + } + }, + { + "name": "projection without alias", + "dsl": { + "select": [ + { + "field": "sales" + } + ], + "orderBy": [ + { + "field": "id" + } + ], + "limit": 1 + } + }, + { + "name": "all fields and zero limit", + "dsl": { + "select": [], + "limit": 0 + } + }, + { + "name": "empty grouping and ordering", + "dsl": { + "select": ["id"], + "groupBy": [], + "orderBy": [], + "limit": 0 + } + }, + { + "name": "raw grouping alias", + "dsl": { + "select": [ + { + "field": "product_type", + "alias": "product_category" + }, + { + "field": "sales", + "aggr": { + "func": "median" + } + } + ], + "groupBy": ["product_category"], + "orderBy": [ + { + "field": "product_category" + } + ] + } + }, + { + "name": "unprojected grouping and sorting", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "median" + } + } + ], + "groupBy": ["product_type"], + "orderBy": [ + { + "field": "product_type" + } + ] + } + }, + { + "name": "HAVING only median and nested count", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">", + "value": 0 + } + ] + }, + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + } + ] + } + } + }, + { + "name": "LIKE NULL", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": null + } + ] + } + } + }, + { + "name": "unaliased count", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "count" + } + } + ] + } + }, + { + "name": "unaliased count_distinct", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + } + } + ] + } + }, + { + "name": "unaliased sum", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ] + } + }, + { + "name": "unaliased avg", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "avg" + } + } + ] + } + }, + { + "name": "unaliased min", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "min" + } + } + ] + } + }, + { + "name": "unaliased max", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "max" + } + } + ] + } + }, + { + "name": "unaliased variance", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "variance" + } + } + ] + } + }, + { + "name": "unaliased variance_pop", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + } + } + ] + } + }, + { + "name": "unaliased stddev", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + } + } + ] + } + }, + { + "name": "unaliased median", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "median" + } + } + ] + } + }, + { + "name": "unaliased quantile", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + } + } + ] + } + }, + { + "name": "empty where and", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [] + } + } + }, + { + "name": "empty where or", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "or", + "conditions": [] + } + } + }, + { + "name": "empty having and", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "having": { + "op": "and", + "conditions": [] + } + } + }, + { + "name": "empty having or", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "having": { + "op": "or", + "conditions": [] + } + } + }, + { + "name": "single WHERE in", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [ + { + "field": "id", + "op": "in", + "value": 1 + } + ] + } + } + }, + { + "name": "array HAVING in", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "in", + "value": [1, 2] + } + ] + } + } + }, + { + "name": "single HAVING in", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": "in", + "value": 10 + } + ] + } + } + }, + { + "name": "single WHERE not in", + "dsl": { + "select": ["id"], + "where": { + "op": "and", + "conditions": [ + { + "field": "id", + "op": "not in", + "value": 1 + } + ] + } + } + }, + { + "name": "array HAVING not in", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "not in", + "value": [1, 2] + } + ] + } + } + }, + { + "name": "single HAVING not in", + "dsl": { + "select": [ + { + "field": "id", + "aggr": { + "func": "count" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": "not in", + "value": 10 + } + ] + } + } + }, + { + "name": "HAVING between", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "between", + "value": [1, 4] + } + ] + } + } + }, + { + "name": "HAVING not between", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "not between", + "value": [1, 4] + } + ] + } + } + }, + { + "name": "HAVING is null", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "is null" + } + ] + } + } + }, + { + "name": "HAVING is not null", + "dsl": { + "select": [ + { + "field": "sales", + "aggr": { + "func": "sum" + } + } + ], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "is not null" + } + ] + } + } + }, + { + "name": "HAVING matrix count =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix count_distinct is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix sum is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix avg is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix min is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix max is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix variance_pop is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix stddev is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix median is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "!=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "<", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "<=", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "not in", + "value": [0, 10, null] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "not between", + "value": [-10, 100] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "is null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "HAVING matrix quantile is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 1] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "is not null" + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "max" + }, + "op": "is not null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "date aggregate matrix to_year count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_year quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_year" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_quarter quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_quarter" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_month quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_week quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_week" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "first" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_day quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_day" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_hour quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_hour" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_minute quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_minute" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "asc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second count", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second count_distinct", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "count_distinct" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "count_distinct" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second sum", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second avg", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "avg" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "avg" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second min", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "min" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second max", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "max" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second variance", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second variance_pop", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "variance_pop" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "variance_pop" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second stddev", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "stddev" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "stddev" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second median", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "date aggregate matrix to_second quantile", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_period", + "aggr": { + "func": "to_second" + } + }, + "product_type", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": -10 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + } + ] + }, + "groupBy": ["order_period", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">=", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "min" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc" + }, + { + "field": "order_period", + "order": "asc" + } + ], + "limit": 25 + } + }, + { + "name": "nested WHERE matrix and =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "!=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": ">", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "<", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "<=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "in", + "value": [0, 1, null] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not in", + "value": [0, 1, null] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [-1, 100] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 100] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "is null" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "is not null" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and like", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and not like", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and ilike", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix and not ilike", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or =", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or !=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "!=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or >", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or >=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or <", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "<", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or <=", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "<=", + "value": 2 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "in", + "value": [0, 1, null] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or not in", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "not in", + "value": [0, 1, null] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [-1, 100] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or not between", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "not between", + "value": [-1, 100] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or is null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "is null" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or is not null", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": "is not null" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or like", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "like", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or not like", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not like", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or ilike", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "nested WHERE matrix or not ilike", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%打印机%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": ">", + "value": 1 + }, + { + "op": "or", + "conditions": [ + { + "field": "id", + "aggr": { + "func": "count" + }, + "op": ">", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": "is null" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "string HAVING matrix min =", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min !=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "!=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min >", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": ">", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min >=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": ">=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min <", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "<", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min <=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "<=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min in", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "in", + "value": ["Fiskars 剪刀, 蓝色", "GlobeWeis 搭扣信封, 红色", null] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min not in", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "not in", + "value": ["Fiskars 剪刀, 蓝色", "GlobeWeis 搭扣信封, 红色", null] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min between", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "between", + "value": ["Acco 孔加固材料, 回收", "贝尔金 鼠标, 耐用"] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min not between", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "not between", + "value": ["Acco 孔加固材料, 回收", "贝尔金 鼠标, 耐用"] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min is null", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "is null" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix min is not null", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "min" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "min" + }, + "op": "is not null" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max =", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max !=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "!=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max >", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": ">", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max >=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": ">=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max <", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "<", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max <=", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "<=", + "value": "Fiskars 剪刀, 蓝色" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max in", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "in", + "value": ["Fiskars 剪刀, 蓝色", "GlobeWeis 搭扣信封, 红色", null] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max not in", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "not in", + "value": ["Fiskars 剪刀, 蓝色", "GlobeWeis 搭扣信封, 红色", null] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max between", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "between", + "value": ["Acco 孔加固材料, 回收", "贝尔金 鼠标, 耐用"] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max not between", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "not between", + "value": ["Acco 孔加固材料, 回收", "贝尔金 鼠标, 耐用"] + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max is null", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "is null" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "string HAVING matrix max is not null", + "dsl": { + "select": [ + "product_type", + { + "field": "product_name", + "alias": "product_name_boundary", + "aggr": { + "func": "max" + } + }, + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "not ilike", + "value": "%开信刀%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "product_name", + "aggr": { + "func": "max" + }, + "op": "is not null" + }, + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": ">", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "product_name_boundary", + "order": "asc", + "nulls": "last" + }, + { + "field": "sales_metric", + "order": "desc" + } + ], + "limit": 10 + } + }, + { + "name": "deep mixed WHERE HAVING depth 2", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [-10000000000, 10000000000] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "between", + "value": [-10, 100] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "deep mixed WHERE HAVING depth 4", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [-10000000000, 10000000000] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "between", + "value": [-10, 100] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "deep mixed WHERE HAVING depth 8", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "between", + "value": [-10000000000, 10000000000] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + { + "field": "product_type", + "op": "=", + "value": "办公用品" + } + ] + }, + { + "field": "product_name", + "op": "like", + "value": "%剪刀%" + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile" + }, + "op": "between", + "value": [-10, 100] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "op": "<=", + "value": 1 + } + ] + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "multiple date grouping aliases with multiple statistical fields", + "description": "同时分组两个日期别名与字符串维度,两个字段的 median/quantile 共用各自窗口,HAVING 包含未投影统计。", + "dsl": { + "select": [ + { + "field": "order_date", + "alias": "order_year", + "aggr": { + "func": "to_year" + } + }, + { + "field": "order_date", + "alias": "order_month", + "aggr": { + "func": "to_month" + } + }, + "product_type", + { + "field": "sales", + "alias": "median_value", + "aggr": { + "func": "median" + } + }, + { + "field": "sales", + "alias": "q90", + "aggr": { + "func": "quantile", + "quantile": 0.9 + } + }, + { + "field": "profit", + "alias": "q10_profit", + "aggr": { + "func": "quantile", + "quantile": -0.1 + } + }, + { + "field": "profit", + "alias": "total", + "aggr": { + "func": "sum" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2016-01-01", "2019-12-30"] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["order_year", "order_month", "product_type"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile", + "quantile": 0.1 + }, + "op": ">", + "value": 1 + }, + { + "op": "and", + "conditions": [ + { + "field": "profit", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "field": "sales", + "aggr": { + "func": "variance" + }, + "op": ">", + "value": 1 + } + ] + } + ] + }, + "orderBy": [ + { + "field": "order_year" + }, + { + "field": "order_month" + }, + { + "field": "q90", + "order": "desc", + "nulls": "first" + } + ], + "limit": 100 + } + }, + { + "name": "statistical aliases collide with internal rank names and source names", + "description": "业务别名占用内部窗口名称,源字段与 SELECT 别名冲突时 GROUP BY 优先解析源字段。", + "dsl": { + "select": [ + "product_type", + { + "field": "profit", + "alias": "sales", + "aggr": { + "func": "sum" + } + }, + { + "field": "sales", + "alias": "__vquery_stat_0", + "aggr": { + "func": "median" + } + }, + { + "field": "profit", + "alias": "__vquery_stat_1", + "aggr": { + "func": "quantile", + "quantile": 0.9 + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 0 + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "sales"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "median" + }, + "op": ">=", + "value": 1 + }, + { + "field": "profit", + "aggr": { + "func": "quantile" + }, + "op": "<=", + "value": 1 + } + ] + }, + "orderBy": [ + { + "field": "__vquery_stat_0", + "order": "desc" + }, + { + "field": "product_type" + } + ], + "limit": 5 + } + }, + { + "name": "all-column detail with nested filters and no limit", + "dsl": { + "select": [], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "product_name", + "op": "ilike", + "value": "Fiskars%" + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "orderBy": [ + { + "field": "order_date", + "order": "desc", + "nulls": "first" + }, + { + "field": "id", + "order": "desc" + } + ] + } + }, + { + "name": "empty groups embedded in complete statistical query", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "median" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [] + }, + { + "op": "and", + "conditions": [] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [] + }, + { + "op": "or", + "conditions": [] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 50 + } + }, + { + "name": "signed fractional and scientific notation parameters with zero result limit", + "dsl": { + "select": [ + "product_type", + "product_name", + { + "field": "sales", + "alias": "sales_metric", + "aggr": { + "func": "quantile" + } + } + ], + "where": { + "op": "and", + "conditions": [ + { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": "in", + "value": [0, 0.125, -123.456, 1e-12, 1000000000000, null] + }, + { + "field": "profit", + "op": "is null" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "id", + "op": ">=", + "value": 1 + }, + { + "field": "product_type", + "op": "not in", + "value": ["技术", "家具"] + } + ] + } + ] + }, + "groupBy": ["product_type", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "aggr": { + "func": "quantile", + "quantile": -0.14 + }, + "op": "between", + "value": [-1000000, 1000000] + } + ] + }, + "orderBy": [ + { + "field": "sales_metric", + "order": "desc", + "nulls": "last" + }, + { + "field": "product_type", + "order": "asc" + } + ], + "limit": 0 + } + }, + { + "name": "超市全年经营汇总", + "description": "订单号、客户和商品按真实标识去重,汇总销售额、利润、件数与折扣。", + "dsl": { + "select": [ + { + "field": "order_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "order_count" + }, + { + "field": "customer_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "customer_count" + }, + { + "field": "product_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "product_count" + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_profit" + }, + { + "field": "amount", + "aggr": { + "func": "sum" + }, + "alias": "total_amount" + }, + { + "field": "discount", + "aggr": { + "func": "avg" + }, + "alias": "average_discount" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + } + ] + } + } + }, + { + "name": "按月份省份和商品类别比较销售利润", + "dsl": { + "select": [ + { + "field": "order_date", + "aggr": { + "func": "to_month" + }, + "alias": "order_month" + }, + "province", + "product_type", + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_profit" + }, + { + "field": "sales", + "aggr": { + "func": "median" + }, + "alias": "median_sales" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "area", + "op": "in", + "value": ["华东", "中南"] + } + ] + }, + "groupBy": ["order_month", "province", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 1000, + "aggr": { + "func": "sum" + } + }, + { + "field": "profit", + "op": ">", + "value": 0, + "aggr": { + "func": "sum" + } + } + ] + }, + "orderBy": [ + { + "field": "order_month" + }, + { + "field": "total_sales", + "order": "desc" + }, + { + "field": "province" + } + ], + "limit": 100 + } + }, + { + "name": "浙江城市销售排行榜", + "dsl": { + "select": [ + "province", + "city", + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "order_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "order_count" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "province", + "op": "=", + "value": "浙江" + }, + { + "field": "delivery_method", + "op": "in", + "value": ["标准级", "二级"] + } + ] + }, + "groupBy": ["province", "city"], + "having": { + "op": "and", + "conditions": [ + { + "field": "order_id", + "op": ">=", + "value": 5, + "aggr": { + "func": "count_distinct" + } + } + ] + }, + "orderBy": [ + { + "field": "total_sales", + "order": "desc" + }, + { + "field": "city" + } + ], + "limit": 20 + } + }, + { + "name": "客户类型与复购客户贡献", + "dsl": { + "select": [ + "customer_type", + "customer_id", + "customer_name", + { + "field": "order_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "order_count" + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_profit" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "customer_type", + "op": "in", + "value": ["公司", "消费者", "小型企业"] + } + ] + }, + "groupBy": ["customer_type", "customer_id", "customer_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "order_id", + "op": ">", + "value": 1, + "aggr": { + "func": "count_distinct" + } + } + ] + }, + "orderBy": [ + { + "field": "total_sales", + "order": "desc" + }, + { + "field": "customer_id" + } + ], + "limit": 50 + } + }, + { + "name": "商品层级利润与销售分位数", + "dsl": { + "select": [ + "product_type", + "product_sub_type", + "product_id", + "product_name", + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_profit" + }, + { + "field": "sales", + "aggr": { + "func": "quantile", + "quantile": 0.9 + }, + "alias": "sales_q90" + }, + { + "field": "amount", + "aggr": { + "func": "sum" + }, + "alias": "total_amount" + }, + { + "field": "discount", + "aggr": { + "func": "avg" + }, + "alias": "average_discount" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "field": "product_type", + "op": "=", + "value": "办公用品" + }, + { + "field": "product_name", + "op": "like", + "value": "%打印机%" + } + ] + } + ] + }, + "groupBy": ["product_type", "product_sub_type", "product_id", "product_name"], + "having": { + "op": "and", + "conditions": [ + { + "field": "amount", + "op": ">=", + "value": 10, + "aggr": { + "func": "sum" + } + } + ] + }, + "orderBy": [ + { + "field": "total_profit", + "order": "desc" + }, + { + "field": "product_id" + } + ], + "limit": 50 + } + }, + { + "name": "配送月份与配送方式销售构成", + "dsl": { + "select": [ + { + "field": "delivery_date", + "aggr": { + "func": "to_month" + }, + "alias": "delivery_month" + }, + "delivery_method", + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "order_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "order_count" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "delivery_date", + "op": "between", + "value": ["2019-01-01", "2020-01-10"] + } + ] + }, + "groupBy": ["delivery_month", "delivery_method"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">", + "value": 0, + "aggr": { + "func": "sum" + } + } + ] + }, + "orderBy": [ + { + "field": "delivery_month" + }, + { + "field": "total_sales", + "order": "desc" + } + ], + "limit": 100 + } + }, + { + "name": "折扣亏损商品在地域中的分布", + "dsl": { + "select": [ + "country_or_region", + "area", + "province", + "product_type", + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_loss" + }, + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "discount", + "aggr": { + "func": "avg" + }, + "alias": "average_discount" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "profit", + "op": "<", + "value": 0 + }, + { + "field": "discount", + "op": ">", + "value": 0 + } + ] + }, + "groupBy": ["country_or_region", "area", "province", "product_type"], + "having": { + "op": "and", + "conditions": [ + { + "field": "profit", + "op": "<", + "value": 0, + "aggr": { + "func": "sum" + } + } + ] + }, + "orderBy": [ + { + "field": "total_loss", + "order": "asc" + }, + { + "field": "province" + } + ], + "limit": 100 + } + }, + { + "name": "全部真实字段的订单明细", + "description": "明细投影完整覆盖 CSV 的 20 列,不引入合成源字段。", + "dsl": { + "select": [ + "id", + "order_id", + "order_date", + "delivery_date", + "delivery_method", + "customer_id", + "customer_name", + "customer_type", + "city", + "province", + "country_or_region", + "area", + "product_id", + "product_type", + "product_sub_type", + "product_name", + "sales", + "amount", + "discount", + "profit" + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "field": "province", + "op": "=", + "value": "浙江" + }, + { + "field": "province", + "op": "=", + "value": "四川" + } + ] + } + ] + }, + "orderBy": [ + { + "field": "order_date", + "order": "desc" + }, + { + "field": "id", + "order": "desc" + } + ], + "limit": 100 + } + }, + { + "name": "下单日和配送日双日期分组", + "dsl": { + "select": [ + { + "field": "order_date", + "aggr": { + "func": "to_day" + }, + "alias": "order_day" + }, + { + "field": "delivery_date", + "aggr": { + "func": "to_day" + }, + "alias": "delivery_day" + }, + "delivery_method", + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "profit", + "aggr": { + "func": "median" + }, + "alias": "median_profit" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "field": "delivery_method", + "op": "=", + "value": "当日" + } + ] + }, + "groupBy": ["order_day", "delivery_day", "delivery_method"], + "having": { + "op": "or", + "conditions": [ + { + "field": "sales", + "op": ">", + "value": 500, + "aggr": { + "func": "sum" + } + }, + { + "field": "profit", + "op": "<", + "value": 0, + "aggr": { + "func": "median" + } + } + ] + }, + "orderBy": [ + { + "field": "order_day" + }, + { + "field": "delivery_day" + } + ], + "limit": 100 + } + }, + { + "name": "客户商品地域交叉销售分析", + "dsl": { + "select": [ + "customer_type", + "product_type", + "area", + { + "field": "sales", + "aggr": { + "func": "sum" + }, + "alias": "total_sales" + }, + { + "field": "profit", + "aggr": { + "func": "sum" + }, + "alias": "total_profit" + }, + { + "field": "order_id", + "aggr": { + "func": "count_distinct" + }, + "alias": "order_count" + } + ], + "where": { + "op": "and", + "conditions": [ + { + "field": "order_date", + "op": "between", + "value": ["2019-01-01", "2019-12-30"] + }, + { + "op": "or", + "conditions": [ + { + "op": "and", + "conditions": [ + { + "field": "customer_type", + "op": "=", + "value": "公司" + }, + { + "field": "product_type", + "op": "=", + "value": "技术" + } + ] + }, + { + "op": "and", + "conditions": [ + { + "field": "customer_type", + "op": "=", + "value": "消费者" + }, + { + "field": "product_type", + "op": "=", + "value": "家具" + } + ] + } + ] + } + ] + }, + "groupBy": ["customer_type", "product_type", "area"], + "having": { + "op": "and", + "conditions": [ + { + "field": "sales", + "op": ">=", + "value": 1000, + "aggr": { + "func": "sum" + } + }, + { + "op": "or", + "conditions": [ + { + "field": "profit", + "op": ">", + "value": 0, + "aggr": { + "func": "sum" + } + }, + { + "field": "order_id", + "op": ">", + "value": 5, + "aggr": { + "func": "count_distinct" + } + } + ] + } + ] + }, + "orderBy": [ + { + "field": "total_sales", + "order": "desc" + }, + { + "field": "area" + } + ], + "limit": 50 + } + } + ] +} diff --git a/packages/vquery/tests/examples/groupBy/basic.test.ts b/packages/vquery/tests/examples/groupBy/basic.test.ts index d382956407..73227dd032 100644 --- a/packages/vquery/tests/examples/groupBy/basic.test.ts +++ b/packages/vquery/tests/examples/groupBy/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic GroupBy Example', () => { @@ -17,7 +17,7 @@ describe('Basic GroupBy Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", avg("salary") as "Average Salary" from "groupBy-basic" group by "department""`, diff --git a/packages/vquery/tests/examples/having/basic.test.ts b/packages/vquery/tests/examples/having/basic.test.ts index f6575cb714..1c5bed5615 100644 --- a/packages/vquery/tests/examples/having/basic.test.ts +++ b/packages/vquery/tests/examples/having/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic Having Example - filter aggregated results', () => { @@ -17,7 +17,7 @@ describe('Basic Having Example - filter aggregated results', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-basic" group by "department" having (sum("salary") > 5000)"`, diff --git a/packages/vquery/tests/examples/having/between.test.ts b/packages/vquery/tests/examples/having/between.test.ts index ab4c628ad7..f85c0d4eb3 100644 --- a/packages/vquery/tests/examples/having/between.test.ts +++ b/packages/vquery/tests/examples/having/between.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './between.json' describe('Having Example with BETWEEN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with BETWEEN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-between" group by "department" having (sum("salary") between 5000 and 12000)"`, diff --git a/packages/vquery/tests/examples/having/in-array.test.ts b/packages/vquery/tests/examples/having/in-array.test.ts index ebca81b089..3d9552fed0 100644 --- a/packages/vquery/tests/examples/having/in-array.test.ts +++ b/packages/vquery/tests/examples/having/in-array.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './in-array.json' describe('Having Example with array IN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with array IN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-in-array" group by "department" having (min("department") in ('HR', 'Engineering'))"`, diff --git a/packages/vquery/tests/examples/having/in-single.test.ts b/packages/vquery/tests/examples/having/in-single.test.ts index 9104e9c14e..d380406b1e 100644 --- a/packages/vquery/tests/examples/having/in-single.test.ts +++ b/packages/vquery/tests/examples/having/in-single.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './in-single.json' describe('Having Example with single value IN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with single value IN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-in-single" group by "department" having (min("department") in ('HR'))"`, diff --git a/packages/vquery/tests/examples/having/is-not-null.test.ts b/packages/vquery/tests/examples/having/is-not-null.test.ts index 3129d5b9fa..52958c3280 100644 --- a/packages/vquery/tests/examples/having/is-not-null.test.ts +++ b/packages/vquery/tests/examples/having/is-not-null.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './is-not-null.json' describe('Having Example with IS NOT NULL operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with IS NOT NULL operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-is-not-null" group by "department" having (sum("salary") is not null)"`, diff --git a/packages/vquery/tests/examples/having/is-null.test.ts b/packages/vquery/tests/examples/having/is-null.test.ts index f6b55ceffe..838e5d8e57 100644 --- a/packages/vquery/tests/examples/having/is-null.test.ts +++ b/packages/vquery/tests/examples/having/is-null.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './is-null.json' describe('Having Example with IS NULL operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with IS NULL operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-is-null" group by "department" having (sum("salary") is null)"`, diff --git a/packages/vquery/tests/examples/having/max.test.ts b/packages/vquery/tests/examples/having/max.test.ts index 98743ea7a3..0721deb0ad 100644 --- a/packages/vquery/tests/examples/having/max.test.ts +++ b/packages/vquery/tests/examples/having/max.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './max.json' describe('Having Example with MAX aggregate function', () => { @@ -17,7 +17,7 @@ describe('Having Example with MAX aggregate function', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", max("salary") as "Max Salary" from "having-max" group by "department" having (max("salary") = 9000)"`, diff --git a/packages/vquery/tests/examples/having/min.test.ts b/packages/vquery/tests/examples/having/min.test.ts index d665abdeb0..5487c80599 100644 --- a/packages/vquery/tests/examples/having/min.test.ts +++ b/packages/vquery/tests/examples/having/min.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './min.json' describe('Having Example with MIN aggregate function', () => { @@ -17,7 +17,7 @@ describe('Having Example with MIN aggregate function', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", min("salary") as "Min Salary" from "having-min" group by "department" having (min("salary") = 5000)"`, diff --git a/packages/vquery/tests/examples/having/multi-conditions.test.ts b/packages/vquery/tests/examples/having/multi-conditions.test.ts index e5947040c1..51d9220c39 100644 --- a/packages/vquery/tests/examples/having/multi-conditions.test.ts +++ b/packages/vquery/tests/examples/having/multi-conditions.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './multi-conditions.json' describe('Having Example with multiple conditions (AND/OR)', () => { @@ -17,10 +17,10 @@ describe('Having Example with multiple conditions (AND/OR)', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "department", sum("salary") as "Total Salary", CAST(count("salary") AS INTEGER) as "Count" from "having-multi" group by "department" having (sum("salary") > 5000 and count("salary") > 1)"`, + `"select "department", sum("salary") as "Total Salary", count("salary") as "Count" from "having-multi" group by "department" having (sum("salary") > 5000 and count("salary") > 1)"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/having/not-between.test.ts b/packages/vquery/tests/examples/having/not-between.test.ts index 2b75aff5d5..7f6d1e9c89 100644 --- a/packages/vquery/tests/examples/having/not-between.test.ts +++ b/packages/vquery/tests/examples/having/not-between.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './not-between.json' describe('Having Example with NOT BETWEEN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with NOT BETWEEN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-not-between" group by "department" having (sum("salary") not between 5000 and 12000)"`, diff --git a/packages/vquery/tests/examples/having/not-in-single.test.ts b/packages/vquery/tests/examples/having/not-in-single.test.ts index 57c1093004..e251b432f6 100644 --- a/packages/vquery/tests/examples/having/not-in-single.test.ts +++ b/packages/vquery/tests/examples/having/not-in-single.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './not-in-single.json' describe('Having Example with single value NOT IN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with single value NOT IN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-not-in-single" group by "department" having (not min("department") in ('HR'))"`, diff --git a/packages/vquery/tests/examples/having/not-in.test.ts b/packages/vquery/tests/examples/having/not-in.test.ts index f3ea2e713b..21f6ebb645 100644 --- a/packages/vquery/tests/examples/having/not-in.test.ts +++ b/packages/vquery/tests/examples/having/not-in.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './not-in.json' describe('Having Example with NOT IN operator', () => { @@ -17,7 +17,7 @@ describe('Having Example with NOT IN operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-not-in" group by "department" having (not min("department") in ('Marketing'))"`, diff --git a/packages/vquery/tests/examples/having/or-conditions.test.ts b/packages/vquery/tests/examples/having/or-conditions.test.ts index f8a2445fbd..5dbee294e4 100644 --- a/packages/vquery/tests/examples/having/or-conditions.test.ts +++ b/packages/vquery/tests/examples/having/or-conditions.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './or-conditions.json' describe('Having Example with OR conditions', () => { @@ -17,7 +17,7 @@ describe('Having Example with OR conditions', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "department", sum("salary") as "Total Salary" from "having-or" group by "department" having (sum("salary") > 15000 or sum("salary") < 5000)"`, diff --git a/packages/vquery/tests/examples/limit/basic.test.ts b/packages/vquery/tests/examples/limit/basic.test.ts index 5e74adb1a2..16ddbfb969 100644 --- a/packages/vquery/tests/examples/limit/basic.test.ts +++ b/packages/vquery/tests/examples/limit/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic Limit Example', () => { @@ -17,7 +17,7 @@ describe('Basic Limit Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select "name" from "limit-basic" limit 2"`) diff --git a/packages/vquery/tests/examples/orderBy/basic.test.ts b/packages/vquery/tests/examples/orderBy/basic.test.ts index 448cc94cba..d1db8fa82c 100644 --- a/packages/vquery/tests/examples/orderBy/basic.test.ts +++ b/packages/vquery/tests/examples/orderBy/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic OrderBy Example', () => { @@ -17,9 +17,11 @@ describe('Basic OrderBy Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) - expect(sql).toMatchInlineSnapshot(`"select "name", "salary" from "orderBy-basic" order by "salary" desc"`) + expect(sql).toMatchInlineSnapshot( + `"select "name", "salary" from "orderBy-basic" order by "salary" desc nulls last"`, + ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/aggregation/avg.test.ts b/packages/vquery/tests/examples/select/aggregation/avg.test.ts index 94e5213d63..19f40a5e53 100644 --- a/packages/vquery/tests/examples/select/aggregation/avg.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/avg.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './avg.json' describe('Select Avg Example', () => { @@ -17,7 +17,7 @@ describe('Select Avg Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select avg("salary") as "avg_salary" from "select-aggregation-avg""`) diff --git a/packages/vquery/tests/examples/select/aggregation/count.test.ts b/packages/vquery/tests/examples/select/aggregation/count.test.ts index edc0c5ec6b..41f4741f14 100644 --- a/packages/vquery/tests/examples/select/aggregation/count.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/count.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './count.json' describe('Select Count Example', () => { @@ -17,11 +17,9 @@ describe('Select Count Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) - expect(sql).toMatchInlineSnapshot( - `"select CAST(count("id") AS INTEGER) as "total_count" from "select-aggregation-count""`, - ) + expect(sql).toMatchInlineSnapshot(`"select count("id") as "total_count" from "select-aggregation-count""`) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/aggregation/count_distinct.test.ts b/packages/vquery/tests/examples/select/aggregation/count_distinct.test.ts index f1385bf749..da1449a5ac 100644 --- a/packages/vquery/tests/examples/select/aggregation/count_distinct.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/count_distinct.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './count_distinct.json' describe('Select Count Distinct Example', () => { @@ -17,10 +17,10 @@ describe('Select Count Distinct Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select CAST(count(distinct "department") AS INTEGER) as "distinct_departments" from "select-aggregation-count-distinct""`, + `"select count(distinct "department") as "distinct_departments" from "select-aggregation-count-distinct""`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/aggregation/max.test.ts b/packages/vquery/tests/examples/select/aggregation/max.test.ts index fdbfa41c5b..c2e38bc6ac 100644 --- a/packages/vquery/tests/examples/select/aggregation/max.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/max.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './max.json' describe('Select Max Example', () => { @@ -17,7 +17,7 @@ describe('Select Max Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select max("salary") as "max_salary" from "select-aggregation-max""`) diff --git a/packages/vquery/tests/examples/select/aggregation/median.test.ts b/packages/vquery/tests/examples/select/aggregation/median.test.ts index 378820b6fe..2d464cdca0 100644 --- a/packages/vquery/tests/examples/select/aggregation/median.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/median.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './median.json' describe('Select Median Example', () => { @@ -17,7 +17,7 @@ describe('Select Median Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select median("salary") as "salary_median" from "select-aggregation-median""`) diff --git a/packages/vquery/tests/examples/select/aggregation/min.test.ts b/packages/vquery/tests/examples/select/aggregation/min.test.ts index 098f95fdc3..eae7b380ed 100644 --- a/packages/vquery/tests/examples/select/aggregation/min.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/min.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './min.json' describe('Select Min Example', () => { @@ -17,7 +17,7 @@ describe('Select Min Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select min("salary") as "min_salary" from "select-aggregation-min""`) diff --git a/packages/vquery/tests/examples/select/aggregation/quantile.test.ts b/packages/vquery/tests/examples/select/aggregation/quantile.test.ts index a048d9b5fc..aa85567db2 100644 --- a/packages/vquery/tests/examples/select/aggregation/quantile.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/quantile.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './quantile.json' describe('Select Quantile Example', () => { @@ -17,10 +17,10 @@ describe('Select Quantile Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select quantile("salary", 0.9) as "salary_quantile" from "select-aggregation-quantile""`, + `"select quantile("salary", CAST(0.9 AS DOUBLE)) as "salary_quantile" from "select-aggregation-quantile""`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/aggregation/stddev.test.ts b/packages/vquery/tests/examples/select/aggregation/stddev.test.ts index fe0cd0d52c..dcdd53172f 100644 --- a/packages/vquery/tests/examples/select/aggregation/stddev.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/stddev.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './stddev.json' describe('Select Stddev Example', () => { @@ -17,7 +17,7 @@ describe('Select Stddev Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select stddev("salary") as "salary_stddev" from "select-aggregation-stddev""`) diff --git a/packages/vquery/tests/examples/select/aggregation/sum.test.ts b/packages/vquery/tests/examples/select/aggregation/sum.test.ts index e570ba7f20..6d9d955788 100644 --- a/packages/vquery/tests/examples/select/aggregation/sum.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/sum.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './sum.json' describe('Select Sum Example', () => { @@ -17,7 +17,7 @@ describe('Select Sum Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select sum("salary") as "total_salary" from "select-aggregation-sum""`) diff --git a/packages/vquery/tests/examples/select/aggregation/variance.test.ts b/packages/vquery/tests/examples/select/aggregation/variance.test.ts index a2957e5c25..c6fafceff4 100644 --- a/packages/vquery/tests/examples/select/aggregation/variance.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/variance.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './variance.json' describe('Select Variance Example', () => { @@ -17,7 +17,7 @@ describe('Select Variance Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select var_samp("salary") as "salary_variance" from "select-aggregation-variance""`, diff --git a/packages/vquery/tests/examples/select/aggregation/variancePop.test.ts b/packages/vquery/tests/examples/select/aggregation/variancePop.test.ts index 5ab7f8cf65..e46c8ae126 100644 --- a/packages/vquery/tests/examples/select/aggregation/variancePop.test.ts +++ b/packages/vquery/tests/examples/select/aggregation/variancePop.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './variancePop.json' describe('Select VariancePop Example', () => { @@ -17,7 +17,7 @@ describe('Select VariancePop Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select var_pop("salary") as "salary_variance_pop" from "select-aggregation-variance-pop""`, diff --git a/packages/vquery/tests/examples/select/basic.test.ts b/packages/vquery/tests/examples/select/basic.test.ts index 07cbf78a29..28057286a3 100644 --- a/packages/vquery/tests/examples/select/basic.test.ts +++ b/packages/vquery/tests/examples/select/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic Select Example', () => { @@ -17,7 +17,7 @@ describe('Basic Select Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot(`"select "name", "department", "salary" as "Income" from "select-basic""`) diff --git a/packages/vquery/tests/examples/select/date/toDay.test.ts b/packages/vquery/tests/examples/select/date/toDay.test.ts index bbadc602ad..a0a1f4b9f3 100644 --- a/packages/vquery/tests/examples/select/date/toDay.test.ts +++ b/packages/vquery/tests/examples/select/date/toDay.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toDay.json' describe('toDay', () => { @@ -17,10 +17,10 @@ describe('toDay', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d') as "day" from "vquery-demo" group by "day", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d') as "day" from "vquery-demo" group by "day", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toHour.test.ts b/packages/vquery/tests/examples/select/date/toHour.test.ts index 6b8dd86624..fbe3f3fbfa 100644 --- a/packages/vquery/tests/examples/select/date/toHour.test.ts +++ b/packages/vquery/tests/examples/select/date/toHour.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toHour.json' describe('toHour', () => { @@ -17,10 +17,10 @@ describe('toHour', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H') as "hour" from "vquery-demo" group by "hour", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H') as "hour" from "vquery-demo" group by "hour", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toMinute.test.ts b/packages/vquery/tests/examples/select/date/toMinute.test.ts index a01538948b..ba31f8a8d6 100644 --- a/packages/vquery/tests/examples/select/date/toMinute.test.ts +++ b/packages/vquery/tests/examples/select/date/toMinute.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toMinute.json' describe('toMinute', () => { @@ -17,10 +17,10 @@ describe('toMinute', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H:%M') as "minute" from "vquery-demo" group by "minute", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H:%M') as "minute" from "vquery-demo" group by "minute", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toMonth.test.ts b/packages/vquery/tests/examples/select/date/toMonth.test.ts index ce3a3d7fe9..d3f8c040f4 100644 --- a/packages/vquery/tests/examples/select/date/toMonth.test.ts +++ b/packages/vquery/tests/examples/select/date/toMonth.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toMonth.json' describe('toMonth', () => { @@ -17,10 +17,10 @@ describe('toMonth', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m') as "month" from "vquery-demo" where (("area" in ('BEI JING') or "sales" >= 400)) group by "month", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m') as "month" from "vquery-demo" where (("area" in ('BEI JING') or "sales" >= 400)) group by "month", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toMonth_with_date_filter.test.ts b/packages/vquery/tests/examples/select/date/toMonth_with_date_filter.test.ts index 66ac4fd1b4..458fa3a6af 100644 --- a/packages/vquery/tests/examples/select/date/toMonth_with_date_filter.test.ts +++ b/packages/vquery/tests/examples/select/date/toMonth_with_date_filter.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toMonth_with_date_filter.json' describe('toMonth with DATE range filter', () => { @@ -17,10 +17,10 @@ describe('toMonth with DATE range filter', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m') as "month" from "select-date-toMonth-with-filter" where ("date" between '2025-01-01' and '2025-01-31') group by "month", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m') as "month" from "select-date-toMonth-with-filter" where ("date" between '2025-01-01' and '2025-01-31') group by "month", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toQuarter.test.ts b/packages/vquery/tests/examples/select/date/toQuarter.test.ts index 25f763ba20..5247f0e3ca 100644 --- a/packages/vquery/tests/examples/select/date/toQuarter.test.ts +++ b/packages/vquery/tests/examples/select/date/toQuarter.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toQuarter.json' describe('toQuarter', () => { @@ -17,10 +17,10 @@ describe('toQuarter', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("date" AS TIMESTAMP)) as "quarter" from "vquery-demo" group by "quarter", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y') || '-Q' || date_part('quarter', CAST("date" AS TIMESTAMP)) as "quarter" from "vquery-demo" group by "quarter", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toSecond.test.ts b/packages/vquery/tests/examples/select/date/toSecond.test.ts index 194c805d0c..ca8b519390 100644 --- a/packages/vquery/tests/examples/select/date/toSecond.test.ts +++ b/packages/vquery/tests/examples/select/date/toSecond.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toSecond.json' describe('toSecond', () => { @@ -17,10 +17,10 @@ describe('toSecond', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H:%M:%S') as "second" from "vquery-demo" group by "second", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-%m-%d %H:%M:%S') as "second" from "vquery-demo" group by "second", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toWeek.test.ts b/packages/vquery/tests/examples/select/date/toWeek.test.ts index 353b3b45a9..f2330e3039 100644 --- a/packages/vquery/tests/examples/select/date/toWeek.test.ts +++ b/packages/vquery/tests/examples/select/date/toWeek.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toWeek.json' describe('toWeek', () => { @@ -17,10 +17,10 @@ describe('toWeek', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-W%W') as "week" from "vquery-demo" group by "week", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y-W%W') as "week" from "vquery-demo" group by "week", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/select/date/toYear.test.ts b/packages/vquery/tests/examples/select/date/toYear.test.ts index 4f5cbc9bd1..7f6c964707 100644 --- a/packages/vquery/tests/examples/select/date/toYear.test.ts +++ b/packages/vquery/tests/examples/select/date/toYear.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './toYear.json' describe('toYear', () => { @@ -17,10 +17,10 @@ describe('toYear', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y') as "year" from "vquery-demo" where (("area" in ('BEI JING') or "sales" >= 400)) group by "year", "area" order by "Sum(sales)" desc limit 100"`, + `"select "area", sum("sales") as "Sum(sales)", strftime(CAST("date" AS TIMESTAMP), '%Y') as "year" from "vquery-demo" where (("area" in ('BEI JING') or "sales" >= 400)) group by "year", "area" order by "Sum(sales)" desc nulls last limit 100"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/where/basic.test.ts b/packages/vquery/tests/examples/where/basic.test.ts index ab3f6f90f3..5220a659a2 100644 --- a/packages/vquery/tests/examples/where/basic.test.ts +++ b/packages/vquery/tests/examples/where/basic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './basic.json' describe('Basic Where Example', () => { @@ -17,7 +17,7 @@ describe('Basic Where Example', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "name", "department", "salary" from "where-basic" where ("department" = 'Engineering')"`, diff --git a/packages/vquery/tests/examples/where/between_operator.test.ts b/packages/vquery/tests/examples/where/between_operator.test.ts index 6f801fb4e0..daa57281d6 100644 --- a/packages/vquery/tests/examples/where/between_operator.test.ts +++ b/packages/vquery/tests/examples/where/between_operator.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './between_operator.json' describe('Where with BETWEEN / NOT BETWEEN Operator', () => { @@ -17,7 +17,7 @@ describe('Where with BETWEEN / NOT BETWEEN Operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "id", "name", "age", "gender" from "where-between-operator" where (("age" between 18 and 30 and "gender" in ('male', 'female')) or ("age" not between 18 and 30 and not "gender" in ('male', 'female')))"`, diff --git a/packages/vquery/tests/examples/where/complex_logic.test.ts b/packages/vquery/tests/examples/where/complex_logic.test.ts index c7bb9c4f5e..57f0703a70 100644 --- a/packages/vquery/tests/examples/where/complex_logic.test.ts +++ b/packages/vquery/tests/examples/where/complex_logic.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './complex_logic.json' describe('Where with Complex AND/OR Logic', () => { @@ -17,7 +17,7 @@ describe('Where with Complex AND/OR Logic', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "id", "name", "age", "gender" from "where-complex-logic" where (("age" >= 18 and "gender" = 'male') or ("age" < 18 and "gender" = 'female'))"`, diff --git a/packages/vquery/tests/examples/where/date_between.test.ts b/packages/vquery/tests/examples/where/date_between.test.ts index 41f4a0ccca..24942c5627 100644 --- a/packages/vquery/tests/examples/where/date_between.test.ts +++ b/packages/vquery/tests/examples/where/date_between.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './date_between.json' describe('Where with DATE field BETWEEN filter', () => { @@ -17,10 +17,10 @@ describe('Where with DATE field BETWEEN filter', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "id", "area", "sales", strftime(CAST("order_date" AS TIMESTAMP), '%Y-%m-%d') as "order_day" from "where-date-between" where ("order_date" between '2024-01-01' and '2024-01-31') order by "order_day" asc"`, + `"select "id", "area", "sales", strftime(CAST("order_date" AS TIMESTAMP), '%Y-%m-%d') as "order_day" from "where-date-between" where ("order_date" between '2024-01-01' and '2024-01-31') order by "order_day" asc nulls last"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/examples/where/in_operator.test.ts b/packages/vquery/tests/examples/where/in_operator.test.ts index 3b7cedaa2d..f5d12a8abb 100644 --- a/packages/vquery/tests/examples/where/in_operator.test.ts +++ b/packages/vquery/tests/examples/where/in_operator.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './in_operator.json' describe('Where with IN / NOT IN Operator', () => { @@ -17,7 +17,7 @@ describe('Where with IN / NOT IN Operator', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "id", "name", "age", "gender" from "where-in-operator" where (("age" >= 18 and "gender" in ('male', 'female')) or ("age" < 18 and not "gender" in ('male', 'female')))"`, diff --git a/packages/vquery/tests/examples/where/null_check.test.ts b/packages/vquery/tests/examples/where/null_check.test.ts index 7a0bad2dd5..077831d3d8 100644 --- a/packages/vquery/tests/examples/where/null_check.test.ts +++ b/packages/vquery/tests/examples/where/null_check.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './null_check.json' describe('Where with IS NULL / IS NOT NULL', () => { @@ -17,7 +17,7 @@ describe('Where with IS NULL / IS NOT NULL', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "id", "name", "age", "gender" from "where-null-check" where (("age" >= 18 and "gender" is null) or ("age" < 18 and "gender" is not null))"`, diff --git a/packages/vquery/tests/examples/where/single_value_in.test.ts b/packages/vquery/tests/examples/where/single_value_in.test.ts index af3d5f0927..a21e9aa3bc 100644 --- a/packages/vquery/tests/examples/where/single_value_in.test.ts +++ b/packages/vquery/tests/examples/where/single_value_in.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './single_value_in.json' describe('Where with Single Value IN / NOT IN', () => { @@ -17,7 +17,7 @@ describe('Where with Single Value IN / NOT IN', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( `"select "id", "name", "age", "gender" from "where-single-value-in" where ("gender" in ('male') or not "gender" in ('female'))"`, diff --git a/packages/vquery/tests/examples/where/timestamp_window.test.ts b/packages/vquery/tests/examples/where/timestamp_window.test.ts index 3724520596..f3a4685bc0 100644 --- a/packages/vquery/tests/examples/where/timestamp_window.test.ts +++ b/packages/vquery/tests/examples/where/timestamp_window.test.ts @@ -1,5 +1,5 @@ import type { DatasetColumn, VQueryDSL } from '@visactor/vquery' -import { convertDSLToSQL, VQuery } from '@visactor/vquery' +import { convertDSLToDuckDB, VQuery } from '@visactor/vquery' import vqueryConfig from './timestamp_window.json' describe('Where with TIMESTAMP comparison window', () => { @@ -17,10 +17,10 @@ describe('Where with TIMESTAMP comparison window', () => { const dataset = await vquery.connectDataset(datasetId) - const sql = convertDSLToSQL(vqueryDSL as VQueryDSL>, datasetId) + const sql = convertDSLToDuckDB(vqueryDSL as VQueryDSL>, datasetId) expect(sql).toMatchInlineSnapshot( - `"select "id", "event", "amount", strftime(CAST("created_at" AS TIMESTAMP), '%Y-%m-%d %H:%M') as "created_minute" from "where-timestamp-window" where ("created_at" >= '2024-01-15 12:00:00' and "created_at" < '2024-02-01 00:00:00') order by "created_minute" asc"`, + `"select "id", "event", "amount", strftime(CAST("created_at" AS TIMESTAMP), '%Y-%m-%d %H:%M') as "created_minute" from "where-timestamp-window" where ("created_at" >= '2024-01-15 12:00:00' and "created_at" < '2024-02-01 00:00:00') order by "created_minute" asc nulls last"`, ) const queryResult = await dataset.query(vqueryDSL as VQueryDSL>) diff --git a/packages/vquery/tests/unit/sql-builder/builders/groupBy.test.ts b/packages/vquery/tests/unit/sql-builder/builders/groupBy.test.ts index 8190078c0c..b84bf20a10 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/groupBy.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/groupBy.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('groupBy', () => { it('simple', () => { @@ -10,7 +10,7 @@ describe('groupBy', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id', 'department'], limit: 100, diff --git a/packages/vquery/tests/unit/sql-builder/builders/having.test.ts b/packages/vquery/tests/unit/sql-builder/builders/having.test.ts index 44ae7f411b..37358e061a 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/having.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/having.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('having', () => { it('empty', () => { @@ -8,7 +8,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'sum' }, alias: 'TOTAL_AGE' }], groupBy: ['department'], @@ -28,7 +28,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ 'department', @@ -54,7 +54,7 @@ describe('having', () => { ) expect(sql).toMatchInlineSnapshot( - `"select "department", sum("age") as "SUM_AGE", avg("age") as "AVG_AGE", CAST(count("id") AS INTEGER) as "CNT", min("age") as "MIN_AGE", max("age") as "MAX_AGE" from "orders" group by "department" having (sum("age") = 100 and avg("age") = 20 and count("id") = 2 and min("age") = 10 and max("age") = 80)"`, + `"select "department", sum("age") as "SUM_AGE", avg("age") as "AVG_AGE", count("id") as "CNT", min("age") as "MIN_AGE", max("age") as "MAX_AGE" from "orders" group by "department" having (sum("age") = 100 and avg("age") = 20 and count("id") = 2 and min("age") = 10 and max("age") = 80)"`, ) }) @@ -65,7 +65,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ 'department', @@ -89,7 +89,7 @@ describe('having', () => { ) expect(sql).toMatchInlineSnapshot( - `"select "department", CAST(count(distinct "id") AS INTEGER) as "DISTINCT_ID", var_samp("age") as "VAR_AGE", var_pop("age") as "VAR_POP_AGE", quantile("age", 0.9) as "Q90_AGE" from "orders" group by "department" having (count(distinct "id") > 1 and var_samp("age") >= 2 and var_pop("age") >= 1 and quantile("age", 0.5) > 20)"`, + `"select "department", count(distinct "id") as "DISTINCT_ID", var_samp("age") as "VAR_AGE", var_pop("age") as "VAR_POP_AGE", quantile("age", CAST(0.9 AS DOUBLE)) as "Q90_AGE" from "orders" group by "department" having (count(distinct "id") > 1 and var_samp("age") >= 2 and var_pop("age") >= 1 and quantile("age", CAST(0.5 AS DOUBLE)) > 20)"`, ) }) @@ -101,7 +101,7 @@ describe('having', () => { province: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ { field: 'province', alias: 'province', aggr: { func: 'count_distinct' } }, @@ -119,7 +119,7 @@ describe('having', () => { ) expect(sql).toMatchInlineSnapshot( - `"select CAST(count(distinct "province") AS INTEGER) as "province", sum("profit") as "profit", "area" as "area" from "orders" group by "area" having (sum("sales") > 5) limit 1000"`, + `"select count(distinct "province") as "province", sum("profit") as "profit", "area" as "area" from "orders" group by "area" having (sum("sales") > 5) limit 1000"`, ) }) @@ -130,7 +130,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'avg' }, alias: 'AVG_AGE' }], groupBy: ['department'], @@ -163,7 +163,7 @@ describe('having', () => { department: string | null } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'sum' }, alias: 'TOTAL_AGE' }], groupBy: ['department'], @@ -190,7 +190,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'avg' }, alias: 'AVG_AGE' }], groupBy: ['department'], @@ -217,7 +217,7 @@ describe('having', () => { department: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'sum' }, alias: 'TOTAL_AGE' }], groupBy: ['department'], @@ -244,7 +244,7 @@ describe('having', () => { } expect(() => - convertDSLToSQL( + convertDSLToDuckDB( { select: ['department', { field: 'age', aggr: { func: 'sum' }, alias: 'TOTAL_AGE' }], groupBy: ['department'], diff --git a/packages/vquery/tests/unit/sql-builder/builders/limit.test.ts b/packages/vquery/tests/unit/sql-builder/builders/limit.test.ts index 32711505b0..25eb73b554 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/limit.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/limit.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('limit', () => { it('simple', () => { @@ -10,7 +10,7 @@ describe('limit', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], limit: 100, diff --git a/packages/vquery/tests/unit/sql-builder/builders/orderBy.test.ts b/packages/vquery/tests/unit/sql-builder/builders/orderBy.test.ts index 0ca1809554..f79707091e 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/orderBy.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/orderBy.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('orderBy', () => { it('desc', () => { @@ -10,7 +10,7 @@ describe('orderBy', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], orderBy: [ @@ -23,7 +23,7 @@ describe('orderBy', () => { }, 'orders', ) - expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" desc limit 100"`) + expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" desc nulls last limit 100"`) }) it('asc', () => { @@ -35,7 +35,7 @@ describe('orderBy', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], orderBy: [ @@ -48,14 +48,14 @@ describe('orderBy', () => { }, 'orders', ) - expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" asc limit 100"`) + expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" asc nulls last limit 100"`) }) it('order defaults to asc when omitted', () => { interface USER { id: number } - const sql = convertDSLToSQL({ select: ['id'], orderBy: [{ field: 'id' }] }, 'orders') - expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" asc"`) + const sql = convertDSLToDuckDB({ select: ['id'], orderBy: [{ field: 'id' }] }, 'orders') + expect(sql).toMatchInlineSnapshot(`"select "id" from "orders" order by "id" asc nulls last"`) }) }) diff --git a/packages/vquery/tests/unit/sql-builder/builders/select.test.ts b/packages/vquery/tests/unit/sql-builder/builders/select.test.ts index 286ea13973..3ede0dfded 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/select.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/select.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('select', () => { it('simple', () => { @@ -10,7 +10,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], }, @@ -25,7 +25,7 @@ describe('select', () => { profit: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ { @@ -57,7 +57,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ 'department', @@ -79,7 +79,7 @@ describe('select', () => { 'orders', ) expect(sql).toMatchInlineSnapshot( - `"select "department", "name", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc"`, + `"select "department", "name", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc nulls last"`, ) }) @@ -92,7 +92,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ 'department', @@ -117,7 +117,7 @@ describe('select', () => { 'orders', ) expect(sql).toMatchInlineSnapshot( - `"select "department", "name" as "NAME", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc"`, + `"select "department", "name" as "NAME", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc nulls last"`, ) }) @@ -130,7 +130,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ { @@ -157,7 +157,7 @@ describe('select', () => { 'orders', ) expect(sql).toMatchInlineSnapshot( - `"select "department" as "department", "name" as "NAME", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc"`, + `"select "department" as "department", "name" as "NAME", avg("age") as "AGE" from "orders" group by "department", "name" order by "age" desc nulls last"`, ) }) @@ -170,7 +170,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [ { field: 'age', aggr: { func: 'sum' }, alias: 'SUM' }, @@ -182,7 +182,7 @@ describe('select', () => { 'orders', ) expect(sql).toMatchInlineSnapshot( - `"select sum("age") as "SUM", min("age") as "MIN", max("age") as "MAX", CAST(count("id") AS INTEGER) as "CNT" from "orders""`, + `"select sum("age") as "SUM", min("age") as "MIN", max("age") as "MAX", count("id") as "CNT" from "orders""`, ) }) @@ -195,7 +195,7 @@ describe('select', () => { active: number } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: [], groupBy: ['department', 'name'], @@ -208,7 +208,9 @@ describe('select', () => { }, 'orders', ) - expect(sql).toMatchInlineSnapshot(`"select * from "orders" group by "department", "name" order by "age" desc"`) + expect(sql).toMatchInlineSnapshot( + `"select * from "orders" group by "department", "name" order by "age" desc nulls last"`, + ) }) it('aggregate without alias falls back to field name', () => { @@ -216,7 +218,7 @@ describe('select', () => { id: number age: number } - const sql = convertDSLToSQL({ select: [{ field: 'age', aggr: { func: 'avg' } }] }, 'orders') + const sql = convertDSLToDuckDB({ select: [{ field: 'age', aggr: { func: 'avg' } }] }, 'orders') expect(sql).toMatchInlineSnapshot(`"select avg("age") as "age" from "orders""`) }) @@ -225,7 +227,10 @@ describe('select', () => { value: number } - const sql = convertDSLToSQL({ select: [{ field: 'value', aggr: { func: 'quantile' } }] }, 'orders') - expect(sql).toMatchInlineSnapshot(`"select quantile("value", 0.5) as "value" from "orders""`) + const sql = convertDSLToDuckDB( + { select: [{ field: 'value', aggr: { func: 'quantile' } }] }, + 'orders', + ) + expect(sql).toMatchInlineSnapshot(`"select quantile("value", CAST(0.5 AS DOUBLE)) as "value" from "orders""`) }) }) diff --git a/packages/vquery/tests/unit/sql-builder/builders/where.test.ts b/packages/vquery/tests/unit/sql-builder/builders/where.test.ts index c7ff74bc2c..53294c8aa0 100644 --- a/packages/vquery/tests/unit/sql-builder/builders/where.test.ts +++ b/packages/vquery/tests/unit/sql-builder/builders/where.test.ts @@ -1,4 +1,4 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' describe('where', () => { it('simple', () => { @@ -11,7 +11,7 @@ describe('where', () => { gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -67,7 +67,7 @@ describe('where', () => { gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], }, @@ -86,7 +86,7 @@ describe('where', () => { gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -140,7 +140,7 @@ describe('where', () => { gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -196,7 +196,7 @@ describe('where', () => { gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -247,7 +247,7 @@ describe('where', () => { id: number gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { op: 'and', conditions: [{ field: 'gender', op: 'in', value: 'male' }] } }, 'orders', ) @@ -259,7 +259,7 @@ describe('where', () => { id: number gender: 'male' | 'female' } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { op: 'and', conditions: [{ field: 'gender', op: 'not in', value: 'female' }] } }, 'orders', ) @@ -272,7 +272,7 @@ describe('where', () => { order_date: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -310,7 +310,7 @@ describe('where', () => { order_date: string } - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -341,7 +341,7 @@ describe('where', () => { const createdAt = new Date('2024-01-01T00:00:00.000Z') const updatedAt = new Date('2024-02-01T12:30:00.000Z') - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -364,7 +364,7 @@ describe('where', () => { ) expect(sql).toBe( - `select "id" from "orders" where ("created_at" >= '${createdAt.toString()}' and "updated_at" <= '${updatedAt.toString()}')`, + `select "id" from "orders" where ("created_at" >= '${createdAt.toISOString().slice(0, 23).replace('T', ' ')}' and "updated_at" <= '${updatedAt.toISOString().slice(0, 23).replace('T', ' ')}')`, ) }) @@ -376,7 +376,7 @@ describe('where', () => { const start = new Date('2024-01-01T00:00:00.000Z') const end = new Date('2024-01-31T23:59:59.000Z') - const sql = convertDSLToSQL( + const sql = convertDSLToDuckDB( { select: ['id'], where: { @@ -394,7 +394,7 @@ describe('where', () => { ) expect(sql).toBe( - `select "id" from "orders" where ("created_at" between '${start.toString()}' and '${end.toString()}')`, + `select "id" from "orders" where ("created_at" between '${start.toISOString().slice(0, 23).replace('T', ' ')}' and '${end.toISOString().slice(0, 23).replace('T', ' ')}')`, ) }) }) diff --git a/packages/vquery/tests/unit/sql-builder/compile/dialect.introspector.test.ts b/packages/vquery/tests/unit/sql-builder/compile/dialect.introspector.test.ts index aa5c606354..e5923bf5d8 100644 --- a/packages/vquery/tests/unit/sql-builder/compile/dialect.introspector.test.ts +++ b/packages/vquery/tests/unit/sql-builder/compile/dialect.introspector.test.ts @@ -1,19 +1,17 @@ -import { PostgresDialect } from '../../../../src/sql-builder/dialect/postgresDialect' +import { mysqlStrategy, duckdbStrategy } from '../../../../src/sql-builder/dialect' import { Kysely } from 'kysely' -describe('postgres dialect introspector', () => { - it('introspector methods return empty', async () => { - const dialect = new PostgresDialect() +for (const [name, strategy] of Object.entries({ mysql: mysqlStrategy, duckdb: duckdbStrategy })) { + it(`${name} compiles without a database driver or live schema`, async () => { + const { dialect } = strategy const db = new Kysely<{ t: { id: number } }>({ dialect }) const introspector = dialect.createIntrospector(db) - const schemas = await introspector.getSchemas() - const tables = await introspector.getTables() - const meta = await introspector.getMetadata() - expect(Array.isArray(schemas)).toBe(true) - expect(schemas.length).toBe(0) - expect(Array.isArray(tables)).toBe(true) - expect(tables.length).toBe(0) - expect(Array.isArray(meta.tables)).toBe(true) - expect(meta.tables.length).toBe(0) + expect(await introspector.getSchemas()).toEqual([]) + expect(await introspector.getTables()).toEqual([]) + expect(await introspector.getMetadata()).toEqual({ tables: [] }) + expect(dialect.createDriver()).toBeDefined() + expect(dialect.createQueryCompiler()).toBeDefined() + expect(dialect.createAdapter()).toBeDefined() + await db.destroy() }) -}) +} diff --git a/packages/vquery/tests/unit/sql-builder/compileQuery.test.ts b/packages/vquery/tests/unit/sql-builder/compileQuery.test.ts new file mode 100644 index 0000000000..b378f99193 --- /dev/null +++ b/packages/vquery/tests/unit/sql-builder/compileQuery.test.ts @@ -0,0 +1,195 @@ +import { compileQuery, convertDSLToMysql, convertDSLToDuckDB, VQuery } from '@visactor/vquery' +import type { VQueryDSL } from '@visactor/vquery' + +const invalid: unknown[] = [ + null, + [], + {}, + { select: 'id' }, + { select: [''] }, + { select: [null] }, + { select: [{ field: '' }] }, + { select: [{ field: 'id', alias: 1 }] }, + { select: ['id'], sql: 'DROP TABLE orders' }, + ...[ + null, + { func: 'sleep' }, + { func: 'sum', evil: true }, + { func: 'sum', quantile: 0.5 }, + { func: 'quantile', quantile: '0.5' }, + { func: 'quantile', quantile: Infinity }, + { func: 'quantile', quantile: -2 }, + { func: 'quantile', quantile: 2 }, + ].map((aggr) => ({ select: [{ field: 'id', aggr }] })), + ...[ + null, + { op: 'xor', conditions: [] }, + { op: 'and', conditions: {} }, + { field: '' }, + { field: 'id', op: 1 }, + { field: 'id', op: 'sleep' }, + { field: 'id', op: '=', value: {} }, + { field: 'id', op: '=', value: Infinity }, + { field: 'id', op: 'in', value: [] }, + { field: 'id', op: 'in', value: [1, {}] }, + { field: 'id', op: 'in', value: {} }, + { field: 'id', op: 'between', value: 1 }, + { field: 'id', op: 'between', value: [1] }, + { field: 'id', op: 'between', value: [1, {}] }, + ].map((where) => ({ select: ['id'], where })), + ...[null, { field: 'id', op: '=', value: 1 }, { field: 'id', op: '=', value: 1, aggr: { func: 'to_year' } }].map( + (having) => ({ select: ['id'], having }), + ), + ...['id', [null], ['']].map((groupBy) => ({ select: ['id'], groupBy })), + ...['id', [null], [{ field: '' }], [{ field: 'id', order: 'evil' }]].map((orderBy) => ({ + select: ['id'], + orderBy, + })), + ...[-1, 1.5, Infinity, '1;DROP'].map((limit) => ({ select: ['id'], limit })), +] + +const compile = (dsl: unknown, dialect: 'mysql' | 'duckdb' = 'mysql') => + compileQuery(dsl as VQueryDSL, { table: 'orders', dialect }) + +it('defaults to parameterized MySQL, quotes qualified tables, and preserves parameter order', () => { + const dsl: VQueryDSL = { + select: [{ field: 'sales', alias: 'total', aggr: { func: 'sum' } }], + where: { op: 'and', conditions: [{ field: 'province', op: '=', value: "x\\' OR 1=1; -- ? $1" }] }, + groupBy: ['province'], + having: { op: 'and', conditions: [{ field: 'sales', aggr: { func: 'sum' }, op: '>', value: 10 }] }, + orderBy: [{ field: 'total', order: 'desc' }], + limit: 8, + } + const result = compileQuery(dsl, { table: { database: 'local_data', name: 'supermarket' } }) + expect(result.sql).toBe( + 'select sum(`sales`) as `total` from `local_data`.`supermarket` where (`province` = convert(? using utf8mb4) collate utf8mb4_0900_bin) group by `province` having (sum(`sales`) > ?) order by `total` is null asc, `total` desc limit 8', + ) + expect(result.parameters).toEqual(["x\\' OR 1=1; -- ? $1", 10]) + expect(result.sql).not.toContain('OR 1=1') + expect(compile({ select: ['id'], limit: 0 })).toEqual({ sql: 'select `id` from `orders` limit 0', parameters: [] }) + expect(() => compileQuery(dsl, { table: 'orders', dialect: 'postgres' as never })).toThrow( + 'Unsupported query dialect', + ) +}) + +it('uses distinct date/aggregate expressions for each backend in SELECT and HAVING', () => { + for (const func of ['to_year', 'to_quarter', 'to_month', 'to_week', 'to_day', 'to_hour', 'to_minute', 'to_second']) { + const dsl = { select: [{ field: 'date', alias: 'bucket', aggr: { func } }], groupBy: ['bucket'] } + expect(compile(dsl).sql).toContain(func === 'to_quarter' ? 'quarter(' : 'date_format(') + expect(compile(dsl, 'duckdb').sql).toContain(func === 'to_quarter' ? 'date_part(' : 'strftime(') + } + expect(compile({ select: [{ field: 'date', aggr: { func: 'to_minute' } }] }).parameters).toEqual(['%Y-%m-%d %H:%i']) + for (const func of ['count', 'count_distinct', 'variance', 'variance_pop', 'stddev', 'sum', 'avg', 'min', 'max']) { + const dsl = { + select: [{ field: 'sales', aggr: { func } }], + having: { field: 'sales', aggr: { func }, op: '>', value: 1 }, + } + const mysql = compile(dsl) + expect(mysql.sql).not.toContain('AS INTEGER') + expect(mysql.parameters).toEqual([1]) + expect(compile(dsl, 'duckdb').parameters).toEqual([1]) + } + expect(compile({ select: [{ field: 'sales', aggr: { func: 'stddev' } }] }).sql).toContain('stddev_samp(') + for (const func of ['median', 'quantile']) { + expect(compile({ select: [{ field: 'sales', aggr: { func } }] }).sql).toContain('row_number() over') + expect(compile({ select: [{ field: 'sales', aggr: { func } }] }, 'duckdb').sql).toContain(`${func}(`) + expect(compile({ select: ['sales'], having: { field: 'sales', aggr: { func }, op: '>', value: 1 } }).sql).toContain( + 'row_number() over', + ) + } + expect( + compile({ select: [{ field: 'sales', aggr: { func: 'quantile', quantile: 0.9 } }] }, 'duckdb').parameters, + ).toEqual([0.9]) +}) + +it('adapts insensitive matches and empty boolean groups to both dialects', () => { + for (const dialect of ['mysql', 'duckdb'] as const) { + for (const op of ['ilike', 'not ilike']) { + const result = compile({ select: ['name'], where: { field: 'name', op, value: 'Ab%' } }, dialect) + expect(result.sql).toContain(dialect === 'mysql' ? 'lower(convert(' : op) + expect(result.parameters).toEqual(['Ab%']) + } + for (const clause of ['where', 'having']) { + for (const op of ['and', 'or']) { + expect(compile({ select: ['id'], [clause]: { op, conditions: [] } }, dialect).sql).toContain( + op === 'and' ? '1=1' : '0=1', + ) + } + } + } +}) + +it('renders explicit dialect SQL without replacing placeholders inside identifiers or bound values', () => { + const dsl: VQueryDSL = { + select: [{ field: 'name', alias: '? $1' }], + where: { + op: 'and', + conditions: [ + { field: 'name', op: '=', value: "O'Reilly ? $1\\path" }, + { field: 'active', op: '=', value: true }, + ], + }, + limit: 2, + } + expect(convertDSLToMysql(dsl, 'orders')).toBe( + "select `name` as `? $1` from `orders` where (`name` = convert('O''Reilly ? $1\\\\path' using utf8mb4) collate utf8mb4_0900_bin and `active` = TRUE) limit 2", + ) + expect(convertDSLToDuckDB(dsl, 'orders')).toBe( + 'select "name" as "? $1" from "orders" where ("name" = \'O\'\'Reilly ? $1\\path\' and "active" = TRUE) limit 2', + ) +}) + +it('rejects malformed JSON before producing SQL', () => { + for (const dsl of invalid) expect(() => compile(dsl)).toThrow() + expect(compile({ select: ['id'], where: { field: 'id', op: 'in', value: null } }).parameters).toEqual([null]) + expect(compile({ select: ['id'], where: { field: 'id', op: 'in', value: true } }).parameters).toEqual([true]) +}) + +it('retains DuckDB date, median and quantile behavior for in-memory datasets', async () => { + const vquery = new VQuery() + await vquery.createDataset( + 'orders', + [ + { name: 'date', type: 'string' }, + { name: 'sales', type: 'number' }, + ], + { + type: 'json', + rawDataset: [ + { date: '2026-10-13 12:34:56', sales: 3 }, + { date: '2026-10-13 15:00:00', sales: 9 }, + ], + }, + ) + const dataset = await vquery.connectDataset('orders') + const result = await dataset.query({ + select: [ + { field: 'date', alias: 'day', aggr: { func: 'to_day' } }, + { field: 'sales', alias: 'median', aggr: { func: 'median' } }, + { field: 'sales', alias: 'quantile', aggr: { func: 'quantile' } }, + ], + groupBy: ['day'], + }) + expect(result.dataset).toEqual([{ day: '2026-10-13', median: 6, quantile: 3 }]) + await vquery.close() +}) + +it('preserves VBI comparison aliases and HAVING lists', () => { + for (const op of ['gt', 'gte', 'lt', 'lte', 'eq', 'neq']) { + expect( + compile({ + select: ['sales'], + where: { field: 'sales', op, value: 1 }, + having: { field: 'sales', aggr: { func: 'sum' }, op, value: 2 }, + }).parameters, + ).toEqual([1, 2]) + } + for (const op of ['in', 'not in']) { + expect( + compile({ select: ['sales'], having: { field: 'sales', aggr: { func: 'sum' }, op, value: [1, 2] } }).parameters, + ).toEqual([1, 2]) + } + expect(() => + compile({ select: ['id'], having: { field: 'id', aggr: { func: 'count' }, op: 'ilike', value: '%' } }), + ).toThrow('Unsupported filter operator') +}) diff --git a/packages/vquery/tests/unit/sql-builder/dialectParity.test.ts b/packages/vquery/tests/unit/sql-builder/dialectParity.test.ts new file mode 100644 index 0000000000..70edfaf003 --- /dev/null +++ b/packages/vquery/tests/unit/sql-builder/dialectParity.test.ts @@ -0,0 +1,176 @@ +import { compileQuery, convertDSLToMysql, convertDSLToDuckDB } from '@visactor/vquery' +import type { VQueryDSL, DatasetColumn } from '@visactor/vquery' + +const columns: DatasetColumn[] = [ + { name: 'category', type: 'string' }, + { name: 'value', type: 'number' }, + { name: 'date', type: 'datetime' }, +] +const compile = (dsl: unknown, dialect: 'mysql' | 'duckdb' = 'mysql', schema = columns) => + compileQuery(dsl as VQueryDSL, { table: 'orders', dialect, columns: schema }) + +it('normalizes source text collations without coercing numeric or temporal columns', () => { + const dsl = { + select: ['category', { field: 'value', alias: 'total', aggr: { func: 'sum' } }], + groupBy: ['category'], + orderBy: [{ field: 'total', order: 'desc' }], + } + expect(compile(dsl).sql).toContain('convert(`category` using utf8mb4) collate utf8mb4_0900_bin as `category`') + expect(compile(dsl).sql).toContain('`value` as `value`') + expect(compile(dsl, 'duckdb').sql).toContain('"category" collate "binary" as "category"') + expect(convertDSLToMysql(dsl as VQueryDSL, 'orders', { columns })).toContain('utf8mb4_0900_bin') + expect(convertDSLToDuckDB(dsl as VQueryDSL, 'orders', { columns })).toContain('collate "binary"') +}) + +it('ranks each statistical field within its logical groups and preserves WHERE/HAVING/limit', () => { + const dsl = { + select: [ + 'category', + { field: 'value', alias: 'median', aggr: { func: 'median' } }, + { field: 'value', alias: 'q', aggr: { func: 'quantile', quantile: -0.5 } }, + { field: 'value', alias: 'sum', aggr: { func: 'sum' } }, + ], + where: { op: 'and', conditions: [{ field: 'value', op: '>=', value: 1 }] }, + groupBy: ['category'], + having: { op: 'and', conditions: [{ field: 'value', aggr: { func: 'quantile' }, op: '>', value: 2 }] }, + orderBy: [{ field: 'median', order: 'desc' }], + limit: 2, + } + const result = compile(dsl) + expect(result.sql).toContain('row_number() over (partition by `category` order by `value` is null, `value`)') + expect(result.sql.match(/row_number\(\)/g)).toHaveLength(1) + expect(result.sql).toContain('avg(case when') + expect(result.sql).toContain('max(case when') + expect(result.sql).toContain('having (max(case when') + expect(result.sql).toContain('limit 2') + expect(result.parameters).toEqual([0.5, 1, 0.5, 2]) +}) + +it('handles unprojected grouping/sort keys and nested HAVING-only statistics', () => { + const result = compile({ + select: [{ field: 'value', alias: 'result', aggr: { func: 'median' } }], + groupBy: ['category'], + orderBy: [{ field: 'category' }], + having: { + op: 'or', + conditions: [{ op: 'and', conditions: [{ field: 'value', aggr: { func: 'median' }, op: '>', value: 1 }] }], + }, + }) + expect(result.sql).toContain('partition by `category`') + expect(result.sql).toContain('having ((avg(case when') + const date = compile({ + select: [ + { field: 'date', alias: 'day', aggr: { func: 'to_day' } }, + { field: 'value', aggr: { func: 'median' } }, + ], + groupBy: ['day'], + }) + expect(date.sql).toContain('partition by date_format(`date`, ?)') + const collision = compile({ + select: [ + { field: 'value', alias: 'category', aggr: { func: 'sum' } }, + { field: 'value', aggr: { func: 'median' } }, + ], + groupBy: ['category'], + }) + expect(collision.sql).toContain('partition by `category`') + expect(() => + compile({ select: [{ field: 'value', alias: 'median', aggr: { func: 'median' } }], groupBy: ['median'] }), + ).toThrow('Statistical aggregates cannot be used as grouping keys') +}) + +it('avoids internal name collisions and supports every quantile direction/boundary', () => { + for (const quantile of [-1, -0.5, 0, 0.5, 1]) { + const result = compile({ + select: [{ field: 'value', alias: '__vquery_stat_0', aggr: { func: 'quantile', quantile } }], + }) + expect(result.sql).toContain('as `__vquery_stat_1`') + expect(result.parameters).toEqual([Math.abs(quantile)]) + } + expect(compile({ select: [{ field: 'value', aggr: { func: 'quantile' } }] }).parameters).toEqual([0.5]) +}) + +it('validates portable numeric aggregate types identically for both engines', () => { + for (const dialect of ['mysql', 'duckdb'] as const) { + for (const func of ['sum', 'avg', 'variance', 'variance_pop', 'stddev', 'median', 'quantile']) { + expect(() => compile({ select: [{ field: 'category', aggr: { func } }] }, dialect)).toThrow( + 'requires a number column', + ) + expect(() => + compile({ select: ['category'], having: { field: 'category', aggr: { func }, op: '>', value: 1 } }, dialect), + ).toThrow('requires a number column') + } + expect(() => compile({ select: ['value'], orderBy: [{ field: 'value', nulls: 'random' }] }, dialect)).toThrow( + 'Invalid orderBy', + ) + for (const order of ['asc', 'desc']) + for (const nulls of ['first', 'last']) { + const result = compile({ select: ['value'], orderBy: [{ field: 'value', order, nulls }] }, dialect) + expect(result.sql).toContain( + dialect === 'mysql' ? `is null ${nulls === 'last' ? 'asc' : 'desc'}` : `nulls ${nulls}`, + ) + } + } +}) + +it('quotes exact string values and fixes LIKE escape semantics in both dialects', () => { + for (const dialect of ['mysql', 'duckdb'] as const) { + for (const op of ['like', 'not like', 'ilike', 'not ilike']) { + const result = compile({ select: ['category'], where: { field: 'category', op, value: 'a\\_b' } }, dialect) + expect(result.sql).toContain("escape ''") + expect(result.parameters).toEqual(['a\\_b']) + for (const value of [1, false]) + expect(() => compile({ select: ['category'], where: { field: 'category', op, value } }, dialect)).toThrow( + 'LIKE requires a string pattern', + ) + } + expect( + compile({ select: ['category'], where: { field: 'category', op: 'like', value: null } }, dialect).parameters, + ).toEqual([null]) + expect(() => compile({ select: ['value'], where: { field: 'value', op: 'like', value: '%' } }, dialect)).toThrow( + 'LIKE requires a string column', + ) + const date = new Date('2026-10-13T01:02:03.004Z') + expect(compile({ select: ['date'], where: { field: 'date', op: '=', value: date } }, dialect).parameters).toEqual([ + '2026-10-13 01:02:03.004', + ]) + } + expect(compile({ select: [{ field: 'value', aggr: { func: 'count' } }] }, 'duckdb').sql).not.toContain('AS INTEGER') +}) + +it('rejects mixed comparison types before native implicit conversions diverge', () => { + for (const dialect of ['mysql', 'duckdb'] as const) { + for (const [field, value] of [ + ['value', '2'], + ['category', 2], + ['date', 2], + ]) { + expect(() => compile({ select: [field], where: { field, op: '=', value } }, dialect)).toThrow( + 'Filter value does not match', + ) + } + expect( + compile({ select: ['value'], where: { field: 'value', op: 'in', value: [1, null] } }, dialect).parameters, + ).toEqual([1, null]) + expect( + compile( + { select: ['category'], having: { field: 'category', aggr: { func: 'count' }, op: '>', value: 1 } }, + dialect, + ).parameters, + ).toEqual([1]) + expect( + compile( + { select: ['category'], having: { field: 'category', aggr: { func: 'min' }, op: '=', value: 'A' } }, + dialect, + ).parameters, + ).toEqual(['A']) + expect( + compile({ select: ['category'], having: { field: 'category', aggr: { func: 'max' }, op: 'is null' } }, dialect) + .parameters, + ).toEqual([]) + expect( + compile({ select: ['date'], where: { field: 'date', op: '>=', value: '2026-01-01' } }, dialect).parameters, + ).toEqual(['2026-01-01']) + expect(compile({ select: ['date'], where: { field: 'date', op: 'is null' } }, dialect).parameters).toEqual([]) + } +}) diff --git a/packages/vquery/tests/unit/sql-builder/index-export.test.ts b/packages/vquery/tests/unit/sql-builder/index-export.test.ts index b6280a013f..0e3522556d 100644 --- a/packages/vquery/tests/unit/sql-builder/index-export.test.ts +++ b/packages/vquery/tests/unit/sql-builder/index-export.test.ts @@ -1,7 +1,7 @@ import * as convert from '../../../src/sql-builder' describe('convert index export', () => { - it('has convertDSLToSQL function', () => { - expect(typeof convert.convertDSLToSQL).toBe('function') + it('has convertDSLToDuckDB function', () => { + expect(typeof convert.convertDSLToDuckDB).toBe('function') }) }) diff --git a/packages/vquery/tests/unit/sql-builder/utils/dialect.test.ts b/packages/vquery/tests/unit/sql-builder/utils/dialect.test.ts deleted file mode 100644 index 0bfb2708a1..0000000000 --- a/packages/vquery/tests/unit/sql-builder/utils/dialect.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { PostgresDialect } from '../../../../src/sql-builder/dialect/postgresDialect' -import { Kysely } from 'kysely' - -describe('kysely dialect coverage', () => { - it('createIntrospector executes', async () => { - const dialect = new PostgresDialect() - const db = new Kysely<{ t: { id: number } }>({ dialect }) - const introspector = dialect.createIntrospector(db) - expect(introspector).toBeDefined() - }) - it('driver/compiler/adapter are creatable', () => { - const dialect = new PostgresDialect() - const driver = dialect.createDriver() - const compiler = dialect.createQueryCompiler() - const adapter = dialect.createAdapter() - expect(driver).toBeDefined() - expect(compiler).toBeDefined() - expect(adapter).toBeDefined() - }) -}) diff --git a/packages/vquery/tests/unit/sql-builder/utils/escape.test.ts b/packages/vquery/tests/unit/sql-builder/utils/escape.test.ts index a3c588befa..ffebfb7603 100644 --- a/packages/vquery/tests/unit/sql-builder/utils/escape.test.ts +++ b/packages/vquery/tests/unit/sql-builder/utils/escape.test.ts @@ -1,29 +1,16 @@ -import { convertDSLToSQL } from '@visactor/vquery' +import { convertDSLToDuckDB } from '@visactor/vquery' -describe('escapeValue paths', () => { - it('boolean and object values', () => { - interface T { - id: number - flag: boolean - meta: Record - } - - const sql = convertDSLToSQL( - { - select: ['id'], - where: { - op: 'and', - conditions: [ - { field: 'flag', op: '=', value: true }, - { field: 'meta', op: '=', value: { a: 1 } }, - ], - }, - }, +it('renders booleans and rejects object filter values', () => { + expect( + convertDSLToDuckDB( + { select: ['id'], where: { op: 'and', conditions: [{ field: 'flag', op: '=', value: true }] } }, 'orders', - ) - - expect(sql).toMatchInlineSnapshot( - `"select "id" from "orders" where ("flag" = TRUE and "meta" = '[object Object]')"`, - ) - }) + ), + ).toBe('select "id" from "orders" where ("flag" = TRUE)') + expect(() => + convertDSLToDuckDB( + { select: ['id'], where: { op: 'and', conditions: [{ field: 'meta', op: '=', value: { a: 1 } }] } }, + 'orders', + ), + ).toThrow('Invalid filter value') }) diff --git a/packages/vquery/tests/unit/sql-engine/predicateSemantics.test.ts b/packages/vquery/tests/unit/sql-engine/predicateSemantics.test.ts new file mode 100644 index 0000000000..3393c3cb18 --- /dev/null +++ b/packages/vquery/tests/unit/sql-engine/predicateSemantics.test.ts @@ -0,0 +1,61 @@ +import { executeSQL, parseSQL } from '../../../src/query-engine/sql' + +it('preserves null predicates and three-valued boolean logic', () => { + const rows = [{ value: null }, { value: 3 }] + expect(executeSQL(parseSQL('select * from orders where value is null'), rows)).toEqual([{ value: null }]) + expect(executeSQL(parseSQL('select * from orders where value is not null'), rows)).toEqual([{ value: 3 }]) + expect(executeSQL(parseSQL('select * from orders where null = 1 and 1 = 1'), rows)).toEqual([]) + expect(executeSQL(parseSQL('select * from orders where null = 1 or 1 = 0'), rows)).toEqual([]) +}) + +it('computes extrema regardless of input ordering', () => { + expect( + executeSQL(parseSQL('select min(value) as minimum, max(value) as maximum from orders'), [ + { value: 3 }, + { value: 9 }, + { value: 1 }, + ]), + ).toEqual([{ minimum: 1, maximum: 9 }]) +}) + +it('keeps explicit and default NULL ordering independent of sort direction', () => { + const rows = [{ value: null }, { value: 2 }, { value: 1 }] + for (const direction of ['asc', 'desc']) { + const sorted = direction === 'asc' ? [{ value: 1 }, { value: 2 }] : [{ value: 2 }, { value: 1 }] + for (const suffix of ['', ' nulls last']) + expect(executeSQL(parseSQL(`select * from orders order by value ${direction}${suffix}`), rows)).toEqual([ + ...sorted, + { value: null }, + ]) + expect(executeSQL(parseSQL(`select * from orders order by value ${direction} nulls first`), rows)).toEqual([ + { value: null }, + ...sorted, + ]) + } + expect(() => parseSQL('select * from orders order by value nulls random')).toThrow('Expected last') +}) + +it('uses literal backslashes for DSL LIKE patterns', () => { + const rows = [{ label: 'a\\_b' }, { label: 'a_b' }] + expect(executeSQL(parseSQL("select * from orders where label like 'a\\_b' escape ''"), rows)).toEqual([ + { label: 'a\\_b' }, + ]) + expect(() => parseSQL("select * from orders where label like 'a%' escape '!'")).toThrow('Only empty LIKE escape') + expect(() => parseSQL("select * from orders where label like 'a%' escape label")).toThrow('Only empty LIKE escape') +}) + +it('matches DuckDB DOUBLE quantile rounding near integer rank boundaries', () => { + const rows = Array.from({ length: 50 }, (_, index) => ({ value: index + 1 })) + expect(executeSQL(parseSQL('select quantile(value, 0.14) as q from orders'), rows)).toEqual([{ q: 7 }]) + expect(executeSQL(parseSQL('select quantile(value, -0.14) as q from orders'), rows)).toEqual([{ q: 44 }]) + expect(executeSQL(parseSQL('select quantile(value, 0.140000000000001) as q from orders'), rows)).toEqual([{ q: 8 }]) + expect( + executeSQL(parseSQL('select * from orders order by value, id'), [ + { id: 2, value: undefined }, + { id: 1, value: null }, + ]), + ).toEqual([ + { id: 1, value: null }, + { id: 2, value: undefined }, + ]) +}) diff --git a/packages/vquery/tests/unit/sql-engine/sqlLogicTest.test.ts b/packages/vquery/tests/unit/sql-engine/sqlLogicTest.test.ts index 58ae3bf751..15ed477882 100644 --- a/packages/vquery/tests/unit/sql-engine/sqlLogicTest.test.ts +++ b/packages/vquery/tests/unit/sql-engine/sqlLogicTest.test.ts @@ -171,7 +171,7 @@ class SQLLogicTestDatabase { if (quantileTable) { const [, name, rangeColumn, randomAlias, countText, values] = quantileTable const randomColumn = randomAlias ?? 'random()' - const rows = Array.from({ length: Number(countText) }, (_, value) => ({ + const rows: DataRow[] = Array.from({ length: Number(countText) }, (_, value) => ({ [rangeColumn]: value, [randomColumn]: Math.random(), })) diff --git a/packages/vquery/tests/unit/vquery/storage.test.ts b/packages/vquery/tests/unit/vquery/storage.test.ts new file mode 100644 index 0000000000..d32ebbc405 --- /dev/null +++ b/packages/vquery/tests/unit/vquery/storage.test.ts @@ -0,0 +1,101 @@ +import { VQuery as BrowserVQuery, type VQueryOptions } from '../../../src/browser' +import { VQuery as NodeVQuery } from '../../../src/node' + +const originalIndexedDB = Object.getOwnPropertyDescriptor(globalThis, 'indexedDB') + +beforeEach(() => { + Object.defineProperty(globalThis, 'indexedDB', { + configurable: true, + get: () => { + throw new Error('IndexedDB unavailable') + }, + }) +}) + +afterEach(() => { + rstest.restoreAllMocks() + if (originalIndexedDB) Object.defineProperty(globalThis, 'indexedDB', originalIndexedDB) + else Reflect.deleteProperty(globalThis, 'indexedDB') +}) + +for (const [entrypoint, VQuery] of [ + ['browser', BrowserVQuery], + ['node', NodeVQuery], +] as const) { + describe(`${entrypoint} dataset storage`, () => { + const defaults: Array<[string, VQueryOptions | undefined]> = [ + ['no options', undefined], + ['empty options', {}], + ['explicitly disabled', { enableIndexedDB: false }], + ] + + for (const [name, options] of defaults) { + it(`queries isolated memory datasets without IndexedDB: ${name}`, async () => { + const vquery = new VQuery(options) + const other = new VQuery(options) + const columns = [{ name: 'sales', type: 'number' as const }] + try { + await vquery.createDataset('sales', columns, { + type: 'json', + rawDataset: [{ sales: 10 }, { sales: 20 }], + }) + const dataset = await vquery.connectDataset('sales') + expect( + ( + await dataset.query({ + select: [{ field: 'sales', alias: 'total', aggr: { func: 'sum' } }], + }) + ).dataset, + ).toEqual([{ total: 30 }]) + expect(await other.listDatasets()).toEqual([]) + + await vquery.updateDatasetSource('sales', columns, { type: 'json', rawDataset: [{ sales: 50 }] }) + const updated = await vquery.connectDataset('sales') + expect((await updated.query({ select: ['sales'] })).dataset).toEqual([{ sales: 50 }]) + await vquery.dropDataset('sales') + expect(await vquery.hasDataset('sales')).toBe(false) + } finally { + await vquery.close() + await other.close() + } + }) + } + + it('opens IndexedDB lazily when explicitly enabled and closes it', async () => { + const close = rstest.fn() + const getAll = rstest.fn(() => { + const request = { result: [], onsuccess: undefined as (() => void) | undefined } + queueMicrotask(() => request.onsuccess?.()) + return request + }) + const transaction = rstest.fn(() => ({ objectStore: () => ({ getAll }) })) + const open = rstest.fn(() => { + const request = { + result: { close, transaction }, + onsuccess: undefined as ((event: unknown) => void) | undefined, + } + queueMicrotask(() => request.onsuccess?.({ target: request })) + return request + }) + Object.defineProperty(globalThis, 'indexedDB', { configurable: true, value: { open } }) + const vquery = new VQuery({ enableIndexedDB: true }) + expect(open).not.toHaveBeenCalled() + try { + expect(await vquery.listDatasets()).toEqual([]) + expect(await vquery.listDatasets()).toEqual([]) + expect(open).toHaveBeenCalledTimes(1) + expect(open).toHaveBeenCalledWith('vquery', 2) + expect(transaction).toHaveBeenCalledWith(['vqueryDatasets'], 'readonly') + expect(getAll).toHaveBeenCalledTimes(2) + } finally { + await vquery.close() + } + expect(close).toHaveBeenCalledTimes(1) + }) + + it('reports unavailable IndexedDB when explicitly enabled', async () => { + const vquery = new VQuery({ enableIndexedDB: true }) + await expect(vquery.listDatasets()).rejects.toThrow('IndexedDB unavailable') + }) + }) +}