@narrative.io/data-collaboration-sdk-ts 0.26.0 → 0.27.0

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.
@@ -1,5 +1,5 @@
1
1
  import { type NqlBudget } from "./Ast";
2
- import { type CreateMaterializedView, type Deduplication, type Explain, type Expression, type Raw, type Select, type Statement, type Table } from "./AstParser";
2
+ import { type Output, type CreateMaterializedView, type Deduplication, type Explain, type Expression, type Raw, type Select, type Statement, type Table } from "./AstParser";
3
3
  export type CompiledNql = string;
4
4
  export declare function compileStatement(n: Statement): CompiledNql;
5
5
  export declare function compileCreateMaterializedView(n: CreateMaterializedView): CompiledNql;
@@ -8,4 +8,5 @@ export declare function compileSelect(q: Select): CompiledNql;
8
8
  export declare function compileBudget(budget: NqlBudget): CompiledNql;
9
9
  export declare function compileDeduplication(d: Deduplication | Raw): CompiledNql;
10
10
  export declare function compileFrom(tables: Table[] | Raw): CompiledNql;
11
+ export declare function compileOutput(n: Output): CompiledNql;
11
12
  export declare function compileExpression(n: Expression): CompiledNql;
@@ -17,7 +17,7 @@ export function compileExplain(n) {
17
17
  return `EXPLAIN ${compileSelect(n.query)}`;
18
18
  }
19
19
  export function compileSelect(q) {
20
- const columns = q.columns.map((e) => compileExpression(e));
20
+ const columns = q.columns.map((e) => compileOutput(e));
21
21
  const select = `SELECT ${columns.join(", ")}`;
22
22
  const budget = q.budget !== null ? compileBudget(q.budget) : "";
23
23
  const from = `FROM ${compileFrom(q.from)}`;
@@ -144,6 +144,21 @@ function compileTableRefs(tables) {
144
144
  }
145
145
  return nql;
146
146
  }
147
+ export function compileOutput(n) {
148
+ switch (n.type) {
149
+ case "attribute_ref":
150
+ return compileAttributeRef(n.column, n.as, false);
151
+ case "dataset_column_ref":
152
+ return compileDatasetColumnRef(n.datasetId, n.column, n.as, false);
153
+ case "lit":
154
+ return compileLit(n.value, n.value_type, n.as);
155
+ case "raw_ref":
156
+ return compileRawRef(n.nql, n.as);
157
+ case "nql":
158
+ return raw(n);
159
+ }
160
+ return unreachable(n);
161
+ }
147
162
  export function compileExpression(n) {
148
163
  switch (n.type) {
149
164
  case "=":
@@ -199,7 +214,7 @@ export function compileExpression(n) {
199
214
  }
200
215
  return unreachable(n);
201
216
  }
202
- function compileAttributeRef(column, as) {
217
+ function compileAttributeRef(column, as, aliasParens) {
203
218
  const segments = column.split(".");
204
219
  const quotedSegments = segments.reduce((acc, segment, index) => {
205
220
  if (index === 0) {
@@ -209,7 +224,7 @@ function compileAttributeRef(column, as) {
209
224
  return `${acc}.${quote(segment)}`;
210
225
  }
211
226
  }, "");
212
- return aliased(`narrative.rosetta_stone.${quotedSegments}`, as);
227
+ return aliased(`narrative.rosetta_stone.${quotedSegments}`, as, aliasParens);
213
228
  }
214
229
  function compileBetween(operand, lower, upper, as) {
215
230
  const operandNql = compileExpression(operand);
@@ -220,7 +235,7 @@ function compileBetween(operand, lower, upper, as) {
220
235
  function compileBinaryOperator(op, operands, as) {
221
236
  return aliased(`(${operands.map((e) => compileExpression(e)).join(` ${op} `)})`, as);
222
237
  }
223
- function compileDatasetColumnRef(datasetId, column, as) {
238
+ function compileDatasetColumnRef(datasetId, column, as, aliasParen) {
224
239
  const formattedColumn = column
225
240
  .split(".")
226
241
  .reduce((acc, segment, index) => {
@@ -231,7 +246,7 @@ function compileDatasetColumnRef(datasetId, column, as) {
231
246
  return `${acc}.${quote(segment)}`;
232
247
  }
233
248
  }, "");
234
- return aliased(`company_data.${quote(datasetId.toString())}.${formattedColumn}`, as);
249
+ return aliased(`company_data.${quote(datasetId.toString())}.${formattedColumn}`, as, false);
235
250
  }
236
251
  function compileFunctionCall(name, args, as) {
237
252
  // Calling convenions for functions are all over the place:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",