@malloydata/render 0.0.119-dev240118211537 → 0.0.119-dev240123183113

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.
@@ -235,8 +235,8 @@
235
235
  "../malloy/dist/model/malloy_types.js"(exports) {
236
236
  "use strict";
237
237
  Object.defineProperty(exports, "__esModule", { value: true });
238
- exports.isMatrixOperation = exports.isIndexSegment = exports.isRawSegment = exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isPartialSegment = exports.isReduceSegment = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.FieldIsIntrinsic = exports.isCastType = exports.isAtomicFieldType = exports.isTimeFieldType = exports.hasExpression = exports.maxOfExpressionTypes = exports.maxExpressionType = exports.isExpressionTypeLEQ = exports.expressionIsAnalytic = exports.expressionIsCalculation = exports.expressionInvolvesAggregate = exports.expressionIsUngroupedAggregate = exports.expressionIsAggregate = exports.expressionIsScalar = exports.mkExpr = exports.isApplyFragment = exports.isApplyValue = exports.isParameterFragment = exports.isFieldFragment = exports.isSpreadFragment = exports.isSQLExpressionFragment = exports.isFunctionCallFragment = exports.isFunctionParameterFragment = exports.isUngroupFragment = exports.isAsymmetricFragment = exports.isAggregateFragment = exports.isDialectFragment = exports.isFilterFragment = exports.isOutputFieldFragment = exports.isFilteredAliasedName = exports.paramHasValue = exports.isConditionParameter = exports.isValueParameter = void 0;
239
- exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = exports.isMeasureLike = exports.getPhysicalFields = exports.getDimensions = exports.isPhysical = exports.isDimensional = exports.isAtomicField = exports.isTurtleDef = exports.getIdentifier = exports.isFieldStructDef = exports.isFieldTimeBased = exports.isFieldTypeDef = exports.isSQLBlockStruct = exports.mergeEvalSpaces = exports.isSQLFragment = exports.isJoinOn = void 0;
238
+ exports.isSamplingEnable = exports.isSamplingPercent = exports.isSamplingRows = exports.isQuerySegment = exports.isProjectSegment = exports.isPartialSegment = exports.isReduceSegment = exports.refIsStructDef = exports.isByExpression = exports.isByName = exports.ValueType = exports.isExtractUnit = exports.isTimestampUnit = exports.isDateUnit = exports.FieldIsIntrinsic = exports.isCastType = exports.isAtomicFieldType = exports.isTimeFieldType = exports.hasExpression = exports.maxOfExpressionTypes = exports.maxExpressionType = exports.isExpressionTypeLEQ = exports.expressionIsAnalytic = exports.expressionIsCalculation = exports.expressionInvolvesAggregate = exports.expressionIsUngroupedAggregate = exports.expressionIsAggregate = exports.expressionIsScalar = exports.mkExpr = exports.isApplyFragment = exports.isApplyValue = exports.isParameterFragment = exports.isSourceReferenceFragment = exports.isSqlStringFragment = exports.isFieldReferenceFragment = exports.isFieldFragment = exports.isSpreadFragment = exports.isSQLExpressionFragment = exports.isFunctionCallFragment = exports.isFunctionParameterFragment = exports.isUngroupFragment = exports.isAsymmetricFragment = exports.isAggregateFragment = exports.isDialectFragment = exports.isFilterFragment = exports.isOutputFieldFragment = exports.isFilteredAliasedName = exports.paramHasValue = exports.isConditionParameter = exports.isValueParameter = void 0;
239
+ exports.isValueDate = exports.isValueTimestamp = exports.isValueBoolean = exports.isValueNumber = exports.isValueString = exports.isMeasureLike = exports.getPhysicalFields = exports.getDimensions = exports.isPhysical = exports.isDimensional = exports.isAtomicField = exports.isTurtleDef = exports.getIdentifier = exports.isFieldStructDef = exports.isFieldTimeBased = exports.isFieldTypeDef = exports.isSQLBlockStruct = exports.mergeEvalSpaces = exports.isSQLFragment = exports.isJoinOn = exports.isMatrixOperation = exports.isIndexSegment = exports.isRawSegment = void 0;
240
240
  function isValueParameter(p3) {
241
241
  return p3.value !== void 0;
242
242
  }
@@ -303,6 +303,18 @@
303
303
  return (f4 === null || f4 === void 0 ? void 0 : f4.type) === "field";
304
304
  }
305
305
  exports.isFieldFragment = isFieldFragment;
