@holistics/cli-core 2.5.5 → 2.5.6

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.
Files changed (2) hide show
  1. package/dist/commands.js +517 -287
  2. package/package.json +1 -1
package/dist/commands.js CHANGED
@@ -24022,7 +24022,7 @@ var require_dist4 = __commonJS((exports2) => {
24022
24022
  exports2.default = deferred;
24023
24023
  });
24024
24024
  // package.json
24025
- var version = "2.5.5";
24025
+ var version = "2.5.6";
24026
24026
 
24027
24027
  // ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
24028
24028
  class CommanderError extends Error {
@@ -105272,7 +105272,7 @@ var TypeClass = /* @__PURE__ */ function(e9) {
105272
105272
  return e9.SCALAR = "scalar", e9.FIELD = "field", e9.ROW = "row", e9.TABLE = "table", e9.RELATIONSHIP = "relationship", e9.ARRAY = "array", e9.GROUPING_SET = "grouping_set", e9.FUNCTION = "function", e9.UNION = "union", e9.TYPE_PARAMETER = "type_parameter", e9.TYPE_CLASS = "type_class", e9.USER_ATTRIBUTE = "user_attribute", e9.MODULE = "module", e9.ERROR_ANY = "error_any", e9.NULL = "null", e9;
105273
105273
  }({});
105274
105274
  var ErrorCode = /* @__PURE__ */ function(e9) {
105275
- return e9[e9.UNEXPECTED_ERROR = 0] = "UNEXPECTED_ERROR", e9[e9.SYNTAX_ERROR = 1] = "SYNTAX_ERROR", e9[e9.INVALID_EXPRESSION_0 = 100] = "INVALID_EXPRESSION_0", e9[e9.RELATIONSHIP_NOT_FOUND_0 = 101] = "RELATIONSHIP_NOT_FOUND_0", e9[e9.MODEL_0_NOT_FOUND = 102] = "MODEL_0_NOT_FOUND", e9[e9.FIELD_0_NOT_FOUND_IN_MODEL_1 = 103] = "FIELD_0_NOT_FOUND_IN_MODEL_1", e9[e9.FANOUT_ON_0_FROM_1 = 104] = "FANOUT_ON_0_FROM_1", e9[e9.MODEL_IN_AQL_FIELD_NOT_FOUND = 105] = "MODEL_IN_AQL_FIELD_NOT_FOUND", e9[e9.RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1 = 106] = "RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1", e9[e9.INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2 = 200] = "INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2", e9[e9.INVALID_ARGUMENT_TYPE = 201] = "INVALID_ARGUMENT_TYPE", e9[e9.UNKNOWN_IDENTIFIER_0 = 202] = "UNKNOWN_IDENTIFIER_0", e9[e9.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1 = 203] = "UNSUPPORTED_OPERATOR_0_FOR_TYPE_1", e9[e9.EXPECTED_0_FOUND_1 = 204] = "EXPECTED_0_FOUND_1", e9[e9.NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0 = 205] = "NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0", e9[e9.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0 = 206] = "EXPECTED_SCALAR_LIKE_TYPE_FOUND_0", e9[e9.NO_MATCHING_SIGNATURE_FOR_FUNCTION_0 = 207] = "NO_MATCHING_SIGNATURE_FOR_FUNCTION_0", e9[e9.INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1 = 208] = "INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1", e9[e9.DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0 = 209] = "DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0", e9[e9.CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL = 210] = "CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL", e9[e9.RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION = 211] = "RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION", e9[e9.INVALID_METRIC_DEFINITION_0_IN_DATASET_1 = 212] = "INVALID_METRIC_DEFINITION_0_IN_DATASET_1", e9[e9.MEMBER_0_NOT_FOUND_IN_MODULE_1 = 213] = "MEMBER_0_NOT_FOUND_IN_MODULE_1", e9[e9.INVALID_BIZ_CAL_FUNCTION_0 = 214] = "INVALID_BIZ_CAL_FUNCTION_0", e9[e9.USER_ATTRIBUTE_0_NOT_FOUND = 215] = "USER_ATTRIBUTE_0_NOT_FOUND", e9[e9.INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES = 216] = "INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES", e9[e9.TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS = 217] = "TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS", e9[e9.INVALID_ROW_LEVEL_PERMISSION = 218] = "INVALID_ROW_LEVEL_PERMISSION", e9[e9.PERMISSION_RULE_VIOLATION_ERROR = 219] = "PERMISSION_RULE_VIOLATION_ERROR", e9[e9.UNSUPPORTED_BEHAVIOR_0 = 220] = "UNSUPPORTED_BEHAVIOR_0", e9[e9.POTENTIAL_DB_RUNTIME_ERROR_0 = 221] = "POTENTIAL_DB_RUNTIME_ERROR_0", e9[e9.AMBIGUOUS_RELATIONSHIP_0 = 222] = "AMBIGUOUS_RELATIONSHIP_0", e9[e9.QUERY_PARAM_UNSUPPORTED_OPERATOR = 223] = "QUERY_PARAM_UNSUPPORTED_OPERATOR", e9[e9.QUERY_PARAM_INVALID_PARAM_INPUT = 224] = "QUERY_PARAM_INVALID_PARAM_INPUT", e9[e9.ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0 = 225] = "ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0", e9[e9.ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS = 226] = "ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS", e9[e9.CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0 = 227] = "CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0", e9[e9.INVALID_FIELD_DECLARATION = 228] = "INVALID_FIELD_DECLARATION", e9[e9.CANNOT_REDECLARE_FIELD = 229] = "CANNOT_REDECLARE_FIELD", e9[e9.ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE = 230] = "ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE", e9[e9.CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0 = 231] = "CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0", e9[e9.INVALID_WINDOW_FRAME_0 = 232] = "INVALID_WINDOW_FRAME_0", e9[e9.CYLIC_FIELD_DEPENDENCY_DETECTED_0 = 233] = "CYLIC_FIELD_DEPENDENCY_DETECTED_0", e9[e9.INVALID_SHORTHAND_AGGREGATION_0 = 234] = "INVALID_SHORTHAND_AGGREGATION_0", e9[e9.UNSUPPORTED_DATE_UNIT_0 = 235] = "UNSUPPORTED_DATE_UNIT_0", e9[e9.INVALID_CONDITIONAL_EXPRESSION_IN_0 = 236] = "INVALID_CONDITIONAL_EXPRESSION_IN_0", e9[e9.UNKNOWN_FUNCTION_0 = 237] = "UNKNOWN_FUNCTION_0", e9[e9.CANNOT_MATCH_ROW_WITH_TABLE_0 = 238] = "CANNOT_MATCH_ROW_WITH_TABLE_0", e9[e9.DUPLICATE_FIELD_NAME_0 = 239] = "DUPLICATE_FIELD_NAME_0", e9[e9.FUNCTION_0_EXPECT_1_GOT_2 = 240] = "FUNCTION_0_EXPECT_1_GOT_2", e9[e9.NESTED_WINDOW_FUNCTION = 241] = "NESTED_WINDOW_FUNCTION", e9[e9.FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS = 242] = "FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS", e9[e9.REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED = 243] = "REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED", e9[e9.INVALID_TABLE_CONDITION_0 = 244] = "INVALID_TABLE_CONDITION_0", e9[e9.INVALID_DATETIME_LITERAL_0 = 245] = "INVALID_DATETIME_LITERAL_0", e9[e9.NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1 = 246] = "NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1", e9[e9.RECURSIVE_AQL_FUNCTION_0_CHAIN_1 = 247] = "RECURSIVE_AQL_FUNCTION_0_CHAIN_1", e9[e9.INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2 = 248] = "INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2", e9[e9.INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2 = 249] = "INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2", e9[e9.AQL_0_1_SHADOWS_BUILTIN = 250] = "AQL_0_1_SHADOWS_BUILTIN", e9[e9.RELATIONSHIP_FILTER_ON_0_READS_1 = 251] = "RELATIONSHIP_FILTER_ON_0_READS_1", e9[e9.RELATIONSHIP_MATCH_READS_0 = 252] = "RELATIONSHIP_MATCH_READS_0", e9[e9.RELATIONSHIP_MATCH_MISSES_0 = 253] = "RELATIONSHIP_MATCH_MISSES_0", e9[e9.AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3 = 254] = "AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3", e9[e9.SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER = 300] = "SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER", e9;
105275
+ return e9[e9.UNEXPECTED_ERROR = 0] = "UNEXPECTED_ERROR", e9[e9.SYNTAX_ERROR = 1] = "SYNTAX_ERROR", e9[e9.INVALID_EXPRESSION_0 = 100] = "INVALID_EXPRESSION_0", e9[e9.RELATIONSHIP_NOT_FOUND_0 = 101] = "RELATIONSHIP_NOT_FOUND_0", e9[e9.MODEL_0_NOT_FOUND = 102] = "MODEL_0_NOT_FOUND", e9[e9.FIELD_0_NOT_FOUND_IN_MODEL_1 = 103] = "FIELD_0_NOT_FOUND_IN_MODEL_1", e9[e9.FANOUT_ON_0_FROM_1 = 104] = "FANOUT_ON_0_FROM_1", e9[e9.MODEL_IN_AQL_FIELD_NOT_FOUND = 105] = "MODEL_IN_AQL_FIELD_NOT_FOUND", e9[e9.RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1 = 106] = "RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1", e9[e9.INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2 = 200] = "INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2", e9[e9.INVALID_ARGUMENT_TYPE = 201] = "INVALID_ARGUMENT_TYPE", e9[e9.UNKNOWN_IDENTIFIER_0 = 202] = "UNKNOWN_IDENTIFIER_0", e9[e9.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1 = 203] = "UNSUPPORTED_OPERATOR_0_FOR_TYPE_1", e9[e9.EXPECTED_0_FOUND_1 = 204] = "EXPECTED_0_FOUND_1", e9[e9.NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0 = 205] = "NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0", e9[e9.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0 = 206] = "EXPECTED_SCALAR_LIKE_TYPE_FOUND_0", e9[e9.NO_MATCHING_SIGNATURE_FOR_FUNCTION_0 = 207] = "NO_MATCHING_SIGNATURE_FOR_FUNCTION_0", e9[e9.INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1 = 208] = "INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1", e9[e9.DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0 = 209] = "DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0", e9[e9.CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL = 210] = "CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL", e9[e9.RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION = 211] = "RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION", e9[e9.INVALID_METRIC_DEFINITION_0_IN_DATASET_1 = 212] = "INVALID_METRIC_DEFINITION_0_IN_DATASET_1", e9[e9.MEMBER_0_NOT_FOUND_IN_MODULE_1 = 213] = "MEMBER_0_NOT_FOUND_IN_MODULE_1", e9[e9.INVALID_BIZ_CAL_FUNCTION_0 = 214] = "INVALID_BIZ_CAL_FUNCTION_0", e9[e9.USER_ATTRIBUTE_0_NOT_FOUND = 215] = "USER_ATTRIBUTE_0_NOT_FOUND", e9[e9.INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES = 216] = "INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES", e9[e9.TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS = 217] = "TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS", e9[e9.INVALID_ROW_LEVEL_PERMISSION = 218] = "INVALID_ROW_LEVEL_PERMISSION", e9[e9.PERMISSION_RULE_VIOLATION_ERROR = 219] = "PERMISSION_RULE_VIOLATION_ERROR", e9[e9.UNSUPPORTED_BEHAVIOR_0 = 220] = "UNSUPPORTED_BEHAVIOR_0", e9[e9.POTENTIAL_DB_RUNTIME_ERROR_0 = 221] = "POTENTIAL_DB_RUNTIME_ERROR_0", e9[e9.AMBIGUOUS_RELATIONSHIP_0 = 222] = "AMBIGUOUS_RELATIONSHIP_0", e9[e9.QUERY_PARAM_UNSUPPORTED_OPERATOR = 223] = "QUERY_PARAM_UNSUPPORTED_OPERATOR", e9[e9.QUERY_PARAM_INVALID_PARAM_INPUT = 224] = "QUERY_PARAM_INVALID_PARAM_INPUT", e9[e9.ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0 = 225] = "ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0", e9[e9.ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS = 226] = "ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS", e9[e9.CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0 = 227] = "CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0", e9[e9.INVALID_FIELD_DECLARATION = 228] = "INVALID_FIELD_DECLARATION", e9[e9.CANNOT_REDECLARE_FIELD = 229] = "CANNOT_REDECLARE_FIELD", e9[e9.ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE = 230] = "ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE", e9[e9.CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0 = 231] = "CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0", e9[e9.INVALID_WINDOW_FRAME_0 = 232] = "INVALID_WINDOW_FRAME_0", e9[e9.CYLIC_FIELD_DEPENDENCY_DETECTED_0 = 233] = "CYLIC_FIELD_DEPENDENCY_DETECTED_0", e9[e9.INVALID_SHORTHAND_AGGREGATION_0 = 234] = "INVALID_SHORTHAND_AGGREGATION_0", e9[e9.UNSUPPORTED_DATE_UNIT_0 = 235] = "UNSUPPORTED_DATE_UNIT_0", e9[e9.INVALID_CONDITIONAL_EXPRESSION_IN_0 = 236] = "INVALID_CONDITIONAL_EXPRESSION_IN_0", e9[e9.UNKNOWN_FUNCTION_0 = 237] = "UNKNOWN_FUNCTION_0", e9[e9.CANNOT_MATCH_ROW_WITH_TABLE_0 = 238] = "CANNOT_MATCH_ROW_WITH_TABLE_0", e9[e9.DUPLICATE_FIELD_NAME_0 = 239] = "DUPLICATE_FIELD_NAME_0", e9[e9.FUNCTION_0_EXPECT_1_GOT_2 = 240] = "FUNCTION_0_EXPECT_1_GOT_2", e9[e9.NESTED_WINDOW_FUNCTION = 241] = "NESTED_WINDOW_FUNCTION", e9[e9.FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS = 242] = "FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS", e9[e9.REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED = 243] = "REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED", e9[e9.INVALID_TABLE_CONDITION_0 = 244] = "INVALID_TABLE_CONDITION_0", e9[e9.INVALID_DATETIME_LITERAL_0 = 245] = "INVALID_DATETIME_LITERAL_0", e9[e9.NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1 = 246] = "NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1", e9[e9.RECURSIVE_AQL_FUNCTION_0_CHAIN_1 = 247] = "RECURSIVE_AQL_FUNCTION_0_CHAIN_1", e9[e9.INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2 = 248] = "INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2", e9[e9.INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2 = 249] = "INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2", e9[e9.AQL_0_1_SHADOWS_BUILTIN = 250] = "AQL_0_1_SHADOWS_BUILTIN", e9[e9.RELATIONSHIP_FILTER_ON_0_READS_1 = 251] = "RELATIONSHIP_FILTER_ON_0_READS_1", e9[e9.RELATIONSHIP_MATCH_READS_0 = 252] = "RELATIONSHIP_MATCH_READS_0", e9[e9.RELATIONSHIP_MATCH_MISSES_0 = 253] = "RELATIONSHIP_MATCH_MISSES_0", e9[e9.AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3 = 254] = "AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3", e9[e9.OPERATOR_0_ON_PARAM_1 = 255] = "OPERATOR_0_ON_PARAM_1", e9[e9.SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER = 300] = "SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER", e9;
105276
105276
  }({});
105277
105277
  var isFieldTrace = (e9) => e9.type !== "udf";
105278
105278
  var isUdfTrace = (e9) => e9.type === "udf";
@@ -108060,6 +108060,7 @@ var errorMessages = {
108060
108060
  [ErrorCode.INVALID_ARGUMENT_TYPE]: "Invalid argument type.",
108061
108061
  [ErrorCode.UNKNOWN_IDENTIFIER_0]: "Unknown identifier `{0}` is not defined.",
108062
108062
  [ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1]: "Unsupported operator `{0}` for type `{1}`.",
108063
+ [ErrorCode.OPERATOR_0_ON_PARAM_1]: "Param `{1}` holds a list of values, so operator `{0}` cannot use it directly. To read it, use `first({1})` for the first value, or `in {1}` to match any value.",
108063
108064
  [ErrorCode.EXPECTED_0_FOUND_1]: "Expected `{0}`, found `{1}`.",
108064
108065
  [ErrorCode.FUNCTION_0_EXPECT_1_GOT_2]: "The `{0}` function expects `{1}`, but got `{2}` instead. Please update the input or use another function.",
108065
108066
  [ErrorCode.NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0]: "Named expression expects a field or scalar value, found `{0}`",
@@ -108122,7 +108123,7 @@ Complex conditions:
108122
108123
  [ErrorCode.RELATIONSHIP_MATCH_MISSES_0]: "A relationship `match` must read columns of both models, but it never reads `{0}`."
108123
108124
  };
108124
108125
  function createError(e9, t, n, r3, i, a, s3) {
108125
- let c3 = `${errorMessages[e9]} ${n || ""}`.replace("{0}", u(r3)).replace("{1}", u(i)).replace("{2}", u(a)).replace("{3}", u(s3));
108126
+ let c3 = `${errorMessages[e9]} ${n || ""}`.replace(/\{0\}/g, () => u(r3)).replace(/\{1\}/g, () => u(i)).replace(/\{2\}/g, () => u(a)).replace(/\{3\}/g, () => u(s3));
108126
108127
  (e9 === ErrorCode.EXPECTED_0_FOUND_1 && (u(r3) === "NamedField" || u(r3).match(/Union\(.*NamedField.*\)/)) || e9 === ErrorCode.FUNCTION_0_EXPECT_1_GOT_2 && (u(i) === "NamedField" || u(i).match(/Union\(.*NamedField.*\)/))) && (c3 = "Cannot infer a name for this field. Please provide an explicit name for this field.");
108127
108128
  let l = SyntaxError(String(c3));
108128
108129
  return l.args = [
@@ -119697,7 +119698,9 @@ function checkRowLevelExpression(e10, t, n) {
119697
119698
  function u(t3, n3) {
119698
119699
  e10.checkExpression(t3.right, n3);
119699
119700
  let r4 = e10.getTypeFromNode(t3.right);
119700
- if (isScalarLikeType(r4)) {
119701
+ if (isTableType(r4) && r4.param)
119702
+ e10.addError(t3.right, ErrorCode.OPERATOR_0_ON_PARAM_1, t3.operator.loc.source, r4.param);
119703
+ else if (isScalarLikeType(r4)) {
119701
119704
  let n4 = getScalarType(r4), i3 = t3.operator.kind, a3;
119702
119705
  if (n4 === numberType$1 && i3 === Kind.MINUS ? a3 = numberType$1 : isAssignable$1(e10, n4, truefalseType$1) && (i3 === Kind.NOT_KEYWORD || i3 === Kind.EXCLAMATION) && (a3 = truefalseType$1), a3) {
119703
119706
  if (isFieldType(r4)) {
@@ -119715,7 +119718,21 @@ function checkRowLevelExpression(e10, t, n) {
119715
119718
  }
119716
119719
  function f(t3, n3) {
119717
119720
  e10.checkExpression(t3.left, n3), e10.checkExpression(t3.right, n3);
119718
- let r4 = e10.getTypeFromNode(t3.left), i3 = e10.getTypeFromNode(t3.right), a3 = isFieldType(r4) && r4.hasWindowFunction || isFieldType(i3) && i3.hasWindowFunction;
119721
+ let r4 = e10.getTypeFromNode(t3.left), i3 = e10.getTypeFromNode(t3.right), a3 = isFieldType(r4) && r4.hasWindowFunction || isFieldType(i3) && i3.hasWindowFunction, s4 = t3.operator.kind === Kind.IN_KEYWORD ? [{
119722
+ expr: t3.left,
119723
+ type: r4
119724
+ }] : [{
119725
+ expr: t3.left,
119726
+ type: r4
119727
+ }, {
119728
+ expr: t3.right,
119729
+ type: i3
119730
+ }];
119731
+ for (let { expr: n4, type: r5 } of s4)
119732
+ if (isTableType(r5) && r5.param) {
119733
+ e10.addError(n4, ErrorCode.OPERATOR_0_ON_PARAM_1, t3.operator.loc.source, r5.param);
119734
+ return;
119735
+ }
119719
119736
  if (isTableType(r4))
119720
119737
  e10.addError(t3.left, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, t3.operator.loc.source, "Table");
119721
119738
  else if (isRowType(r4))
@@ -119728,14 +119745,14 @@ function checkRowLevelExpression(e10, t, n) {
119728
119745
  e10.addError(t3, ErrorCode.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0, r4);
119729
119746
  return;
119730
119747
  }
119731
- let s4;
119748
+ let s5;
119732
119749
  if (isTableType(i3)) {
119733
119750
  if (isTableLiteral(t3.right) && i3.rowType.columns.length > 1) {
119734
119751
  e10.addError(t3.right, ErrorCode.EXPECTED_0_FOUND_1, "Table Literal with one column", i3);
119735
119752
  return;
119736
119753
  }
119737
119754
  if (isTableLiteral(t3.right) || i3.isLiteral)
119738
- s4 = i3.rowType.columns[0]?.type || getScalarType(r4);
119755
+ s5 = i3.rowType.columns[0]?.type || getScalarType(r4);
119739
119756
  else if (isFieldType(r4) && r4.subClass === "dimension" && t3.operator.kind === Kind.IN_KEYWORD) {
119740
119757
  let n5 = r4, a4 = i3.rowType.columns.some((e11) => e11.origin && n5.origin && refEq(e11.origin, n5.origin)), c5 = i3.rowType.columns.length === 1 && isAssignable$1(e10, n5.type, i3.rowType.columns[0].type);
119741
119758
  if (i3.name) {
@@ -119743,7 +119760,7 @@ function checkRowLevelExpression(e10, t, n) {
119743
119760
  return;
119744
119761
  }
119745
119762
  if (a4 || c5)
119746
- s4 = getScalarType(r4);
119763
+ s5 = getScalarType(r4);
119747
119764
  else {
119748
119765
  e10.addError(t3.right, ErrorCode.EXPECTED_0_FOUND_1, `Table that includes the \`${r4.fieldName}\` dimension`, i3);
119749
119766
  return;
@@ -119753,9 +119770,9 @@ function checkRowLevelExpression(e10, t, n) {
119753
119770
  return;
119754
119771
  }
119755
119772
  } else
119756
- s4 = isNullType(i3) ? n4 : getScalarType(i3);
119773
+ s5 = isNullType(i3) ? n4 : getScalarType(i3);
119757
119774
  let c4 = t3.operator.kind;
119758
- if (sqlTypeEquivalent(n4.sqlType, s4.sqlType)) {
119775
+ if (sqlTypeEquivalent(n4.sqlType, s5.sqlType)) {
119759
119776
  if (isTableType(i3) && c4 !== Kind.IN_KEYWORD || !isTableType(i3) && !isUserAttributeType(i3) && c4 === Kind.IN_KEYWORD) {
119760
119777
  e10.addError(t3.operator, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, i3);
119761
119778
  return;
@@ -119800,26 +119817,26 @@ function checkRowLevelExpression(e10, t, n) {
119800
119817
  default:
119801
119818
  e10.addError(t3, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, n4);
119802
119819
  }
119803
- } else if (isAssignable$1(e10, n4, datetimeType$1) && isAssignable$1(e10, s4, durationType$1)) {
119820
+ } else if (isAssignable$1(e10, n4, datetimeType$1) && isAssignable$1(e10, s5, durationType$1)) {
119804
119821
  if (c4 === Kind.PLUS || c4 === Kind.MINUS) {
119805
119822
  let r5 = createFieldType$1("", n4, undefined);
119806
119823
  r5.hasWindowFunction = a3, e10.setNodeType(t3, r5);
119807
119824
  } else
119808
119825
  e10.addError(t3, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, n4);
119809
119826
  } else if (isAssignable$1(e10, n4, durationType$1)) {
119810
- if (c4 === Kind.PLUS && isAssignable$1(e10, s4, datetimeType$1)) {
119811
- let n5 = createFieldType$1("", s4, undefined);
119827
+ if (c4 === Kind.PLUS && isAssignable$1(e10, s5, datetimeType$1)) {
119828
+ let n5 = createFieldType$1("", s5, undefined);
119812
119829
  n5.hasWindowFunction = a3, e10.setNodeType(t3, n5);
119813
119830
  } else
119814
119831
  e10.addError(t3, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, n4);
119815
- } else if (isAssignable$1(e10, n4, numberType$1) && isAssignable$1(e10, s4, rangeType$1)) {
119832
+ } else if (isAssignable$1(e10, n4, numberType$1) && isAssignable$1(e10, s5, rangeType$1)) {
119816
119833
  if (c4 === Kind.IN_KEYWORD) {
119817
119834
  let n5 = createFieldType$1("", truefalseType$1, undefined);
119818
119835
  n5.hasWindowFunction = a3, e10.setNodeType(t3, n5);
119819
119836
  } else
119820
- e10.addError(t3, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, s4);
119837
+ e10.addError(t3, ErrorCode.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1, c4, s5);
119821
119838
  } else
119822
- c4 === Kind.OR_KEYWORD || c4 === Kind.AND_KEYWORD ? (isAssignable$1(e10, n4, truefalseType$1) || e10.addError(t3, ErrorCode.EXPECTED_0_FOUND_1, truefalseType$1, n4), isAssignable$1(e10, s4, truefalseType$1) || e10.addError(t3, ErrorCode.EXPECTED_0_FOUND_1, truefalseType$1, s4)) : e10.addError(t3.right, ErrorCode.EXPECTED_0_FOUND_1, n4, s4);
119839
+ c4 === Kind.OR_KEYWORD || c4 === Kind.AND_KEYWORD ? (isAssignable$1(e10, n4, truefalseType$1) || e10.addError(t3, ErrorCode.EXPECTED_0_FOUND_1, truefalseType$1, n4), isAssignable$1(e10, s5, truefalseType$1) || e10.addError(t3, ErrorCode.EXPECTED_0_FOUND_1, truefalseType$1, s5)) : e10.addError(t3.right, ErrorCode.EXPECTED_0_FOUND_1, n4, s5);
119823
119840
  } else
119824
119841
  isErrType(r4) || isErrType(i3) || e10.addError(t3, ErrorCode.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0, r4);
119825
119842
  }
@@ -120991,10 +121008,13 @@ function _createTypeChecker(e10, t, n, r3, i = CheckFlags.Normal) {
120991
121008
  fieldName: u3
120992
121009
  };
120993
121010
  } else
120994
- f3 = c4.subClass === "param" ? createTableLiteralType$1(createRowType$1([{
120995
- ...c4,
120996
- subClass: undefined
120997
- }])) : {
121011
+ f3 = c4.subClass === "param" ? {
121012
+ ...createTableLiteralType$1(createRowType$1([{
121013
+ ...c4,
121014
+ subClass: undefined
121015
+ }])),
121016
+ param: `${i3}.${s4}`
121017
+ } : {
120998
121018
  ...c4,
120999
121019
  fieldName: u3
121000
121020
  };
@@ -121003,10 +121023,13 @@ function _createTypeChecker(e10, t, n, r3, i = CheckFlags.Normal) {
121003
121023
  n4 && isFieldType(n4) ? n4.origin && n4.subClass !== "param" ? (checkModelField(k3, n4.origin, t3), f3 = {
121004
121024
  ...n4,
121005
121025
  fieldName: u3
121006
- }) : f3 = n4.subClass === "param" ? createTableLiteralType$1(createRowType$1([{
121007
- ...n4,
121008
- subClass: undefined
121009
- }])) : {
121026
+ }) : f3 = n4.subClass === "param" ? {
121027
+ ...createTableLiteralType$1(createRowType$1([{
121028
+ ...n4,
121029
+ subClass: undefined
121030
+ }])),
121031
+ param: `${i3}.${s4}`
121032
+ } : {
121010
121033
  ...n4,
121011
121034
  fieldName: u3
121012
121035
  } : k3.addError(e11.right, ErrorCode.FIELD_0_NOT_FOUND_IN_MODEL_1, s4, i3);
@@ -122032,6 +122055,11 @@ function unsupportedOperator(e10, t, n, r3) {
122032
122055
  function checkOperatorCall(e10, t, n, r3, i = r3, a = []) {
122033
122056
  if (n.some(isErrType))
122034
122057
  return errType;
122058
+ for (let [i3, s4] of n.entries()) {
122059
+ let n3 = t === Kind.IN_KEYWORD && i3 === 1;
122060
+ if (isTableType(s4) && s4.param && !n3)
122061
+ return e10.dataset.diagnostics.push(createError(ErrorCode.OPERATOR_0_ON_PARAM_1, a[i3] ?? r3, undefined, t, s4.param)), errType;
122062
+ }
122035
122063
  if (n.length === 2) {
122036
122064
  if (isRowType(n[0]))
122037
122065
  return checkTableCondition(e10, t, n[0], n[1], r3);
@@ -123048,6 +123076,16 @@ function resolveBlock(e10, t, n) {
123048
123076
  n3.kind === Kind.FIELD_DECLARATION ? registerConstDecl(e10, n3, r3, i) : n3.kind === Kind.FUNCTION_DECLARATION ? registerFunctionDecl(e10, n3, r3, i) : r3.result = e10.resolveExpr(n3, i);
123049
123077
  return r3.ty = r3.result.ty, r3;
123050
123078
  }
123079
+ function makeBlock(e10, t, n, r3) {
123080
+ return {
123081
+ kind: "block",
123082
+ id: e10.newNodeId(t),
123083
+ ty: r3 ?? n.ty,
123084
+ result: n,
123085
+ declarations: /* @__PURE__ */ new Map,
123086
+ synthetic: true
123087
+ };
123088
+ }
123051
123089
  function registerConstDecl(e10, t, n, r3) {
123052
123090
  let { name: i } = flattenName(t.name), a = e10.iterationDepth, s3 = e10.resolveExpr(t.expr, r3);
123053
123091
  n.declarations.set(i, {
@@ -123665,12 +123703,12 @@ function involvesAggregation(e11) {
123665
123703
  return e11 ? e11.kind === "computed_ref" || isFieldType(e11.ty) && (e11.ty.subClass === "measure" || e11.ty.subClass === "aggregate") ? true : e11.kind === Kind.FUNCTION_CALL ? e11.args.some(involvesAggregation) : e11.kind === Kind.NAMED_EXPRESSION ? involvesAggregation(e11.expr) : e11.kind === "block" ? involvesAggregation(e11.result) : e11.kind === "lod" || e11.kind === "where" || e11.kind === Kind.INTERVAL ? involvesAggregation(e11.value) : false : false;
123666
123704
  }
123667
123705
  function expandMetric(e11, t, n, r3) {
123668
- let i = `metric:${t.name.name}`;
123669
- return recordDep(e11, i), e11.expanding.has(i) ? (reportCycle(e11, i, r3), makeRef(e11, t.name.name, [], t.ty, r3)) : (resolveMetricDecl(e11, t, n), withGuard(e11, i, () => makeRef(e11, t.name.name, [], t.ty, r3), () => {
123706
+ let i = `metric:${t.name.name}`, a = t.source ?? t.name.name;
123707
+ return recordDep(e11, i), e11.expanding.has(i) ? (reportCycle(e11, i, r3), makeRef(e11, a, [], t.ty, r3)) : (resolveMetricDecl(e11, t, n), withGuard(e11, i, () => makeRef(e11, a, [], t.ty, r3), () => {
123670
123708
  if (!t.resolved)
123671
- return makeRef(e11, t.name.name, [], t.ty, r3);
123709
+ return makeRef(e11, a, [], t.ty, r3);
123672
123710
  let n3 = t.resolved;
123673
- return nameInlined(e11, t.name.name, n3, r3, "measure", createModelFieldReference("", t.name.name));
123711
+ return nameInlined(e11, a, n3, r3, "measure", createModelFieldReference("", a));
123674
123712
  }));
123675
123713
  }
123676
123714
  var CUSTOM_AGG_FN = "custom_agg";
@@ -124623,7 +124661,7 @@ var ExtendFold = class extends HirFold {
124623
124661
  let t = this.planning.size === 0 ? e11 : {
124624
124662
  ...e11,
124625
124663
  children: e11.children.filter((e12) => e12.edge.join !== "semi" || !(e12.input.predicates ?? []).some((e13) => referencesPlanning(this, e13.predicate)))
124626
- }, n = materialiseExpandGrain(this, t);
124664
+ }, n = materialiseExpandGrain(this, t, [], "scan");
124627
124665
  return {
124628
124666
  ...t,
124629
124667
  ...foldExpandedPredicates(this, n)
@@ -124667,25 +124705,51 @@ function declOrigin(e11, t) {
124667
124705
  let n = e11.declarationsMap.get(t);
124668
124706
  return n?.kind === "dimension" ? n.origin : undefined;
124669
124707
  }
124670
- function materialiseExpandGrain(e11, t, n = []) {
124671
- let r3 = partGrainKeys(e11, t, n), i = (e12, t3 = []) => [
124708
+ function materialiseExpandGrain(e11, t, n = [], r3 = undefined) {
124709
+ let i = partGrainKeys(e11, t, n), a = (e12, t3 = []) => [
124672
124710
  ...e12,
124673
124711
  ...n,
124674
- ...r3,
124712
+ ...i,
124675
124713
  ...t3 ?? []
124676
- ], a = slotKeys(t), s3 = (t3, n3) => ({
124714
+ ], s3 = slotKeys(t), c3 = /* @__PURE__ */ new Set;
124715
+ walkTree(t, (e12) => c3.add(e12.model));
124716
+ let l = (n3, i3) => {
124717
+ let l3 = n3.extend ?? extendSlot(e11, n3.model, a(n3.fields ?? [], i3), s3.get(n3.model) ?? []), f = r3 ? joinPartKeyModels(e11, n3, l3, c3, r3 === "scan" && n3 === t) : n3;
124718
+ return u(f, l3, i3);
124719
+ }, u = (t3, n3, r4) => ({
124677
124720
  ...t3,
124678
- ...import_lodash2.omitBy({ extend: t3.extend ?? extendSlot(e11, t3.model, i(t3.fields ?? [], n3), a.get(t3.model) ?? []) }, import_lodash2.isUndefined),
124721
+ ...import_lodash2.omitBy({ extend: n3 }, import_lodash2.isUndefined),
124679
124722
  ...t3.fields ? { fields: foldComputedKeys(e11, t3.fields) } : {},
124680
124723
  children: t3.children.map((t4) => ownScope(t4) && !t4.expanded ? {
124681
124724
  ...t4,
124682
- input: materialiseExpandGrain(e11, t4.input, levelSubjects(t4.input))
124725
+ input: materialiseExpandGrain(e11, t4.input, levelSubjects(t4.input), "branch")
124683
124726
  } : {
124684
124727
  ...t4,
124685
- input: s3(t4.input, t4.expanded ? (t4.input.predicates ?? []).flatMap((e12) => e12.targets) : n3)
124728
+ input: l(t4.input, t4.expanded ? (t4.input.predicates ?? []).flatMap((e12) => e12.targets) : r4)
124686
124729
  })
124687
124730
  });
124688
- return s3(t);
124731
+ return l(t);
124732
+ }
124733
+ function keyModelPaths(e11, t, n, r3) {
124734
+ let i = import_lodash2.uniq(n.map((e12) => e12.modelName)).filter((e12) => !r3.has(e12));
124735
+ if (i.length === 0)
124736
+ return [];
124737
+ let a = resolveJoinTree(i, baseGraph(e11), t, true);
124738
+ return a ? a.paths.filter((e12) => e12[0].length > 0).map((n3) => pathToEdges(e11, t, n3[0])).filter((e12) => !r3.has(e12[e12.length - 1].destModel)) : [];
124739
+ }
124740
+ function joinPartKeyModels(e11, t, n, r3, i) {
124741
+ if (n === undefined || !i && !bareNode(extendDef(e11.resolver.dataset, n).base))
124742
+ return t;
124743
+ let a = partKeysOf(e11, t.fields ?? []).map((e12) => e12.origin), s3 = keyModelPaths(e11.resolver, t.model, a, r3);
124744
+ if (s3.length === 0)
124745
+ return t;
124746
+ let c3 = cloneTree(t);
124747
+ for (let e12 of s3) {
124748
+ for (let t3 of e12)
124749
+ r3.add(t3.destModel);
124750
+ placeChain(c3, e12);
124751
+ }
124752
+ return c3;
124689
124753
  }
124690
124754
  function levelSubjects(e11) {
124691
124755
  return (e11.predicates ?? []).flatMap((e12) => e12.targets);
@@ -124697,26 +124761,28 @@ function foldComputedKeys(e11, t) {
124697
124761
  } : t3);
124698
124762
  }
124699
124763
  function partGrainKeys(e11, t, n) {
124700
- let r3 = [], i = /* @__PURE__ */ new Set, a = [...n];
124701
- walkTree(t, (e12) => a.push(...e12.fields ?? []));
124702
- let s3 = /* @__PURE__ */ new Set, c3 = (t3) => {
124764
+ let r3 = [...n];
124765
+ return walkTree(t, (e12) => r3.push(...e12.fields ?? [])), partKeysOf(e11, r3);
124766
+ }
124767
+ function partKeysOf(e11, t) {
124768
+ let n = [], r3 = /* @__PURE__ */ new Set, i = /* @__PURE__ */ new Set, a = (t3) => {
124703
124769
  t3 && walkAll(t3, (t4) => {
124704
124770
  if (t4.kind === "computed_ref") {
124705
124771
  for (let e12 of t4.reduce.by) {
124706
124772
  let t5 = modelFieldRefAsKey(e12.origin);
124707
- i.has(t5) || (i.add(t5), r3.push(e12));
124773
+ r3.has(t5) || (r3.add(t5), n.push(e12));
124708
124774
  }
124709
124775
  return false;
124710
124776
  }
124711
124777
  if (t4.kind !== Kind.IDENTIFIER)
124712
124778
  return false;
124713
- let n3 = lookupDim(e11.resolver, t4);
124714
- return !n3 || s3.has(n3) || n3.body?.syntax !== "aql" || (s3.add(n3), c3(unwrapDimBody(n3))), false;
124779
+ let s3 = lookupDim(e11.resolver, t4);
124780
+ return !s3 || i.has(s3) || s3.body?.syntax !== "aql" || (i.add(s3), a(unwrapDimBody(s3))), false;
124715
124781
  });
124716
124782
  };
124717
- for (let t3 of a)
124718
- c3(dimBodyOf(e11, t3));
124719
- return r3;
124783
+ for (let n3 of t)
124784
+ a(dimBodyOf(e11, n3));
124785
+ return n;
124720
124786
  }
124721
124787
  function dimBodyOf(e11, t) {
124722
124788
  let n = lookupDim(e11.resolver, unwrapNamed(t.expr));
@@ -124823,13 +124889,20 @@ function defineSlot(e11, t, n, r3) {
124823
124889
  };
124824
124890
  }
124825
124891
  let f = n.filter((e12) => !l.has(e12)), p3 = {
124826
- base: f.some((e12) => e12.dependentModels.length > 0) ? dependentBase(e11, t, f, u) : u,
124892
+ base: f.some((e12) => e12.dependentModels.length > 0) ? dependentBase(e11, t, f.map(withPartKeyModels), u) : u,
124827
124893
  computed: f.map((t3) => foldPartScans(e11, t3)),
124828
124894
  projected: f.filter((e12) => !e12.unrollOnly).map((e12) => e12.computed.origin),
124829
124895
  parts: []
124830
124896
  };
124831
124897
  return a && (p3.sealed = true), defineExtend(i.dataset, p3);
124832
124898
  }
124899
+ function withPartKeyModels(e11) {
124900
+ let t = e11.partKeyModels.filter((t3) => !e11.dependentModels.includes(t3));
124901
+ return t.length === 0 ? e11 : {
124902
+ ...e11,
124903
+ dependentModels: [...e11.dependentModels, ...t]
124904
+ };
124905
+ }
124833
124906
  function planKeys(e11, t, n, r3) {
124834
124907
  let { resolver: i } = e11, a = [], s3 = (e12) => r3.some((t3) => t3.field.name.name === e12) || a.some((t3) => t3.field.name.name === e12);
124835
124908
  for (let r4 of n) {
@@ -124937,7 +125010,8 @@ function planDim(e11, t, n) {
124937
125010
  let u = t.modelPaths ? [...t.modelPaths.keys()] : dependentModels(r3, i, n), f = u.filter((e12) => c3.has(e12)), p3 = hasComputedRef$1(a) ? f.length === 0 ? [] : u.filter((e12) => c3.has(e12) || l.has(e12)) : u, m3 = {
124938
125011
  field: t,
124939
125012
  computed: computedColumn(r3, t),
124940
- dependentModels: p3
125013
+ dependentModels: p3,
125014
+ partKeyModels: u.filter((e12) => l.has(e12))
124941
125015
  };
124942
125016
  if (s3.length === 0)
124943
125017
  return [m3];
@@ -125690,7 +125764,10 @@ function resolveModuleRef(e11, t, n, r3, i, a, s3 = i) {
125690
125764
  function resolveFieldRef(e11, t, n, r3, i, a, s3) {
125691
125765
  if ((n.kind === "dimension" || n.kind === "measure") && resolveModelField(e11, t, n), n.kind === "measure")
125692
125766
  return expandMeasure(e11, t, n, a);
125693
- let c3 = createFieldType(genUniqueFieldName({ name: n.name.name }, t.name), n.ty.type, n.ty.origin, t.name, n.kind), l = n.kind === "param" ? createTableLiteralType(createRowType([createFieldType(n.name.name, n.ty.type, n.ty.origin, t.name, "param")])) : c3;
125767
+ let c3 = createFieldType(genUniqueFieldName({ name: n.name.name }, t.name), n.ty.type, n.ty.origin, t.name, n.kind), l = n.kind === "param" ? {
125768
+ ...createTableLiteralType(createRowType([createFieldType(n.name.name, n.ty.type, n.ty.origin, t.name, "param")])),
125769
+ param: `${t.name}.${n.name.name}`
125770
+ } : c3;
125694
125771
  if (n.kind === "param" && n.ty.origin) {
125695
125772
  let t3 = getParamBinding(e11, n.ty.origin);
125696
125773
  if (t3)
@@ -127549,6 +127626,18 @@ function applyFilter(e11, t, n, r3, i) {
127549
127626
  let w3 = m3.find((t3) => t3.edge.keys.some((e12) => p3.keys.some((t4) => originEq$1(e12.from, t4.from))) && treeFitsCondition(e11, a, s3, t3, r3)), E3 = w3 ? conjoinScalarExistenceFilter(e11, a, s3, w3, r3) : buildScalarExistenceFilter(e11, a, s3, [r3], [p3.destModel]);
127550
127627
  return E3 ? (i.add(r3), withMembershipHops(S3(w3, E3))) : n;
127551
127628
  }
127629
+ function narrowToReachableRows(e11, t, n, r3) {
127630
+ let i = (r4) => r4 === n || r4 === "H.calendar" || joinPathTo(e11, t, n, r4) !== undefined;
127631
+ return r3.flatMap((t3) => {
127632
+ if (t3.predicate.kind !== "in_table_condition" || t3.role === "rlp")
127633
+ return [t3];
127634
+ let n3 = t3.predicate.row.filter((e12) => exprModels(e12.expr).every(i));
127635
+ return n3.length === t3.predicate.row.length ? [t3] : n3.length === 0 ? [] : [makeCondition(e11, {
127636
+ ...t3.predicate,
127637
+ row: n3
127638
+ }, t3.role)];
127639
+ });
127640
+ }
127552
127641
  function joinPathTo(e11, t, n, r3) {
127553
127642
  let i = t.findPath(n, r3, true);
127554
127643
  if (i && i[0].length !== 0)
@@ -128427,7 +128516,7 @@ var Window = class {
128427
128516
  return u.foldFunctionCall(e12);
128428
128517
  if (f.kind === "unsupported")
128429
128518
  return u.resolver.dataset.diagnostics.push(createError(ErrorCode.INVALID_EXPRESSION_0, l, undefined, `Window aggregation does not support \`${f.type}\` yet.`)), u.foldFunctionCall(e12);
128430
- let p3 = dedupKeys([...u.aggGrain(), ...modelFieldExprs(u.resolver, [...s3, ...a])]), m3 = f.kind === "simple" ? [{
128519
+ let p3 = [...s3, ...a].filter((e13) => !this.hasAggregate(e13)), m3 = dedupKeys([...u.aggGrain(), ...modelFieldExprs(u.resolver, p3)]), S3 = f.kind === "simple" ? [{
128431
128520
  windowFn: t,
128432
128521
  rollupFn: f.func,
128433
128522
  arg: n
@@ -128435,8 +128524,8 @@ var Window = class {
128435
128524
  windowFn: e13.aggFn,
128436
128525
  rollupFn: e13.rollupFn,
128437
128526
  arg: e13.arg
128438
- })), S3 = this.buildWindowLodParts(e12, m3, p3, r3, i, s3, a, c3, l);
128439
- return f.kind === "simple" ? S3[0] : f.combine(S3, e12.ty, l);
128527
+ })), w3 = this.buildWindowLodParts(e12, S3, m3, r3, i, s3, a, c3, l);
128528
+ return f.kind === "simple" ? w3[0] : f.combine(w3, e12.ty, l);
128440
128529
  }
128441
128530
  aggregateValue(e12, t, n, r3) {
128442
128531
  let i = createFieldType(n, e12 === "count" ? numberType : scalarOf(t.ty), undefined, exprModels(t)[0], "measure");
@@ -128445,24 +128534,47 @@ var Window = class {
128445
128534
  buildWindowLodParts(e12, t, n, r3, i, a, s3, c3, l) {
128446
128535
  let { g: u } = this, f = e12.ty, p3 = windowLodPartitionKeys(u, s3, a), m3 = u.currentIteration(), S3 = m3.groups;
128447
128536
  m3.groups = n;
128448
- let w3 = [], E3 = /* @__PURE__ */ new Map, k3 = u.inScope("window-lod", e12, () => t.map((e13) => {
128449
- let t3 = !this.hasAggregate(e13.arg), n3 = t3 ? `${e13.windowFn}(${argSig(e13.arg)})` : argSig(e13.arg), r4 = E3.get(n3);
128450
- if (r4)
128451
- return r4;
128452
- let i3 = `__wv_${this.windowLodCounter++}`, a3 = cloneResolved(u.resolver, e13.arg), s4 = u.foldExpr(t3 ? this.aggregateValue(e13.windowFn, a3, i3, l) : a3), c4 = createFieldType(i3, scalarOf(s4.ty));
128537
+ let w3 = [], E3 = /* @__PURE__ */ new Map, k3 = (e13, t3) => {
128538
+ let n3 = E3.get(e13);
128539
+ if (n3)
128540
+ return n3;
128541
+ let r4 = `__wv_${this.windowLodCounter++}`, i3 = u.foldExpr(t3(r4)), a3 = createFieldType(r4, scalarOf(i3.ty));
128453
128542
  w3.push({
128454
- name: i3,
128455
- ty: c4,
128456
- expr: s4
128543
+ name: r4,
128544
+ ty: a3,
128545
+ expr: i3
128457
128546
  });
128458
- let f3 = {
128459
- name: i3,
128460
- ty: c4
128547
+ let s4 = {
128548
+ name: r4,
128549
+ ty: a3
128461
128550
  };
128462
- return E3.set(n3, f3), f3;
128551
+ return E3.set(e13, s4), s4;
128552
+ }, { partValues: N3, orderCols: I3 } = u.inScope("window-lod", e12, () => ({
128553
+ partValues: t.map((e13) => {
128554
+ let t3 = !this.hasAggregate(e13.arg), n3 = t3 ? `${e13.windowFn}(${argSig(e13.arg)})` : argSig(e13.arg);
128555
+ return k3(n3, (n4) => {
128556
+ let r4 = cloneResolved(u.resolver, e13.arg);
128557
+ return t3 ? this.aggregateValue(e13.windowFn, r4, n4, l) : r4;
128558
+ });
128559
+ }),
128560
+ orderCols: a.map((e13) => this.hasAggregate(e13) ? k3(argSig(e13), () => cloneResolved(u.resolver, e13)) : undefined)
128463
128561
  }));
128464
128562
  m3.groups = S3;
128465
- let N3 = {
128563
+ let L3 = i.map((e13, t3) => {
128564
+ let n3 = I3[t3];
128565
+ if (!n3)
128566
+ return cloneResolved(u.resolver, e13);
128567
+ let r4 = makeIdent(u.resolver, n3.name, [], n3.ty, l), { expr: i3 } = e13, a3 = i3.kind === Kind.FUNCTION_CALL && unwrapOrderKey(i3) !== i3 ? {
128568
+ ...i3,
128569
+ id: u.resolver.newNodeId(l),
128570
+ args: [r4, ...i3.args.slice(1).map((e14) => cloneResolved(u.resolver, e14))]
128571
+ } : r4;
128572
+ return {
128573
+ ...e13,
128574
+ id: u.resolver.newNodeId(l),
128575
+ expr: a3
128576
+ };
128577
+ }), U3 = {
128466
128578
  kind: "merge",
128467
128579
  id: u.resolver.newNodeId(l),
128468
128580
  ty: createTableType(createRowType([...n.map((e13) => e13.ty), ...w3.map((e13) => e13.ty)]), undefined),
@@ -128475,37 +128587,37 @@ var Window = class {
128475
128587
  name: makeIdent(u.resolver, e13.name, [], e13.ty, l),
128476
128588
  expr: e13.expr
128477
128589
  }))]
128478
- }, I3 = t.map((e13, t3) => {
128479
- let n3 = `__w_${this.windowLodCounter++}`, a3 = createFieldType(n3, scalarOf(f)), s4 = k3[t3];
128590
+ }, pe3 = t.map((e13, t3) => {
128591
+ let n3 = `__w_${this.windowLodCounter++}`, i3 = createFieldType(n3, scalarOf(f)), a3 = N3[t3];
128480
128592
  return {
128481
128593
  name: n3,
128482
- ty: a3,
128594
+ ty: i3,
128483
128595
  value: {
128484
128596
  kind: Kind.FUNCTION_CALL,
128485
128597
  id: u.resolver.newNodeId(l),
128486
- ty: a3,
128487
- name: makeIdent(u.resolver, `window_${e13.windowFn}`, [], a3, l),
128598
+ ty: i3,
128599
+ name: makeIdent(u.resolver, `window_${e13.windowFn}`, [], i3, l),
128488
128600
  args: [
128489
- makeIdent(u.resolver, s4.name, [], s4.ty, l),
128601
+ makeIdent(u.resolver, a3.name, [], a3.ty, l),
128490
128602
  ...r3 ? [cloneResolved(u.resolver, r3)] : [],
128491
- ...i.map((e14) => cloneResolved(u.resolver, e14)),
128603
+ ...L3,
128492
128604
  ...p3.map((e14) => namedPartitionArg(u, e14, l)),
128493
128605
  ...c3 ? [cloneResolved(u.resolver, c3)] : []
128494
128606
  ]
128495
128607
  }
128496
128608
  };
128497
- }), L3 = {
128609
+ }), me3 = {
128498
128610
  kind: "window",
128499
128611
  id: u.resolver.newNodeId(l),
128500
- ty: N3.ty,
128501
- input: N3,
128502
- columns: I3.map((e13) => ({
128612
+ ty: U3.ty,
128613
+ input: U3,
128614
+ columns: pe3.map((e13) => ({
128503
128615
  name: e13.name,
128504
128616
  value: e13.value
128505
128617
  }))
128506
128618
  };
128507
128619
  return t.map((e13, t3) => {
128508
- let { name: n3, ty: r4 } = I3[t3], i3 = u.grain().map((e14) => cloneResolved(u.resolver, e14)), a3 = createFieldType(n3, scalarOf(f), undefined, undefined, "aggregate"), s4 = {
128620
+ let { name: n3, ty: r4 } = pe3[t3], i3 = u.grain().map((e14) => cloneResolved(u.resolver, e14)), a3 = createFieldType(n3, scalarOf(f), undefined, undefined, "aggregate"), s4 = {
128509
128621
  kind: Kind.FUNCTION_CALL,
128510
128622
  id: u.resolver.newNodeId(l),
128511
128623
  ty: a3,
@@ -128515,7 +128627,7 @@ var Window = class {
128515
128627
  kind: "reduce",
128516
128628
  id: u.resolver.newNodeId(l),
128517
128629
  ty: createTableType(createRowType([...i3.map((e14) => e14.ty), a3]), undefined),
128518
- input: L3,
128630
+ input: me3,
128519
128631
  by: i3,
128520
128632
  aggregates: [s4]
128521
128633
  }, p4 = isFieldType(f) ? createFieldType(n3, f.type, undefined, undefined, "aggregate") : a3;
@@ -129248,20 +129360,56 @@ function nonCyclicRlp(e13, t) {
129248
129360
  return t.filter((t3) => t3.role !== "rlp" || !filterRefKeys(t3.predicate).some((t4) => e13.foldingDimKeys.has(t4) || n.some((n3) => dependsOn(e13.resolver.dataset, t4, n3))));
129249
129361
  }
129250
129362
  function foldWhere(e13, t) {
129251
- let n = e13.contextFilters, r3 = mergeGrainsOf(t.value), i = e13.currentIteration(), a = t.conditions.map((t3) => {
129252
- let n3 = i.inheritedGroups, a3 = inheritsViz(t3) && r3.length === 0;
129253
- inheritsViz(t3) && r3.length > 0 && (i.inheritedGroups = r3);
129254
- let s4 = () => e13.withoutIteration(t3, () => makeCondition(e13.resolver, unwrapBlock$1(e13.foldExpr(t3)), "where"));
129255
- a3 && (i.inheritedGroups = e13.period.rawKeys(e13.grain()));
129256
- let c3 = a3 ? e13.period.withoutShift(t3, s4) : s4();
129257
- return i.inheritedGroups = n3, c3;
129363
+ let n = t.conditions.filter(isShorthand);
129364
+ if (n.length > 0 && hasUnion(t.value))
129365
+ return foldWhere(e13, {
129366
+ ...t,
129367
+ value: distributeOverBranches(e13, t.value, n),
129368
+ conditions: t.conditions.filter((e14) => !isShorthand(e14))
129369
+ });
129370
+ let r3 = e13.contextFilters, i = mergeGrainsOf(t.value), a = i.length > 0 ? [] : relationKeysOf(t.value), s3 = a.length > 0 ? dedupKeys([...e13.grain(), ...a]) : i, c3 = e13.currentIteration(), l = t.conditions.map((t3) => {
129371
+ let n3 = c3.inheritedGroups, r4 = inheritsViz(t3) && s3.length === 0;
129372
+ inheritsViz(t3) && s3.length > 0 && (c3.inheritedGroups = s3);
129373
+ let i3 = () => e13.withoutIteration(t3, () => makeCondition(e13.resolver, unwrapBlock$1(e13.foldExpr(t3)), "where"));
129374
+ r4 && (c3.inheritedGroups = e13.period.rawKeys(e13.grain()));
129375
+ let a3 = r4 ? e13.period.withoutShift(t3, i3) : i3();
129376
+ return c3.inheritedGroups = n3, a3;
129258
129377
  });
129259
- e13.contextFilters = [...n, ...a];
129260
- let s3 = e13.inScope("where-value", t, () => e13.foldExpr(t.value));
129261
- return e13.contextFilters = n, s3;
129378
+ e13.contextFilters = [...r3, ...l];
129379
+ let u = e13.inScope("where-value", t, () => e13.foldExpr(t.value));
129380
+ return e13.contextFilters = r3, u;
129262
129381
  }
129263
129382
  function mergeGrainsOf(e13) {
129264
- return e13.kind === "merge" ? e13.grains : e13.kind === "pivot_context" ? mergeGrainsOf(e13.value) : e13.kind === "union" && e13.branches.length > 0 ? mergeGrainsOf(e13.branches[0]) : [];
129383
+ return e13.kind === "merge" ? e13.grains : e13.kind === "pivot_context" ? mergeGrainsOf(e13.value) : e13.kind === "union" ? dedupKeys(e13.branches.flatMap(mergeGrainsOf)) : [];
129384
+ }
129385
+ function relationKeysOf(e13) {
129386
+ return e13.kind === "unique" || e13.kind === "group" ? e13.keys : [];
129387
+ }
129388
+ function isShorthand(e13) {
129389
+ return e13.kind === "block" && inheritsViz(e13);
129390
+ }
129391
+ function hasUnion(e13) {
129392
+ return e13.kind === "union" || e13.kind === "pivot_context" && hasUnion(e13.value);
129393
+ }
129394
+ function distributeOverBranches(e13, t, n) {
129395
+ if (t.kind === "pivot_context")
129396
+ return {
129397
+ ...t,
129398
+ value: distributeOverBranches(e13, t.value, n)
129399
+ };
129400
+ if (t.kind !== "union")
129401
+ return t;
129402
+ let r3 = e13.resolver.dataset.spans.get(t.id) ?? locStub();
129403
+ return {
129404
+ ...t,
129405
+ branches: t.branches.map((t3) => ({
129406
+ kind: "where",
129407
+ id: e13.resolver.newNodeId(r3),
129408
+ ty: t3.ty,
129409
+ value: t3,
129410
+ conditions: n.map((t4) => cloneResolved(e13.resolver, t4))
129411
+ }))
129412
+ };
129265
129413
  }
129266
129414
  function unwrapBlock$1(e13) {
129267
129415
  return e13.kind === "block" ? unwrapBlock$1(e13.result) : e13;
@@ -129279,7 +129427,7 @@ function grainTableCondition(e13, t) {
129279
129427
  table: foldTableAtGrain(e13, t.table, e13.grain())
129280
129428
  };
129281
129429
  }
129282
- let n = (t.inheritGrains ? e13.grain() : []).map((t3) => cloneResolved(e13.resolver, t3)), r3 = t.row.map((t3) => cloneResolved(e13.resolver, t3)), i = dedupKeys([...n, ...r3]), a = foldTableAtGrain(e13, t.table, i), s3 = a.kind === "filter" ? {
129430
+ let n = (t.inheritGrains ? e13.grain() : []).map((t3) => cloneResolved(e13.resolver, t3)), r3 = t.row.map((t3) => cloneResolved(e13.resolver, t3)), i = dedupKeys([...n, ...r3]), a = foldTableAtGrain(e13, withOwnGrain(t.table, i), []), s3 = a.kind === "filter" ? {
129283
129431
  ...a,
129284
129432
  ty: a.input.ty
129285
129433
  } : a;
@@ -129289,6 +129437,25 @@ function grainTableCondition(e13, t) {
129289
129437
  table: s3
129290
129438
  };
129291
129439
  }
129440
+ function withOwnGrain(e13, t) {
129441
+ if (e13.kind === "where")
129442
+ return {
129443
+ ...e13,
129444
+ value: withOwnGrain(e13.value, t)
129445
+ };
129446
+ if (e13.kind !== "filter" || e13.input.kind !== "unique")
129447
+ return e13;
129448
+ let n = createTableType(createRowType(t.map((e14) => e14.ty)), undefined);
129449
+ return {
129450
+ ...e13,
129451
+ ty: n,
129452
+ input: {
129453
+ ...e13.input,
129454
+ ty: n,
129455
+ keys: t
129456
+ }
129457
+ };
129458
+ }
129292
129459
  function foldTableAtGrain(e13, t, n) {
129293
129460
  return e13.inIteration({
129294
129461
  groups: undefined,
@@ -129551,7 +129718,7 @@ var GrainFold = class e13 extends HirFold {
129551
129718
  }
129552
129719
  }
129553
129720
  stateFingerprint() {
129554
- let { pkGrain: e14, inheritedGroups: t, groups: n, dim: r3, noSlice: i, source: a } = this.currentIteration();
129721
+ let { pkGrain: e14, inheritedGroups: t, groups: n, dim: r3, droppable: i, source: a } = this.currentIteration();
129555
129722
  return [
129556
129723
  `pk=${keyFingerprint(e14)}`,
129557
129724
  `inherited=${keyFingerprint(t)}`,
@@ -129699,29 +129866,40 @@ var GrainFold = class e13 extends HirFold {
129699
129866
  }
129700
129867
  }
129701
129868
  foldTransform(e14) {
129702
- let t = this.currentIteration(), n = groupingOf(e14.input), r3 = (t3, r4, i3) => this.inIteration({
129703
- groups: n,
129704
- source: {
129705
- relation: t3,
129706
- depth: r4
129707
- }
129708
- }, () => this.inScope("agg-output", e14, i3)), i;
129869
+ let t = this.currentIteration(), n = groupingOf(e14.input), r3 = (r4, i3, a) => {
129870
+ let s3 = new Set(unslicedOf(r4).keys.map((e15) => modelFieldRefAsKey(e15.origin)));
129871
+ return this.inIteration({
129872
+ groups: n,
129873
+ source: {
129874
+ relation: r4,
129875
+ depth: i3
129876
+ },
129877
+ inheritedGroups: t.inheritedGroups.filter((e15) => !s3.has(modelFieldRefAsKey(e15.origin)))
129878
+ }, () => this.inScope("agg-output", e14, a));
129879
+ }, i;
129709
129880
  switch (e14.kind) {
129710
129881
  case "group": {
129711
- let r4 = dedupKeys([...this.grain(), ...n ?? []]), a = this.foldKeys(this.period.applyToKeys(e14.keys)), s3 = dedupKeys([...a, ...r4]), c3 = this.inIteration({
129882
+ let r4 = dedupKeys([...this.grain(), ...n ?? []]), a = this.foldKeys(this.period.applyToKeys(e14.keys)), s3 = dedupKeys([...a, ...r4]), c3 = dedupKeys([...s3, ...t.inheritedGroups]), l = this.inIteration({
129712
129883
  groups: n,
129713
- inheritedGroups: dedupKeys([...s3, ...t.inheritedGroups])
129714
- }, () => this.inScope("group-input", e14, () => this.foldExpr(e14.input))), l = scanRootOf(c3);
129715
- l && this.diagnoseGroupFanout(this.graphContext.currentGraph(), l, a);
129716
- let u = this.resolver.dataset.spans.get(e14.id) ?? locStub();
129884
+ inheritedGroups: c3,
129885
+ droppable: c3.filter((e15) => !a.includes(e15))
129886
+ }, () => this.inScope("group-input", e14, () => this.foldExpr(e14.input))), u = scanRootOf(l);
129887
+ u && this.diagnoseGroupFanout(this.graphContext.currentGraph(), u, a);
129888
+ let f = unslicedOf(l), p3 = s3.filter((e15) => !f.keys.includes(e15)), m3 = f.scanRoot ? this.noSliceComments(f.scanRoot, f.keys) : [], S3 = this.resolver.dataset.spans.get(e14.id) ?? locStub();
129717
129889
  i = {
129718
129890
  kind: "reduce",
129719
- id: this.resolver.newNodeId(u),
129720
- ty: createTableType(createRowType(s3.map((e15) => e15.ty)), e14.ty.rootModel),
129721
- input: c3,
129722
- by: s3,
129891
+ id: this.resolver.newNodeId(S3),
129892
+ ty: createTableType(createRowType(p3.map((e15) => e15.ty)), e14.ty.rootModel),
129893
+ input: l,
129894
+ by: p3,
129723
129895
  aggregates: []
129724
- };
129896
+ }, f.keys.length > 0 && (i = {
129897
+ ...i,
129898
+ unsliced: f.keys
129899
+ }), m3.length > 0 && (i = {
129900
+ ...i,
129901
+ annotations: m3
129902
+ });
129725
129903
  break;
129726
129904
  }
129727
129905
  case "select": {
@@ -129781,26 +129959,28 @@ var GrainFold = class e13 extends HirFold {
129781
129959
  break;
129782
129960
  }
129783
129961
  case "reduce": {
129784
- let t3 = this.timeSpine.graphWithCalendar(this.graphContext.currentGraph()), r4 = this.inScope("reduce-keys", e14, () => this.foldKeys(this.period.applyToKeys(e14.by, e14))), a = dedupKeys([...r4, ...this.grain()]), s3 = [], c3 = this.inIteration({
129962
+ let t3 = this.timeSpine.graphWithCalendar(this.graphContext.currentGraph()), r4 = this.inScope("reduce-keys", e14, () => this.foldKeys(this.period.applyToKeys(e14.by, e14))), a = dedupKeys([...r4, ...this.grain()]), s3 = this.inIteration({
129785
129963
  groups: n,
129786
129964
  inheritedGroups: a,
129787
- noSlice: s3
129788
- }, () => this.inScope("reduce-input", e14, () => this.foldExpr(e14.input))), l = s3.filter((e15) => r4.includes(e15.key)), u = l.length > 0 ? r4.filter((e15) => !l.some((t4) => t4.key === e15)) : r4, f = bareLeafKeys(this.resolver, u, materialisedOrigins(c3)), p3 = this.inIteration({
129965
+ droppable: a
129966
+ }, () => this.inScope("reduce-input", e14, () => this.foldExpr(e14.input))), c3 = unslicedOf(s3), l = c3.keys.filter((e15) => r4.includes(e15)), u = l.length > 0 ? r4.filter((e15) => !l.includes(e15)) : r4, f = bareLeafKeys(this.resolver, u, materialisedOrigins(s3)), p3 = this.inIteration({
129789
129967
  groups: n,
129790
129968
  inheritedGroups: a,
129791
129969
  source: {
129792
- relation: c3,
129793
- depth: iterationDepthOf(c3)
129970
+ relation: s3,
129971
+ depth: iterationDepthOf(s3)
129794
129972
  }
129795
- }, () => this.inScope("agg-output", e14, () => this.foldExprs(e14.aggregates))), m3 = this.collectAccessedFields(p3, iterationDepthOf(c3));
129796
- c3 = addJoins(this.resolver, t3, c3, m3, e14.allowFanout ? "fanInvariant" : "rowLevel"), i = {
129973
+ }, () => this.inScope("agg-output", e14, () => this.foldExprs(e14.aggregates))), m3 = this.collectAccessedFields(p3, iterationDepthOf(s3));
129974
+ s3 = addJoins(this.resolver, t3, s3, m3, e14.allowFanout ? "fanInvariant" : "rowLevel"), i = {
129797
129975
  ...e14,
129798
129976
  by: f,
129799
- input: c3,
129977
+ input: s3,
129800
129978
  aggregates: p3
129801
- }, l.length > 0 && (i = {
129979
+ };
129980
+ let S3 = c3.scanRoot ? this.noSliceComments(c3.scanRoot, l) : [];
129981
+ S3.length > 0 && (i = {
129802
129982
  ...i,
129803
- annotations: [...e14.annotations ?? [], ...l.map((e15) => e15.comment)]
129983
+ annotations: [...e14.annotations ?? [], ...S3]
129804
129984
  });
129805
129985
  break;
129806
129986
  }
@@ -129979,26 +130159,18 @@ var GrainFold = class e13 extends HirFold {
129979
130159
  return;
129980
130160
  let n = this.graphContext.currentGraph(), r3 = t.model, i = this.timeSpine.graphWithCalendar(n), a = this.period.withExactRange(e14, () => effectiveFiltersForModel(this, r3));
129981
130161
  a = [...a, ...this.period.dayRoundtripFilters(this.period.rawKeys(this.currentIteration().inheritedGroups).map((e15) => e15.expr))], a = this.applicableRlp(r3, a), a = this.applicableFilters(i, r3, a);
129982
- let s3 = normalizeConditions(this.resolver, a, i, r3), c3 = /* @__PURE__ */ new Set, { noSlice: l } = this.currentIteration(), u = this.currentIteration().inheritedGroups;
129983
- if (l) {
129984
- let e15 = (e16) => e16 === "H.calendar" || n.canReach(r3, e16, {
129985
- allowFanout: true,
129986
- respectFilterDirection: true
129987
- }), t3 = u.filter((t4) => !exprModels(t4.expr).every(e15));
129988
- if (t3.length > 0) {
129989
- u = u.filter((e17) => !t3.includes(e17));
129990
- let e16 = this.noSliceComments(r3, t3);
129991
- l.push(...t3.map((t4, n3) => ({
129992
- key: t4,
129993
- comment: e16[n3]
129994
- })));
129995
- }
129996
- }
129997
- t = addJoins(this.resolver, i, t, u, "grainKey", s3, c3), t.kind === "expand_model" && (t = applyFilters(this.resolver, i, t, s3, c3));
129998
- let f = s3.filter((e15) => !c3.has(e15)), p3 = this.resolver.dataset.spans.get(e14.id) ?? locStub(), m3 = f.flatMap((e15) => e15.predicate.kind === "in_table_condition" ? e15.predicate.row.map((e16) => e16.expr) : []);
129999
- m3.length > 0 && (t = addJoins(this.resolver, n, t, leafFields(this.resolver, m3))), f.length > 0 && (t = this.filterInput(t, p3, f));
130000
- let S3 = this.period.strictBounds(bareLeafKeys(this.resolver, u, materialisedOrigins(t)).map((e15) => e15.expr), p3);
130001
- return S3.length > 0 ? this.filterInput(t, p3, S3) : t;
130162
+ let s3 = narrowToReachableRows(this.resolver, i, r3, normalizeConditions(this.resolver, a, i, r3)), c3 = /* @__PURE__ */ new Set, { droppable: l = [] } = this.currentIteration(), u = (e15) => e15 === "H.calendar" || n.canReach(r3, e15, {
130163
+ allowFanout: true,
130164
+ respectFilterDirection: true
130165
+ }), f = l.filter((e15) => !exprModels(e15.expr).every(u)), p3 = this.currentIteration().inheritedGroups.filter((e15) => !f.includes(e15));
130166
+ t = addJoins(this.resolver, i, t, p3, "grainKey", s3, c3), t.kind === "expand_model" && (t = applyFilters(this.resolver, i, t, s3, c3));
130167
+ let m3 = s3.filter((e15) => !c3.has(e15)), S3 = this.resolver.dataset.spans.get(e14.id) ?? locStub(), w3 = m3.flatMap((e15) => e15.predicate.kind === "in_table_condition" ? e15.predicate.row.map((e16) => e16.expr) : []);
130168
+ w3.length > 0 && (t = addJoins(this.resolver, n, t, leafFields(this.resolver, w3))), f.length > 0 && t.kind === "expand_model" && (t = {
130169
+ ...t,
130170
+ unsliced: f
130171
+ }), m3.length > 0 && (t = this.filterInput(t, S3, m3));
130172
+ let E3 = this.period.strictBounds(bareLeafKeys(this.resolver, p3, materialisedOrigins(t)).map((e15) => e15.expr), S3);
130173
+ return E3.length > 0 ? this.filterInput(t, S3, E3) : t;
130002
130174
  }
130003
130175
  diagnoseGroupFanout(e14, t, n) {
130004
130176
  let r3 = /* @__PURE__ */ new Set;
@@ -130195,6 +130367,15 @@ function wireGrains(e14, t) {
130195
130367
  let n = new GrainFold(e14);
130196
130368
  return n.foldRelationshipKeyDims(), n.foldBlock(t);
130197
130369
  }
130370
+ function unslicedOf(e14) {
130371
+ let t = e14;
130372
+ for (;t.kind === "filter" || t.kind === "select" || t.kind === "sort"; )
130373
+ t = t.input;
130374
+ return t.kind === "expand_model" ? {
130375
+ keys: t.unsliced ?? [],
130376
+ scanRoot: t.model
130377
+ } : t.kind === "reduce" ? { keys: t.unsliced ?? [] } : { keys: [] };
130378
+ }
130198
130379
  function scanRootOf(e14) {
130199
130380
  let t = e14;
130200
130381
  for (;; ) {
@@ -130208,18 +130389,6 @@ function scanRootOf(e14) {
130208
130389
  return;
130209
130390
  }
130210
130391
  }
130211
- function partGrainPaths(e14, t, n, r3) {
130212
- let i = [];
130213
- for (let e15 of n)
130214
- for (let t3 of e15.by) {
130215
- let e16 = isFieldType(t3.ty) ? t3.ty.origin : undefined;
130216
- e16 && !r3.has(e16.modelName) && !i.includes(e16.modelName) && i.push(e16.modelName);
130217
- }
130218
- if (i.length === 0)
130219
- return [];
130220
- let a = resolveJoinTree(i, baseGraph(e14), t, true);
130221
- return a ? a.paths.filter((e15) => e15[0].length > 0).map((n3) => pathToEdges(e14, t, n3[0])).filter((e15) => !r3.has(e15[e15.length - 1].destModel)) : [];
130222
- }
130223
130392
  function appendPartGrains(e14, t, n) {
130224
130393
  let r3 = (t3) => extendDef(e14.dataset, t3), i = /* @__PURE__ */ new Set;
130225
130394
  walkTree(t, (e15) => i.add(e15.model)), n && t.extend !== undefined && walkTree(r3(t.extend).base, (e15) => i.add(e15.model));
@@ -130230,12 +130399,14 @@ function appendPartGrains(e14, t, n) {
130230
130399
  if (t3.extend === undefined)
130231
130400
  continue;
130232
130401
  let { base: s4, parts: l } = r3(t3.extend);
130233
- if (l.length !== 0 && (bareNode(s4) || n && t3 === a))
130234
- for (let n3 of partGrainPaths(e14, t3.model, l, i)) {
130235
- for (let e15 of n3)
130236
- i.add(e15.destModel);
130237
- placeChain(t3, n3), c3 = true;
130238
- }
130402
+ if (l.length === 0 || !bareNode(s4) && !(n && t3 === a))
130403
+ continue;
130404
+ let u = l.flatMap((e15) => e15.by.flatMap((e16) => isFieldType(e16.ty) && e16.ty.origin ? [e16.ty.origin] : []));
130405
+ for (let n3 of keyModelPaths(e14, t3.model, u, i)) {
130406
+ for (let e15 of n3)
130407
+ i.add(e15.destModel);
130408
+ placeChain(t3, n3), c3 = true;
130409
+ }
130239
130410
  }
130240
130411
  return c3 ? a : t;
130241
130412
  }
@@ -130732,7 +130903,15 @@ var WindowFold = class extends HirFold {
130732
130903
  }
130733
130904
  return t;
130734
130905
  }
130906
+ levels = /* @__PURE__ */ new Map;
130735
130907
  windowInput(e15, t) {
130908
+ let n = [];
130909
+ for (let e16 of t)
130910
+ (n[this.levels.get(e16) ?? 0] ??= []).push(e16);
130911
+ let [r3, ...i] = n;
130912
+ return i.reduce((e16, t3) => this.windowLevel(e16, t3), this.windowLevel(e15, r3));
130913
+ }
130914
+ windowLevel(e15, t) {
130736
130915
  return {
130737
130916
  kind: "window",
130738
130917
  id: this.resolver.newNodeId(),
@@ -130775,17 +130954,17 @@ var WindowFold = class extends HirFold {
130775
130954
  if (!this.hasWindowBelow(e15))
130776
130955
  return e15;
130777
130956
  if (e15.kind === Kind.FUNCTION_CALL) {
130778
- let n = {
130957
+ let n = t.length, r3 = {
130779
130958
  ...e15,
130780
130959
  args: e15.args.map((e16) => this.hoistWindows(e16, t))
130781
130960
  };
130782
130961
  if (!isWindowFn(e15.name.name))
130783
- return n;
130784
- let r3 = `__w${this.counter++}`;
130785
- return t.push({
130786
- name: r3,
130787
- value: n
130788
- }), this.columnRef(r3, n.ty);
130962
+ return r3;
130963
+ let i = `__w${this.counter++}`, a = {
130964
+ name: i,
130965
+ value: r3
130966
+ }, s3 = t.slice(n).map((e16) => this.levels.get(e16) ?? 0);
130967
+ return this.levels.set(a, s3.length > 0 ? Math.max(...s3) + 1 : 0), t.push(a), this.columnRef(i, r3.ty);
130789
130968
  }
130790
130969
  return e15.kind === Kind.NAMED_EXPRESSION ? {
130791
130970
  ...e15,
@@ -131088,6 +131267,8 @@ function resolvePrefix(e15, t, n) {
131088
131267
  let s3;
131089
131268
  if (isErrType(r3.ty))
131090
131269
  s3 = errType;
131270
+ else if (isTableType(r3.ty) && r3.ty.param)
131271
+ e15.dataset.diagnostics.push(createError(ErrorCode.OPERATOR_0_ON_PARAM_1, t.right.loc, undefined, i, r3.ty.param)), s3 = errType;
131091
131272
  else if (!isScalarLikeType(r3.ty))
131092
131273
  e15.dataset.diagnostics.push(createError(ErrorCode.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0, t.loc, undefined, r3.ty)), s3 = errType;
131093
131274
  else {
@@ -131510,6 +131691,27 @@ function resolveSorts(e15, t, n, r3) {
131510
131691
  return !isErrType(a.ty) && !isAssignable(SHIM, a.ty, fieldTypeClass) && e15.dataset.diagnostics.push(createError(ErrorCode.EXPECTED_0_FOUND_1, t3.loc, undefined, fieldTypeClass, a.ty)), [a, i];
131511
131692
  });
131512
131693
  }
131694
+ function measureAliasScope(e15, t, n) {
131695
+ let r3 = locStub(), i = makeBlock(e15, r3, aqlNull(e15, r3));
131696
+ for (let r4 of n) {
131697
+ if (!isNamedExpression(r4))
131698
+ continue;
131699
+ let n3 = r4.name.value, a = `${n3}'`, s3 = createFieldType(n3, unknownType, undefined, undefined, "metric");
131700
+ i.declarations.set(n3, {
131701
+ id: e15.newNodeId(r4.loc),
131702
+ kind: "metric",
131703
+ name: makeIdent(e15, a, [], s3),
131704
+ ty: s3,
131705
+ body: {
131706
+ syntax: "aql",
131707
+ definition: r4.expr
131708
+ },
131709
+ scope: t,
131710
+ source: n3
131711
+ });
131712
+ }
131713
+ return makeScope(t, i);
131714
+ }
131513
131715
  function namesResultField(e15, t) {
131514
131716
  if (isFunctionCall(e15) && functionCallName(e15) === Kind.NOT_KEYWORD && e15.args.length === 1)
131515
131717
  return namesResultField(e15.args[0], t);
@@ -131522,7 +131724,7 @@ function classifyFilters(e15, t, n, r3, i) {
131522
131724
  let a = [], s3 = [];
131523
131725
  return t.filters.forEach((t3) => {
131524
131726
  let c3 = namesResultField(t3, i) ? n : r3, l = e15.resolveExpr(t3, c3);
131525
- validateExploreFilter(e15, t3, l), !isErrType(l.ty) && (isResultFieldFilter(l) ? a.push(l) : isTableType(l.ty) ? s3.push(desugarTableCondition(e15, l, n)) : referencesAggregateAlias(l) ? e15.dataset.diagnostics.push(createError(ErrorCode.INVALID_CONDITIONAL_EXPRESSION_IN_0, t3.loc, undefined, "filters")) : involvesTable(l) || s3.push(desugarMeasureCondition(e15, desugarSimpleModelCondition(e15, desugarShorthandCondition(e15, l)))));
131727
+ validateExploreFilter(e15, t3, l), !isErrType(l.ty) && (isResultFieldFilter(l, i) ? a.push(l) : isTableType(l.ty) ? s3.push(desugarTableCondition(e15, l, n)) : referencesAggregateAlias(l) ? e15.dataset.diagnostics.push(createError(ErrorCode.INVALID_CONDITIONAL_EXPRESSION_IN_0, t3.loc, undefined, "filters")) : involvesTable(l) || s3.push(desugarMeasureCondition(e15, desugarSimpleModelCondition(e15, desugarShorthandCondition(e15, l)))));
131526
131728
  }), {
131527
131729
  resultFilterNodes: a,
131528
131730
  contextFilterNodes: s3
@@ -131579,35 +131781,35 @@ function resolveDynamicExploreInner(e15, t, n) {
131579
131781
  let t3 = originOf(e16.ty);
131580
131782
  t3 && li3.add(modelFieldRefAsKey(t3));
131581
131783
  }
131582
- let di3 = [...oi3];
131784
+ let di3 = [...oi3], fi3 = measureAliasScope(e15, me3, t.measures);
131583
131785
  for (let n3 of t.having) {
131584
- let t3 = e15.resolveExpr(n3, U3);
131786
+ let t3 = e15.resolveExpr(n3, fi3);
131585
131787
  validateHavingGrouped(e15, n3, t3, li3) && oi3.push(desugarMeasureCondition(e15, t3, di3, true));
131586
131788
  }
131587
131789
  r3.length === 0 && t.measures.length === 0 && e15.dataset.diagnostics.push(createError(ErrorCode.INVALID_EXPRESSION_0, t.loc, undefined, "Explore must have at least one dimension or measure."));
131588
- let fi3 = grainDimsOf(r3), pi3 = S3.map((e16) => e16.ty), mi3 = new Set(pi3.map((e16) => e16.fieldName)), hi3 = (e16) => {
131790
+ let pi3 = grainDimsOf(r3), mi3 = S3.map((e16) => e16.ty), hi3 = new Set(mi3.map((e16) => e16.fieldName)), gi3 = (e16) => {
131589
131791
  let t3 = unwrapNot(e16);
131590
- return t3.kind === Kind.FUNCTION_CALL && t3.args.length > 0 && t3.args[0].kind === Kind.IDENTIFIER && mi3.has(t3.args[0].name);
131591
- }, gi3 = yr4.filter(hi3), _i3 = yr4.filter((e16) => !hi3(e16)), vi3 = {
131792
+ return t3.kind === Kind.FUNCTION_CALL && t3.args.length > 0 && t3.args[0].kind === Kind.IDENTIFIER && hi3.has(t3.args[0].name);
131793
+ }, _i3 = yr4.filter(gi3), vi3 = yr4.filter((e16) => !gi3(e16)), yi3 = {
131592
131794
  resolver: e15,
131593
131795
  loc: t.loc,
131594
131796
  dimColumns: i,
131595
131797
  markedDims: k3,
131596
131798
  typedMeasures: w3,
131597
131799
  resultTableTy: L3,
131598
- grainDims: fi3
131599
- }, yi3 = {};
131800
+ grainDims: pi3
131801
+ }, bi3 = {};
131600
131802
  for (let [e16, t3] of Ze4) {
131601
131803
  let { ty: n3 } = e16;
131602
- isFieldType(n3) && n3.origin && (yi3[modelFieldRefAsKey(n3.origin)] = t3);
131804
+ isFieldType(n3) && n3.origin && (bi3[modelFieldRefAsKey(n3.origin)] = t3);
131603
131805
  }
131604
- let bi3 = (e16) => isFieldType(e16.ty) && e16.ty.origin ? modelFieldRefAsKey(e16.ty.origin) : undefined, xi3 = f.length + p3.length > 0, Si2 = (n3, r4) => {
131605
- if (!xi3)
131806
+ let xi3 = (e16) => isFieldType(e16.ty) && e16.ty.origin ? modelFieldRefAsKey(e16.ty.origin) : undefined, Si2 = f.length + p3.length > 0, Ci3 = (n3, r4) => {
131807
+ if (!Si2)
131606
131808
  return n3;
131607
131809
  let i3 = (e16) => {
131608
131810
  if (!r4)
131609
131811
  return true;
131610
- let t3 = bi3(e16);
131812
+ let t3 = xi3(e16);
131611
131813
  return t3 !== undefined && r4.has(t3);
131612
131814
  };
131613
131815
  return {
@@ -131616,35 +131818,35 @@ function resolveDynamicExploreInner(e15, t, n) {
131616
131818
  ty: n3.ty,
131617
131819
  rows: f.filter(i3),
131618
131820
  cols: p3.filter(i3),
131619
- sortDirs: yi3,
131821
+ sortDirs: bi3,
131620
131822
  value: n3
131621
131823
  };
131622
- }, Ci3 = f.length, wi3 = p3.length, Ti3 = [...new Set(t.measures.map((e16) => (isNamedExpression(e16) ? e16.expr : e16).loc.source))], Ei3 = (e16, t3) => {
131824
+ }, wi3 = f.length, Ti3 = p3.length, Ei3 = [...new Set(t.measures.map((e16) => (isNamedExpression(e16) ? e16.expr : e16).loc.source))], Di3 = (e16, t3) => {
131623
131825
  let n3 = new Set(t3.map((e17) => e17.origin ? modelFieldRefAsKey(e17.origin) : "").filter(Boolean)), r4 = (e17) => {
131624
- let t4 = bi3(e17);
131826
+ let t4 = xi3(e17);
131625
131827
  return t4 !== undefined && n3.has(t4);
131626
- }, i3 = exploreTypeLabel(f.filter(r4).length, p3.filter(r4).length, Ci3, wi3), a3 = t3.filter((e17) => e17.origin).map((e17) => `${e17.origin.modelName}.${e17.origin.fieldName}`), s4 = {
131828
+ }, i3 = exploreTypeLabel(f.filter(r4).length, p3.filter(r4).length, wi3, Ti3), a3 = t3.filter((e17) => e17.origin).map((e17) => `${e17.origin.modelName}.${e17.origin.fieldName}`), s4 = {
131627
131829
  ...a3.length > 0 ? { dimensions: a3 } : {},
131628
- ...Ti3.length > 0 ? { metrics: Ti3 } : {}
131830
+ ...Ei3.length > 0 ? { metrics: Ei3 } : {}
131629
131831
  };
131630
131832
  return {
131631
131833
  ...e16,
131632
131834
  annotation: [
131633
131835
  ...e16.annotation ?? [],
131634
131836
  { comments: [i3] },
131635
- ...a3.length > 0 || Ti3.length > 0 ? [{ meta: s4 }] : []
131837
+ ...a3.length > 0 || Ei3.length > 0 ? [{ meta: s4 }] : []
131636
131838
  ]
131637
131839
  };
131638
- }, Di3 = r3.filter((e16) => isConstantArrayType(e16.ty)), Oi3;
131639
- if (Di3.length > 0) {
131640
- let n3 = dedupeGrains(c3), r4 = expandRollup(Di3.map(groupingDimSets)), i3 = n3.map(grainName), a3 = /* @__PURE__ */ new Set, s4 = r4.filter((e16) => {
131840
+ }, Oi3 = r3.filter((e16) => isConstantArrayType(e16.ty)), ki4;
131841
+ if (Oi3.length > 0) {
131842
+ let n3 = dedupeGrains(c3), r4 = expandRollup(Oi3.map(groupingDimSets)), i3 = n3.map(grainName), a3 = /* @__PURE__ */ new Set, s4 = r4.filter((e16) => {
131641
131843
  let t3 = [.../* @__PURE__ */ new Set([...i3, ...e16.map(grainName)])].sort().join(" ");
131642
131844
  return !a3.has(t3) && (a3.add(t3), true);
131643
131845
  }).map((r5) => {
131644
- let i4 = dedupeGrains([...n3, ...r5]), a4 = grainFields(i4), s5 = buildBranch(vi3, i4), c4 = new Set(a4.map((e16) => e16.fieldName)), l3 = k3.length > 0 && k3.every((e16) => c4.has(e16.fieldName)) && _i3.length > 0 ? makeTransform(e15, "filter", [s5, ..._i3], s5.ty, t.loc) : s5, u3 = new Set(a4.map((e16) => e16.origin ? modelFieldRefAsKey(e16.origin) : "").filter(Boolean));
131645
- return Ei3(Si2(l3, u3), a4);
131846
+ let i4 = dedupeGrains([...n3, ...r5]), a4 = grainFields(i4), s5 = buildBranch(yi3, i4), c4 = new Set(a4.map((e16) => e16.fieldName)), l3 = k3.length > 0 && k3.every((e16) => c4.has(e16.fieldName)) && vi3.length > 0 ? makeTransform(e15, "filter", [s5, ...vi3], s5.ty, t.loc) : s5, u3 = new Set(a4.map((e16) => e16.origin ? modelFieldRefAsKey(e16.origin) : "").filter(Boolean));
131847
+ return Di3(Ci3(l3, u3), a4);
131646
131848
  });
131647
- Oi3 = s4.length === 1 ? s4[0] : {
131849
+ ki4 = s4.length === 1 ? s4[0] : {
131648
131850
  kind: "union",
131649
131851
  id: e15.newNodeId(t.loc),
131650
131852
  ty: L3,
@@ -131653,17 +131855,17 @@ function resolveDynamicExploreInner(e15, t, n) {
131653
131855
  branches: s4
131654
131856
  };
131655
131857
  } else
131656
- Oi3 = Ei3(buildBranch(vi3, fi3), grainFields(fi3));
131657
- oi3.length > 0 && (Oi3 = {
131858
+ ki4 = Di3(buildBranch(yi3, pi3), grainFields(pi3));
131859
+ oi3.length > 0 && (ki4 = {
131658
131860
  kind: "where",
131659
131861
  id: e15.newNodeId(t.loc),
131660
- ty: Oi3.ty,
131661
- value: Oi3,
131862
+ ty: ki4.ty,
131863
+ value: ki4,
131662
131864
  conditions: oi3
131663
131865
  });
131664
- let ki4 = t.options.some((e16) => e16.value === "include_empty_children_rows") || undefined, Ai3 = w3.length > 0, ji4 = [...oi3, ...yr4];
131665
- ki4 && !m3 && Ai3 && Di3.length === 0 && i.length > 0 && (Oi3 = buildEmptyChildrenChain(vi3, i, ji4, Oi3, [...i, ...I3]));
131666
- let Mi3 = S3.flatMap((e16) => {
131866
+ let Ai3 = t.options.some((e16) => e16.value === "include_empty_children_rows") || undefined, ji4 = w3.length > 0, Mi3 = [...oi3, ...yr4];
131867
+ Ai3 && !m3 && ji4 && Oi3.length === 0 && i.length > 0 && (ki4 = buildEmptyChildrenChain(yi3, i, Mi3, ki4, [...i, ...I3]));
131868
+ let Ni3 = S3.flatMap((e16) => {
131667
131869
  if (!e16.rollup)
131668
131870
  return [];
131669
131871
  let t3 = bizCalDimRefs(e16.expr).map((e17) => e17.ty.fieldName).find((e17) => s3.has(e17));
@@ -131671,91 +131873,97 @@ function resolveDynamicExploreInner(e15, t, n) {
131671
131873
  ty: createFieldType(rollupMarkerFieldName(e16.ty.fieldName), numberType),
131672
131874
  sourceName: rollupMarkerFieldName(t3)
131673
131875
  }] : [];
131674
- }), Ni3 = [
131876
+ }), Pi3 = [
131675
131877
  ...a,
131676
131878
  ...I3,
131677
- ...Mi3.map((e16) => e16.ty)
131879
+ ...Ni3.map((e16) => e16.ty)
131678
131880
  ].map((e16) => e16.fieldName);
131679
131881
  if (S3.length > 0) {
131680
131882
  let n3 = new Set(a.map((e16) => e16.fieldName)), r4 = m3 ? [...a, ...i.filter((e16) => !n3.has(e16.fieldName))] : a, s4 = createTableType(createRowType([
131681
131883
  ...r4,
131682
131884
  ...I3,
131683
- ...Mi3.map((e16) => e16.ty)
131885
+ ...Ni3.map((e16) => e16.ty)
131684
131886
  ]), undefined);
131685
- Oi3 = buildBizCalWrapper(e15, Oi3, r4, I3, S3, Mi3, s4, t.loc);
131887
+ ki4 = buildBizCalWrapper(e15, ki4, r4, I3, S3, Ni3, s4, t.loc);
131686
131888
  }
131687
- let Pi3 = Di3.length === 0 ? yr4 : gi3;
131688
- Pi3.length > 0 && (Oi3 = makeTransform(e15, "filter", [Oi3, ...Pi3], Oi3.ty, t.loc));
131689
- let Fi3 = !!e15.dataset.sqlGenerationFlags.shouldApplySortings, Ii2 = Fi3 && S3.length === 0 && ![...l].some((e16) => u.has(e16)), Li3 = Ze4.flatMap(([e16, t3]) => isFieldType(e16.ty) ? [[e16.ty.fieldName, t3]] : []);
131690
- if (!m3 && Fi3 && Ze4.length > 0 && (Oi3 = {
131889
+ let Fi3 = Oi3.length === 0 ? yr4 : _i3;
131890
+ Fi3.length > 0 && (ki4 = makeTransform(e15, "filter", [ki4, ...Fi3], ki4.ty, t.loc));
131891
+ let Ii2 = !!e15.dataset.sqlGenerationFlags.shouldApplySortings, Li3 = Ii2 && S3.length === 0 && ![...l].some((e16) => u.has(e16)), Ri3 = Ze4.flatMap(([e16, t3]) => isFieldType(e16.ty) ? [[e16.ty.fieldName, t3]] : []);
131892
+ if (!m3 && Ii2 && Ze4.length > 0 && (ki4 = {
131691
131893
  kind: "sort",
131692
131894
  id: e15.newNodeId(t.loc),
131693
- ty: Oi3.ty,
131694
- input: Oi3,
131695
- iterationDepth: iterationDepthOf(Oi3),
131895
+ ty: ki4.ty,
131896
+ input: ki4,
131897
+ iterationDepth: iterationDepthOf(ki4),
131696
131898
  by: Ze4
131697
131899
  }), m3) {
131698
- let n3 = fi3.filter((e16) => l.has(grainName(e16))), r4 = ki4 && n3.length > 0 && Ai3 ? buildEmptyChildrenPrefixes(vi3, n3, ji4).map((e16) => e16.node) : undefined;
131699
- Oi3 = {
131900
+ let n3 = pi3.filter((e16) => l.has(grainName(e16))), r4 = Ai3 && n3.length > 0 && ji4 ? buildEmptyChildrenPrefixes(yi3, n3, Mi3).map((e16) => e16.node) : undefined;
131901
+ ki4 = {
131700
131902
  kind: "pivot",
131701
131903
  id: e15.newNodeId(t.loc),
131702
- ty: Oi3.ty,
131703
- input: Oi3,
131704
- iterationDepth: iterationDepthOf(Oi3),
131904
+ ty: ki4.ty,
131905
+ input: ki4,
131906
+ iterationDepth: iterationDepthOf(ki4),
131705
131907
  rows: [...l],
131706
131908
  columns: [...u],
131707
131909
  rollupRows: [...l].filter((e16) => s3.has(e16)),
131708
131910
  rollupColumns: [...u].filter((e16) => s3.has(e16)),
131709
- includeEmptyChildrenRows: ki4,
131911
+ includeEmptyChildrenRows: Ai3,
131710
131912
  emptyChildrenPrefixes: r4,
131711
- outputColumns: S3.length > 0 ? Ni3 : undefined,
131712
- sorts: Ii2 ? Li3 : undefined
131913
+ outputColumns: S3.length > 0 ? Pi3 : undefined,
131914
+ sorts: Li3 ? Ri3 : undefined
131713
131915
  };
131714
131916
  }
131715
- return Di3.length === 0 && (Oi3 = Si2(Oi3)), {
131917
+ return Oi3.length === 0 && (ki4 = Ci3(ki4)), {
131716
131918
  kind: "explore_context",
131717
131919
  id: e15.newNodeId(t.loc),
131718
- ty: Oi3.ty,
131719
- value: Oi3,
131920
+ ty: ki4.ty,
131921
+ value: ki4,
131720
131922
  filters: ci3,
131721
131923
  allDimensions: [...f, ...p3]
131722
131924
  };
131723
131925
  }
131724
- function isBareAliasConstantFilter(e15) {
131725
- return e15.length === 2 && e15[0].kind === Kind.IDENTIFIER && e15[0].path.length === 0 && !involvesField(e15[1]);
131926
+ function isBareAliasResultFilter(e15, t) {
131927
+ return e15.length === 2 && e15[0].kind === Kind.IDENTIFIER && e15[0].path.length === 0 && readsOnlyResultColumns(e15[1], t);
131928
+ }
131929
+ function rhsAliases(e15) {
131930
+ return e15.kind === Kind.IDENTIFIER ? isFieldType(e15.ty) ? [e15.ty] : [] : e15.kind === Kind.FUNCTION_CALL ? e15.args.flatMap(rhsAliases) : e15.kind === Kind.NAMED_EXPRESSION ? rhsAliases(e15.expr) : [];
131931
+ }
131932
+ function readsOnlyResultColumns(e15, t) {
131933
+ return e15.kind === "computed_ref" ? false : e15.kind === Kind.IDENTIFIER ? !isFieldType(e15.ty) || e15.path.length === 0 && t.has(e15.name) : e15.kind === Kind.FUNCTION_CALL ? e15.args.every((e16) => readsOnlyResultColumns(e16, t)) : e15.kind !== Kind.NAMED_EXPRESSION || readsOnlyResultColumns(e15.expr, t);
131726
131934
  }
131727
131935
  function unwrapNot(e15) {
131728
131936
  return e15.kind === Kind.FUNCTION_CALL && e15.name.name === Kind.NOT_KEYWORD && e15.args.length === 1 ? unwrapNot(e15.args[0]) : e15;
131729
131937
  }
131730
- function isResultFieldFilter(e15) {
131938
+ function isResultFieldFilter(e15, t) {
131731
131939
  if (isErrType(e15.ty))
131732
131940
  return false;
131733
- let t = unwrapNot(e15);
131734
- if (t.kind !== Kind.FUNCTION_CALL)
131941
+ let n = unwrapNot(e15);
131942
+ if (n.kind !== Kind.FUNCTION_CALL)
131735
131943
  return false;
131736
- if (isBareAliasConstantFilter(t.args))
131944
+ if (isBareAliasResultFilter(n.args, t))
131737
131945
  return true;
131738
- let n = bareAliasLeaves(t);
131739
- return !!n && n.some(isAggregateAlias);
131946
+ let r3 = bareAliasLeaves(n, t);
131947
+ return !!r3 && r3.some(isAggregateAlias);
131740
131948
  }
131741
- function bareAliasLeaves(e15) {
131742
- let t = unwrapNot(e15);
131743
- if (t.kind !== Kind.FUNCTION_CALL)
131949
+ function bareAliasLeaves(e15, t) {
131950
+ let n = unwrapNot(e15);
131951
+ if (n.kind !== Kind.FUNCTION_CALL)
131744
131952
  return;
131745
- if (isBareAliasConstantFilter(t.args)) {
131746
- let e16 = t.args[0];
131747
- return isFieldType(e16.ty) ? [e16.ty] : undefined;
131953
+ if (isBareAliasResultFilter(n.args, t)) {
131954
+ let e16 = n.args[0];
131955
+ return isFieldType(e16.ty) ? [e16.ty, ...rhsAliases(n.args[1])] : undefined;
131748
131956
  }
131749
- if (t.name.name !== Kind.AND_KEYWORD && t.name.name !== Kind.OR_KEYWORD)
131957
+ if (n.name.name !== Kind.AND_KEYWORD && n.name.name !== Kind.OR_KEYWORD)
131750
131958
  return;
131751
- let n = [];
131752
- for (let e16 of t.args) {
131753
- let t3 = bareAliasLeaves(e16);
131754
- if (!t3)
131959
+ let r3 = [];
131960
+ for (let e16 of n.args) {
131961
+ let n3 = bareAliasLeaves(e16, t);
131962
+ if (!n3)
131755
131963
  return;
131756
- n.push(...t3);
131964
+ r3.push(...n3);
131757
131965
  }
131758
- return n;
131966
+ return r3;
131759
131967
  }
131760
131968
  function isAggregateAlias(e15) {
131761
131969
  return e15.subClass === "aggregate" || e15.subClass === "measure" || e15.subClass === "metric";
@@ -131766,9 +131974,6 @@ function referencesAggregateAlias(e15) {
131766
131974
  function involvesTable(e15) {
131767
131975
  return isTableType(e15.ty) && !e15.ty.isLiteral ? true : e15.kind === Kind.FUNCTION_CALL ? e15.args.some(involvesTable) : e15.kind === Kind.NAMED_EXPRESSION ? involvesTable(e15.expr) : e15.kind === "block" && involvesTable(e15.result);
131768
131976
  }
131769
- function involvesField(e15) {
131770
- return e15 ? e15.kind === "computed_ref" ? true : e15.kind === Kind.IDENTIFIER ? isFieldType(e15.ty) : e15.kind === Kind.FUNCTION_CALL ? e15.args.some(involvesField) : e15.kind === Kind.NAMED_EXPRESSION && involvesField(e15.expr) : false;
131771
- }
131772
131977
  function validateExploreFilter(e15, t, n) {
131773
131978
  let { ty: r3 } = n;
131774
131979
  isErrType(r3) || !isAssignable(SHIM, r3, truefalseType) && !isAssignable(SHIM, r3, tableTypeClass) && e15.dataset.diagnostics.push(createError(ErrorCode.EXPECTED_0_FOUND_1, t.loc, undefined, "Condition", r3));
@@ -135304,7 +135509,12 @@ function matchToPlan(e16, t) {
135304
135509
  type: SqlType.TRUEFALSE
135305
135510
  };
135306
135511
  }
135307
- return isUserAttributeType(n.ty) ? datetimeUaToPlan(e16[0], n, t) : unsupported$1("match against a non-literal range");
135512
+ return isUserAttributeType(n.ty) ? datetimeUaToPlan(e16[0], n, t) : isNullValue$1(n) ? {
135513
+ kind: "call_variadic",
135514
+ func: "is",
135515
+ exprs: [scalarToPlan(e16[0], t), scalarToPlan(n, t)],
135516
+ type: SqlType.TRUEFALSE
135517
+ } : unsupported$1("match against a non-literal range");
135308
135518
  }
135309
135519
  function negateMagnitude(e16) {
135310
135520
  return e16.kind === "literal" && e16.literal === "number" ? {
@@ -136418,7 +136628,7 @@ function attachLodParts(e17, t, n, r3, i, a) {
136418
136628
  type: SqlType.UNKNOWN
136419
136629
  }), k3 = relationType(n.relation), N3 = i3.by.map((e18, r5) => {
136420
136630
  let { expr: a4, origin: s4 } = i3.by[r5];
136421
- return grainKeyEq(t, s4, a4.kind === Kind.IDENTIFIER && s4.fieldName.includes("->") && l(a4) == null && n.tryIndexOf(a4) == null ? subtimeGrainScalar(n, k3, s4) : lodKeyScalar(derefExtend(t, i3.input, a4), n, u), E3(w3 + r5));
136631
+ return grainKeyEq(t, s4, a4.kind === Kind.IDENTIFIER && s4.fieldName.includes("->") && l(a4) == null && n.tryIndexOf(a4) == null ? subtimeGrainScalar(n, k3, s4) : lodKeyScalar(joinBackKey(t, i3.input, a4, n), n, u), E3(w3 + r5));
136422
136632
  });
136423
136633
  f = cons({
136424
136634
  kind: "join",
@@ -136586,6 +136796,7 @@ function lowerModelSourceRelation(e17, t, n) {
136586
136796
  return buildJoinScope(t, r3, i, s4, {
136587
136797
  rootRel: a,
136588
136798
  fanouts: c4,
136799
+ substitute: slotSubstitutes(t, n, e17),
136589
136800
  tree: n
136590
136801
  });
136591
136802
  })() : buildJoinScope(t, r3, i, [], { rootRel: a }), c3 = n.kind === "expand_model" ? expandTreeComputed(t, n) : [], l = n.kind === "expand_model" ? expandTreeComputedAll(t, n) : [], u = (e18) => {
@@ -136969,13 +137180,19 @@ function buildJoinScopeUncached(e17, t, n, r3, i) {
136969
137180
  };
136970
137181
  }
136971
137182
  function extendSlotsOf(e17) {
137183
+ let t = [];
137184
+ for (let n of scansOf(e17))
137185
+ forEachTreeNode(n, (e18) => {
137186
+ e18.extend !== undefined && t.push(e18);
137187
+ });
137188
+ return t;
137189
+ }
137190
+ function scansOf(e17) {
136972
137191
  let t = [], n = /* @__PURE__ */ new Set, r3 = (e18) => {
136973
137192
  if (!e18 || typeof e18 != "object" || n.has(e18))
136974
137193
  return;
136975
137194
  if (n.add(e18), e18.kind === "expand_model") {
136976
- forEachTreeNode(e18, (e19) => {
136977
- e19.extend !== undefined && t.push(e19);
136978
- });
137195
+ t.push(e18);
136979
137196
  return;
136980
137197
  }
136981
137198
  let i = e18;
@@ -136989,6 +137206,22 @@ function extendSlotsOf(e17) {
136989
137206
  };
136990
137207
  return r3(e17), t;
136991
137208
  }
137209
+ function joinBackKey(e17, t, n, r3) {
137210
+ let i = n.kind === Kind.IDENTIFIER ? refOrigin(n) : undefined;
137211
+ if (!i)
137212
+ return n;
137213
+ for (let a of scansOf(t)) {
137214
+ let t3;
137215
+ if (forEachTreeNode(a, (a3) => {
137216
+ if (t3 !== undefined || a3.extend === undefined)
137217
+ return;
137218
+ let s3 = extendDef(e17, a3.extend), c3 = s3.computed.find((e18) => e18.origin && originKey(e18.origin) === originKey(i));
137219
+ c3 && (t3 = !isCrossModelExtend(e17, a3) || readsPart(s3.parts, c3.expr) || r3.tryIndexOf(n) == null ? c3.expr : n);
137220
+ }), t3)
137221
+ return t3;
137222
+ }
137223
+ return n;
137224
+ }
136992
137225
  function derefExtend(e17, t, n) {
136993
137226
  if (n.kind !== Kind.IDENTIFIER)
136994
137227
  return n;
@@ -137248,51 +137481,54 @@ function extendRootRelation(e17, t, n) {
137248
137481
  function lowerExtendRelation(e17, t, n) {
137249
137482
  return memoized("extendRelation", `${extendIdOf(t)}|${identityToken(n)}`, () => lowerExtendRelationUncached(e17, t, n));
137250
137483
  }
137484
+ function slotSubstitutes(e17, t, n) {
137485
+ let r3 = [];
137486
+ walkTree(t, (e18) => {
137487
+ e18 !== t && r3.push(e18);
137488
+ });
137489
+ let i = crossModelSubstitute(e17, r3.filter((t3) => isCrossModelExtend(e17, t3)), scopeModelsOf(t), n);
137490
+ for (let t3 of r3)
137491
+ sealedSlot(e17, t3) && i.set(t3.model, lowerSealedSlot(e17, t3, n));
137492
+ return i;
137493
+ }
137251
137494
  function lowerExtendRelationUncached(e17, t, n) {
137252
137495
  let r3 = extendDef(e17, extendIdOf(t)), i = r3.base;
137253
137496
  bareNode(i) && unsupported$1(`extend on '${t.model}' has no join tree`);
137254
- let a = [];
137255
- walkTree(i, (e18) => {
137256
- e18 !== i && a.push(e18);
137257
- });
137258
- let s3 = crossModelSubstitute(e17, a.filter((t3) => isCrossModelExtend(e17, t3)), scopeModelsOf(i), n);
137259
- for (let t3 of a)
137260
- sealedSlot(e17, t3) && s3.set(t3.model, lowerSealedSlot(e17, t3, n));
137261
- let c3 = i.model, l = /* @__PURE__ */ new Set([c3]), u = (t3, n3) => ({
137497
+ let a = slotSubstitutes(e17, i, n), s3 = i.model, c3 = /* @__PURE__ */ new Set([s3]), l = (t3, n3) => ({
137262
137498
  ...t3,
137263
137499
  children: t3.children.map((t4) => {
137264
137500
  let r4 = t4.input.model, i3 = [...n3, t4.edge];
137265
- if (!l.has(r4))
137266
- return l.add(r4), {
137501
+ if (!c3.has(r4))
137502
+ return c3.add(r4), {
137267
137503
  ...t4,
137268
- input: u(t4.input, i3)
137504
+ input: l(t4.input, i3)
137269
137505
  };
137270
137506
  let a3 = mintModelAlias(e17, r4, pathSig(i3));
137271
137507
  return {
137272
137508
  edge: retargetEdge(t4.edge, a3),
137273
- input: u(t4.input, i3)
137509
+ input: l(t4.input, i3)
137274
137510
  };
137275
137511
  })
137276
- }), f = buildJoinScope(e17, c3, undefined, expandEdges(u(i, [])), {
137512
+ }), u = buildJoinScope(e17, s3, undefined, expandEdges(l(i, [])), {
137277
137513
  rootRel: extendRootRelation(e17, i, n),
137278
- substitute: s3,
137514
+ substitute: a,
137279
137515
  tree: i
137280
- }), p3 = [...r3.parts, ...baseTreeParts(e17, r3)], m3 = f.relation, S3 = () => {
137516
+ }), f = [...r3.parts, ...baseTreeParts(e17, r3)], p3 = u.relation, m3 = () => {
137281
137517
  return;
137282
137518
  };
137283
- n && p3.length > 0 && ({ base: m3, partOf: S3 } = attachLodParts(n, e17, f, p3, f.relation, f.arity));
137284
- let w3 = inlineExtendComputed([...expandTreeComputedAll(e17, i), ...r3.computed]), E3 = projectedComputed(e17, t).filter((e18) => n != null && p3.length > 0 || !readsPart(p3, w3(e18.expr))), k3 = (t3) => {
137519
+ n && f.length > 0 && ({ base: p3, partOf: m3 } = attachLodParts(n, e17, u, f, u.relation, u.arity));
137520
+ let S3 = inlineExtendComputed([...expandTreeComputedAll(e17, i), ...r3.computed]), w3 = projectedComputed(e17, t).filter((e18) => n != null && f.length > 0 || !readsPart(f, S3(e18.expr))), E3 = (t3) => {
137285
137521
  let n3 = aliasedOrigin(e17, t3);
137286
- return n3 ? f.indexOfOrigin(n3) : S3(t3) ?? f.indexOf(t3);
137287
- }, N3 = E3.map((e18) => scalarToPlan(w3(e18.expr), k3)), I3 = E3.map((e18) => e18.origin);
137522
+ return n3 ? u.indexOfOrigin(n3) : m3(t3) ?? u.indexOf(t3);
137523
+ }, k3 = w3.map((e18) => scalarToPlan(S3(e18.expr), E3)), N3 = w3.map((e18) => e18.origin);
137288
137524
  return {
137289
- relation: N3.length > 0 ? cons({
137525
+ relation: k3.length > 0 ? cons({
137290
137526
  kind: "map",
137291
- input: m3,
137292
- scalars: N3,
137293
- origins: I3
137294
- }) : m3,
137295
- columns: [...relationType(m3), ...E3.map((e18) => ({
137527
+ input: p3,
137528
+ scalars: k3,
137529
+ origins: N3
137530
+ }) : p3,
137531
+ columns: [...relationType(p3), ...w3.map((e18) => ({
137296
137532
  type: sqlTypeOf(e18.ty),
137297
137533
  origin: e18.origin
137298
137534
  }))]
@@ -138428,7 +138664,8 @@ function lowerTransitionCoalesce(e17, t, n) {
138428
138664
  measureAt: (t4) => e18.get(t4),
138429
138665
  measures: k3.map((e19) => ({
138430
138666
  name: e19.name,
138431
- pos: e19.abs
138667
+ pos: e19.abs,
138668
+ alias: e19.alias
138432
138669
  }))
138433
138670
  };
138434
138671
  }
@@ -138458,7 +138695,8 @@ function lowerTransitionCoalesce(e17, t, n) {
138458
138695
  measureAt: (e19) => t3.get(e19),
138459
138696
  measures: k3.map((e19) => ({
138460
138697
  name: e19.name,
138461
- pos: e19.abs
138698
+ pos: e19.abs,
138699
+ alias: e19.alias
138462
138700
  })),
138463
138701
  nullMeasureFilter: true
138464
138702
  };
@@ -138531,7 +138769,8 @@ function lowerTransitionCoalesce(e17, t, n) {
138531
138769
  measureAt: (e18) => Ze4.get(e18),
138532
138770
  measures: k3.map((e18, t3) => ({
138533
138771
  name: e18.name,
138534
- pos: f + t3
138772
+ pos: f + t3,
138773
+ alias: e18.alias
138535
138774
  })),
138536
138775
  nullMeasureFilter: true
138537
138776
  };
@@ -143306,9 +143545,11 @@ function collectJoins(e17, t = [], n = /* @__PURE__ */ new Set) {
143306
143545
  purpose: JoinPurpose.EXPANSION
143307
143546
  });
143308
143547
  } else {
143309
- let n3 = onLeftModel(e17.on) ?? fromRootAlias(e17.left);
143548
+ let n3 = /* @__PURE__ */ new Map;
143549
+ collectFieldRefs(e17.on, n3);
143550
+ let i = [...n3.keys()].filter((e18) => e18 !== r3);
143310
143551
  t.push({
143311
- sourceTable: [n3],
143552
+ sourceTable: i.length > 0 ? i : [fromRootAlias(e17.left)],
143312
143553
  destTable: r3,
143313
143554
  joinType: JOIN_TYPE[e17.joinType],
143314
143555
  joinOn: e17.on,
@@ -143335,17 +143576,6 @@ function toPlaceholderJoinOn(e17, t, n, r3) {
143335
143576
  operands: e17.operands.map((e18) => toPlaceholderJoinOn(e18, t, n, r3))
143336
143577
  };
143337
143578
  }
143338
- function onLeftModel(e17) {
143339
- if (typeof e17 != "string") {
143340
- if (e17.operator === OperationType.AND)
143341
- return onLeftModel(e17.operands[0]);
143342
- if (e17.operator === OperationType.EQ) {
143343
- let t = e17.operands[0];
143344
- if (typeof t != "string" && t.operator === OperationType.FIELD && typeof t.operands[0] == "string")
143345
- return t.operands[0];
143346
- }
143347
- }
143348
- }
143349
143579
  function collectJoinOnRefs(e17, t) {
143350
143580
  e17.kind === "join" ? (e17.on && collectFieldRefs(e17.on, t), collectJoinOnRefs(e17.left, t), collectJoinOnRefs(e17.right, t)) : e17.kind === "subquery" && e17.select;
143351
143581
  }
@@ -146582,7 +146812,7 @@ function _transform(e17, t) {
146582
146812
  });
146583
146813
  }
146584
146814
  function wi3(e18, t3, r4, i3) {
146585
- let a3 = createFunctionCallExpression(createIdentifier("select"), [t3, r4], e18.loc), s4 = i3.find((e19) => e19.name.value === "sep")?.expr ?? createTextLiteral(","), c4 = i3.find((e19) => e19.name.value === "order")?.expr ?? createTextLiteral("ASC"), l3 = i3.find((e19) => e19.name.value === "distinct")?.expr ?? createTruefalseLiteral(false), u3 = getSqlFromRowLevelObject(n, getRowLevelObjectFromExpression(n, getTextLiteralFromExpression(n, s4), false)), f3 = import_lodash2.toUpper(c4.value), p4 = l3.value ? "DISTINCT" : "", m4 = computeAggregationKey(n, "string_agg", a3, `sep: ${stableStringify(u3)}, order: ${f3}, distinctOp: ${p4}`);
146815
+ let a3 = createFunctionCallExpression(createIdentifier("select"), [t3, createNamedExpression(createIdentifier("_f1"), r4)], e18.loc), s4 = i3.find((e19) => e19.name.value === "sep")?.expr ?? createTextLiteral(","), c4 = i3.find((e19) => e19.name.value === "order")?.expr ?? createTextLiteral("ASC"), l3 = i3.find((e19) => e19.name.value === "distinct")?.expr ?? createTruefalseLiteral(false), u3 = getSqlFromRowLevelObject(n, getRowLevelObjectFromExpression(n, getTextLiteralFromExpression(n, s4), false)), f3 = import_lodash2.toUpper(c4.value), p4 = l3.value ? "DISTINCT" : "", m4 = computeAggregationKey(n, "string_agg", a3, `sep: ${stableStringify(u3)}, order: ${f3}, distinctOp: ${p4}`);
146586
146816
  return aggregateOnTable(n, e18, a3, m4, (e19, t4) => {
146587
146817
  let n3 = t4 ? createOperation(OperationType.FIELD, ["SOURCE", e19.fields[e19.fields.length - 1].name]) : e19.fields[e19.fields.length - 1].sql;
146588
146818
  return {