From 408a61df4f40d4abefc5fd3e47d4381ea39936c3 Mon Sep 17 00:00:00 2001 From: xiaoyong Date: Fri, 19 Dec 2025 10:10:15 +0800 Subject: [PATCH] Fix Formula, when the cache is setted by STRING, but is get by NUMBER. Such as `=SUMIFS(A:A, B:B, "2025")`, when the type of B is STRING (Set cache), the "2025" is transformed by findCompareToken to NUMBER (Get cache) --- .../src/basics/inverted-index-cache.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/engine-formula/src/basics/inverted-index-cache.ts b/packages/engine-formula/src/basics/inverted-index-cache.ts index 759f7b5c1ee4..18131313091c 100644 --- a/packages/engine-formula/src/basics/inverted-index-cache.ts +++ b/packages/engine-formula/src/basics/inverted-index-cache.ts @@ -70,11 +70,7 @@ export class InvertedIndexCache { } } - // Because the inverted index cache is used for compare operation, it should be case-insensitive. - let _value = typeof value === 'string' ? value.toLowerCase() : value; - if (_value === '' || _value === null) { - _value = DEFAULT_EMPTY_CELL_KEY; - } + const _value = this.getValueKey(value); let cellList = columnMap.get(_value); if (cellList == null) { @@ -85,16 +81,26 @@ export class InvertedIndexCache { cellList.add(row); } - getCellValuePositions(unitId: string, sheetId: string, column: number) { - return this._cache.get(unitId)?.get(sheetId)?.get(column); - } - - getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, rowsInCache: NumericTuple[]) { + private getValueKey(value: string | number | boolean | null | symbol) { // Because the inverted index cache is used for compare operation, it should be case-insensitive. let _value = typeof value === 'string' ? value.toLowerCase() : value; if (_value === '' || _value === null) { _value = DEFAULT_EMPTY_CELL_KEY; } + + // Ignore the NUMBER and STRING,such as 2025 and "2025" + if (typeof _value === 'number') { + _value = String(_value); + } + return _value; + } + + getCellValuePositions(unitId: string, sheetId: string, column: number) { + return this._cache.get(unitId)?.get(sheetId)?.get(column); + } + + getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, rowsInCache: NumericTuple[]) { + const _value = this.getValueKey(value); const rows = this._cache.get(unitId)?.get(sheetId)?.get(column)?.get(_value); return rows && [...rows].filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end)); }