306
+ function isFieldReferenceFragment(f4) {
307
+ return (f4 === null || f4 === void 0 ? void 0 : f4.type) === "field-reference";
308
+ }
309
+ exports.isFieldReferenceFragment = isFieldReferenceFragment;
310
+ function isSqlStringFragment(f4) {
311
+ return (f4 === null || f4 === void 0 ? void 0 : f4.type) === "sql-string";
312
+ }
313
+ exports.isSqlStringFragment = isSqlStringFragment;
314
+ function isSourceReferenceFragment(f4) {
315
+ return (f4 === null || f4 === void 0 ? void 0 : f4.type) === "source-reference";
316
+ }
317
+ exports.isSourceReferenceFragment = isSourceReferenceFragment;
306
318
  function isParameterFragment(f4) {
307
319
  return (f4 === null || f4 === void 0 ? void 0 : f4.type) === "parameter";
308
320
  }
@@ -1349,6 +1361,11 @@
1349
1361
  case "parameter":
1350
1362
  case "outputField":
1351
1363
  return fragment2;
1364
+ case "sql-string":
1365
+ return {
1366
+ ...fragment2,
1367
+ e: exprMap(fragment2.e, func)
1368
+ };
1352
1369
  case "function_call":
1353
1370
  return {
1354
1371
  ...fragment2,
@@ -1455,6 +1472,11 @@
1455
1472
  ...fragment,
1456
1473
  args: fragment.args.map((arg) => exprWalk(arg, func))
1457
1474
  };
1475
+ case "sql-string":
1476
+ return {
1477
+ ...fragment,
1478
+ e: exprWalk(fragment.e, func)
1479
+ };
1458
1480
  case "filterExpression":
1459
1481
  return {
1460
1482
  ...fragment,
@@ -2433,6 +2455,51 @@
2433
2455
  }
2434
2456
  });
2435
2457
 
2458
+ // ../malloy/dist/dialect/functions/sql.js
2459
+ var require_sql = __commonJS({
2460
+ "../malloy/dist/dialect/functions/sql.js"(exports) {
2461
+ "use strict";
2462
+ Object.defineProperty(exports, "__esModule", { value: true });
2463
+ exports.fnSqlBoolean = exports.fnSqlTimestamp = exports.fnSqlDate = exports.fnSqlString = exports.fnSqlNumber = void 0;
2464
+ var util_1 = require_util();
2465
+ function fnSqlNumber() {
2466
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.literal)((0, util_1.maxScalar)("string")));
2467
+ return [
2468
+ (0, util_1.overload)((0, util_1.minScalar)("number"), [value3.param], [{ type: "sql-string", e: [value3.arg] }])
2469
+ ];
2470
+ }
2471
+ exports.fnSqlNumber = fnSqlNumber;
2472
+ function fnSqlString() {
2473
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.literal)((0, util_1.maxScalar)("string")));
2474
+ return [
2475
+ (0, util_1.overload)((0, util_1.minScalar)("string"), [value3.param], [{ type: "sql-string", e: [value3.arg] }])
2476
+ ];
2477
+ }
2478
+ exports.fnSqlString = fnSqlString;
2479
+ function fnSqlDate() {
2480
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.literal)((0, util_1.maxScalar)("string")));
2481
+ return [
2482
+ (0, util_1.overload)((0, util_1.minScalar)("date"), [value3.param], [{ type: "sql-string", e: [value3.arg] }])
2483
+ ];
2484
+ }
2485
+ exports.fnSqlDate = fnSqlDate;
2486
+ function fnSqlTimestamp() {
2487
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.literal)((0, util_1.maxScalar)("string")));
2488
+ return [
2489
+ (0, util_1.overload)((0, util_1.minScalar)("timestamp"), [value3.param], [{ type: "sql-string", e: [value3.arg] }])
2490
+ ];
2491
+ }
2492
+ exports.fnSqlTimestamp = fnSqlTimestamp;
2493
+ function fnSqlBoolean() {
2494
+ const value3 = (0, util_1.makeParam)("value", (0, util_1.literal)((0, util_1.maxScalar)("string")));
2495
+ return [
2496
+ (0, util_1.overload)((0, util_1.minScalar)("boolean"), [value3.param], [{ type: "sql-string", e: [value3.arg] }])
2497
+ ];
2498
+ }
2499
+ exports.fnSqlBoolean = fnSqlBoolean;
2500
+ }
2501
+ });
2502
+
2436
2503
  // ../malloy/dist/dialect/functions/all_functions.js
