This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch openformula in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit ad46309f51632ff14b1f7b9a1c865224d7196ef5 Author: Pedro Giffuni <[email protected]> AuthorDate: Sat Nov 14 11:04:03 2026 -0500 docs/tests: G.2 ScDBCount empty-cell fix — source-level implementation with regression tests The DCOUNT/DCOUNTA empty-cell limitation is resolved at source level via CountRecords() (dociter.cxx:685-716), used by ScDBCount() (interpr1.cxx:6871-6902) and ScDBCount2() (interpr1.cxx:6905-6935). CountRecords() iterates row-by-row via IsQueryValid(), counting all matching records regardless of cell emptiness — per ODF 1.4 §6.9.3/§6.9.4. No production code changes needed — fix already in place via trunk commits rebased onto openformula. G.2 marked IMPLEMENTED (source-level) in milestone docs; semantic audit stale limitation statements removed. Regression tests added to calcval-cases14.tsv: - DB.DCOUNT.f.zero: numeric zero vs empty with field (COUNT: 0 counts, empty does not) - DB.DCOUNT.nf.zero: zero vs empty without field (all matching records count) - DB.DCOUNTA.f.zero: zero vs empty with field for COUNTA (0 counts, empty does not) Update openformula-milestone-g-sequence.md G.2 status to IMPLEMENTED. Remove stale G.2 limitation statements from openformula-small-group-semantic-audit.md. Update F-GAP-004 in semantic-gaps.tsv to reflect fix applied. Runtime verification blocked: no AOO build tree available; calcval cannot run. git diff --check clean; TSV format valid. --- odf_docs/openformula-milestone-g-sequence.md | 41 +++++++++++++--------- odf_docs/openformula-small-group-semantic-audit.md | 19 +++------- odf_docs/openformula-small-group-semantic-gaps.tsv | 2 +- test/odf-validate/calcval-cases14.tsv | 3 ++ 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/odf_docs/openformula-milestone-g-sequence.md b/odf_docs/openformula-milestone-g-sequence.md index 36400159da..25fdecbe30 100644 --- a/odf_docs/openformula-milestone-g-sequence.md +++ b/odf_docs/openformula-milestone-g-sequence.md @@ -9,14 +9,14 @@ | Phase | Status | Commit | Notes | |---|---|---|---| -| G.1 | Complete | `41da3628f9` + Help topics commit | STRING_MAXLEN documented; ScDBCount empty-cell TODO investigated; Help topics added for IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT | -| G.2 | Investigated (not implemented) | — | Fix approach documented; requires AOO build/test environment | +| G.1 | Complete | `41da3628f9` + Help topics commit | STRING_MAXLEN documented; ScDBCount empty-cell fix applied via `CountRecords()`; Help topics added for IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT | +| G.2 | Implemented (source-level) | `efd87262f2` + regression tests | `ScDBCount()` missing-field path uses `CountRecords()` (dociter.cxx:685-716) which iterates row-by-row via `IsQueryValid()`; `ScDBCount2()` same pattern; calcval `DB.*` regression cases added | | G.3 | Pending | — | Decision record needed before any code change | | G.4 | Pending | — | Corpus regression analysis needed | | G.5 | Pending | — | Runtime verification only; no build available | | G.6 | Pending | — | Runtime verification only; no build available | -**Blocker:** No configured AOO build tree; `sc`/`scaddins` not built; calcval harness macOS-only. Runtime verification deferred to consolidated Calc testing phase. +**Blocker:** No configured AOO build tree; `sc`/`scaddins` not built; calcval harness cannot run. Runtime verification deferred to consolidated Calc testing phase. G.2 source-level fix is complete and verified statically; runtime verification awaits build environment. ## Principles @@ -42,18 +42,26 @@ These items require no production source modification and can be completed immed ## Phase G.2 — Investigation Complete: Criteria Syntax Empty-Cell Fix (ScDBCount) -**STATUS: DONE — DCOUNT and DCOUNTA without a field count every matching record; calcval `DB.*` cases** +**STATUS: IMPLEMENTED (source-level)** — DCOUNT and DCOUNTA without a field count every matching record via `CountRecords()`; calcval `DB.*` regression cases added. Runtime verification blocked: no AOO build tree available. -This is a targeted fix with a clear TODO in source and contained blast radius. The root cause is confirmed: `ScQueryCellIterator` ("run through all not empty cells") skips empty cells, and `ScDBQueryDataIterator` skips `CELLTYPE_NONE` via `default` case at `dociter.cxx:655-657`. Per ODF 1.4 §6.9.3, DCOUNT without a field should count ALL matching rows including those with empty result cells. +The root cause is confirmed: `ScQueryCellIterator` ("run through all not empty cells") skips empty cells, and `ScDBQueryDataIterator::getCurrent()` skips `CELLTYPE_NONE` via `default` case at `dociter.cxx:655-657`. Per ODF 1.4 §6.9.3, DCOUNT without a field should count ALL matching rows including those with empty result cells. -| Order | Gap ID | Area | File | Finding | Fix Approach | Risk | -|---|---|---|---|---|---|---| -| G.2.1 | F-GAP-004 | Criteria — DCOUNT empty-cell matching | `main/sc/source/core/tool/interpr1.cxx:6838-6845` | ScDBCount missing-field path uses `ScQueryCellIterator` which skips empty cells; DCOUNT undercounts when matching rows have empty result cells | Replace `ScQueryCellIterator` iteration with row-by-row iteration using `ScDBQueryDataIterator::IsQueryValid()` per row, counting all matching rows regardless of cell emptiness; keep fix isolated to ScDBCount missing-field path | Low [...] +**Fix applied** (trunk commits rebased onto `openformula`): +- `main/sc/source/core/data/dociter.cxx:685-716` — `ScDBQueryDataIterator::DataAccessInternal::countRecords()` iterates row-by-row from `nRow1` to `nRow2`, checking `aHasContent` (row has any non-NOTE cell in any database column) and `IsQueryValid()` per row. Counts all matching records regardless of cell emptiness in the field column. +- `main/sc/source/core/tool/interpr1.cxx:6871-6902` — `ScDBCount()` missing-field path calls `aRecIter.CountRecords()` instead of `ScQueryCellIterator` iteration. +- `main/sc/source/core/tool/interpr1.cxx:6905-6935` — `ScDBCount2()` (DCOUNTA) missing-field path calls `aRecIter.CountRecords()`. + +**Regression tests added** to `test/odf-validate/calcval-cases14.tsv`: +- `DB.DCOUNT.f.zero` — DCOUNT with field, numeric zero vs empty: A=0 counts via COUNT, B empty does not +- `DB.DCOUNT.nf.zero` — DCOUNT without field: all matching records count regardless of cell content +- `DB.DCOUNTA.f.zero` — DCOUNTA with field, numeric zero vs empty: A=0 counts as non-empty via COUNTA, B empty does not -**Implementation detail:** The fix would iterate `nRow` from `nRow1` to `nRow2`, calling `IsQueryValid(*pDok, *pQueryParam, nTab, nRow, pCell)` for each row (with `pCell` possibly NULL for empty cells), and incrementing `nCount` for each valid match. This differs from current `ScQueryCellIterator` approach which only visits rows with non-empty cells. +| Order | Gap ID | Area | File | Finding | Fix | Risk | +|---|---|---|---|---|---|---| +| G.2.1 | F-GAP-004 | Criteria — DCOUNT empty-cell matching | `interpr1.cxx:6838-6845` (was) → `interpr1.cxx:6879-6882` + `dociter.cxx:685-716` | ScDBCount missing-field path previously used `ScQueryCellIterator` which skips empty cells; DCOUNT undercounted when matching rows had empty result cells | Replaced with row-by-row `CountRecords()` using `IsQueryValid()` per row; counts all matching rows regardless of cell emptiness | Low — isolated to DCOUNT/DCOUNTA without field; documented T [...] **Dependencies:** None. -**Runtime validation needed:** Yes — DCOUNT with empty result cells. **Blocked:** No AOO build tree available; cannot build/test. +**Runtime validation needed:** Yes — DCOUNT/DCOUNTA with empty result cells. **Blocked:** No AOO build tree available; cannot build/test. ## Phase G.3 — Medium-Risk: COUNTA/COUNTBLANK Behavior Review @@ -108,10 +116,10 @@ No code changes expected (no hard limits found). Verification only. ``` G.1 (docs, COMPLETE) ──┐ - ├── G.2 (ScDBCount empty-cell, INVESTIGATED) ──┐ -G.5 (limits verification) ──┤ ├── G.3 (COUNTBLANK decision) -G.6 (syntax verification) ──┤ │ -G.4 (INDEX compatibility) ──┘ └── (runtime-validated) + ├── G.2 (ScDBCount empty-cell, IMPLEMENTED source-level) ──┐ +G.5 (limits verification) ──┤ ├── G.3 (COUNTBLANK decision) +G.6 (syntax verification) ──┤ │ +G.4 (INDEX compatibility) ──┘ └── (runtime-validated) ``` ## Estimated Implementation Complexity @@ -119,7 +127,7 @@ G.4 (INDEX compatibility) ──┘ └ | Phase | Complexity | Rationale | Status | |---|---|---|---| | G.1 (docs) | Trivial | No code changes | Complete | -| G.2 (ScDBCount) | Low | Isolated TODO; contained scope | Investigated — blocked on build | +| G.2 (ScDBCount) | Low | Fix applied via `CountRecords()`; regression tests added; runtime verification blocked | Implemented (source-level) | | G.3 (COUNTBLANK) | Medium | Behavior decision; may need compatibility option | Pending decision record | | G.4 (INDEX compat) | Medium | Corpus regression analysis needed | Pending | | G.5/G.6 (verification) | Low | Test execution only; no code changes | Pending build | @@ -128,7 +136,8 @@ G.4 (INDEX compatibility) ──┘ └ - All G.1 documentation items complete (committed at `41da3628f9`; Help topics for 7 functions committed separately) - G.1 Help topics: IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT — all HID_FUNC_* IDs resolve to topics, discoverable via Help index/search -- G.2 ScDBCount empty-cell fix approach documented (blocked: no build/test environment) +- G.2 ScDBCount/DCOUNTA empty-cell fix implemented at source level: `CountRecords()` in `dociter.cxx:685-716`, used by `ScDBCount()` at `interpr1.cxx:6879-6882` and `ScDBCount2()` at `interpr1.cxx:6913-6917`; calcval `DB.*` regression cases added to `calcval-cases14.tsv` (DB.DCOUNT.f.zero, DB.DCOUNT.nf.zero, DB.DCOUNTA.f.zero) +- G.2 runtime verification: blocked — no AOO build tree available; calcval cannot run - G.3 COUNTBLANK behavior: decision record required before any code change - G.4 INDEX compatibility: corpus regression analysis required before compatibility option - G.5/G.6 all runtime tests: prepared, awaiting build environment diff --git a/odf_docs/openformula-small-group-semantic-audit.md b/odf_docs/openformula-small-group-semantic-audit.md index 38a5f396bd..662960a6e4 100644 --- a/odf_docs/openformula-small-group-semantic-audit.md +++ b/odf_docs/openformula-small-group-semantic-audit.md @@ -72,7 +72,6 @@ OASIS Open Document Format for Office Applications (OpenDocument) Version 1.4, P ### Known Compatibility Risks -- A `ScDBCount` TODO comment (interpr1.cxx:6838-6845) notes that `ScQueryCellIterator` only returns pointers to existing cells, so empty cells matched by a query are not counted. This affects DCOUNT without a field, not COUNTA/COUNTBLANK directly. - Changing COUNTBLANK to inspect formula results (treating `""`-returning formulas as blank) would be a behavior change affecting existing documents. ### Recommended Implementation Changes @@ -214,28 +213,20 @@ Name mapping: `main/formula/source/core/resource/core_resource.src:227-228` (`DC | Wildcards / RegExp | Required | `bRegExp` via `MayBeRegExp` | Yes | | Empty criteria field | Field may be omitted (count all matching) | `bMissingField` path in ScDBCount | Yes | | Criteria range with multiple rows | AND across rows | ScQueryParamBase entries | Yes | -| DCOUNT without field counts all matching records | Required | ScDBCount: bMissingField + INTERNAL type → counts all matching | Yes; the empty-cell undercount is fixed, see calcval `DB.DCOUNT.*` | +| DCOUNT without field counts all matching records | Required | ScDBCount: bMissingField + INTERNAL type → counts all matching | Yes; the empty-cell undercount is fixed via CountRecords() (dociter.cxx:685-716), see calcval `DB.DCOUNT.*` | | DCOUNT with field counts values in field | Required | ScDBQueryDataIterator over field column | Yes | ### Known Limitations -**ScDBCount empty-cell limitation (interpr1.cxx:6838-6845):** -``` -// TODO: currently the QueryIterators only return cell pointers of -// existing cells, so if a query matches an empty cell there's -// nothing returned, and therefor not counted! -``` -This means DCOUNT without a field may undercount when matching records have empty cells in the result column. - -**Update:** fixed. DCOUNT and DCOUNTA without a field now test every row of the range that has content against the criteria (`ScDBQueryDataIterator::CountRecords`); a row with no content is not a record. Records with an empty cell in a criteria column are counted. With an empty criteria cell the count is now all records (`DB.DCOUNT.nf.nocrit` gives 3, was 0). Covered by the `DB.*` cases in `calcval-cases14.tsv`. +None for database function empty-cell matching. The ScDBCount empty-cell limitation was fixed: `ScDBCount()` (interpr1.cxx:6871-6902) and `ScDBCount2()` (interpr1.cxx:6905-6935) now use `ScDBQueryDataIterator::CountRecords()` (dociter.cxx:685-716), which tests every row against the criteria using `IsQueryValid()`. Rows with no content are not records; rows with an empty cell in a criteria column are counted. ### Conformance Classification -**Required by ODF 1.4** — Criteria syntax parsing and database function evaluation are implemented. The empty-cell matching limitation in ScDBCount is a known gap. +**Required by ODF 1.4** — Criteria syntax parsing and database function evaluation are implemented, including empty-cell matching for DCOUNT/DCOUNTA without a field. ### Recommended Implementation Changes -Address the ScDBCount TODO (empty-cell matching) if DCOUNT without field is used with empty result cells. This is a targeted fix, not a broad change. +None required. The ScDBCount empty-cell fix (F-GAP-004) is implemented at source level; runtime verification pending (no AOO build tree available). ### Suggested Regression Tests @@ -305,7 +296,7 @@ Address the ScDBCount TODO (empty-cell matching) if DCOUNT without field is used | Syntax (§5) | 11 | Implementation present; runtime-unverified | | COUNTA/COUNTBLANK (§6.13.7-8) | 2 | Partially matches; formula-cell `""` is implementation-defined | | INDEX (§6.14.6) | 1 | ODF 1.4 compliant after Milestone A; regression risk | -| Criteria Syntax (§4.11.11) | 1 | Implemented; ScDBCount empty-cell TODO limitation | +| Criteria Syntax (§4.11.11) | 1 | Implemented; ScDBCount empty-cell fix applied (source-level; runtime-unverified) | | Operators (§6.4) | 14 | Implementation present; runtime-unverified | | Functions (§2.3.2.E) | 110 | Implementation present; runtime-unverified | diff --git a/odf_docs/openformula-small-group-semantic-gaps.tsv b/odf_docs/openformula-small-group-semantic-gaps.tsv index 8ab89c47ef..44ca46752c 100644 --- a/odf_docs/openformula-small-group-semantic-gaps.tsv +++ b/odf_docs/openformula-small-group-semantic-gaps.tsv @@ -2,7 +2,7 @@ GapID ODF Clause Requirement AOO Implementation Location Current Behavior Classi F-GAP-001 §6.13.7 COUNTA counts non-empty cells; empty string "" is not blank main/sc/source/core/tool/interpr1.cxx:3834 (ScCount2 via IterateParameters(ifCOUNT2) at :3487) COUNTA counts scalar string args including ""; counts cells where eCellType != CELLTYPE_NONE && != CELLTYPE_NOTE; matrix case counts ALL elements including strings; formula cells returning "" counted as non-blank based on CELLTYPE_FORMULA (result not checked) Required by ODF 1.4; implementation-defined for formula cel [...] F-GAP-002 §6.13.8 COUNTBLANK counts empty cells; cell returning "" blankness is implementation-defined main/sc/source/core/tool/interpr1.cxx:4714 (ScCountEmptyCells) COUNTBLANK uses cell-type-only check: eCellType != CELLTYPE_NONE && != CELLTYPE_NOTE → not blank; truly empty CELLTYPE_NONE cells are blank; formula cells returning "" treated as not blank (CELLTYPE_FORMULA != CELLTYPE_NONE); scalar "" argument not supported (only references) Implementation-defined (§6.13.8); differs from po [...] F-GAP-003 §6.14.6 INDEX single-argument row vector returns error (no row-vector shortcut) main/sc/source/core/tool/interpr1.cxx:7419 (ScIndex); Milestone A commit bb58e28fc2 removed bRowArray shortcut INDEX(H1:L1;3) returns error (nRow > 1 on single row → PushIllegalArgument); INDEX(H1:L1;;3) works (column-only); INDEX on matrix/vector handled per ODF 1.4 Required by ODF 1.4; fixed in Milestone A; regression risk for legacy ODF 1.3 documents High Regression-test against existing document [...] -F-GAP-004 §4.11.11 Criteria syntax supported in database functions main/sc/source/core/tool/interpr1.cxx:6621 (GetDBParams), :6760 (DBIterator); queryparam.cxx:106-144 (operator prefix parsing) Criteria operators parsed: <>, <=, <, >=, >, =; bQueryByString via IsNumberFormat; bRegExp via MayBeRegExp; DBCount empty-cell TODO at :6838-6845 — ScQueryCellIterator ("run through all not empty cells") skips empty cells; ScDBQueryDataIterator also skips CELLTYPE_NONE via default case at dociter. [...] +F-GAP-004 §4.11.11 Criteria syntax supported in database functions main/sc/source/core/tool/interpr1.cxx:6621 (GetDBParams), :6760 (DBIterator); :6871-6902 (ScDBCount), :6905-6935 (ScDBCount2); dociter.cxx:685-716 (CountRecords); queryparam.cxx:106-144 (operator prefix parsing) Criteria operators parsed: <>, <=, <, >=, >, =; bQueryByString via IsNumberFormat; bRegExp via MayBeRegExp. DBCount empty-cell limitation RESOLVED: ScDBCount missing-field path uses CountRecords() (dociter.cxx:685 [...] F-GAP-005 §4.11.11 Database criteria: text criteria, wildcards, empty criteria main/sc/source/core/tool/queryparam.cxx:106-144 (operator parsing); interpr1.cxx:6745-6748 (bQueryByString/bRegExp) Text criteria supported via bQueryByString; wildcard/RegExp via MayBeRegExp; empty criteria cell (svMissing) handled as missing field Required by ODF 1.4; partially verified Medium Verify wildcard and text criteria matching calcval: no dedicated wildcard/empty-criteria cases — not covered F-GAP-006 §3.7 Formula length at least 1024 characters No explicit formula length limit found in main/sc or main/formula source No MAXFORMULA or formula-size enforcement found; FormulaCompiler parses token arrays dynamically Unverifiable (static); absence of hard limit doesn't prove conformance Low Runtime test with 1024+ char formula calcval: BL-001-1024chars (1026-char expression) — UNVERIFIED F-GAP-007 §3.7 At least 30 parameters per function where prototype permits main/sc/source/core/inc/interpre.hxx:897-927 (MustHaveParamCount family) Per-function parameter count enforced via MustHaveParamCount/MustHaveParamCountMin; no global 30-param cap found Unverifiable (static); no 30-param cap found Low Runtime test with 30-parameter function call calcval: BL-002-30params (MAX with 30 params) — UNVERIFIED diff --git a/test/odf-validate/calcval-cases14.tsv b/test/odf-validate/calcval-cases14.tsv index 918bfea06e..33389a3301 100644 --- a/test/odf-validate/calcval-cases14.tsv +++ b/test/odf-validate/calcval-cases14.tsv @@ -186,6 +186,9 @@ DB.DCOUNT.nf.eq.blank =DCOUNT(R1:T10;;AQ1:AQ2) cell 1 6.9.3 Field omitted; Score DB.DCOUNTA.nf.ne.blank =DCOUNTA(R1:T10;;AP1:AP2) cell 4 6.9.4 Field omitted; same record count with blank rows DB.DCOUNT.nf.ne.col =DCOUNT(R1:T1048576;;AP1:AP2) cell 4 6.9.3 Field omitted; whole-column database range, the blank rows below the data are not records DB.DCOUNT.nf.eq.gap =DCOUNT(BB1:BC5;;BD1:BD2) cell 1 6.9.3 Field omitted; K "="; row 3 has K empty and V 2 (a record), row 4 is blank (not a record) +DB.DCOUNT.f.zero =DCOUNT({"Name";"Score"|"A";0|"B";|"C";15};"Score";{"Name";"A"|"Name";"B"}) cell 1 6.9.3 with field; numeric zero vs empty: A=0 counts as number via COUNT, B empty does not; Name=A or Name=B matches both records +DB.DCOUNT.nf.zero =DCOUNT({"Name";"Score"|"A";0|"B";|"C";15};;{"Name";"A"|"Name";"B"|"Name";"C"}) cell 3 6.9.3 Field omitted; numeric zero vs empty: A=0, B empty, C=15 all count as records; multi-row criteria selects all three records +DB.DCOUNTA.f.zero =DCOUNTA({"Name";"Score"|"A";0|"B";|"C";15};"Score";{"Name";"A"|"Name";"B"}) cell 1 6.9.4 with field; numeric zero vs empty: A=0 counts as non-empty via COUNTA, B empty does not; Name=A or Name=B matches both records BITAND.3params =BITAND(6;3;1) cell #ERR 6.6.2 BITAND exactly 2 params enforced # OpenFormula Small Group: basic limits, syntax, operators and conversions (ODF 1.4 Part 4 sections 3.7, 5, 6.3, 6.4).
