@gingkoo/pandora-metabase 1.0.158-alpha.19 → 1.0.158-alpha.20

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.
@@ -574,7 +574,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
574
574
  children: (0, _jsxRuntime.jsx)(_pandora.Select, {
575
575
  maxWidth: '500px',
576
576
  size: 'large',
577
- placeholder: "\u53EF\u8F93\u5165\u56DE\u8F66\u65B0\u589E\u4E0B\u62C9\u9009\u9879",
577
+ placeholder: (0, _locale.__)('customColumn.inputListPlaceholder'),
578
578
  allowCreate: true,
579
579
  multiple: true,
580
580
  getPopupContainer: getCurrentPopupContainer,
@@ -105,6 +105,8 @@ var getQuotes = exports.getQuotes = function getQuotes(fun, _args, formulaList)
105
105
  }).join(', ');
106
106
  }
107
107
  return getOptionText(vv.val || '');
108
+ } else if ((0, _utils.isInputListType)(vv === null || vv === void 0 ? void 0 : vv.type)) {
109
+ return (0, _utils.getInputListValues)(vv.val).join(', ');
108
110
  } else {
109
111
  return vv.val;
110
112
  }
@@ -1214,6 +1214,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1214
1214
  if (v.type === _types.AtomsTypeEnum.SELECT) {
1215
1215
  return getSelectDisplayText(v);
1216
1216
  }
1217
+ if ((0, _utils3.isInputListType)(v.type)) {
1218
+ return (0, _utils3.getInputListValues)(v.val).join(', ');
1219
+ }
1217
1220
  if (Array.isArray(v.val)) {
1218
1221
  return v.val.join(', ');
1219
1222
  }
@@ -2668,6 +2671,12 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
2668
2671
  message: (0, _locale.__)('metabase.sqlErrorMissingCustomInput')
2669
2672
  };
2670
2673
  }
2674
+ if ((0, _utils3.isInputListType)(v.type) && !(0, _utils3.getInputListValues)(v.val).length) {
2675
+ return {
2676
+ isError: true,
2677
+ message: (0, _locale.__)('metabase.sqlErrorMissingSelection')
2678
+ };
2679
+ }
2671
2680
  if (v.type === _types.AtomsTypeEnum.CONSTANT) {
2672
2681
  return {
2673
2682
  isError: !!(v.id || v.val) && !(0, _utils3.getConstantLabel)(store.constantList, v.id || v.val),
@@ -2936,6 +2945,47 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
2936
2945
  })
2937
2946
  };
2938
2947
  }