2437
2504
  var require_all_functions = __commonJS({
2438
2505
  "../malloy/dist/dialect/functions/all_functions.js"(exports) {
@@ -2476,6 +2543,7 @@
2476
2543
  var avg_moving_1 = require_avg_moving();
2477
2544
  var function_map_1 = require_function_map();
2478
2545
  var coalesce_1 = require_coalesce();
2546
+ var sql_1 = require_sql();
2479
2547
  exports.FUNCTIONS = new function_map_1.FunctionMap();
2480
2548
  exports.FUNCTIONS.add("concat", concat_1.fnConcat);
2481
2549
  exports.FUNCTIONS.add("round", round_1.fnRound);
@@ -2538,6 +2606,11 @@
2538
2606
  exports.FUNCTIONS.add("max_window", sum_min_max_window_1.fnMaxWindow);
2539
2607
  exports.FUNCTIONS.add("sum_window", sum_min_max_window_1.fnSumWindow);
2540
2608
  exports.FUNCTIONS.add("avg_moving", avg_moving_1.fnAvgRolling);
2609
+ exports.FUNCTIONS.add("sql_number", sql_1.fnSqlNumber);
2610
+ exports.FUNCTIONS.add("sql_string", sql_1.fnSqlString);
2611
+ exports.FUNCTIONS.add("sql_date", sql_1.fnSqlDate);
2612
+ exports.FUNCTIONS.add("sql_timestamp", sql_1.fnSqlTimestamp);
2613
+ exports.FUNCTIONS.add("sql_boolean", sql_1.fnSqlBoolean);
2541
2614
  exports.FUNCTIONS.seal();
2542
2615
  }
2543
2616
  });
@@ -5059,6 +5132,19 @@ ${(0, utils_1.indent)(sql)})
5059
5132
  generateDialect(resultSet, context3, expr2, state) {
5060
5133
  return this.generateExpressionFromExpr(resultSet, context3, context3.dialect.dialectExpr(resultSet.getQueryInfo(), expr2), state);
5061
5134
  }
5135
+ generateFieldReference(resultSet, context3, expr2, state) {
5136
+ return this.generateFieldFragment(resultSet, context3, { type: "field", path: expr2.path }, state);
5137
+ }
5138
+ generateSqlString(resultSet, context3, expr2, state) {
5139
+ return expr2.e.map((part) => typeof part === "string" ? part : this.generateExpressionFromExpr(resultSet, context3, [part], state)).join("");
5140
+ }
5141
+ generateSourceReference(resultSet, context3, expr2) {
5142
+ if (expr2.path === void 0) {
5143
+ return context3.getSQLIdentifier();
5144
+ } else {
5145
+ return context3.getFieldByName(expr2.path).getIdentifier();
5146
+ }
5147
+ }
5062
5148
  getAnalyticPartitions(resultStruct) {
5063
5149
  const ret = [];
5064
5150
  let p3 = resultStruct.parent;
@@ -5192,6 +5278,12 @@ ${(0, utils_1.indent)(sql)})
5192
5278
  s8 += this.generateSpread(resultSet, context3, expr2, state);
5193
5279
  } else if (expr2.type === "dialect") {
5194
5280
  s8 += this.generateDialect(resultSet, context3, expr2, state);
5281
+ } else if (expr2.type === "sql-string") {
5282
+ s8 += this.generateSqlString(resultSet, context3, expr2, state);
5283
+ } else if (expr2.type === "source-reference") {
5284
+ s8 += this.generateSourceReference(resultSet, context3, expr2);
5285
+ } else if (expr2.type === "field-reference") {
5286
+ s8 += this.generateFieldReference(resultSet, context3, expr2, state);
5195
5287
  } else {
5196
5288
  throw new Error(`Internal Error: Unknown expression fragment ${JSON.stringify(expr2, void 0, 2)}`);
5197
5289
  }
@@ -55177,7 +55269,7 @@ QUERY: ${(0, util_1.inspect)(opDesc, { breakLength: 72, depth: Infinity })}`);
55177
55269
  this.log(`Cannot call function ${this.name}(${argExprs.map((e12) => e12.dataType).join(", ")}) with source`);
55178
55270
  return (0, ast_utils_1.errorFor)("cannot call with source");
55179
55271
  }
55180
- const funcCall = [
55272
+ let funcCall = [
55181
55273
  {
55182
55274
  type: "function_call",
55183
55275
  overload,
@@ -55186,6 +55278,36 @@ QUERY: ${(0, util_1.inspect)(opDesc, { breakLength: 72, depth: Infinity })}`);
55186
55278
  structPath
55187
55279
  }
55188
55280
  ];
