@malloydata/malloy 0.0.22-dev230117165007 → 0.0.22-dev230117200639

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,4 @@
1
- import { AtomicFieldTypeInner, TimeFieldType, TimestampUnit, ExtractUnit, DialectFragment, TimeValue } from "..";
2
- import { Expr, Sampling, StructDef, TypecastFragment } from "../model/malloy_types";
1
+ import { AtomicFieldType as AtomicFieldTypeInner, TimeFieldType, TimestampUnit, ExtractUnit, DialectFragment, TimeValue, Expr, Sampling, StructDef, TypecastFragment } from "../model/malloy_types";
3
2
  interface DialectField {
4
3
  type: string;
5
4
  sqlExpression: string;
@@ -23,10 +23,6 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.Dialect = void 0;
26
- // Can't get these from "../model" because model includes this file
27
- // and that can create a circular reference problem. This is a patch
28
- // and really indicates a problem in the relationship between
29
- // dialect and model, it's going to come up again some time.
30
26
  const malloy_types_1 = require("../model/malloy_types");
31
27
  class Dialect {
32
28
  sqlFinalStage(_lastStageName, _fields) {
@@ -23,7 +23,7 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.registerDialect = exports.getDialect = void 0;
26
- const _1 = require(".");
26
+ const duckdb_1 = require("./duckdb");
27
27
  const postgres_1 = require("./postgres");
28
28
  const standardsql_1 = require("./standardsql");
29
29
  const dialectMap = new Map();
@@ -41,5 +41,5 @@ function registerDialect(d) {
41
41
  exports.registerDialect = registerDialect;
42
42
  registerDialect(new postgres_1.PostgresDialect());
43
43
  registerDialect(new standardsql_1.StandardSQLDialect());
44
- registerDialect(new _1.DuckDBDialect());
44
+ registerDialect(new duckdb_1.DuckDBDialect());
45
45
  //# sourceMappingURL=dialect_map.js.map
@@ -1,4 +1,4 @@
1
- import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimestampUnit, TimeValue, TypecastFragment } from "../model";
1
+ import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimestampUnit, TimeValue, TypecastFragment } from "../model/malloy_types";
2
2
  import { Dialect, DialectFieldList, FunctionInfo } from "./dialect";
3
3
  export declare class DuckDBDialect extends Dialect {
4
4
  name: string;
@@ -23,7 +23,7 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.DuckDBDialect = void 0;
26
- const model_1 = require("../model");
26
+ const malloy_types_1 = require("../model/malloy_types");
27
27
  const utils_1 = require("../model/utils");
28
28
  const dialect_1 = require("./dialect");
29
29
  // need to refactor runSQL to take a SQLBlock instead of just a sql string.
@@ -220,7 +220,7 @@ class DuckDBDialect extends dialect_1.Dialect {
220
220
  }
221
221
  sqlCreateFunctionCombineLastStage(lastStageName, structDef) {
222
222
  return `SELECT LIST(ROW(${structDef.fields
223
- .map((fieldDef) => this.sqlMaybeQuoteIdentifier((0, model_1.getIdentifier)(fieldDef)))
223
+ .map((fieldDef) => this.sqlMaybeQuoteIdentifier((0, malloy_types_1.getIdentifier)(fieldDef)))
224
224
  .join(",")})) FROM ${lastStageName}\n`;
225
225
  }
226
226
  sqlSelectAliasAsStruct(alias, physicalFieldNames) {
@@ -251,64 +251,64 @@ class DuckDBDialect extends dialect_1.Dialect {
251
251
  let lVal = from.value;
252
252
  let rVal = to.value;
253
253
  if (inSeconds[units]) {
254
- lVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
255
- rVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
256
- const duration = (0, model_1.mkExpr) `(${rVal} - ${lVal})`;
254
+ lVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
255
+ rVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
256
+ const duration = (0, malloy_types_1.mkExpr) `(${rVal} - ${lVal})`;
257
257
  return units == "second"
258
258
  ? duration
259
- : (0, model_1.mkExpr) `FLOOR(${duration}/${inSeconds[units].toString()})`;
259
+ : (0, malloy_types_1.mkExpr) `FLOOR(${duration}/${inSeconds[units].toString()})`;
260
260
  }
261
261
  if (from.valueType != "date") {
262
- lVal = (0, model_1.mkExpr) `CAST((${lVal}) AS DATE)`;
262
+ lVal = (0, malloy_types_1.mkExpr) `CAST((${lVal}) AS DATE)`;
263
263
  }
264
264
  if (to.valueType != "date") {
265
- rVal = (0, model_1.mkExpr) `CAST((${rVal}) AS DATE)`;
265
+ rVal = (0, malloy_types_1.mkExpr) `CAST((${rVal}) AS DATE)`;
266
266
  }
267
267
  if (units == "week") {
268
268
  // DuckDB's weeks start on Monday, but Malloy's weeks start on Sunday
269
- lVal = (0, model_1.mkExpr) `(${lVal} + INTERVAL 1 DAY)`;
270
- rVal = (0, model_1.mkExpr) `(${rVal} + INTERVAL 1 DAY)`;
269
+ lVal = (0, malloy_types_1.mkExpr) `(${lVal} + INTERVAL 1 DAY)`;
270
+ rVal = (0, malloy_types_1.mkExpr) `(${rVal} + INTERVAL 1 DAY)`;
271
271
  }
272
- return (0, model_1.mkExpr) `DATE_DIFF('${units}', ${lVal}, ${rVal})`;
272
+ return (0, malloy_types_1.mkExpr) `DATE_DIFF('${units}', ${lVal}, ${rVal})`;
273
273
  }
274
274
  sqlNow() {
275
- return (0, model_1.mkExpr) `CURRENT_TIMESTAMP::TIMESTAMP`;
275
+ return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP::TIMESTAMP`;
276
276
  }
277
277
  sqlTrunc(sqlTime, units) {
278
278
  // adjusting for monday/sunday weeks
279
279
  const week = units == "week";
280
280
  const truncThis = week
281
- ? (0, model_1.mkExpr) `${sqlTime.value} + INTERVAL 1 DAY`
281
+ ? (0, malloy_types_1.mkExpr) `${sqlTime.value} + INTERVAL 1 DAY`
282
282
  : sqlTime.value;
283
- const trunced = (0, model_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
284
- return week ? (0, model_1.mkExpr) `(${trunced} - INTERVAL 1 DAY)` : trunced;
283
+ const trunced = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
284
+ return week ? (0, malloy_types_1.mkExpr) `(${trunced} - INTERVAL 1 DAY)` : trunced;
285
285
  }
286
286
  sqlExtract(from, units) {
287
287
  const pgUnits = pgExtractionMap[units] || units;
288
- const extracted = (0, model_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
289
- return units == "day_of_week" ? (0, model_1.mkExpr) `(${extracted}+1)` : extracted;
288
+ const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
289
+ return units == "day_of_week" ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
290
290
  }
291
291
  sqlAlterTime(op, expr, n, timeframe) {
292
292
  if (timeframe == "quarter") {
293
293
  timeframe = "month";
294
- n = (0, model_1.mkExpr) `${n}*3`;
294
+ n = (0, malloy_types_1.mkExpr) `${n}*3`;
295
295
  }
296
296
  if (timeframe == "week") {
297
297
  timeframe = "day";
298
- n = (0, model_1.mkExpr) `${n}*7`;
298
+ n = (0, malloy_types_1.mkExpr) `${n}*7`;
299
299
  }
300
- const interval = (0, model_1.mkExpr) `INTERVAL (${n}) ${timeframe}`;
301
- return (0, model_1.mkExpr) `((${expr.value})) ${op} ${interval}`;
300
+ const interval = (0, malloy_types_1.mkExpr) `INTERVAL (${n}) ${timeframe}`;
301
+ return (0, malloy_types_1.mkExpr) `((${expr.value})) ${op} ${interval}`;
302
302
  }
303
303
  sqlCast(cast) {
304
304
  if (cast.dstType !== cast.srcType) {
305
305
  const castTo = castMap[cast.dstType] || cast.dstType;
306
- return (0, model_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
306
+ return (0, malloy_types_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
307
307
  }
308
308
  return cast.expr;
309
309
  }
310
310
  sqlRegexpMatch(expr, regexp) {
311
- return (0, model_1.mkExpr) `REGEXP_MATCHES(${expr}, ${regexp})`;
311
+ return (0, malloy_types_1.mkExpr) `REGEXP_MATCHES(${expr}, ${regexp})`;
312
312
  }
313
313
  sqlLiteralTime(timeString, type, _timezone) {
314
314
  if (type == "date") {
@@ -341,13 +341,13 @@ class DuckDBDialect extends dialect_1.Dialect {
341
341
  // default duckdb to sampling 50K rows.
342
342
  sqlSampleTable(tableSQL, sample) {
343
343
  if (sample !== undefined) {
344
- if ((0, model_1.isSamplingEnable)(sample) && sample.enable) {
344
+ if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
345
345
  sample = this.defaultSampling;
346
346
  }
347
- if ((0, model_1.isSamplingRows)(sample)) {
347
+ if ((0, malloy_types_1.isSamplingRows)(sample)) {
348
348
  return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.rows})`;
349
349
  }
350
- else if ((0, model_1.isSamplingPercent)(sample)) {
350
+ else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
351
351
  return `(SELECT * FROM ${tableSQL} USING SAMPLE ${sample.percent} PERCENT (bernoulli))`;
352
352
  }
353
353
  }
@@ -1,4 +1,4 @@
1
- import { DateUnit, ExtractUnit, TimeFieldType, TimestampUnit, Expr, TimeValue, TypecastFragment, Sampling } from "../model";
1
+ import { DateUnit, ExtractUnit, TimeFieldType, TimestampUnit, Expr, TimeValue, TypecastFragment, Sampling } from "../model/malloy_types";
2
2
  import { Dialect, DialectFieldList, FunctionInfo } from "./dialect";
3
3
  export declare class PostgresDialect extends Dialect {
4
4
  name: string;
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.PostgresDialect = void 0;
26
26
  const utils_1 = require("../model/utils");
27
- const model_1 = require("../model");
27
+ const malloy_types_1 = require("../model/malloy_types");
28
28
  const dialect_1 = require("./dialect");
29
29
  const castMap = {
30
30
  number: "double precision",
@@ -216,39 +216,39 @@ class PostgresDialect extends dialect_1.Dialect {
216
216
  throw new Error("Not implemented Yet");
217
217
  }
218
218
  sqlNow() {
219
- return (0, model_1.mkExpr) `CURRENT_TIMESTAMP`;
219
+ return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP`;
220
220
  }
221
221
  sqlTrunc(sqlTime, units) {
222
222
  // adjusting for monday/sunday weeks
223
223
  const week = units == "week";
224
224
  const truncThis = week
225
- ? (0, model_1.mkExpr) `${sqlTime.value}+interval'1'day`
225
+ ? (0, malloy_types_1.mkExpr) `${sqlTime.value}+interval'1'day`
226
226
  : sqlTime.value;
227
- const trunced = (0, model_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
228
- return week ? (0, model_1.mkExpr) `(${trunced}-interval'1'day)` : trunced;
227
+ const trunced = (0, malloy_types_1.mkExpr) `DATE_TRUNC('${units}', ${truncThis})`;
228
+ return week ? (0, malloy_types_1.mkExpr) `(${trunced}-interval'1'day)` : trunced;
229
229
  }
230
230
  sqlExtract(from, units) {
231
231
  const pgUnits = pgExtractionMap[units] || units;
232
- const extracted = (0, model_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
233
- return units == "day_of_week" ? (0, model_1.mkExpr) `(${extracted}+1)` : extracted;
232
+ const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${from.value})`;
233
+ return units == "day_of_week" ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
234
234
  }
235
235
  sqlAlterTime(op, expr, n, timeframe) {
236
236
  if (timeframe == "quarter") {
237
237
  timeframe = "month";
238
- n = (0, model_1.mkExpr) `${n}*3`;
238
+ n = (0, malloy_types_1.mkExpr) `${n}*3`;
239
239
  }
240
- const interval = (0, model_1.mkExpr) `make_interval(${pgMakeIntervalMap[timeframe]}=>${n})`;
241
- return (0, model_1.mkExpr) `((${expr.value})${op}${interval})`;
240
+ const interval = (0, malloy_types_1.mkExpr) `make_interval(${pgMakeIntervalMap[timeframe]}=>${n})`;
241
+ return (0, malloy_types_1.mkExpr) `((${expr.value})${op}${interval})`;
242
242
  }
243
243
  sqlCast(cast) {
244
244
  if (cast.dstType !== cast.srcType) {
245
245
  const castTo = castMap[cast.dstType] || cast.dstType;
246
- return (0, model_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
246
+ return (0, malloy_types_1.mkExpr) `cast(${cast.expr} as ${castTo})`;
247
247
  }
248
248
  return cast.expr;
249
249
  }
250
250
  sqlRegexpMatch(expr, regexp) {
251
- return (0, model_1.mkExpr) `(${expr} ~ ${regexp})`;
251
+ return (0, malloy_types_1.mkExpr) `(${expr} ~ ${regexp})`;
252
252
  }
253
253
  sqlLiteralTime(timeString, type, _timezone) {
254
254
  if (type == "date") {
@@ -268,31 +268,31 @@ class PostgresDialect extends dialect_1.Dialect {
268
268
  let lVal = from.value;
269
269
  let rVal = to.value;
270
270
  if (inSeconds[units]) {
271
- lVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
272
- rVal = (0, model_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
273
- const duration = (0, model_1.mkExpr) `(${rVal} - ${lVal})`;
271
+ lVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${lVal})`;
272
+ rVal = (0, malloy_types_1.mkExpr) `EXTRACT(EPOCH FROM ${rVal})`;
273
+ const duration = (0, malloy_types_1.mkExpr) `(${rVal} - ${lVal})`;
274
274
  return units == "second"
275
275
  ? duration
276
- : (0, model_1.mkExpr) `TRUNC(${duration}/${inSeconds[units].toString()})`;
276
+ : (0, malloy_types_1.mkExpr) `TRUNC(${duration}/${inSeconds[units].toString()})`;
277
277
  }
278
278
  if (units === "day") {
279
- return (0, model_1.mkExpr) `${rVal}::date - ${lVal}::date`;
279
+ return (0, malloy_types_1.mkExpr) `${rVal}::date - ${lVal}::date`;
280
280
  }
281
- const yearDiff = (0, model_1.mkExpr) `(DATE_PART('year', ${rVal}) - DATE_PART('year', ${lVal}))`;
281
+ const yearDiff = (0, malloy_types_1.mkExpr) `(DATE_PART('year', ${rVal}) - DATE_PART('year', ${lVal}))`;
282
282
  if (units == "year") {
283
283
  return yearDiff;
284
284
  }
285
285
  if (units == "week") {
286
- const dayDiffForWeekStart = (0, model_1.mkExpr) `(DATE_TRUNC('week', ${rVal} + '1 day'::interval)::date - DATE_TRUNC('week', ${lVal} + '1 day'::interval)::date)`;
287
- return (0, model_1.mkExpr) `${dayDiffForWeekStart} / 7`;
286
+ const dayDiffForWeekStart = (0, malloy_types_1.mkExpr) `(DATE_TRUNC('week', ${rVal} + '1 day'::interval)::date - DATE_TRUNC('week', ${lVal} + '1 day'::interval)::date)`;
287
+ return (0, malloy_types_1.mkExpr) `${dayDiffForWeekStart} / 7`;
288
288
  }
289
289
  if (units == "month") {
290
- const monthDiff = (0, model_1.mkExpr) `DATE_PART('month', ${rVal}) - DATE_PART('month', ${lVal})`;
291
- return (0, model_1.mkExpr) `${yearDiff} * 12 + ${monthDiff}`;
290
+ const monthDiff = (0, malloy_types_1.mkExpr) `DATE_PART('month', ${rVal}) - DATE_PART('month', ${lVal})`;
291
+ return (0, malloy_types_1.mkExpr) `${yearDiff} * 12 + ${monthDiff}`;
292
292
  }
293
293
  if (units == "quarter") {
294
- const qDiff = (0, model_1.mkExpr) `DATE_PART('quarter', ${rVal}) - DATE_PART('quarter', ${lVal})`;
295
- return (0, model_1.mkExpr) `${yearDiff} * 4 + ${qDiff}`;
294
+ const qDiff = (0, malloy_types_1.mkExpr) `DATE_PART('quarter', ${rVal}) - DATE_PART('quarter', ${lVal})`;
295
+ return (0, malloy_types_1.mkExpr) `${yearDiff} * 4 + ${qDiff}`;
296
296
  }
297
297
  throw new Error(`Unknown or unhandled postgres time unit: ${units}`);
298
298
  }
@@ -307,13 +307,13 @@ class PostgresDialect extends dialect_1.Dialect {
307
307
  }
308
308
  sqlSampleTable(tableSQL, sample) {
309
309
  if (sample !== undefined) {
310
- if ((0, model_1.isSamplingEnable)(sample) && sample.enable) {
310
+ if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
311
311
  sample = this.defaultSampling;
312
312
  }
313
- if ((0, model_1.isSamplingRows)(sample)) {
313
+ if ((0, malloy_types_1.isSamplingRows)(sample)) {
314
314
  return `(SELECT * FROM ${tableSQL} TABLESAMPLE SYSTEM_ROWS(${sample.rows}))`;
315
315
  }
316
- else if ((0, model_1.isSamplingPercent)(sample)) {
316
+ else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
317
317
  return `(SELECT * FROM ${tableSQL} TABLESAMPLE SYSTEM (${sample.percent}))`;
318
318
  }
319
319
  }
@@ -1,4 +1,4 @@
1
- import { TimestampUnit, ExtractUnit, Expr, TimeValue, TypecastFragment, Sampling } from "../model";
1
+ import { TimestampUnit, ExtractUnit, Expr, TimeValue, TypecastFragment, Sampling } from "../model/malloy_types";
2
2
  import { Dialect, DialectFieldList, FunctionInfo } from "./dialect";
3
3
  export declare class StandardSQLDialect extends Dialect {
4
4
  name: string;
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.StandardSQLDialect = void 0;
26
26
  const utils_1 = require("../model/utils");
27
- const model_1 = require("../model");
27
+ const malloy_types_1 = require("../model/malloy_types");
28
28
  const dialect_1 = require("./dialect");
29
29
  const castMap = {
30
30
  number: "float64",
@@ -270,20 +270,20 @@ ${(0, utils_1.indent)(sql)}
270
270
  : identifier;
271
271
  }
272
272
  sqlNow() {
273
- return (0, model_1.mkExpr) `CURRENT_TIMESTAMP()`;
273
+ return (0, malloy_types_1.mkExpr) `CURRENT_TIMESTAMP()`;
274
274
  }
275
275
  sqlTrunc(sqlTime, units) {
276
276
  if (sqlTime.valueType == "date") {
277
- if ((0, model_1.isDateUnit)(units)) {
278
- return (0, model_1.mkExpr) `DATE_TRUNC(${sqlTime.value},${units})`;
277
+ if ((0, malloy_types_1.isDateUnit)(units)) {
278
+ return (0, malloy_types_1.mkExpr) `DATE_TRUNC(${sqlTime.value},${units})`;
279
279
  }
280
- return (0, model_1.mkExpr) `TIMESTAMP(${sqlTime.value})`;
280
+ return (0, malloy_types_1.mkExpr) `TIMESTAMP(${sqlTime.value})`;
281
281
  }
282
- return (0, model_1.mkExpr) `TIMESTAMP_TRUNC(${sqlTime.value},${units})`;
282
+ return (0, malloy_types_1.mkExpr) `TIMESTAMP_TRUNC(${sqlTime.value},${units})`;
283
283
  }
284
284
  sqlExtract(expr, units) {
285
285
  const extractTo = extractMap[units] || units;
286
- return (0, model_1.mkExpr) `EXTRACT(${extractTo} FROM ${expr.value})`;
286
+ return (0, malloy_types_1.mkExpr) `EXTRACT(${extractTo} FROM ${expr.value})`;
287
287
  }
288
288
  sqlAlterTime(op, expr, n, timeframe) {
289
289
  let theTime = expr.value;
@@ -292,16 +292,16 @@ ${(0, utils_1.indent)(sql)}
292
292
  // The units must be done in timestamp, no matter the input type
293
293
  computeType = "timestamp";
294
294
  if (expr.valueType != "timestamp") {
295
- theTime = (0, model_1.mkExpr) `TIMESTAMP(${theTime})`;
295
+ theTime = (0, malloy_types_1.mkExpr) `TIMESTAMP(${theTime})`;
296
296
  }
297
297
  }
298
298
  else if (expr.valueType == "timestamp") {
299
- theTime = (0, model_1.mkExpr) `DATETIME(${theTime})`;
299
+ theTime = (0, malloy_types_1.mkExpr) `DATETIME(${theTime})`;
300
300
  computeType = "datetime";
301
301
  }
302
302
  const funcName = computeType.toUpperCase() + (op == "+" ? "_ADD" : "_SUB");
303
- const newTime = (0, model_1.mkExpr) `${funcName}(${theTime}, INTERVAL ${n} ${timeframe})`;
304
- return computeType == "datetime" ? (0, model_1.mkExpr) `TIMESTAMP(${newTime})` : newTime;
303
+ const newTime = (0, malloy_types_1.mkExpr) `${funcName}(${theTime}, INTERVAL ${n} ${timeframe})`;
304
+ return computeType == "datetime" ? (0, malloy_types_1.mkExpr) `TIMESTAMP(${newTime})` : newTime;
305
305
  }
306
306
  ignoreInProject(fieldName) {
307
307
  return fieldName === "_PARTITIONTIME";
@@ -310,19 +310,19 @@ ${(0, utils_1.indent)(sql)}
310
310
  if (cast.srcType !== cast.dstType) {
311
311
  const dstType = castMap[cast.dstType] || cast.dstType;
312
312
  // This just makes the code look a little prettier ...
313
- if (!cast.safe && cast.srcType && (0, model_1.isTimeFieldType)(cast.srcType)) {
313
+ if (!cast.safe && cast.srcType && (0, malloy_types_1.isTimeFieldType)(cast.srcType)) {
314
314
  if (dstType == "date") {
315
- return (0, model_1.mkExpr) `DATE(${cast.expr})`;
315
+ return (0, malloy_types_1.mkExpr) `DATE(${cast.expr})`;
316
316
  }
317
- return (0, model_1.mkExpr) `TIMESTAMP(${cast.expr})`;
317
+ return (0, malloy_types_1.mkExpr) `TIMESTAMP(${cast.expr})`;
318
318
  }
319
319
  const castFunc = cast.safe ? "SAFE_CAST" : "CAST";
320
- return (0, model_1.mkExpr) `${castFunc}(${cast.expr} AS ${dstType})`;
320
+ return (0, malloy_types_1.mkExpr) `${castFunc}(${cast.expr} AS ${dstType})`;
321
321
  }
322
322
  return cast.expr;
323
323
  }
324
324
  sqlRegexpMatch(expr, regexp) {
325
- return (0, model_1.mkExpr) `REGEXP_CONTAINS(${expr}, r${regexp})`;
325
+ return (0, malloy_types_1.mkExpr) `REGEXP_CONTAINS(${expr}, r${regexp})`;
326
326
  }
327
327
  sqlLiteralTime(timeString, type, timezone) {
328
328
  if (type === "date") {
@@ -341,32 +341,32 @@ ${(0, utils_1.indent)(sql)}
341
341
  let diffUsing = "TIMESTAMP_DIFF";
342
342
  if (units == "second" || units == "minute" || units == "hour") {
343
343
  if (from.valueType != "timestamp") {
344
- lVal = (0, model_1.mkExpr) `TIMESTAMP(${lVal})`;
344
+ lVal = (0, malloy_types_1.mkExpr) `TIMESTAMP(${lVal})`;
345
345
  }
346
346
  if (to.valueType != "timestamp") {
347
- rVal = (0, model_1.mkExpr) `TIMESTAMP(${rVal})`;
347
+ rVal = (0, malloy_types_1.mkExpr) `TIMESTAMP(${rVal})`;
348
348
  }
349
349
  }
350
350
  else {
351
351
  diffUsing = "DATE_DIFF";
352
352
  if (from.valueType != "date") {
353
- lVal = (0, model_1.mkExpr) `DATE(${lVal})`;
353
+ lVal = (0, malloy_types_1.mkExpr) `DATE(${lVal})`;
354
354
  }
355
355
  if (to.valueType != "date") {
356
- rVal = (0, model_1.mkExpr) `DATE(${rVal})`;
356
+ rVal = (0, malloy_types_1.mkExpr) `DATE(${rVal})`;
357
357
  }
358
358
  }
359
- return (0, model_1.mkExpr) `${diffUsing}(${rVal}, ${lVal}, ${units})`;
359
+ return (0, malloy_types_1.mkExpr) `${diffUsing}(${rVal}, ${lVal}, ${units})`;
360
360
  }
361
361
  sqlSampleTable(tableSQL, sample) {
362
362
  if (sample !== undefined) {
363
- if ((0, model_1.isSamplingEnable)(sample) && sample.enable) {
363
+ if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
364
364
  sample = this.defaultSampling;
365
365
  }
366
- if ((0, model_1.isSamplingRows)(sample)) {
366
+ if ((0, malloy_types_1.isSamplingRows)(sample)) {
367
367
  throw new Error(`StandardSQL doesn't support sampling by rows only percent`);
368
368
  }
369
- else if ((0, model_1.isSamplingPercent)(sample)) {
369
+ else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
370
370
  return `(SELECT * FROM ${tableSQL} TABLESAMPLE SYSTEM (${sample.percent} PERCENT))`;
371
371
  }
372
372
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ export { Segment, isFilteredAliasedName, flattenQuery, expressionIsCalculation,
3
3
  export { HighlightType, MalloyTranslator, } from "./lang";
4
4
  export type { LogMessage, TranslateResponse } from "./lang";
5
5
  export { Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, Result, parseTableURI, QueryMaterializer, CSVWriter, JSONWriter, DataWriter, } from "./malloy";
6
- export type { Explore, Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, RunSQLOptions, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, } from "./malloy";
6
+ export type { Explore, Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, } from "./malloy";
7
+ export type { RunSQLOptions } from "./run_sql_options";
7
8
  export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from "./runtime_types";
8
9
  export type { Loggable } from "./malloy";
9
10
  export { toAsyncGenerator } from "./connection_utils";
package/dist/malloy.d.ts CHANGED
@@ -1,18 +1,15 @@
1
1
  /// <reference types="node" />
2
- import { InfoConnection } from ".";
2
+ import { RunSQLOptions } from "./run_sql_options";
3
3
  import { DocumentHighlight as DocumentHighlightDefinition, DocumentSymbol as DocumentSymbolDefinition, DocumentCompletion as DocumentCompletionDefinition, LogMessage, MalloyTranslator } from "./lang";
4
4
  import { DocumentHelpContext } from "./lang/parse-tree-walkers/document-help-context-walker";
5
5
  import { CompiledQuery, FieldBooleanDef, FieldDateDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterExpression, ModelDef, Query as InternalQuery, QueryData, QueryDataRow, QueryResult, StructDef, TurtleDef, SQLBlock, DocumentReference, DocumentPosition as ModelDocumentPosition, SearchIndexResult, SearchValueMapResult, NamedQuery, SQLBlockStructDef, FieldJSONDef } from "./model";
6
- import { LookupConnection, ModelString, ModelURL, QueryString, QueryURL, URLReader, Connection } from "./runtime_types";
6
+ import { LookupConnection, ModelString, ModelURL, QueryString, QueryURL, URLReader, Connection, InfoConnection } from "./runtime_types";
7
7
  export interface Loggable {
8
8
  debug: (message?: any, ...optionalParams: any[]) => void;
9
9
  info: (message?: any, ...optionalParams: any[]) => void;
10
10
  warn: (message?: any, ...optionalParams: any[]) => void;
11
11
  error: (message?: any, ...optionalParams: any[]) => void;
12
12
  }
13
- export interface RunSQLOptions {
14
- rowLimit?: number;
15
- }
16
13
  export declare class Malloy {
17
14
  static get version(): string;
18
15
  private static _log;
@@ -1,8 +1,7 @@
1
1
  import { Dialect, DialectFieldList } from "../dialect";
2
- import { FieldDef, FieldRef, FilterExpression, ModelDef, Query, QueryFieldDef, StructDef, StructRef, OrderBy, ResultMetadataDef, Expr, FieldFragment, AggregateFragment, CompiledQuery, FilterFragment, PipeSegment, TurtleDef, QuerySegment, Filtered, ParameterFragment, Parameter, JoinRelationship, DialectFragment, UngroupFragment, NamedQuery, AnalyticFragment } from "./malloy_types";
2
+ import { FieldDef, FieldRef, FilterExpression, ModelDef, Query, QueryFieldDef, StructDef, StructRef, OrderBy, ResultMetadataDef, Expr, FieldFragment, AggregateFragment, CompiledQuery, FilterFragment, PipeSegment, TurtleDef, QuerySegment, Filtered, ParameterFragment, Parameter, JoinRelationship, DialectFragment, UngroupFragment, NamedQuery, AnalyticFragment, ResultStructMetadataDef, SearchIndexResult } from "./malloy_types";
3
3
  import { AndChain } from "./utils";
4
- import { ResultStructMetadataDef, SearchIndexResult } from ".";
5
- import { Connection } from "..";
4
+ import { Connection } from "../runtime_types";
6
5
  interface TurtleDefPlus extends TurtleDef, Filtered {
7
6
  }
8
7
  interface OutputPipelinedSQL {
@@ -0,0 +1,3 @@
1
+ export interface RunSQLOptions {
2
+ rowLimit?: number;
3
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ //# sourceMappingURL=run_sql_options.js.map
@@ -1,5 +1,5 @@
1
- import { RunSQLOptions } from "./malloy";
2
- import { MalloyQueryData, QueryDataRow, SQLBlock, StructDef } from "./model";
1
+ import { RunSQLOptions } from "./run_sql_options";
2
+ import { MalloyQueryData, QueryDataRow, SQLBlock, StructDef } from "./model/malloy_types";
3
3
  /**
4
4
  * The contents of a Malloy query document.
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.22-dev230117165007",
3
+ "version": "0.0.22-dev230117200639",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",