@devrev/meerkat-node 0.0.111 → 0.0.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{__tests__/test-data.js → __fixtures__/test-data-with-safe-alias.js} +6 -94
- package/__fixtures__/test-data-with-safe-alias.js.map +1 -0
- package/__fixtures__/test-data.js +105 -0
- package/__fixtures__/test-data.js.map +1 -0
- package/__fixtures__/with-dot-alias.js +1228 -0
- package/__fixtures__/with-dot-alias.js.map +1 -0
- package/cube-to-sql/cube-to-sql.js +11 -5
- package/cube-to-sql/cube-to-sql.js.map +1 -1
- package/cube-to-sql-with-resolution/cube-to-sql-with-resolution.js +76 -19
- package/cube-to-sql-with-resolution/cube-to-sql-with-resolution.js.map +1 -1
- package/package.json +1 -1
- package/src/{__tests__/test-data.d.ts → __fixtures__/test-data-with-safe-alias.d.ts} +1 -17
- package/src/__fixtures__/test-data.d.ts +616 -0
- package/src/__fixtures__/with-dot-alias.d.ts +297 -0
- package/src/cube-to-sql/cube-to-sql.d.ts +8 -2
- package/__tests__/test-data.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-node/src/__fixtures__/with-dot-alias.ts"],"sourcesContent":["export const WITH_DOT_ALIAS_TEST_DATA = [\n [\n {\n testName: 'GroupBySQLInnerQuery',\n expectedSQL: `SELECT SUM(order_amount) AS \"orders.total_order_amount\" , \"orders.order_month\" FROM (SELECT DATE_TRUNC('month', order_date) AS \"orders.order_month\", * FROM (select * from orders) AS orders) AS orders GROUP BY \"orders.order_month\" LIMIT 1`,\n cubeInput: {\n measures: ['orders.total_order_amount'],\n filters: [],\n dimensions: ['orders.order_month'],\n limit: 1,\n },\n expectedOutput: [\n {\n 'orders.order_month': '2022-01-01T00:00:00.000Z',\n 'orders.total_order_amount': 130,\n },\n ],\n },\n ],\n [\n {\n testName: 'GroupBy',\n expectedSQL: `SELECT SUM(order_amount) AS \"orders.total_order_amount\" , \"orders.customer_id\" FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders GROUP BY \"orders.customer_id\" ORDER BY \"orders.total_order_amount\" ASC, \"orders.customer_id\" ASC`,\n cubeInput: {\n measures: ['orders.total_order_amount'],\n filters: [],\n dimensions: ['orders.customer_id'],\n order: {\n 'orders.total_order_amount': 'asc',\n 'orders.customer_id': 'asc',\n },\n },\n expectedOutput: [\n {\n 'orders.customer_id': '6aa6',\n 'orders.total_order_amount': 0,\n },\n {\n 'orders.customer_id': '2',\n 'orders.total_order_amount': 100,\n },\n {\n 'orders.customer_id': '3',\n 'orders.total_order_amount': 100,\n },\n {\n 'orders.customer_id': '7',\n 'orders.total_order_amount': 100,\n },\n {\n 'orders.customer_id': null,\n 'orders.total_order_amount': 100,\n },\n {\n 'orders.customer_id': '6',\n 'orders.total_order_amount': 120,\n },\n {\n 'orders.customer_id': '1',\n 'orders.total_order_amount': 130,\n },\n {\n 'orders.customer_id': '4',\n 'orders.total_order_amount': 135,\n },\n {\n 'orders.customer_id': '5',\n 'orders.total_order_amount': 150,\n },\n ],\n },\n ],\n [\n {\n testName: 'Equals',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders WHERE (\"orders.customer_id\" = '1')`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.customer_id',\n operator: 'equals',\n values: ['1'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 1,\n customer_id: '1',\n 'orders.customer_id': '1',\n product_id: '1',\n order_date: '2022-01-01',\n order_amount: 50.0,\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n order_id: 2,\n customer_id: '1',\n 'orders.customer_id': '1',\n product_id: '2',\n order_date: '2022-01-02',\n order_amount: 80.0,\n vendors: ['myntra'],\n },\n ],\n },\n {\n testName: 'Equals for multiple values',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.customer_id\" = '1') AND (\"orders.customer_id\" = '2'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.customer_id',\n operator: 'equals',\n values: ['1', '2'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [],\n },\n ],\n [\n {\n testName: 'NotEquals',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders WHERE (\"orders.customer_id\" != '1')`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.customer_id',\n operator: 'notEquals',\n values: ['1'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 3,\n customer_id: '2',\n 'orders.customer_id': '2',\n product_id: '3',\n order_date: '2022-02-01',\n order_amount: 25.0,\n vendors: [],\n },\n {\n order_id: 4,\n customer_id: '2',\n 'orders.customer_id': '2',\n product_id: '1',\n order_date: '2022-03-01',\n order_amount: 75.0,\n vendors: ['flipkart'],\n },\n {\n order_id: 5,\n customer_id: '3',\n 'orders.customer_id': '3',\n product_id: '1',\n order_date: '2022-03-02',\n order_amount: 100.0,\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n order_id: 6,\n customer_id: '4',\n 'orders.customer_id': '4',\n product_id: '2',\n order_date: '2022-04-01',\n order_amount: 45.0,\n vendors: [],\n },\n {\n order_id: 7,\n customer_id: '4',\n 'orders.customer_id': '4',\n product_id: '3',\n order_date: '2022-05-01',\n order_amount: 90.0,\n vendors: ['myntra', 'flipkart'],\n },\n {\n order_id: 8,\n customer_id: '5',\n 'orders.customer_id': '5',\n product_id: '1',\n order_date: '2022-05-02',\n order_amount: 65.0,\n vendors: ['amazon', 'flipkart'],\n },\n {\n order_id: 9,\n customer_id: '5',\n 'orders.customer_id': '5',\n product_id: '2',\n order_date: '2022-05-05',\n order_amount: 85.0,\n vendors: [],\n },\n {\n order_id: 10,\n customer_id: '6',\n 'orders.customer_id': '6',\n product_id: '3',\n order_date: '2022-06-01',\n order_amount: 120.0,\n vendors: ['myntra', 'amazon'],\n },\n {\n order_id: 11,\n customer_id: '6aa6',\n 'orders.customer_id': '6aa6',\n product_id: '3',\n order_date: '2024-06-01',\n order_amount: 0.0,\n vendors: ['amazon'],\n },\n {\n order_id: 13,\n customer_id: '7',\n 'orders.customer_id': '7',\n product_id: '6',\n order_date: '2024-08-01',\n order_amount: 100.0,\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n [\n {\n testName: 'Contains',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders WHERE (\"orders.customer_id\" ~~* '%aa%')`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.customer_id',\n operator: 'contains',\n values: ['aa'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 11,\n customer_id: '6aa6',\n 'orders.customer_id': '6aa6',\n product_id: '3',\n order_date: '2024-06-01',\n order_amount: 0.0,\n vendors: ['amazon'],\n },\n ],\n },\n ],\n [\n {\n testName: 'NotContains',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.customer_id\" !~~ '%1%') AND (\"orders.customer_id\" !~~ '%2%') AND (\"orders.customer_id\" !~~ '%3%') AND (\"orders.customer_id\" !~~ '%4%') AND (\"orders.customer_id\" !~~ '%5%') AND (\"orders.customer_id\" !~~ '%aa%'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['1'],\n },\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['2'],\n },\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['3'],\n },\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['4'],\n },\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['5'],\n },\n {\n member: 'orders.customer_id',\n operator: 'notContains',\n values: ['aa'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 10,\n customer_id: '6',\n 'orders.customer_id': '6',\n product_id: '3',\n order_date: '2022-06-01',\n order_amount: 120,\n vendors: ['myntra', 'amazon'],\n },\n {\n customer_id: '7',\n order_amount: 100,\n order_date: '2024-08-01T00:00:00.000Z',\n order_id: 13,\n 'orders.customer_id': '7',\n 'orders.order_date': undefined,\n product_id: '6',\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n [\n {\n testName: 'GreaterThan',\n expectedSQL: `SELECT orders.* FROM (SELECT orders.order_amount AS \"orders.order_amount\", * FROM (select * from orders) AS orders) AS orders WHERE (\"orders.order_amount\" > 50)`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.order_amount',\n operator: 'gt',\n values: ['50'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 2,\n customer_id: '1',\n product_id: '2',\n order_date: '2022-01-02',\n order_amount: 80.0,\n 'orders.order_amount': 80.0,\n vendors: ['myntra'],\n },\n {\n order_id: 4,\n customer_id: '2',\n product_id: '1',\n order_date: '2022-03-01',\n order_amount: 75.0,\n 'orders.order_amount': 75.0,\n vendors: ['flipkart'],\n },\n {\n order_id: 5,\n customer_id: '3',\n product_id: '1',\n order_date: '2022-03-02',\n order_amount: 100.0,\n 'orders.order_amount': 100.0,\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n order_id: 7,\n customer_id: '4',\n product_id: '3',\n order_date: '2022-05-01',\n order_amount: 90.0,\n 'orders.order_amount': 90.0,\n vendors: ['myntra', 'flipkart'],\n },\n {\n order_id: 8,\n customer_id: '5',\n product_id: '1',\n order_date: '2022-05-02',\n order_amount: 65.0,\n 'orders.order_amount': 65.0,\n vendors: ['amazon', 'flipkart'],\n },\n {\n order_id: 9,\n customer_id: '5',\n product_id: '2',\n order_date: '2022-05-05',\n order_amount: 85.0,\n 'orders.order_amount': 85.0,\n vendors: [],\n },\n {\n order_id: 10,\n customer_id: '6',\n product_id: '3',\n order_date: '2022-06-01',\n order_amount: 120.0,\n 'orders.order_amount': 120.0,\n vendors: ['myntra', 'amazon'],\n },\n {\n customer_id: null,\n order_amount: 100,\n order_date: '2024-07-01T00:00:00.000Z',\n order_id: 12,\n 'orders.order_amount': 100,\n 'orders.order_date': undefined,\n product_id: '3',\n vendors: ['flipkart'],\n },\n {\n customer_id: '7',\n order_amount: 100,\n order_date: '2024-08-01T00:00:00.000Z',\n order_id: 13,\n 'orders.order_amount': 100,\n 'orders.order_date': undefined,\n product_id: '6',\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n [\n {\n testName: 'LessThan',\n expectedSQL: `SELECT orders.* FROM (SELECT orders.order_amount AS \"orders.order_amount\", * FROM (select * from orders) AS orders) AS orders WHERE (\"orders.order_amount\" < 50)`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.order_amount',\n operator: 'lt',\n values: ['50'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 3,\n customer_id: '2',\n product_id: '3',\n order_date: '2022-02-01',\n order_amount: 25.0,\n 'orders.order_amount': 25.0,\n vendors: [],\n },\n {\n order_id: 6,\n customer_id: '4',\n product_id: '2',\n order_date: '2022-04-01',\n order_amount: 45.0,\n 'orders.order_amount': 45.0,\n vendors: [],\n },\n {\n order_id: 11,\n customer_id: '6aa6',\n product_id: '3',\n order_date: '2024-06-01',\n order_amount: 0.0,\n 'orders.order_amount': 0.0,\n vendors: ['amazon'],\n },\n ],\n },\n ],\n [\n {\n testName: 'InDateRange',\n expectedSQL: `SELECT orders.* FROM (SELECT order_date AS \"orders.order_date\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.order_date\" >= '2022-02-01') AND (\"orders.order_date\" <= '2022-03-31'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.order_date',\n operator: 'inDateRange',\n values: ['2022-02-01', '2022-03-31'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 3,\n customer_id: '2',\n product_id: '3',\n order_date: '2022-02-01',\n 'orders.order_date': '2022-02-01',\n order_amount: 25.0,\n vendors: [],\n },\n {\n order_id: 4,\n customer_id: '2',\n product_id: '1',\n order_date: '2022-03-01',\n 'orders.order_date': '2022-03-01',\n order_amount: 75.0,\n vendors: ['flipkart'],\n },\n {\n order_id: 5,\n customer_id: '3',\n product_id: '1',\n order_date: '2022-03-02',\n 'orders.order_date': '2022-03-02',\n order_amount: 100.0,\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n ],\n },\n ],\n [\n {\n testName: 'NotInDateRange',\n expectedSQL: `SELECT orders.* FROM (SELECT order_date AS \"orders.order_date\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.order_date\" < '2022-02-01') OR (\"orders.order_date\" > '2022-03-31'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n member: 'orders.order_date',\n operator: 'notInDateRange',\n values: ['2022-02-01', '2022-03-31'],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 1,\n customer_id: '1',\n product_id: '1',\n order_date: '2022-01-01',\n order_amount: 50.0,\n 'orders.order_date': '2022-01-01',\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n order_id: 2,\n customer_id: '1',\n product_id: '2',\n order_date: '2022-01-02',\n order_amount: 80.0,\n 'orders.order_date': '2022-01-02',\n vendors: ['myntra'],\n },\n {\n order_id: 6,\n customer_id: '4',\n product_id: '2',\n order_date: '2022-04-01',\n 'orders.order_date': '2022-04-01',\n order_amount: 45.0,\n vendors: [],\n },\n {\n order_id: 7,\n customer_id: '4',\n product_id: '3',\n order_date: '2022-05-01',\n 'orders.order_date': '2022-05-01',\n order_amount: 90.0,\n vendors: ['myntra', 'flipkart'],\n },\n {\n order_id: 8,\n customer_id: '5',\n product_id: '1',\n order_date: '2022-05-02',\n 'orders.order_date': '2022-05-02',\n order_amount: 65.0,\n vendors: ['amazon', 'flipkart'],\n },\n {\n order_id: 9,\n customer_id: '5',\n product_id: '2',\n order_date: '2022-05-05',\n 'orders.order_date': '2022-05-05',\n order_amount: 85.0,\n vendors: [],\n },\n {\n order_id: 10,\n customer_id: '6',\n product_id: '3',\n order_date: '2022-06-01',\n 'orders.order_date': '2022-06-01',\n order_amount: 120.0,\n vendors: ['myntra', 'amazon'],\n },\n {\n order_id: 11,\n customer_id: '6aa6',\n product_id: '3',\n order_date: '2024-06-01',\n 'orders.order_date': '2024-06-01',\n order_amount: 0.0,\n vendors: ['amazon'],\n },\n {\n customer_id: null,\n order_amount: 100,\n order_date: '2024-07-01T00:00:00.000Z',\n order_id: 12,\n 'orders.order_date': '2024-07-01T00:00:00.000Z',\n product_id: '3',\n vendors: ['flipkart'],\n },\n {\n customer_id: '7',\n order_amount: 100,\n order_date: '2024-08-01T00:00:00.000Z',\n order_id: 13,\n 'orders.order_date': '2024-08-01T00:00:00.000Z',\n product_id: '6',\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n [\n {\n testName: 'And',\n expectedSQL: `SELECT orders.* FROM (SELECT orders.order_amount AS \"orders.order_amount\", order_date AS \"orders.order_date\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.order_amount\" > 50) AND ((\"orders.order_date\" >= '2022-02-01') AND (\"orders.order_date\" <= '2022-06-01')))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.order_amount',\n operator: 'gt',\n values: ['50'],\n },\n {\n member: 'orders.order_date',\n operator: 'inDateRange',\n values: ['2022-02-01', '2022-06-01'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n order_id: 4,\n customer_id: '2',\n product_id: '1',\n order_date: '2022-03-01',\n order_amount: 75.0,\n 'orders.order_amount': 75.0,\n 'orders.order_date': '2022-03-01',\n vendors: ['flipkart'],\n },\n {\n order_id: 5,\n customer_id: '3',\n product_id: '1',\n order_date: '2022-03-02',\n 'orders.order_date': '2022-03-02',\n order_amount: 100.0,\n 'orders.order_amount': 100.0,\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n order_id: 7,\n customer_id: '4',\n product_id: '3',\n order_date: '2022-05-01',\n 'orders.order_date': '2022-05-01',\n order_amount: 90.0,\n 'orders.order_amount': 90.0,\n vendors: ['myntra', 'flipkart'],\n },\n {\n order_id: 8,\n customer_id: '5',\n product_id: '1',\n order_date: '2022-05-02',\n 'orders.order_date': '2022-05-02',\n order_amount: 65,\n 'orders.order_amount': 65,\n vendors: ['amazon', 'flipkart'],\n },\n {\n order_id: 9,\n customer_id: '5',\n product_id: '2',\n order_date: '2022-05-05',\n 'orders.order_date': '2022-05-05',\n order_amount: 85.0,\n 'orders.order_amount': 85.0,\n vendors: [],\n },\n {\n order_id: 10,\n customer_id: '6',\n product_id: '3',\n order_date: '2022-06-01',\n 'orders.order_date': '2022-06-01',\n order_amount: 120.0,\n 'orders.order_amount': 120.0,\n vendors: ['myntra', 'amazon'],\n },\n ],\n },\n ],\n [\n {\n testName: 'Set',\n expectedSQL: `SELECT orders.* FROM (SELECT orders.order_amount AS \"orders.order_amount\", product_id AS \"orders.product_id\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.order_amount\" IS NOT NULL) AND (\"orders.product_id\" = '3'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.order_amount',\n operator: 'set',\n },\n {\n member: 'orders.product_id',\n operator: 'equals',\n values: ['3'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n customer_id: '2',\n order_amount: 25,\n order_date: '2022-02-01T00:00:00.000Z',\n order_id: 3,\n 'orders.order_amount': 25,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: [],\n },\n {\n customer_id: '4',\n order_amount: 90,\n order_date: '2022-05-01T00:00:00.000Z',\n order_id: 7,\n 'orders.order_amount': 90,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: ['myntra', 'flipkart'],\n },\n {\n customer_id: '6',\n order_amount: 120,\n order_date: '2022-06-01T00:00:00.000Z',\n order_id: 10,\n 'orders.order_amount': 120,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: ['myntra', 'amazon'],\n },\n {\n customer_id: '6aa6',\n order_amount: 0,\n order_date: '2024-06-01T00:00:00.000Z',\n order_id: 11,\n 'orders.order_amount': 0,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: ['amazon'],\n },\n {\n customer_id: null,\n order_amount: 100,\n order_date: '2024-07-01T00:00:00.000Z',\n order_id: 12,\n 'orders.order_amount': 100,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: ['flipkart'],\n },\n ],\n },\n ],\n [\n {\n testName: 'Not Set',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", product_id AS \"orders.product_id\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.customer_id\" IS NULL) AND (\"orders.product_id\" = '3'))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.customer_id',\n operator: 'notSet',\n },\n {\n member: 'orders.product_id',\n operator: 'equals',\n values: ['3'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n 'orders.customer_id': null,\n customer_id: null,\n order_amount: 100,\n order_date: '2024-07-01T00:00:00.000Z',\n order_id: 12,\n 'orders.order_date': undefined,\n 'orders.product_id': '3',\n product_id: '3',\n vendors: ['flipkart'],\n },\n ],\n },\n ],\n [\n {\n testName: 'In',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", vendors AS \"orders.vendors\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.customer_id\" IN ('1', '2')) AND (\"orders.vendors\" && (ARRAY['myntra', 'amazon'])))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.customer_id',\n operator: 'in',\n values: ['1', '2'],\n },\n {\n member: 'orders.vendors',\n operator: 'in',\n values: ['myntra', 'amazon'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n customer_id: '1',\n order_amount: 50,\n order_date: '2022-01-01T00:00:00.000Z',\n order_id: 1,\n 'orders.customer_id': '1',\n 'orders.order_date': undefined,\n 'orders.vendors': ['myntra', 'amazon', 'flipkart'],\n product_id: '1',\n vendors: ['myntra', 'amazon', 'flipkart'],\n },\n {\n customer_id: '1',\n order_amount: 80,\n order_date: '2022-01-02T00:00:00.000Z',\n order_id: 2,\n 'orders.customer_id': '1',\n 'orders.order_date': undefined,\n 'orders.vendors': ['myntra'],\n product_id: '2',\n vendors: ['myntra'],\n },\n ],\n },\n {\n testName: 'In with single quotes',\n expectedSQL: `SELECT orders.* FROM (SELECT vendors AS \"orders.vendors\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.vendors\" && (ARRAY['swiggy''s'])))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.vendors',\n operator: 'in',\n values: [\"swiggy's\"],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n customer_id: '7',\n order_amount: 100,\n order_date: '2024-08-01T00:00:00.000Z',\n order_id: 13,\n 'orders.order_date': undefined,\n 'orders.vendors': [\"swiggy's\"],\n product_id: '6',\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n [\n {\n testName: 'Not In',\n expectedSQL: `SELECT orders.* FROM (SELECT customer_id AS \"orders.customer_id\", vendors AS \"orders.vendors\", * FROM (select * from orders) AS orders) AS orders WHERE ((\"orders.customer_id\" NOT IN ('1', '2')) AND (NOT (\"orders.vendors\" && (ARRAY['myntra', 'flipkart']))))`,\n cubeInput: {\n measures: ['*'],\n filters: [\n {\n and: [\n {\n member: 'orders.customer_id',\n operator: 'notIn',\n values: ['1', '2'],\n },\n {\n member: 'orders.vendors',\n operator: 'notIn',\n values: ['myntra', 'flipkart'],\n },\n ],\n },\n ],\n dimensions: [],\n },\n expectedOutput: [\n {\n customer_id: '4',\n order_amount: 45,\n order_date: '2022-04-01T00:00:00.000Z',\n order_id: 6,\n 'orders.customer_id': '4',\n 'orders.order_date': undefined,\n 'orders.vendors': [],\n product_id: '2',\n vendors: [],\n },\n {\n customer_id: '5',\n order_amount: 85,\n order_date: '2022-05-05T00:00:00.000Z',\n order_id: 9,\n 'orders.customer_id': '5',\n 'orders.order_date': undefined,\n 'orders.vendors': [],\n product_id: '2',\n vendors: [],\n },\n {\n customer_id: '6aa6',\n order_amount: 0,\n order_date: '2024-06-01T00:00:00.000Z',\n order_id: 11,\n 'orders.customer_id': '6aa6',\n 'orders.order_date': undefined,\n 'orders.vendors': ['amazon'],\n product_id: '3',\n vendors: ['amazon'],\n },\n {\n customer_id: '7',\n order_amount: 100,\n order_date: '2024-08-01T00:00:00.000Z',\n order_id: 13,\n 'orders.customer_id': '7',\n 'orders.order_date': undefined,\n 'orders.vendors': [\"swiggy's\"],\n product_id: '6',\n vendors: [\"swiggy's\"],\n },\n ],\n },\n ],\n];\n"],"names":["WITH_DOT_ALIAS_TEST_DATA","testName","expectedSQL","cubeInput","measures","filters","dimensions","limit","expectedOutput","order","member","operator","values","order_id","customer_id","product_id","order_date","order_amount","vendors","and","undefined"],"mappings":";+BAAaA;;;eAAAA;;;AAAN,MAAMA,2BAA2B;IACtC;QACE;YACEC,UAAU;YACVC,aAAa,CAAC,+OAA+O,CAAC;YAC9PC,WAAW;gBACTC,UAAU;oBAAC;iBAA4B;gBACvCC,SAAS,EAAE;gBACXC,YAAY;oBAAC;iBAAqB;gBAClCC,OAAO;YACT;YACAC,gBAAgB;gBACd;oBACE,sBAAsB;oBACtB,6BAA6B;gBAC/B;aACD;QACH;KACD;IACD;QACE;YACEP,UAAU;YACVC,aAAa,CAAC,sRAAsR,CAAC;YACrSC,WAAW;gBACTC,UAAU;oBAAC;iBAA4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4BAChC;yBACD;oBACH;iBACD;gBACDN,YAAY,EAAE;YAChB;YACAE,gBAAgB;gBACd;oBACEM,aAAa;oBACbG,cAAc;oBACdD,YAAY;oBACZH,UAAU;oBACV,sBAAsB;oBACtB,qBAAqBO;oBACrB,kBAAkB,EAAE;oBACpBL,YAAY;oBACZG,SAAS,EAAE;gBACb;gBACA;oBACEJ,aAAa;oBACbG,cAAc;oBACdD,YAAY;oBACZH,UAAU;oBACV,sBAAsB;oBACtB,qBAAqBO;oBACrB,kBAAkB,EAAE;oBACpBL,YAAY;oBACZG,SAAS,EAAE;gBACb;gBACA;oBACEJ,aAAa;oBACbG,cAAc;oBACdD,YAAY;oBACZH,UAAU;oBACV,sBAAsB;oBACtB,qBAAqBO;oBACrB,kBAAkB;wBAAC;qBAAS;oBAC5BL,YAAY;oBACZG,SAAS;wBAAC;qBAAS;gBACrB;gBACA;oBACEJ,aAAa;oBACbG,cAAc;oBACdD,YAAY;oBACZH,UAAU;oBACV,sBAAsB;oBACtB,qBAAqBO;oBACrB,kBAAkB;wBAAC;qBAAW;oBAC9BL,YAAY;oBACZG,SAAS;wBAAC;qBAAW;gBACvB;aACD;QACH;KACD;CACF"}
|
|
@@ -8,19 +8,23 @@ Object.defineProperty(exports, "cubeQueryToSQL", {
|
|
|
8
8
|
const _extends = require("@swc/helpers/_/_extends");
|
|
9
9
|
const _meerkatcore = require("@devrev/meerkat-core");
|
|
10
10
|
const _duckdbexec = require("../duckdb-exec");
|
|
11
|
-
const cubeQueryToSQL = async ({ query, tableSchemas, contextParams })=>{
|
|
11
|
+
const cubeQueryToSQL = async ({ query, tableSchemas, contextParams, options })=>{
|
|
12
12
|
const updatedTableSchemas = await Promise.all(tableSchemas.map(async (schema)=>{
|
|
13
13
|
const baseFilterParamsSQL = await (0, _meerkatcore.getFinalBaseSQL)({
|
|
14
14
|
query,
|
|
15
15
|
tableSchema: schema,
|
|
16
|
-
getQueryOutput: _duckdbexec.duckdbExec
|
|
16
|
+
getQueryOutput: _duckdbexec.duckdbExec,
|
|
17
|
+
config: options
|
|
17
18
|
});
|
|
18
19
|
return _extends._({}, schema, {
|
|
19
20
|
sql: baseFilterParamsSQL
|
|
20
21
|
});
|
|
21
22
|
}));
|
|
22
23
|
const updatedTableSchema = (0, _meerkatcore.getCombinedTableSchema)(updatedTableSchemas, query);
|
|
23
|
-
const ast = (0, _meerkatcore.cubeToDuckdbAST)(query, updatedTableSchema
|
|
24
|
+
const ast = (0, _meerkatcore.cubeToDuckdbAST)(query, updatedTableSchema, {
|
|
25
|
+
filterType: 'PROJECTION_FILTER',
|
|
26
|
+
config: options
|
|
27
|
+
});
|
|
24
28
|
if (!ast) {
|
|
25
29
|
throw new Error('Could not generate AST');
|
|
26
30
|
}
|
|
@@ -30,7 +34,9 @@ const cubeQueryToSQL = async ({ query, tableSchemas, contextParams })=>{
|
|
|
30
34
|
const filterParamsSQL = await (0, _meerkatcore.getFilterParamsSQL)({
|
|
31
35
|
query,
|
|
32
36
|
tableSchema: updatedTableSchema,
|
|
33
|
-
|
|
37
|
+
filterType: 'PROJECTION_FILTER',
|
|
38
|
+
getQueryOutput: _duckdbexec.duckdbExec,
|
|
39
|
+
config: options
|
|
34
40
|
});
|
|
35
41
|
const filterParamQuery = (0, _meerkatcore.applyFilterParamsToBaseSQL)(updatedTableSchema.sql, filterParamsSQL);
|
|
36
42
|
/**
|
|
@@ -43,7 +49,7 @@ const cubeQueryToSQL = async ({ query, tableSchemas, contextParams })=>{
|
|
|
43
49
|
* Add measures to the query
|
|
44
50
|
*/ const measures = query.measures;
|
|
45
51
|
const dimensions = query.dimensions || [];
|
|
46
|
-
const queryWithProjections = (0, _meerkatcore.applyProjectionToSQLQuery)(dimensions, measures, updatedTableSchema, replaceBaseTableName);
|
|
52
|
+
const queryWithProjections = (0, _meerkatcore.applyProjectionToSQLQuery)(dimensions, measures, updatedTableSchema, replaceBaseTableName, options);
|
|
47
53
|
/**
|
|
48
54
|
* Replace SQL expression placeholders with actual SQL
|
|
49
55
|
*/ const finalQuery = (0, _meerkatcore.applySQLExpressions)(queryWithProjections);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql/cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n Query,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n applySQLExpressions,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsSQL,\n getFinalBaseSQL,\n} from '@devrev/meerkat-core';\nimport { duckdbExec } from '../duckdb-exec';\n\nexport interface CubeQueryToSQLParams {\n query: Query;\n tableSchemas: TableSchema[];\n contextParams?: ContextParams;\n}\n\nexport const cubeQueryToSQL = async ({\n query,\n tableSchemas,\n contextParams,\n}: CubeQueryToSQLParams) => {\n const updatedTableSchemas: TableSchema[] = await Promise.all(\n tableSchemas.map(async (schema: TableSchema) => {\n const baseFilterParamsSQL = await getFinalBaseSQL({\n query,\n tableSchema: schema,\n getQueryOutput: duckdbExec,\n });\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = getCombinedTableSchema(updatedTableSchemas, query);\n\n const ast = cubeToDuckdbAST(query, updatedTableSchema);\n if (!ast) {\n throw new Error('Could not generate AST');\n }\n\n const queryTemp = astDeserializerQuery(ast);\n\n const queryOutput = (await duckdbExec(queryTemp)) as Record<string, string>[];\n const preBaseQuery = deserializeQuery(queryOutput);\n\n const filterParamsSQL = await getFilterParamsSQL({\n query,\n tableSchema: updatedTableSchema,\n getQueryOutput: duckdbExec,\n });\n\n const filterParamQuery = applyFilterParamsToBaseSQL(\n updatedTableSchema.sql,\n filterParamsSQL\n );\n\n /**\n * Replace CONTEXT_PARAMS with context params\n */\n const baseQuery = detectApplyContextParamsToBaseSQL(\n filterParamQuery,\n contextParams || {}\n );\n\n /**\n * Replace BASE_TABLE_NAME with cube query\n */\n const replaceBaseTableName = preBaseQuery.replace(\n BASE_TABLE_NAME,\n `(${baseQuery}) AS ${updatedTableSchema.name}`\n );\n\n /**\n * Add measures to the query\n */\n const measures = query.measures;\n const dimensions = query.dimensions || [];\n const queryWithProjections = applyProjectionToSQLQuery(\n dimensions,\n measures,\n updatedTableSchema,\n replaceBaseTableName\n );\n\n /**\n * Replace SQL expression placeholders with actual SQL\n */\n const finalQuery = applySQLExpressions(queryWithProjections);\n\n return finalQuery;\n};\n"],"names":["cubeQueryToSQL","query","tableSchemas","contextParams","updatedTableSchemas","Promise","all","map","schema","baseFilterParamsSQL","getFinalBaseSQL","tableSchema","getQueryOutput","duckdbExec","sql","updatedTableSchema","getCombinedTableSchema","ast","cubeToDuckdbAST","Error","queryTemp","astDeserializerQuery","queryOutput","preBaseQuery","deserializeQuery","filterParamsSQL","getFilterParamsSQL","filterParamQuery","applyFilterParamsToBaseSQL","baseQuery","detectApplyContextParamsToBaseSQL","replaceBaseTableName","replace","BASE_TABLE_NAME","name","measures","dimensions","queryWithProjections","applyProjectionToSQLQuery","finalQuery","applySQLExpressions"],"mappings":";+
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql/cube-to-sql.ts"],"sourcesContent":["import {\n BASE_TABLE_NAME,\n ContextParams,\n Query,\n QueryOptions,\n TableSchema,\n applyFilterParamsToBaseSQL,\n applyProjectionToSQLQuery,\n applySQLExpressions,\n astDeserializerQuery,\n cubeToDuckdbAST,\n deserializeQuery,\n detectApplyContextParamsToBaseSQL,\n getCombinedTableSchema,\n getFilterParamsSQL,\n getFinalBaseSQL,\n} from '@devrev/meerkat-core';\nimport { duckdbExec } from '../duckdb-exec';\n\nexport interface CubeQueryToSQLParams {\n query: Query;\n tableSchemas: TableSchema[];\n contextParams?: ContextParams;\n /**\n * Options for controlling output format.\n * When useDotNotation is true, aliases use dot notation (e.g., \"orders.customer_id\")\n * When useDotNotation is false, aliases use underscore notation (e.g., orders__customer_id)\n */\n options: QueryOptions;\n}\n\nexport const cubeQueryToSQL = async ({\n query,\n tableSchemas,\n contextParams,\n options,\n}: CubeQueryToSQLParams) => {\n const updatedTableSchemas: TableSchema[] = await Promise.all(\n tableSchemas.map(async (schema: TableSchema) => {\n const baseFilterParamsSQL = await getFinalBaseSQL({\n query,\n tableSchema: schema,\n getQueryOutput: duckdbExec,\n config: options,\n });\n return {\n ...schema,\n sql: baseFilterParamsSQL,\n };\n })\n );\n\n const updatedTableSchema = getCombinedTableSchema(updatedTableSchemas, query);\n\n const ast = cubeToDuckdbAST(query, updatedTableSchema, {\n filterType: 'PROJECTION_FILTER',\n config: options,\n });\n if (!ast) {\n throw new Error('Could not generate AST');\n }\n\n const queryTemp = astDeserializerQuery(ast);\n\n const queryOutput = (await duckdbExec(queryTemp)) as Record<string, string>[];\n const preBaseQuery = deserializeQuery(queryOutput);\n\n const filterParamsSQL = await getFilterParamsSQL({\n query,\n tableSchema: updatedTableSchema,\n filterType: 'PROJECTION_FILTER',\n getQueryOutput: duckdbExec,\n config: options,\n });\n\n const filterParamQuery = applyFilterParamsToBaseSQL(\n updatedTableSchema.sql,\n filterParamsSQL\n );\n\n /**\n * Replace CONTEXT_PARAMS with context params\n */\n const baseQuery = detectApplyContextParamsToBaseSQL(\n filterParamQuery,\n contextParams || {}\n );\n\n /**\n * Replace BASE_TABLE_NAME with cube query\n */\n const replaceBaseTableName = preBaseQuery.replace(\n BASE_TABLE_NAME,\n `(${baseQuery}) AS ${updatedTableSchema.name}`\n );\n\n /**\n * Add measures to the query\n */\n const measures = query.measures;\n const dimensions = query.dimensions || [];\n const queryWithProjections = applyProjectionToSQLQuery(\n dimensions,\n measures,\n updatedTableSchema,\n replaceBaseTableName,\n options\n );\n\n /**\n * Replace SQL expression placeholders with actual SQL\n */\n const finalQuery = applySQLExpressions(queryWithProjections);\n\n return finalQuery;\n};\n"],"names":["cubeQueryToSQL","query","tableSchemas","contextParams","options","updatedTableSchemas","Promise","all","map","schema","baseFilterParamsSQL","getFinalBaseSQL","tableSchema","getQueryOutput","duckdbExec","config","sql","updatedTableSchema","getCombinedTableSchema","ast","cubeToDuckdbAST","filterType","Error","queryTemp","astDeserializerQuery","queryOutput","preBaseQuery","deserializeQuery","filterParamsSQL","getFilterParamsSQL","filterParamQuery","applyFilterParamsToBaseSQL","baseQuery","detectApplyContextParamsToBaseSQL","replaceBaseTableName","replace","BASE_TABLE_NAME","name","measures","dimensions","queryWithProjections","applyProjectionToSQLQuery","finalQuery","applySQLExpressions"],"mappings":";+BA+BaA;;;eAAAA;;;;6BAfN;4BACoB;AAcpB,MAAMA,iBAAiB,OAAO,EACnCC,KAAK,EACLC,YAAY,EACZC,aAAa,EACbC,OAAO,EACc;IACrB,MAAMC,sBAAqC,MAAMC,QAAQC,GAAG,CAC1DL,aAAaM,GAAG,CAAC,OAAOC;QACtB,MAAMC,sBAAsB,MAAMC,IAAAA,4BAAe,EAAC;YAChDV;YACAW,aAAaH;YACbI,gBAAgBC,sBAAU;YAC1BC,QAAQX;QACV;QACA,OAAO,eACFK;YACHO,KAAKN;;IAET;IAGF,MAAMO,qBAAqBC,IAAAA,mCAAsB,EAACb,qBAAqBJ;IAEvE,MAAMkB,MAAMC,IAAAA,4BAAe,EAACnB,OAAOgB,oBAAoB;QACrDI,YAAY;QACZN,QAAQX;IACV;IACA,IAAI,CAACe,KAAK;QACR,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMC,YAAYC,IAAAA,iCAAoB,EAACL;IAEvC,MAAMM,cAAe,MAAMX,IAAAA,sBAAU,EAACS;IACtC,MAAMG,eAAeC,IAAAA,6BAAgB,EAACF;IAEtC,MAAMG,kBAAkB,MAAMC,IAAAA,+BAAkB,EAAC;QAC/C5B;QACAW,aAAaK;QACbI,YAAY;QACZR,gBAAgBC,sBAAU;QAC1BC,QAAQX;IACV;IAEA,MAAM0B,mBAAmBC,IAAAA,uCAA0B,EACjDd,mBAAmBD,GAAG,EACtBY;IAGF;;GAEC,GACD,MAAMI,YAAYC,IAAAA,8CAAiC,EACjDH,kBACA3B,iBAAiB,CAAC;IAGpB;;GAEC,GACD,MAAM+B,uBAAuBR,aAAaS,OAAO,CAC/CC,4BAAe,EACf,CAAC,CAAC,EAAEJ,UAAU,KAAK,EAAEf,mBAAmBoB,IAAI,CAAC,CAAC;IAGhD;;GAEC,GACD,MAAMC,WAAWrC,MAAMqC,QAAQ;IAC/B,MAAMC,aAAatC,MAAMsC,UAAU,IAAI,EAAE;IACzC,MAAMC,uBAAuBC,IAAAA,sCAAyB,EACpDF,YACAD,UACArB,oBACAiB,sBACA9B;IAGF;;GAEC,GACD,MAAMsC,aAAaC,IAAAA,gCAAmB,EAACH;IAEvC,OAAOE;AACT"}
|
|
@@ -5,18 +5,55 @@ Object.defineProperty(exports, "cubeQueryToSQLWithResolution", {
|
|
|
5
5
|
return cubeQueryToSQLWithResolution;
|
|
6
6
|
}
|
|
7
7
|
});
|
|
8
|
+
const _extends = require("@swc/helpers/_/_extends");
|
|
8
9
|
const _meerkatcore = require("@devrev/meerkat-core");
|
|
9
10
|
const _cubetosql = require("../cube-to-sql/cube-to-sql");
|
|
10
11
|
const cubeQueryToSQLWithResolution = async ({ query, tableSchemas, resolutionConfig, columnProjections, contextParams })=>{
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
contextParams
|
|
15
|
-
});
|
|
12
|
+
const resolutionOptions = {
|
|
13
|
+
useDotNotation: false
|
|
14
|
+
};
|
|
16
15
|
// Check if resolution should be skipped
|
|
17
16
|
if ((0, _meerkatcore.shouldSkipResolution)(resolutionConfig, query, columnProjections)) {
|
|
18
|
-
return
|
|
17
|
+
return await (0, _cubetosql.cubeQueryToSQL)({
|
|
18
|
+
query,
|
|
19
|
+
tableSchemas,
|
|
20
|
+
contextParams,
|
|
21
|
+
options: resolutionOptions
|
|
22
|
+
});
|
|
19
23
|
}
|
|
24
|
+
// Resolution flow always uses underscore notation (useDotNotation: false)
|
|
25
|
+
// to ensure consistent field naming throughout the resolution pipeline.
|
|
26
|
+
//
|
|
27
|
+
// Why remove aliases?
|
|
28
|
+
// The resolution pipeline (unnest → join lookups → re-aggregate) operates on field names
|
|
29
|
+
// internally for consistency and simplicity. Using aliases throughout would complicate
|
|
30
|
+
// the logic as we transform schemas through multiple steps.
|
|
31
|
+
//
|
|
32
|
+
// Alias handling strategy:
|
|
33
|
+
// 1. Strip aliases here - work with field names (e.g., tickets__id, tickets__owners)
|
|
34
|
+
// 2. Run entire resolution pipeline with field names
|
|
35
|
+
// 3. At the final step (applyAliases), restore aliases from original schemas
|
|
36
|
+
// 4. Generate final SQL with user-friendly aliases (e.g., "ID", "Owners")
|
|
37
|
+
//
|
|
38
|
+
// Benefits:
|
|
39
|
+
// - Cleaner internal logic (no alias tracking through transformations)
|
|
40
|
+
// - Single source of truth for aliases (original tableSchemas)
|
|
41
|
+
// - Easier to debug (field names are consistent throughout pipeline)
|
|
42
|
+
// - Separation of concerns (resolution logic vs. display formatting)
|
|
43
|
+
const tableSchemasWithoutAliases = tableSchemas.map((schema)=>_extends._({}, schema, {
|
|
44
|
+
dimensions: schema.dimensions.map((dim)=>_extends._({}, dim, {
|
|
45
|
+
alias: undefined
|
|
46
|
+
})),
|
|
47
|
+
measures: schema.measures.map((measure)=>_extends._({}, measure, {
|
|
48
|
+
alias: undefined
|
|
49
|
+
}))
|
|
50
|
+
}));
|
|
51
|
+
const baseSql = await (0, _cubetosql.cubeQueryToSQL)({
|
|
52
|
+
query,
|
|
53
|
+
tableSchemas: tableSchemasWithoutAliases,
|
|
54
|
+
contextParams,
|
|
55
|
+
options: resolutionOptions
|
|
56
|
+
});
|
|
20
57
|
if (!columnProjections) {
|
|
21
58
|
columnProjections = [
|
|
22
59
|
...query.dimensions || [],
|
|
@@ -28,25 +65,30 @@ const cubeQueryToSQLWithResolution = async ({ query, tableSchemas, resolutionCon
|
|
|
28
65
|
resolutionConfig.columnConfigs = resolutionConfig.columnConfigs.filter((config)=>{
|
|
29
66
|
return columnProjections == null ? void 0 : columnProjections.includes(config.name);
|
|
30
67
|
});
|
|
31
|
-
const baseSchema = (0, _meerkatcore.createBaseTableSchema)(baseSql,
|
|
68
|
+
const baseSchema = (0, _meerkatcore.createBaseTableSchema)(baseSql, tableSchemasWithoutAliases, resolutionConfig, [], columnProjections);
|
|
69
|
+
// At this point, filters/sorts are baked into baseSql using original values
|
|
70
|
+
// We can now override dimensions/measures in the base schema with custom SQL expressions for display
|
|
71
|
+
const schemaWithOverrides = (0, _meerkatcore.applySqlOverrides)(baseSchema, resolutionConfig);
|
|
72
|
+
// Transform field names in configs to match base table schema format
|
|
73
|
+
resolutionConfig.columnConfigs.forEach((config)=>{
|
|
74
|
+
config.name = (0, _meerkatcore.memberKeyToSafeKey)(config.name, resolutionOptions);
|
|
75
|
+
});
|
|
32
76
|
const rowIdDimension = {
|
|
33
77
|
name: _meerkatcore.ROW_ID_DIMENSION_NAME,
|
|
34
|
-
sql: (0, _meerkatcore.generateRowNumberSql)(query,
|
|
78
|
+
sql: (0, _meerkatcore.generateRowNumberSql)(query, schemaWithOverrides.dimensions, _meerkatcore.BASE_DATA_SOURCE_NAME),
|
|
35
79
|
type: 'number',
|
|
36
80
|
alias: _meerkatcore.ROW_ID_DIMENSION_NAME
|
|
37
81
|
};
|
|
38
|
-
|
|
82
|
+
schemaWithOverrides.dimensions.push(rowIdDimension);
|
|
39
83
|
columnProjections.push(_meerkatcore.ROW_ID_DIMENSION_NAME);
|
|
40
|
-
// Doing this because we need to use the original name of the column in the base table schema.
|
|
41
|
-
resolutionConfig.columnConfigs.forEach((config)=>{
|
|
42
|
-
config.name = (0, _meerkatcore.memberKeyToSafeKey)(config.name);
|
|
43
|
-
});
|
|
44
84
|
// Generate SQL with row_id and unnested arrays
|
|
45
85
|
const unnestTableSchema = await (0, _meerkatcore.getUnnestTableSchema)({
|
|
46
|
-
baseTableSchema:
|
|
86
|
+
baseTableSchema: schemaWithOverrides,
|
|
47
87
|
resolutionConfig,
|
|
48
88
|
contextParams,
|
|
49
|
-
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(params
|
|
89
|
+
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(_extends._({}, params, {
|
|
90
|
+
options: resolutionOptions
|
|
91
|
+
}))
|
|
50
92
|
});
|
|
51
93
|
// Apply resolution (join with lookup tables)
|
|
52
94
|
const resolvedTableSchema = await (0, _meerkatcore.getResolvedTableSchema)({
|
|
@@ -54,16 +96,31 @@ const cubeQueryToSQLWithResolution = async ({ query, tableSchemas, resolutionCon
|
|
|
54
96
|
resolutionConfig,
|
|
55
97
|
contextParams,
|
|
56
98
|
columnProjections,
|
|
57
|
-
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(params
|
|
99
|
+
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(_extends._({}, params, {
|
|
100
|
+
options: resolutionOptions
|
|
101
|
+
}))
|
|
58
102
|
});
|
|
59
103
|
// Re-aggregate to reverse the unnest
|
|
60
|
-
const
|
|
104
|
+
const aggregatedTableSchema = await (0, _meerkatcore.getAggregatedSql)({
|
|
61
105
|
resolvedTableSchema,
|
|
62
106
|
resolutionConfig,
|
|
63
107
|
contextParams,
|
|
64
|
-
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(params
|
|
108
|
+
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(_extends._({}, params, {
|
|
109
|
+
options: resolutionOptions
|
|
110
|
+
}))
|
|
111
|
+
});
|
|
112
|
+
// Apply aliases and generate final SQL
|
|
113
|
+
const sqlWithAliases = await (0, _meerkatcore.applyAliases)({
|
|
114
|
+
aggregatedTableSchema,
|
|
115
|
+
originalTableSchemas: tableSchemas,
|
|
116
|
+
resolutionConfig,
|
|
117
|
+
contextParams,
|
|
118
|
+
cubeQueryToSQL: async (params)=>(0, _cubetosql.cubeQueryToSQL)(_extends._({}, params, {
|
|
119
|
+
options: resolutionOptions
|
|
120
|
+
}))
|
|
65
121
|
});
|
|
66
|
-
|
|
122
|
+
// Wrap with row_id ordering and exclusion
|
|
123
|
+
return (0, _meerkatcore.wrapWithRowIdOrderingAndExclusion)(sqlWithAliases, _meerkatcore.ROW_ID_DIMENSION_NAME);
|
|
67
124
|
};
|
|
68
125
|
|
|
69
126
|
//# sourceMappingURL=cube-to-sql-with-resolution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql-with-resolution/cube-to-sql-with-resolution.ts"],"sourcesContent":["import {\n BASE_DATA_SOURCE_NAME,\n ContextParams,\n getAggregatedSql as coreGetAggregatedSql,\n getResolvedTableSchema as coreGetResolvedTableSchema,\n getUnnestTableSchema as coreGetUnnestTableSchema,\n createBaseTableSchema,\n Dimension,\n generateRowNumberSql,\n memberKeyToSafeKey,\n Query,\n ResolutionConfig,\n ROW_ID_DIMENSION_NAME,\n shouldSkipResolution,\n TableSchema,\n} from '@devrev/meerkat-core';\nimport { cubeQueryToSQL } from '../cube-to-sql/cube-to-sql';\n\nexport interface CubeQueryToSQLWithResolutionParams {\n query: Query;\n tableSchemas: TableSchema[];\n resolutionConfig: ResolutionConfig;\n columnProjections?: string[];\n contextParams?: ContextParams;\n}\n\nexport const cubeQueryToSQLWithResolution = async ({\n query,\n tableSchemas,\n resolutionConfig,\n columnProjections,\n contextParams,\n}: CubeQueryToSQLWithResolutionParams) => {\n const
|
|
1
|
+
{"version":3,"sources":["../../../meerkat-node/src/cube-to-sql-with-resolution/cube-to-sql-with-resolution.ts"],"sourcesContent":["import {\n applyAliases,\n applySqlOverrides,\n BASE_DATA_SOURCE_NAME,\n ContextParams,\n getAggregatedSql as coreGetAggregatedSql,\n getResolvedTableSchema as coreGetResolvedTableSchema,\n getUnnestTableSchema as coreGetUnnestTableSchema,\n createBaseTableSchema,\n Dimension,\n generateRowNumberSql,\n memberKeyToSafeKey,\n Query,\n QueryOptions,\n ResolutionConfig,\n ROW_ID_DIMENSION_NAME,\n shouldSkipResolution,\n TableSchema,\n wrapWithRowIdOrderingAndExclusion,\n} from '@devrev/meerkat-core';\nimport { cubeQueryToSQL } from '../cube-to-sql/cube-to-sql';\n\nexport interface CubeQueryToSQLWithResolutionParams {\n query: Query;\n tableSchemas: TableSchema[];\n resolutionConfig: ResolutionConfig;\n columnProjections?: string[];\n contextParams?: ContextParams;\n}\n\nexport const cubeQueryToSQLWithResolution = async ({\n query,\n tableSchemas,\n resolutionConfig,\n columnProjections,\n contextParams,\n}: CubeQueryToSQLWithResolutionParams) => {\n const resolutionOptions: QueryOptions = {\n useDotNotation: false,\n };\n // Check if resolution should be skipped\n if (shouldSkipResolution(resolutionConfig, query, columnProjections)) {\n return await cubeQueryToSQL({\n query,\n tableSchemas,\n contextParams,\n options: resolutionOptions,\n });\n }\n\n // Resolution flow always uses underscore notation (useDotNotation: false)\n // to ensure consistent field naming throughout the resolution pipeline.\n\n //\n // Why remove aliases?\n // The resolution pipeline (unnest → join lookups → re-aggregate) operates on field names\n // internally for consistency and simplicity. Using aliases throughout would complicate\n // the logic as we transform schemas through multiple steps.\n //\n // Alias handling strategy:\n // 1. Strip aliases here - work with field names (e.g., tickets__id, tickets__owners)\n // 2. Run entire resolution pipeline with field names\n // 3. At the final step (applyAliases), restore aliases from original schemas\n // 4. Generate final SQL with user-friendly aliases (e.g., \"ID\", \"Owners\")\n //\n // Benefits:\n // - Cleaner internal logic (no alias tracking through transformations)\n // - Single source of truth for aliases (original tableSchemas)\n // - Easier to debug (field names are consistent throughout pipeline)\n // - Separation of concerns (resolution logic vs. display formatting)\n const tableSchemasWithoutAliases: TableSchema[] = tableSchemas.map(\n (schema) => ({\n ...schema,\n dimensions: schema.dimensions.map((dim) => ({\n ...dim,\n alias: undefined, // Strip alias for resolution pipeline\n })),\n measures: schema.measures.map((measure) => ({\n ...measure,\n alias: undefined, // Strip alias\n })),\n })\n );\n\n const baseSql = await cubeQueryToSQL({\n query,\n tableSchemas: tableSchemasWithoutAliases,\n contextParams,\n options: resolutionOptions,\n });\n\n if (!columnProjections) {\n columnProjections = [...(query.dimensions || []), ...query.measures];\n }\n // This is to ensure that, only the column projection columns\n // are being resolved and other definitions are ignored.\n resolutionConfig.columnConfigs = resolutionConfig.columnConfigs.filter(\n (config) => {\n return columnProjections?.includes(config.name);\n }\n );\n\n const baseSchema: TableSchema = createBaseTableSchema(\n baseSql,\n tableSchemasWithoutAliases, // Use alias-free schemas\n resolutionConfig,\n [],\n columnProjections\n );\n\n // At this point, filters/sorts are baked into baseSql using original values\n // We can now override dimensions/measures in the base schema with custom SQL expressions for display\n const schemaWithOverrides = applySqlOverrides(baseSchema, resolutionConfig);\n\n // Transform field names in configs to match base table schema format\n resolutionConfig.columnConfigs.forEach((config) => {\n config.name = memberKeyToSafeKey(config.name, resolutionOptions);\n });\n\n const rowIdDimension: Dimension = {\n name: ROW_ID_DIMENSION_NAME,\n sql: generateRowNumberSql(\n query,\n schemaWithOverrides.dimensions,\n BASE_DATA_SOURCE_NAME\n ),\n type: 'number',\n alias: ROW_ID_DIMENSION_NAME,\n };\n schemaWithOverrides.dimensions.push(rowIdDimension);\n columnProjections.push(ROW_ID_DIMENSION_NAME);\n\n // Generate SQL with row_id and unnested arrays\n const unnestTableSchema = await coreGetUnnestTableSchema({\n baseTableSchema: schemaWithOverrides,\n resolutionConfig,\n contextParams,\n cubeQueryToSQL: async (params) =>\n cubeQueryToSQL({ ...params, options: resolutionOptions }),\n });\n\n // Apply resolution (join with lookup tables)\n const resolvedTableSchema = await coreGetResolvedTableSchema({\n baseTableSchema: unnestTableSchema,\n resolutionConfig,\n contextParams,\n columnProjections,\n cubeQueryToSQL: async (params) =>\n cubeQueryToSQL({ ...params, options: resolutionOptions }),\n });\n\n // Re-aggregate to reverse the unnest\n const aggregatedTableSchema = await coreGetAggregatedSql({\n resolvedTableSchema,\n resolutionConfig,\n contextParams,\n cubeQueryToSQL: async (params) =>\n cubeQueryToSQL({ ...params, options: resolutionOptions }),\n });\n\n // Apply aliases and generate final SQL\n const sqlWithAliases = await applyAliases({\n aggregatedTableSchema,\n originalTableSchemas: tableSchemas,\n resolutionConfig,\n contextParams,\n cubeQueryToSQL: async (params) =>\n cubeQueryToSQL({ ...params, options: resolutionOptions }),\n });\n\n // Wrap with row_id ordering and exclusion\n return wrapWithRowIdOrderingAndExclusion(\n sqlWithAliases,\n ROW_ID_DIMENSION_NAME\n );\n};\n"],"names":["cubeQueryToSQLWithResolution","query","tableSchemas","resolutionConfig","columnProjections","contextParams","resolutionOptions","useDotNotation","shouldSkipResolution","cubeQueryToSQL","options","tableSchemasWithoutAliases","map","schema","dimensions","dim","alias","undefined","measures","measure","baseSql","columnConfigs","filter","config","includes","name","baseSchema","createBaseTableSchema","schemaWithOverrides","applySqlOverrides","forEach","memberKeyToSafeKey","rowIdDimension","ROW_ID_DIMENSION_NAME","sql","generateRowNumberSql","BASE_DATA_SOURCE_NAME","type","push","unnestTableSchema","coreGetUnnestTableSchema","baseTableSchema","params","resolvedTableSchema","coreGetResolvedTableSchema","aggregatedTableSchema","coreGetAggregatedSql","sqlWithAliases","applyAliases","originalTableSchemas","wrapWithRowIdOrderingAndExclusion"],"mappings":";+BA8BaA;;;eAAAA;;;;6BAXN;2BACwB;AAUxB,MAAMA,+BAA+B,OAAO,EACjDC,KAAK,EACLC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,EACsB;IACnC,MAAMC,oBAAkC;QACtCC,gBAAgB;IAClB;IACA,wCAAwC;IACxC,IAAIC,IAAAA,iCAAoB,EAACL,kBAAkBF,OAAOG,oBAAoB;QACpE,OAAO,MAAMK,IAAAA,yBAAc,EAAC;YAC1BR;YACAC;YACAG;YACAK,SAASJ;QACX;IACF;IAEA,0EAA0E;IAC1E,wEAAwE;IAExE,EAAE;IACF,sBAAsB;IACtB,yFAAyF;IACzF,uFAAuF;IACvF,4DAA4D;IAC5D,EAAE;IACF,2BAA2B;IAC3B,qFAAqF;IACrF,qDAAqD;IACrD,6EAA6E;IAC7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AAqB;IAE5C,+CAA+C;IAC/C,MAAMM,oBAAoB,MAAMC,IAAAA,iCAAwB,EAAC;QACvDC,iBAAiBb;QACjBzB;QACAE;QACAI,gBAAgB,OAAOiC,SACrBjC,IAAAA,yBAAc,EAAC,eAAKiC;gBAAQhC,SAASJ;;IACzC;IAEA,8CAA8C;IAC9C,MAAMqC,sBAAsB,MAAMC,IAAAA,mCAA0B,EAAC;QAC3DH,iBAAiBF;QACjBpC;QACAE;QACAD;QACAK,gBAAgB,OAAOiC,SACrBjC,IAAAA,yBAAc,EAAC,eAAKiC;gBAAQhC,SAASJ;;IACzC;IAEA,qCAAqC;IACrC,MAAMuC,wBAAwB,MAAMC,IAAAA,6BAAoB,EAAC;QACvDH;QACAxC;QACAE;QACAI,gBAAgB,OAAOiC,SACrBjC,IAAAA,yBAAc,EAAC,eAAKiC;gBAAQhC,SAASJ;;IACzC;IAEA,uCAAuC;IACvC,MAAMyC,iBAAiB,MAAMC,IAAAA,yBAAY,EAAC;QACxCH;QACAI,sBAAsB/C;QACtBC;QACAE;QACAI,gBAAgB,OAAOiC,SACrBjC,IAAAA,yBAAc,EAAC,eAAKiC;gBAAQhC,SAASJ;;IACzC;IAEA,0CAA0C;IAC1C,OAAO4C,IAAAA,8CAAiC,EACtCH,gBACAd,kCAAqB;AAEzB"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const INPUT_DATA_QUERY = "\nINSERT INTO orders VALUES\n(1, '1', '1', '2022-01-01', 50, ['myntra', 'amazon', 'flipkart']),\n(2, '1', '2', '2022-01-02', 80, ['myntra']),\n(3, '2', '3', '2022-02-01', 25, []),\n(4, '2', '1', '2022-03-01', 75, ['flipkart']),\n(5, '3', '1', '2022-03-02', 100, ['myntra', 'amazon', 'flipkart']),\n(6, '4', '2', '2022-04-01', 45, []),\n(7, '4', '3', '2022-05-01', 90, ['myntra', 'flipkart']),\n(8, '5', '1', '2022-05-02', 65, ['amazon', 'flipkart']),\n(9, '5', '2', '2022-05-05', 85, []),\n(10, '6', '3', '2022-06-01', 120, ['myntra', 'amazon']),\n(11, '6aa6', '3', '2024-06-01', 0, ['amazon']),\n(12, NULL, '3', '2024-07-01', 100, ['flipkart']),\n(13, '7', '6', '2024-08-01', 100, ['swiggy''s']);\n";
|
|
3
|
-
export declare const TABLE_SCHEMA: {
|
|
4
|
-
name: string;
|
|
5
|
-
sql: string;
|
|
6
|
-
measures: {
|
|
7
|
-
name: string;
|
|
8
|
-
sql: string;
|
|
9
|
-
type: string;
|
|
10
|
-
}[];
|
|
11
|
-
dimensions: {
|
|
12
|
-
name: string;
|
|
13
|
-
sql: string;
|
|
14
|
-
type: string;
|
|
15
|
-
}[];
|
|
16
|
-
};
|
|
17
|
-
export declare const TEST_DATA: ({
|
|
1
|
+
export declare const TEST_DATA_WITH_SAFE_ALIAS: ({
|
|
18
2
|
testName: string;
|
|
19
3
|
expectedSQL: string;
|
|
20
4
|
cubeInput: {
|