55281
+ if ([
55282
+ "sql_number",
55283
+ "sql_string",
55284
+ "sql_date",
55285
+ "sql_timestamp",
55286
+ "sql_boolean"
55287
+ ].includes(func.name)) {
55288
+ if (!this.inExperiment("sql_functions", true)) {
55289
+ return (0, ast_utils_1.errorFor)(`Cannot use sql_function \`${func.name}\`; use \`sql_functions\` experiment to enable this behavior`);
55290
+ }
55291
+ const str = argExprs[0].value;
55292
+ if (str.length !== 1 || typeof str[0] === "string" || str[0].type !== "dialect" || str[0].function !== "stringLiteral") {
55293
+ this.log(`Invalid string literal for \`${func.name}\``);
55294
+ } else {
55295
+ const literal = str[0].literal;
55296
+ const parts = parseSQLInterpolation(literal);
55297
+ const unsupportedInterpolations = parts.filter((part) => part.type === "interpolation" && part.name.includes(".")).map((unsupportedPart) => unsupportedPart.type === "interpolation" ? `\${${unsupportedPart.name}}` : `\${${unsupportedPart.value}}`);
55298
+ if (unsupportedInterpolations.length > 0) {
55299
+ const unsupportedInterpolationMsg = unsupportedInterpolations.length === 1 ? `'.' paths are not yet supported in sql interpolations, found ${unsupportedInterpolations.at(0)}` : `'.' paths are not yet supported in sql interpolations, found [${unsupportedInterpolations.join(", ")}]`;
55300
+ this.log(unsupportedInterpolationMsg);
55301
+ return (0, ast_utils_1.errorFor)(`${unsupportedInterpolationMsg}. See LookML \${...} documentation at https://cloud.google.com/looker/docs/reference/param-field-sql#sql_for_dimensions`);
55302
+ }
55303
+ funcCall = [
55304
+ {
55305
+ type: "sql-string",
55306
+ e: parts.map((part) => part.type === "string" ? part.value : part.name === "TABLE" ? { type: "source-reference" } : { type: "field-reference", path: part.name })
55307
+ }
55308
+ ];
55309
+ }
55310
+ }
55189
55311
  if (type3.dataType === "any") {
55190
55312
  this.log(`Invalid return type ${type3.dataType} for function '${this.name}'`);
55191
55313
  return (0, ast_utils_1.errorFor)("invalid return type");
@@ -55278,6 +55400,32 @@ QUERY: ${(0, util_1.inspect)(opDesc, { breakLength: 72, depth: Infinity })}`);
55278
55400
  }
55279
55401
  }
55280
55402
  }
55403
+ function parseSQLInterpolation(template) {
55404
+ const parts = [];
55405
+ let remaining = template;
55406
+ while (remaining.length) {
55407
+ const nextInterp = remaining.indexOf("${");
55408
+ if (nextInterp === -1) {
55409
+ parts.push({ type: "string", value: remaining });
55410
+ break;
55411
+ } else {
55412
+ const interpEnd = remaining.slice(nextInterp).indexOf("}");
55413
+ if (interpEnd === -1) {
55414
+ parts.push({ type: "string", value: remaining });
55415
+ break;
55416
+ }
55417
+ if (nextInterp > 0) {
55418
+ parts.push({ type: "string", value: remaining.slice(0, nextInterp) });
55419
+ }
55420
+ parts.push({
55421
+ type: "interpolation",
55422
+ name: remaining.slice(nextInterp + 2, interpEnd + nextInterp)
55423
+ });
55424
+ remaining = remaining.slice(interpEnd + nextInterp + 1);
55425
+ }
55426
+ }
55427
+ return parts;
55428
+ }
55281
55429
  }
55282
55430
  });
55283
55431
 
@@ -135527,12 +135675,12 @@ ${errText}`, errors);
135527
135675
  const fieldMeta = metadata2.fields[fieldKey2];
135528
135676
  let width2 = 0;
135529
135677
  if (f4.isAtomicField()) {
135530
- const font2 = `12px Inter, sans-serif`;
135678
+ const font2 = "12px Inter, sans-serif";
135531
135679
  const titleWidth = getTextWidth(f4.name, font2);
135532
135680
  if (f4.isAtomicField() && f4.isString()) {
135533
135681
  width2 = Math.max(getTextWidth(fieldMeta.maxString, font2), titleWidth) + COLUMN_BUFFER;
135534
135682
  } else if (f4.isAtomicField() && f4.isNumber()) {
135535
- const formattedValue = renderNumericField(f4, fieldMeta.max);
135683
+ const formattedValue = fieldMeta.max === null ? "\u2205" : renderNumericField(f4, fieldMeta.max);
135536
135684
  width2 = Math.max(getTextWidth(formattedValue, font2), titleWidth) + COLUMN_BUFFER;
135537
135685
  } else
135538
135686
  width2 = 130;