2948
+ if ((0, _utils3.isInputListType)(type)) {
2949
+ var tagValues = (0, _utils3.getInputListValues)(v.val);
2950
+ return {
2951
+ className: (0, _classnames["default"])('teal-name sqb-InputListToken', {
2952
+ notSelected: !tagValues.length
2953
+ }),
2954
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
2955
+ children: [(0, _jsxRuntime.jsx)(_pandoraIcons.Tags, {}), (0, _jsxRuntime.jsx)(_pandora.Select, {
2956
+ className: 'sqb-Custom-input',
2957
+ size: 'large',
2958
+ autoWidth: true,
2959
+ maxWidth: '100%',
2960
+ animation: false,
2961
+ placeholder: (0, _locale.__)('customColumn.inputListPlaceholder'),
2962
+ allowCreate: true,
2963
+ multiple: true,
2964
+ dropdownMenuStyle: {
2965
+ minWidth: 160
2966
+ },
2967
+ triggerProps: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, getSelectTriggerProps()), {}, {
2968
+ autoAlignPopupWidth: false,
2969
+ autoAlignPopupMinWidth: true
2970
+ }),
2971
+ getPopupContainer: getCurrentPopupContainer,
2972
+ value: tagValues,
2973
+ onClick: function onClick(e) {
2974
+ return e.stopPropagation();
2975
+ },
2976
+ onChange: function onChange(val) {
2977
+ handleConstant((0, _utils3.getInputListValues)(val).join(','), index);
2978
+ },
2979
+ children: tagValues.map(function (option) {
2980
+ return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
2981
+ value: option,
2982
+ children: option
2983
+ }, option);
2984
+ })
2985
+ }), renderDeleteIcon(v, index, groupType)]
2986
+ })
2987
+ };
2988
+ }
2939
2989
  if (type === _types.AtomsTypeEnum.OPERATOR) {
2940
2990
  return {
2941
2991
  className: (0, _classnames["default"])('operator-trigger', {
@@ -1851,6 +1851,12 @@
1851
1851
  border-color: #c8e6c8 !important;
1852
1852
  }
1853
1853
 
1854
+ .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .Sqb-TableName.teal-name {
1855
+ background: #e4f7f4 !important;
1856
+ color: #0f766e !important;
1857
+ border-color: #b7e2db !important;
1858
+ }
1859
+
1854
1860
  .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .Sqb-TableName.gray-name {
1855
1861
  background: #eef1f4 !important;
1856
1862
  color: #5c6773 !important;
@@ -1876,6 +1882,12 @@
1876
1882
  border-color: #d4e8d4 !important;
1877
1883
  }
1878
1884
 
1885
+ .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .Sqb-TableName.teal-name.notSelected {
1886
+ background: #f1faf8 !important;
1887
+ color: #5b9a93 !important;
1888
+ border-color: #d0ebe7 !important;
1889
+ }
1890
+
1879
1891
  .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .item-del {
1880
1892
  width: 10px;
1881
1893
  height: 10px;
@@ -2305,6 +2317,153 @@
2305
2317
  font-size: 12px !important;
2306
2318
  }
2307
2319
 
2320
+ .Sqb-Filter-item:has(.sqb-InputListToken) {
2321
+ max-width: 100%;
2322
+ box-sizing: border-box;
2323
+ }
2324
+
2325
+ .Sqb-Filter-item .Sqb-TableName.sqb-InputListToken,
2326
+ .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .Sqb-TableName.sqb-InputListToken {
2327
+ align-items: center;
2328
+ width: auto;
2329
+ max-width: 100%;
2330
+ height: auto !important;
2331
+ min-height: 24px !important;
2332
+ max-height: none !important;
2333
+ padding: 3px 8px !important;
2334
+ box-sizing: border-box;
2335
+ overflow: visible;
2336
+ }
2337
+
2338
+ .Sqb-Filter-item .sqb-InputListToken > .pd-Icon {
2339
+ flex: 0 0 auto;
2340
+ width: 12px;
2341
+ height: 12px;
2342
+ margin-right: 6px;
2343
+ font-size: 12px;
2344
+ line-height: 1;
2345
+ }
2346
+
2347
+ .Sqb-Filter-item .sqb-InputListToken .sqb-Custom-input.pd-Select,
2348
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-view,
2349
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select:hover .pd-Select-view,
2350
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select.pd-Select-focused .pd-Select-view,
2351
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag,
2352
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag:hover,
2353
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag.pd-Input-tag-focus,
2354
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-view,
2355
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-inner {
2356
+ width: auto !important;
2357
+ min-width: 0;
2358
+ max-width: 100%;
2359
+ height: auto !important;
2360
+ min-height: 18px !important;
2361
+ max-height: none !important;
2362
+ padding: 0 !important;
2363
+ border: none !important;
2364
+ background: transparent !important;
2365
+ box-shadow: none !important;
2366
+ line-height: 18px !important;
2367
+ }
2368
+
2369
+ .Sqb-Filter-item .sqb-InputListToken .sqb-Custom-input.pd-Select {
2370
+ flex: 0 1 auto;
2371
+ width: auto !important;
2372
+ min-width: 0;
2373
+ max-width: 100%;
2374
+ }
2375
+
2376
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-has-placeholder {
2377
+ min-width: 200px;
2378
+ }
2379
+
2380
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-view {
2381
+ display: flex;
2382
+ align-items: center;
2383
+ }
2384
+
2385
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-view,
2386
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-inner {
2387
+ display: flex;
2388
+ align-items: center;
2389
+ flex-wrap: wrap;
2390
+ overflow: visible;
2391
+ }
2392
+
2393
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-inner {
2394
+ gap: 4px;
2395
+ padding-right: 4px !important;
2396
+ }
2397
+
2398
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-view input,
2399
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-input {
2400
+ flex: 0 0 auto;
2401
+ width: 4px;
2402
+ min-width: 0;
2403
+ max-width: 100%;
2404
+ height: 18px !important;
2405
+ min-height: 18px !important;
2406
+ max-height: 18px !important;
2407
+ margin: 0 !important;
2408
+ padding: 0 !important;
2409
+ line-height: 18px !important;
2410
+ font-size: 12px !important;
2411
+ caret-color: currentColor;
2412
+ }
2413
+
2414
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-has-placeholder .pd-Input-tag-input {
2415
+ width: auto;
2416
+ min-width: 180px;
2417
+ }
2418
+
2419
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-focused .pd-Input-tag:not(.pd-Input-tag-has-placeholder) .pd-Input-tag-input {
2420
+ min-width: 8px;
2421
+ }
2422
+
2423
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-view input::placeholder,
2424
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-input::placeholder {
2425
+ color: rgba(15, 118, 110, 0.45);
2426
+ font-size: 12px;
2427
+ }
2428
+
2429
+ .Sqb-Filter-item .sqb-InputListToken .pd-Input-tag-tag,
2430
+ .Sqb-Filter-item .sqb-InputListToken .pd-Tag {
2431
+ flex: 0 0 auto;
2432
+ height: 18px !important;
2433
+ margin: 0 !important;
2434
+ padding: 0 4px 0 6px !important;
2435
+ line-height: 16px !important;
2436
+ font-size: 12px !important;
2437
+ color: #0f766e !important;
2438
+ background: #fff !important;
2439
+ border: 1px solid #c5e6e1 !important;
2440
+ border-radius: 4px;
2441
+ }
2442
+
2443
+ .Sqb-Filter-item .sqb-InputListToken .pd-Tag svg {
2444
+ color: #5b9a93;
2445
+ }
2446
+
2447
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-suffix,
2448
+ .Sqb-Filter-item .sqb-InputListToken .pd-Select-size-large.pd-Select-multiple .pd-Select-suffix {
2449
+ flex: 0 0 auto;
2450
+ align-self: center;
2451
+ margin-left: 2px;
2452
+ padding-right: 0;
2453
+ color: inherit;
2454
+ }
2455
+
2456
+ .Sqb-Filter-item .sqb-InputListToken .item-del,
2457
+ .Sqb-NotebookCell .Sqb-Filter-item:not(.item-composite) .sqb-InputListToken .item-del {
2458
+ margin-left: 2px;
2459
+ }
2460
+
2461
+ .CwBlock .sqb-InputListToken .sqb-Custom-input.pd-Select {
2462
+ height: auto !important;
2463
+ min-height: 18px !important;
2464
+ max-height: none !important;
2465
+ }
2466
+
2308
2467
  .CwBlock .Sqb-Filter-item:not(.item-composite) .isError {
2309
2468
  width: 12px !important;
2310
2469
  min-width: 12px !important;
@@ -7,6 +7,8 @@ type ExpressionTable = {
7
7
  columns?: any[];
8
8
  };
9
9
  export declare const EMPTY_RHS_CONDITIONS: Set<string>;
10
+ export declare const isInputListType: (type?: string) => type is AtomsTypeEnum.INPUT_LIST | "tag" | "inputTag";
11
+ export declare const getInputListValues: (val: unknown) => string[];
10
12
  export declare const getExpressionDatabaseType: (expression: AtomsExpression, tables?: ExpressionTable[], filterCustomType?: boolean) => string;
11
13
  export declare const normalizeExpressionAtom: (expression: AtomsExpression, tables?: ExpressionTable[], filterCustomType?: boolean) => AtomsExpression;
12
14
  export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[], filterCustomType?: boolean) => AtomsItem[];
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.operatorList = exports.normalizeOperatorList = exports.normalizeExpressionAtoms = exports.normalizeExpressionAtom = exports.isOk = exports.insertTemplateAt = exports.getTemplateItem = exports.getSubstrNegativeLengthIssue = exports.getExpressionDatabaseType = exports.getConstantLabel = exports.getAtomListIssue = exports.findNestedMetaIssue = exports.customTypes = exports.EMPTY_RHS_CONDITIONS = void 0;
7
+ exports.operatorList = exports.normalizeOperatorList = exports.normalizeExpressionAtoms = exports.normalizeExpressionAtom = exports.isOk = exports.isInputListType = exports.insertTemplateAt = exports.getTemplateItem = exports.getSubstrNegativeLengthIssue = exports.getInputListValues = exports.getExpressionDatabaseType = exports.getConstantLabel = exports.getAtomListIssue = exports.findNestedMetaIssue = exports.customTypes = exports.EMPTY_RHS_CONDITIONS = void 0;
8
8
  exports.validateExpressionIntegrity = validateExpressionIntegrity;
9
9
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -13,6 +13,15 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
13
13
  var _locale = require("../../../locale");
14
14
  var _types = require("../../../store/types");
15
15
  var EMPTY_RHS_CONDITIONS = exports.EMPTY_RHS_CONDITIONS = new Set(['为空', '不为空', '是空的', '不是空的']);
16
+ var isInputListType = exports.isInputListType = function isInputListType(type) {
17
+ return type === _types.AtomsTypeEnum.INPUT_LIST || type === 'tag' || type === 'inputTag';
18
+ };
19
+ var getInputListValues = exports.getInputListValues = function getInputListValues(val) {
20
+ var list = Array.isArray(val) ? val : val == null || val === '' ? [] : String(val).split(',');
21
+ return list.map(function (item) {
22
+ return String(item !== null && item !== void 0 ? item : '').trim();
23
+ }).filter(Boolean);
24
+ };
16
25
  var isSameValue = function isSameValue(left, right) {
17
26
  return left !== undefined && left !== null && left !== '' && right !== undefined && right !== null && right !== '' && String(left) === String(right);
18
27
  };
@@ -211,13 +220,7 @@ var insertTemplateAt = exports.insertTemplateAt = function insertTemplateAt(oldT
211
220
  type: _types.AtomsTypeEnum.OPERATOR,
212
221
  val: '('
213
222
  }, {
214
- type: _types.AtomsTypeEnum.INPUT_STRING,
215
- val: ''
216
- }, {
217
- type: _types.AtomsTypeEnum.OPERATOR,
218
- val: ','
219
- }, {
220
- type: _types.AtomsTypeEnum.INPUT_STRING,
223
+ type: _types.AtomsTypeEnum.INPUT_LIST,
221
224
  val: ''
222
225
  }, {
223
226
  type: _types.AtomsTypeEnum.OPERATOR,
@@ -227,7 +230,7 @@ var insertTemplateAt = exports.insertTemplateAt = function insertTemplateAt(oldT
227
230
  list.splice.apply(list, [index + 1, 0].concat((0, _toConsumableArray2["default"])(temList)));
228
231
  return list;
229
232
  };
230
- var operatorList = exports.operatorList = ['and', 'or', '(', ')', ',', '+', '-', '*', '/', '!', '!=', '<=', '>=', '<', '>', '=', 'case', 'when', 'then', 'else', 'end', 'NULL', 'DESC', 'ASC', 'OVER', 'PARTITION BY', 'ORDER BY', 'RANK()', 'DENSE_RANK()', 'ROW_NUMBER()'];
233
+ var operatorList = exports.operatorList = ['and', 'or', '(', ')', ',', '+', '-', '*', '/', '!', '!=', '<=', '>=', '<', '>', '=', 'in', 'not in', 'case', 'when', 'then', 'else', 'end', 'NULL', 'DESC', 'ASC', 'OVER', 'PARTITION BY', 'ORDER BY', 'RANK()', 'DENSE_RANK()', 'ROW_NUMBER()'];
231
234
  var normalizeOperatorList = exports.normalizeOperatorList = function normalizeOperatorList() {
232
235
  var operators = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : operatorList;
233
236
  var pairBrackets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -269,6 +272,9 @@ var customTypes = exports.customTypes = [{
269
272
  }, {
270
273
  value: _types.AtomsTypeEnum.INPUT_STRING,
271
274
  label: (0, _locale.__)('customColumn.input')
275
+ }, {
276
+ value: _types.AtomsTypeEnum.INPUT_LIST,
277
+ label: (0, _locale.__)('customColumn.inputList')
272
278
  }, {
273
279
  value: _types.AtomsTypeEnum.INPUT_NUMBER,
274
280
  label: (0, _locale.__)('customColumn.numberInput')
@@ -346,6 +352,11 @@ var getTemplateItem = exports.getTemplateItem = function getTemplateItem(type, i
346
352
  val: item["default"] || [],
347
353
  type: type
348
354
  };
355
+ } else if (type === _types.AtomsTypeEnum.INPUT_LIST) {
356
+ temItem = {
357
+ val: Array.isArray(item === null || item === void 0 ? void 0 : item["default"]) ? item["default"].join(',') : (item === null || item === void 0 ? void 0 : item["default"]) || '',
358
+ type: type
359
+ };
349
360
  } else if (type === _types.AtomsTypeEnum.FORMULA) {
350
361
  temItem = {
351
362
  args: [],
@@ -429,6 +440,10 @@ var _isOk = exports.isOk = function isOk(rhsVal) {
429
440
  return Array.isArray(v.val) && v.val.every(function (vv) {
430
441
  return Boolean(vv);
431
442
  });
443
+ } else if (isInputListType(v.type)) {
444
+ return getInputListValues(v.val).some(function (vv) {
445
+ return String(vv !== null && vv !== void 0 ? vv : '').trim() !== '';
446
+ });
432
447
  } else if (v.type === _types.AtomsTypeEnum.COLLECTION) {
433
448
  return _isOk(v.list || [], allowEmptyInputString);
434
449
  } else if (v.type === _types.AtomsTypeEnum.CASE_WHEN) {
@@ -40,6 +40,8 @@ var _default = exports["default"] = (0, _index.register)('en', {
40
40
  'SqlQueryBuilder.pickTable': 'Select data table...',
41
41
  'SqlQueryBuilder.pickConstant': 'Select constant...',
42
42
  'customColumn.input': 'Input',
43
+ 'customColumn.inputList': 'Value list',
44
+ 'customColumn.inputListPlaceholder': 'Type and press Enter to add',
43
45
  'customColumn.numberInput': 'Number input',
44
46
  'customColumn.addSql': 'Add SQL',
45
47
  'customColumn.parseSql': 'Parse with AI',
@@ -85,6 +85,8 @@ var _default = exports["default"] = (0, _index.register)('zh', {
85
85
  'customColumn.formula': '公式',
86
86
  'customColumn.selectFormula': '选择公式...',
87
87
  'customColumn.input': '输入框',
88
+ 'customColumn.inputList': '值列表',
89
+ 'customColumn.inputListPlaceholder': '可输入回车新增下拉选项',
88
90
  'customColumn.numberInput': '数字输入框',
89
91
  'customColumn.addSql': '添加 SQL',
90
92
  'customColumn.parseSql': 'AI 解析',
package/lib/cjs/prompt.js CHANGED
@@ -8,7 +8,7 @@ const METABASE_CHAT_DOC = `
8
8
  4. 可自造 tableUuid/fieldUuid 这类实例 ID,但不要自造业务 ID。alias/fieldAlias 必须满足 /^[a-zA-Z][a-zA-Z0-9_]{0,29}$/。
9
9
  5. 不要使用旧结构:summarize.breakout/aggregation、joinData.field1/field2、customColumn 根级 expression、summarize 条目只靠根部 table/alias/name 表达来源字段。
10
10
  6. Atom 能力分级:
11
- - 稳定主动生成:field、inputString、inputNumber、constant、operator、FORMULA、collection、expression、joinDefault、andOr、caseWhen、exists、notExists、subquery,以及区间专用 inputStringList。
11
+ - 稳定主动生成:field、inputString、inputNumber、inputList、constant、operator、FORMULA、collection、expression、joinDefault、andOr、caseWhen、exists、notExists、subquery,以及区间专用 inputStringList。
12
12
  - 上下文条件生成:select 仅在 formulaTemplates 的参数明确要求 select 时生成;宿主 otherTypes/operatorList 扩展仅按上下文给出的 value、字段和允许值原样生成。
13
13
  - 仅兼容已有数据:inputNumberList、unknown,以及上下文未声明 SQL 语义的自定义 Atom。不要主动生成 unknown;不得凭名称猜测扩展 Atom 的 SQL 行为。
14
14
  7. 语义 Atom 优先:所有接收 AtomsItem[] 的位置,遇到逻辑组合/嵌套 and-or/括号优先级用 andOr;遇到 CASE/多分支映射用 caseWhen。operator 里的 and、or、(、)、case、when、then、else、end 只为旧配置兼容保留,主动生成不要用它们硬拼逻辑组或 CASE;operator 主要承担比较符、四则、逗号、NULL 等基础 token。
@@ -66,8 +66,8 @@ const METABASE_CHAT_DOC = `
66
66
  - summarizeType:group、by。
67
67
  - andOr.items[].operator:and、or。
68
68
  - select.displayField:label、value。
69
- - AtomsItem.type:field、inputString、inputNumber、inputStringList、inputNumberList、constant、operator、FORMULA、expression、joinDefault、caseWhen、andOr、collection、select、subquery、exists、notExists、unknown。
70
- - operator.val:and、or、(、)、,、+、-、*、/、!、!=、<=、>=、<、>、=、case、when、then、else、end、NULL、DESC、ASC、OVER、PARTITION BY、ORDER BY、RANK()、DENSE_RANK()、ROW_NUMBER()。主动生成优先只用比较/四则/逗号/NULL;and、or、(、)、case、when、then、else、end 主要用于兼容旧配置,主动生成逻辑组用 andOr,CASE 用 caseWhen,窗口 token 非明确需求不要生成。宿主通过 operatorList 提供 'in'/'not in' 时,公式编辑器选择它们会自动插入左括号、两个 inputString、逗号、右括号的列表骨架;这只是 UI 编辑便捷行为,主动生成 SQL 的 IN/NOT IN 仍使用 expression.condition="In"/"Not In"。
69
+ - AtomsItem.type:field、inputString、inputNumber、inputList、inputStringList、inputNumberList、constant、operator、FORMULA、expression、joinDefault、caseWhen、andOr、collection、select、subquery、exists、notExists、unknown。
70
+ - operator.val:and、or、(、)、,、+、-、*、/、!、!=、<=、>=、<、>、=、case、when、then、else、end、NULL、DESC、ASC、OVER、PARTITION BY、ORDER BY、RANK()、DENSE_RANK()、ROW_NUMBER()。主动生成优先只用比较/四则/逗号/NULL;and、or、(、)、case、when、then、else、end 主要用于兼容旧配置,主动生成逻辑组用 andOr,CASE 用 caseWhen,窗口 token 非明确需求不要生成。宿主通过 operatorList 提供 'in'/'not in' 时,公式编辑器会插入 ( inputList );主动生成 SQL 的 IN/NOT IN 仍使用 expression.condition="In"/"Not In",rhs 用逗号拼接的 inputString,不要用 inputList。
71
71
  - filter.condition:
72
72
  字符串=等于、不等于、大于、小于、大于或等于、小于或等于、包含、不包含、为空、不为空、以...开始、以...结束、不以...开始、不以...结束、In、Not In、正则匹配;
73
73
  数字=等于、不等于、大于、小于、介于之间、大于或等于、小于或等于、为空、不为空、以...开始、以...结束、不以...开始、不以...结束、In、Not In、正则匹配;
@@ -84,11 +84,11 @@ table={id,name,name_zh,alias,tableUuid,datasourceId,datasourceName,table_type?}
84
84
  column={id,name,name_zh?,fieldId?,fieldAlias,fieldUuid,tableId?,tableUuid?,realName?,database_type,field_type?,field_length?,special_type,datasourceId,datasourceName,select,summarizeType?}
85
85
  说明:database_type 保留给 SQL 类型判断;字段列表只用 field_type/field_length 展示类型和长度。field_type 是数据库原始类型文本,field_length 是长度或精度文本;二者只能复制上下文字段的真实值,没有值时省略,不能根据 database_type 猜测。
86
86
  fieldAtom={type:"field",fieldId,fieldName,fieldNameZh,fieldAlias,fieldUuid,tableId,tableName,tableNameZh,tableAlias,tableUuid,datasourceId,datasourceName}
87
- 值={type:"inputString",val:"x"}、{type:"inputNumber",val:1}、{type:"inputStringList",val:["a","b"]}、{type:"inputNumberList",val:[1,2]}、{type:"constant",id,val}、{type:"operator",val:"+"}
88
- 注意:空值条件的 rhs 写 [];空值条件已统一,新建条件所有类型(含 DATE)都使用“为空/不为空”,但旧配置中的“是空的”、“不是空的”也必须兼容,编辑/复制未触达项时不要替换。字符串和数字的 In/Not In 都用 [{type:"inputString",val:"A,B"}];转换器按 database_type 决定是否给各项加引号,逗号分隔值不得含无法区分的裸逗号。只有数字和日期支持介于之间,rhs 用 [{type:"inputStringList",val:["起点","终点"]}] 且必须正好两个有序边界;字符串不支持介于之间。不要主动用 inputNumberList,当前 UI 保存和部分 SQL 转换对它支持不一致。普通数字单值过滤为兼容 UI 优先用 {type:"inputString",val:"123"};inputNumber 只在公式、自定义计算或裸 Atom 数学表达式中使用。inputString 会自动按入口处理 SQL 引号,constant.val 会原样进入 SQL,只能使用上下文提供的可信常量,不能把普通用户文本写成 constant。
87
+ 值={type:"inputString",val:"x"}、{type:"inputNumber",val:1}、{type:"inputList",val:"a,b"}、{type:"inputStringList",val:["a","b"]}、{type:"inputNumberList",val:[1,2]}、{type:"constant",id,val}、{type:"operator",val:"+"}
88
+ 注意:空值条件的 rhs 写 [];空值条件已统一,新建条件所有类型(含 DATE)都使用“为空/不为空”,但旧配置中的“是空的”、“不是空的”也必须兼容,编辑/复制未触达项时不要替换。字符串和数字的 In/Not In 都用 [{type:"inputString",val:"A,B"}];转换器按 database_type 决定是否给各项加引号,逗号分隔值不得含无法区分的裸逗号。inputList 只用于公式编辑器里的 in/not in 列表,固定 {type:"inputList",val:"A,B"}:val 是逗号分隔字符串,不要写成数组,单项里不能再含裸逗号;空 val 表示未完成,不能主动生成。转换时纯数字不加引号,已经带引号的原样保留,其余按字符串加引号。不要把 inputList 写进 expression.rhs。只有数字和日期支持介于之间,rhs 用 [{type:"inputStringList",val:["起点","终点"]}] 且必须正好两个有序边界;字符串不支持介于之间。不要主动用 inputNumberList,当前 UI 保存和部分 SQL 转换对它支持不一致。普通数字单值过滤为兼容 UI 优先用 {type:"inputString",val:"123"};inputNumber 只在公式、自定义计算或裸 Atom 数学表达式中使用。inputString 会自动按入口处理 SQL 引号,constant.val 会原样进入 SQL,只能使用上下文提供的可信常量,不能把普通用户文本写成 constant。
89
89
  quotes 是 UI 展示文案缓存,必须能由当前 Atom 内容动态重算;不要把 quotes 当 SQL 字段名、别名或稳定业务标识。
90
90
  FORMULA={type:"FORMULA",id,name,args:[collection],arity?,quotes},id/name/arity/参数类型必须来自上下文 formulaTemplates,name 大小写保持一致。模板字段为 {name,id,args:[{type,check?,options?,default?,multiple?,fixed?,placeholder?,displayField?}],arity?,output?,description?,example?};check/output 常见为 string、number、null,arity 只能是 {exact:n}、{min:n}、{min:n,max:n}。生成时参数数量必须满足 arity;每个参数必须是 collection,模板要求的参数 Atom 放在 collection.list 内,且类型和值满足对应 args 模板,不能因为 SQL 看似可用就换类型。例如 type=select 的参数写 {type:"collection",quotes:"",list:[selectAtom]}。公式参数中的 inputString 允许 val:"",表示 SQL 空字符串字面量并转换为 '';这不是 unknown 或空槽占位 Atom。可变参数超出模板 args 长度时仍各自使用独立 collection,不把多个 SQL 参数塞进同一个 collection。SUBSTR/SUBSTRING 第三个参数是截取长度,主动生成必须是 >=0 的 inputNumber,或按 arity 省略该参数;不要用负数表示从末尾截取。
91
- 自定义字段根 formulaList 中的 inputString 若 val 为空表示未完成,不能主动生成或提交;只有 FORMULA.args 内的空 inputString 才按合法空字符串字面量处理。
91
+ 自定义字段根 formulaList 中的 inputString 若 val 为空表示未完成,不能主动生成或提交;只有 FORMULA.args 内的空 inputString 才按合法空字符串字面量处理。inputList 的 val 为空同样表示未完成,不能主动生成或提交。
92
92
  collection={type:"collection",quotes:"",list:[AtomsItem...]}
93
93
  expression={type:"expression",lhs:[fieldAtom],rhs:[值或fieldAtom或constant],database_type,condition,quotes,formula?};主动生成不要带 formula。
94
94
  joinDefault={type:"joinDefault",lhs:[fieldAtom],condition:"",rhs:[fieldAtom]}
@@ -161,10 +161,10 @@ const METABASE_FORMULA_SQL_PARSE_DOC = `
161
161
 
162
162
  主动生成结构:
163
163
  - field={type:"field",fieldId,fieldName,fieldNameZh,fieldAlias,fieldUuid,tableId,tableName,tableNameZh,tableAlias,tableUuid,datasourceId,datasourceName}。
164
- - 字符串字面量={type:"inputString",val};数字字面量={type:"inputNumber",val};比较符、四则运算、逗号和 NULL 使用 {type:"operator",val}。
164
+ - 字符串字面量={type:"inputString",val};数字字面量={type:"inputNumber",val};公式编辑器的 in/not in 列表={type:"inputList",val:"逗号分隔完整列表"},val 不是数组,单项不能含裸逗号,空 val 不能生成。比较符、四则运算、逗号和 NULL 使用 {type:"operator",val}。
165
165
  - 字段与值的简单比较优先生成 expression={type:"expression",lhs:[fieldAtom],rhs:[valueAtom],database_type,condition,quotes},不要拆成根部的 field/operator/value。lhs 必须且只能包含 field Atom;database_type 复制字段类型;SQL 中带引号的值即使内容是数字也用 inputString,不带引号的数字才用 inputNumber。例如 GYXXB.NBJGH = '1' 必须生成 lhs=[GYXXB.NBJGH 的完整 field Atom]、rhs=[{type:"inputString",val:"1"}]、condition="等于"。只有无法用 expression.condition 准确表达的比较才保留显式比较 operator。
166
166
  - 日期字面量转换是上述类型复制规则的例外:field = TO_DATE('20260825175400','YYYYMMDDHH24MISS') 必须规范化为 DATE expression,database_type="DATE",rhs=[{type:"inputString",val:"2026-08-25 17:54",format:"YYYY-MM-DD HH:mm"}]。不得把整个 TO_DATE 文本塞进 inputString,不得把 FORMULA 放入 expression.rhs,也不得继续使用字段原始的 STRING 类型。仅当 TO_DATE 不是可无损还原的日期字面量时,才保留为独立 FORMULA Atom。
167
- - SQL 的 IN/NOT IN 必须生成 expression.condition="In"/"Not In",rhs 固定使用一个 {type:"inputString",val:"逗号分隔完整列表"},必须保留原列表中每个值,禁止只取第一个值、禁止改写成单个等于条件。例如 TMP_TABLE1.SJRQ IN ('adff','asdf') 必须生成 condition="In" 且 rhs=[{type:"inputString",val:"adff,asdf"}]。
167
+ - SQL 的 IN/NOT IN 必须生成 expression.condition="In"/"Not In",rhs 固定使用一个 {type:"inputString",val:"逗号分隔完整列表"},必须保留原列表中每个值,禁止只取第一个值、禁止改写成单个等于条件,也不要用 inputList 替换 expression.rhs。例如 TMP_TABLE1.SJRQ IN ('adff','asdf') 必须生成 condition="In" 且 rhs=[{type:"inputString",val:"adff,asdf"}]。公式编辑器里的 in/not in 才写 {type:"operator",val:"in"} + {type:"operator",val:"("} + {type:"inputList",val:"adff,asdf"} + {type:"operator",val:")"}。inputList 转换时纯数字不加引号,已带引号的值原样保留,其余加引号。
168
168
  - SQL 的 LIKE/NOT LIKE 必须按通配符位置生成精确条件,并从 rhs 中去掉 SQL 通配符:LIKE '11%' => condition="以...开始",rhs=[{type:"inputString",val:"11"}];LIKE '%11' => condition="以...结束",val="11";LIKE '%11%' => condition="包含",val="11";NOT LIKE 分别对应“不以...开始/不以...结束/不包含”。禁止把 LIKE '11%' 解析成“包含 11%”。
169
169
  - SQL 正则条件必须生成 expression.condition="正则匹配"。MySQL 写法 field REGEXP 'pattern'、Oracle 写法 REGEXP_LIKE(field,'pattern')、SQL Server 写法 PATINDEX('pattern', field)=1 都必须识别,rhs=[{type:"inputString",val:"pattern"}],禁止改成包含、等于或普通 FORMULA 文本。
170
170
  - SQL 的 field IS NULL/IS NOT NULL 必须生成空值 expression,不得解析为只包含 field 的 Atom,也不得为 rhs 生成 NULL、空字符串或其他输入项。空值条件已统一:所有类型(STRING/FLOAT/LONG/CURRENCY/DATE)的 IS NULL 都生成 condition="为空",rhs=[],IS NOT NULL 都生成 condition="不为空",rhs=[]。
@@ -92,6 +92,7 @@ export declare enum AtomsTypeEnum {
92
92
  INPUT_STRING_LIST = "inputStringList",
93
93
  INPUT_NUMBER_LIST = "inputNumberList",
94
94
  INPUT_NUMBER = "inputNumber",
95
+ INPUT_LIST = "inputList",
95
96
  CONSTANT = "constant",
96
97
  OPERATOR = "operator",
97
98
  UNKNOWN = "unknown",
@@ -111,6 +111,7 @@ var AtomsTypeEnum;
111
111
  AtomsTypeEnum["INPUT_STRING_LIST"] = "inputStringList";
112
112
  AtomsTypeEnum["INPUT_NUMBER_LIST"] = "inputNumberList";
113
113
  AtomsTypeEnum["INPUT_NUMBER"] = "inputNumber";
114
+ AtomsTypeEnum["INPUT_LIST"] = "inputList";
114
115
  AtomsTypeEnum["CONSTANT"] = "constant";
115
116
  AtomsTypeEnum["OPERATOR"] = "operator";
116
117
  AtomsTypeEnum["UNKNOWN"] = "unknown";
@@ -99,6 +99,10 @@ export interface AtomsInputNumber {
99
99
  val: number;
100
100
  type: AtomsTypeEnum.INPUT_NUMBER;
101
101
  }
102
+ export interface AtomsInputList {
103
+ val: string;
104
+ type: AtomsTypeEnum.INPUT_LIST;
105
+ }
102
106
  export interface AtomsConstant {
103
107
  id?: string;
104
108
  val: string;
@@ -131,7 +135,7 @@ export interface AtomsSelect {
131
135
  displayField?: SelectOptionDisplayField;
132
136
  type: AtomsTypeEnum.SELECT;
133
137
  }
134
- export type AtomsItem = AtomsSubQuery | AtomsNotExists | AtomsExists | AtomsJoinDefault | AtomsExpression | AtomsCaseWhen | AtomsAndOr | AtomsFormula | AtomsField | AtomsInputString | AtomsInputStringList | AtomsInputNumberList | AtomsInputNumber | AtomsOprator | AtomsConstant | AtomsUnknown | AtomsCollection | AtomsSelect;
138
+ export type AtomsItem = AtomsSubQuery | AtomsNotExists | AtomsExists | AtomsJoinDefault | AtomsExpression | AtomsCaseWhen | AtomsAndOr | AtomsFormula | AtomsField | AtomsInputString | AtomsInputStringList | AtomsInputNumberList | AtomsInputNumber | AtomsInputList | AtomsOprator | AtomsConstant | AtomsUnknown | AtomsCollection | AtomsSelect;
135
139
  export type ToolbarType = TypeEnum | 'filter' | 'summarize' | 'joinData' | 'permissionTable' | 'customColumn' | 'sort' | 'rowLimit' | 'union';
136
140
  export type MetaListType = MetaData | MetaJoin | MetaCustom | MetaFilter | MetaSummarize | MetaSort | MetaLimit | MetaPermissionTable | MetaUnion;
137
141
  export type initColumnsType = MetaData_ColumnsType;
@@ -37,6 +37,9 @@ var BlockTypeEnum = {
37
37
  constant: 'constant',
38
38
  inputStringList: 'inputStringList',
39
39
  inputNumberList: 'inputNumberList',
40
+ inputList: 'inputList',
41
+ tag: 'tag',
42
+ inputTag: 'inputTag',
40
43
  unknown: 'unknown',
41
44
  notExists: 'notExists',
42
45
  exists: 'exists',
@@ -51,6 +54,19 @@ var SummarizeAlias = 'source';
51
54
  var hasSqlText = function hasSqlText(value) {
52
55
  return value != null && String(value).trim() !== '';
53
56
  };
57
+ var formatInListItem = function formatInListItem(value) {
58
+ var text = String(value !== null && value !== void 0 ? value : '').trim();
59
+ if (!text) return '';
60
+ if (/^'.*'$/.test(text) || /^".*"$/.test(text)) return text;
61
+ if (/^-?\d+(\.\d+)?$/.test(text)) return text;
62
+ return "'".concat(text.replace(/'/g, "''"), "'");
63
+ };
64
+ var formatInListSql = function formatInListSql(values) {
65
+ var list = Array.isArray(values) ? values : String(values !== null && values !== void 0 ? values : '').split(',').map(function (item) {
66
+ return item.trim();
67
+ }).filter(Boolean);
68
+ return list.map(formatInListItem).filter(Boolean).join(', ');
69
+ };
54
70
  var qualifyIdentifier = function qualifyIdentifier(qualifier, name) {
55
71
  if (hasSqlText(qualifier) && hasSqlText(name)) return "".concat(qualifier, ".").concat(name);
56
72
  if (hasSqlText(name)) return String(name);
@@ -137,7 +153,7 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
137
153
  };
138
154
  }
139
155
  list.forEach(function (item) {
140
- var _condition_, _condition_2;
156
+ var _rhs$, _rhs$2, _rhs$3, _condition_, _rhs$4, _rhs$5, _rhs$6, _condition_2;
141
157
  var type = item.type;
142
158
  if (type === BlockTypeEnum.unknown) {}
143
159
  if (type === BlockTypeEnum.operator) {
@@ -185,6 +201,13 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
185
201
  });
186
202
  }
187
203
  }
204
+ if (type === BlockTypeEnum.inputList || type === BlockTypeEnum.tag || type === BlockTypeEnum.inputTag) {
205
+ var listSql = formatInListSql(item.val);
206
+ if (listSql) {
207
+ sql += " ".concat(listSql);
208
+ sql_items.push(listSql);
209
+ }
210
+ }
188
211
  if (type === BlockTypeEnum.joinDefault) {
189
212
  var lhs = item.lhs,
190
213
  rhs = item.rhs;
@@ -325,7 +348,7 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
325
348
  _right_condition = "NOT LIKE '%".concat(condition_1, "'");
326
349
  break;
327
350
  case 'In':
328
- condition_1 = (_condition_ = condition_1) === null || _condition_ === void 0 || (_condition_ = _condition_.split(',')) === null || _condition_ === void 0 || (_condition_ = _condition_.map(function (v) {
351
+ condition_1 = (_rhs === null || _rhs === void 0 || (_rhs$ = _rhs[0]) === null || _rhs$ === void 0 ? void 0 : _rhs$.type) === BlockTypeEnum.inputList || (_rhs === null || _rhs === void 0 || (_rhs$2 = _rhs[0]) === null || _rhs$2 === void 0 ? void 0 : _rhs$2.type) === BlockTypeEnum.tag || (_rhs === null || _rhs === void 0 || (_rhs$3 = _rhs[0]) === null || _rhs$3 === void 0 ? void 0 : _rhs$3.type) === BlockTypeEnum.inputTag ? formatInListSql(_rhs[0].val) : (_condition_ = condition_1) === null || _condition_ === void 0 || (_condition_ = _condition_.split(',')) === null || _condition_ === void 0 || (_condition_ = _condition_.map(function (v) {
329
352
  var _v;
330
353
  v = (_v = v) === null || _v === void 0 ? void 0 : _v.trim();
331
354
  if (v && (/^'.*'$/.test(v) || /^".*"$/.test(v))) {
@@ -337,7 +360,7 @@ var _handleBaseType2Sql9 = exports.handleBaseType2Sql = function handleBaseType2
337
360
  _right_condition = "IN (".concat(condition_1, ")");
338
361
  break;
339
362
  case 'Not In':
340
- condition_1 = (_condition_2 = condition_1) === null || _condition_2 === void 0 || (_condition_2 = _condition_2.split(',')) === null || _condition_2 === void 0 || (_condition_2 = _condition_2.map(function (v) {
363
+ condition_1 = (_rhs === null || _rhs === void 0 || (_rhs$4 = _rhs[0]) === null || _rhs$4 === void 0 ? void 0 : _rhs$4.type) === BlockTypeEnum.inputList || (_rhs === null || _rhs === void 0 || (_rhs$5 = _rhs[0]) === null || _rhs$5 === void 0 ? void 0 : _rhs$5.type) === BlockTypeEnum.tag || (_rhs === null || _rhs === void 0 || (_rhs$6 = _rhs[0]) === null || _rhs$6 === void 0 ? void 0 : _rhs$6.type) === BlockTypeEnum.inputTag ? formatInListSql(_rhs[0].val) : (_condition_2 = condition_1) === null || _condition_2 === void 0 || (_condition_2 = _condition_2.split(',')) === null || _condition_2 === void 0 || (_condition_2 = _condition_2.map(function (v) {
341
364
  var _v2;
342
365
  v = (_v2 = v) === null || _v2 === void 0 ? void 0 : _v2.trim();
343
366
  if (v && (/^'.*'$/.test(v) || /^".*"$/.test(v))) {
@@ -1759,6 +1782,8 @@ var _walkAtomsDeepForSyntax = function walkAtomsDeepForSyntax(list, ctx, db) {
1759
1782
  ctx.addIssue('missing-custom-input', 'error', path);
1760
1783
  } else if (item.type === BlockTypeEnum.field && !item.fieldName && !item.fieldAlias) {
1761
1784
  ctx.addIssue('missing-field', 'error', path);
1785
+ } else if ((item.type === BlockTypeEnum.inputList || item.type === BlockTypeEnum.tag || item.type === BlockTypeEnum.inputTag) && isEmptyValue(item.val)) {
1786
+ ctx.addIssue('missing-selection', 'error', path);
1762
1787
  } else if (item.type === BlockTypeEnum.operator && !item.val || item.type === BlockTypeEnum.constant && isEmptyValue(item.id || item.val) || item.type === BlockTypeEnum.select && isEmptyValue(item.val) || item.type === BlockTypeEnum.FORMULA && !item.name || !emptyInputAllowed && !Object.values(BlockTypeEnum).includes(item.type) && 'val' in item && isEmptyValue(item.val)) {
1763
1788
  ctx.addIssue('missing-selection', 'error', path);
1764
1789
  }
@@ -566,7 +566,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
566
566
  children: _jsx(Select, {
567
567
  maxWidth: '500px',
568
568
  size: 'large',
569
- placeholder: "\u53EF\u8F93\u5165\u56DE\u8F66\u65B0\u589E\u4E0B\u62C9\u9009\u9879",
569
+ placeholder: __('customColumn.inputListPlaceholder'),
570
570
  allowCreate: true,
571
571
  multiple: true,
572
572
  getPopupContainer: getCurrentPopupContainer,
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { AtomsTypeEnum } from '../../../store/types';
3
- import { getTemplateItem } from '../formula-list/utils';
3
+ import { getInputListValues, getTemplateItem, isInputListType } from '../formula-list/utils';
4
4
  export var getObjTem = function getObjTem(arr) {
5
5
  var obj = {};
6
6
  arr === null || arr === void 0 || arr.map(function (v) {
@@ -96,6 +96,8 @@ export var getQuotes = function getQuotes(fun, _args, formulaList) {
96
96
  }).join(', ');
97
97
  }
98
98
  return getOptionText(vv.val || '');
99
+ } else if (isInputListType(vv === null || vv === void 0 ? void 0 : vv.type)) {
100
+ return getInputListValues(vv.val).join(', ');
99
101
  } else {
100
102
  return vv.val;
101
103
  }