Matches, Combine, Split, ToDate and calendar-duration equivalence don't follow the spec
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 47/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
Research direction
Start with src/elm/string.ts for Matches, Combine, and Split, then read src/datatypes/datetime.ts for ToDate and src/datatypes/quantity.ts for calendar-duration equivalence. Check the related cases in test/spec-tests/xml and the equivalence skips in test/spec-tests/skip-list.txt; the report also points to upstream cases in the named cql-tests XML files. Done means the listed expressions match the CQL Reference and regression tests cover the corrected behavior.
Written by the indexing model from the issue text.
Description
Running cql-tests through the test server turned up five operators whose results differ from the CQL Reference. In each case the text is the same in CQL 2.0.0 and 1.5.3.
Versions: cql-execution master e8096c6, via test-server with @cqframework/cql 5.2.0. The build I used has two unrelated Quantity modulo commits on top.
| Expression | cql-execution | Spec |
|---|---|---|
Matches('abc', 'b') |
false |
true |
Matches('http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1', 'Library') |
false |
true (the spec's MatchesTrue2 example) |
Combine({'a', 'b', 'c'}, null) |
'anullbnullc' |
'abc' |
Split('', ',') |
null |
{ '' } |
ToDate('2014-01-01T12:05:05.955') |
null |
@2014-01-01 |
1 year ~ 365 days |
false |
true |
1 month ~ 30 days |
false |
true |
Matches
Matches: "Regular expressions should … use partial matching … The start/end of line markers ^ and $ can be used to match the entire string." The 2.0 example define "MatchesTrue2": Matches('http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1', 'Library') is true. 2.0 adds MatchesFull for whole-string matching.
Matches.exec (src/elm/string.ts:173) anchors the pattern instead:
return new RegExp('^' + pattern + '$').test(string);
new RegExp(pattern).test(string) would give partial matching. Patterns that need a whole-string match already include ^ and $.
One thing in 1.5.3 points the other way: its example define "MatchesFalse": Matches('1,2three', '\\w+') is marked false, although \w+ matches part of the string. 2.0 changed that example to '^\\w+$', which agrees with the description. The description itself is the same in both versions.
Combine with a null separator
Combine: "If the separator argument is null, it is ignored."
Combine.exec (src/elm/string.ts:32) checks whether a separator expression exists, not whether its value is null:
const separator = this.separator != null ? await this.separator.execute(ctx) : '';
With null as the argument, the expression exists and evaluates to null. Then filteredArray.join(null) writes the separator as the text "null". (await this.separator.execute(ctx)) ?? '' would fix it.
Split of an empty string
Split: "If the stringToSplit argument is null, the result is null. If the stringToSplit argument does not contain any appearances of the separator, the result is a list of strings containing one element that is the value of the stringToSplit argument." '' contains no ,, so the result should be { '' }.
Split.exec (src/elm/string.ts:59-62) tests the string by truthiness, so '' returns null for the whole list (Split('', ',') is null is true):
if (stringToSplit && separator) {
return stringToSplit.split(separator);
}
return stringToSplit ? [stringToSplit] : null;
Checking stringToSplit == null instead would keep ''. Note that ''.split(',') already returns [''] in JavaScript.
ToDate of a string with a time part
ToDate: "Note that the operator can take datetime formatted strings and will ignore the time portions." The spec's examples include '2014-01-01T12:30:00' // Still January 1st, 2014, time portion will be ignored.
Date.parse (src/datatypes/datetime.ts) reads the date fields with a regex, but then also requires isValidDateStringFormat(string). That looks the whole string's length up in LENGTH_TO_DATE_FORMAT_MAP, so any string with a time part returns null. ConvertsToDate('2014-01-01T12:05:05.955') returns false for the same reason.
Calendar-duration equivalence
Equivalent: "calendar-time duration unit conversions shall be performed according to calendar duration semantics using the shortest number of conversion steps … 1 year ~ 12 months, 1 year ~ 365 days, 1 month ~ 30 days". 1 year ~ 12 months already returns true. The 1 year ~ 365 days and 1 month ~ 30 days cases don't.
This one is already known. Quantity.equals (src/datatypes/quantity.ts:99) has a TODO saying calendar duration semantics aren't implemented. test/spec-tests/skip-list.txt skips TestYearEquivalentDays and TestMonthEquivalentDays ("Quantity =/~ should have special semantics for calendar-based units"). I couldn't find an issue for it, so I've included it here.
Tests
From cqframework/cql-tests:
| Test | File | |
|---|---|---|
CombineNullSeparator |
CqlStringOperatorsTest.xml |
on main |
ToDateIgnoresTime |
CqlTypeOperatorsTest.xml |
on main |
TestYearEquivalentDays, TestMonthEquivalentDays |
CqlComparisonOperatorsTest.xml |
on main |
MatchesPartialTrue |
CqlStringOperatorsTest.xml |
cqframework/cql-tests#177 |
SplitEmptyStringComma |
CqlStringOperatorsTest.xml |
cqframework/cql-tests#132 |
The copy in test/spec-tests/xml predates most of these, which is probably why only the equivalence tests appear in the skip list.
I'm happy to split this into separate issues, or to send PRs for the first four.
- Dominant language
- JavaScript
- Stars
- 86
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cqframework/cql-execution
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cqframework/cql-execution#410 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cqframework/cql-execution#407 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cqframework/cql-execution#406 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
cqframework/cql-execution#414 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
cqframework/cql-execution#413 ·
All issues in cqframework/cql-execution
Similar issues
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ManageIQ/manageiq-ui-service#2259 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sagemathinc/sagebrush-agent#230 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
electerious/Ackee#411 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
babalae/bettergi-scripts-list#3905 · 1 comment ·
Maintainers usually reply within 1 day