Quantity literals lose trailing zeros when the ELM JSON is parsed, so successor of 1.0 'cm' returns 2 'cm'
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
Hướng nghiên cứu
Start by reading src/elm/quantity.ts and src/datatypes/decimal.ts, then inspect how the ELM JSON is parsed before it reaches Quantity. Run the PredecessorOf1QCMPrecision and SuccessorOf1QCMPrecision spec tests described in the issue. Done means quantity literals preserve their decimal scale so these cases produce 0.9 'cm' and 1.1 'cm', and the ToString example retains 1.50.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In CQL 2.0, Successor and Predecessor step a Quantity by its precision: "For Quantity values, the successor is equivalent to adding 1 * the precision of the quantity value. The units are unchanged." So successor of 1.0 'cm' should be 1.1 'cm'. cql-execution returns 2 'cm'.
Decimals and the Quantity selector are already right. Only Quantity literals are affected (cql-execution master e8096c6, via the test server with @cqframework/cql 5.2.0):
| Expression | Result | Expected (2.0) |
|---|---|---|
successor of 1.0 |
1.1 |
1.1 |
successor of Quantity { value: 1.0, unit: 'cm' } |
1.1 'cm' |
1.1 'cm' |
successor of 1.0 'cm' |
2 'cm' |
1.1 'cm' |
predecessor of 1.0 'cm' |
0 'cm' |
0.9 'cm' |
successor of 1.50 'cm' |
1.6 'cm' |
1.51 'cm' |
successor of 1.05 'cm' |
1.06 'cm' |
1.06 'cm' |
The lost scale also shows in ToString(1.50 'cm'), which returns '1.5 'cm''; the Java engine returns '1.50 'cm''.
Cause
The translator keeps the trailing zeros. CqlTranslator.toJson() writes the two literals as:
{"type":"Quantity", ..., "value":1.0, "unit":"cm", ...}
{"type":"Quantity", ..., "value":1.50, "unit":"cm", ...}
JSON.parse then turns 1.0 into the number 1 and 1.50 into 1.5. By the time Quantity's constructor runs DT.Decimal.from(json.value) (src/elm/quantity.ts:13), the scale is gone, so Decimal.successor() (src/datatypes/decimal.ts:197) steps by 1 and 0.1 instead of by 0.1 and 0.01. A Decimal literal and the Quantity { value: … } selector aren't affected, because the ELM Literal carries its value as a string.
The skip reason for PredecessorOf1QCMPrecision in test/spec-tests/skip-list.txt (added in #376) says "Translator loses Decimal precision (trailing zeros) in ELM representation of Quantity literal". The precision is still in the ELM JSON text, though. It's lost when the text is parsed.
Possible fix
Since the caller parses the ELM before handing it to cql-execution, the fix needs the number's source text. One option: JSON.parse revivers get each value's original text (context.source, from the JSON.parse source text access proposal). Node 22 supports this:
JSON.parse('{"value":1.50}', (k, v, ctx) => k === 'value' ? ctx.source : v) // { value: '1.50' }
DT.Decimal.from already accepts a string, so a Quantity value kept as '1.50' would carry its scale through. The other option is for the ELM JSON to carry the Quantity value as a string, like Literal. That would be a translator and ELM change.
Tests
PredecessorOf1QCMPrecision(cql-testsCqlArithmeticFunctionsTest.xml) fails with0 'cm', and is skipped intest/spec-tests/skip-list.txt.- cqframework/cql-tests#187 adds
SuccessorOf1QCMPrecision(successor of 1.0 'cm',1.1'cm'), which fails the same way with2 'cm'.
- Ngôn ngữ chính
- JavaScript
- Star
- 86
- Fork
- 40
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cqframework/cql-execution
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cqframework/cql-execution#410 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cqframework/cql-execution#407 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
cqframework/cql-execution#406 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
cqframework/cql-execution#414 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
cqframework/cql-execution#413 ·
Tất cả issue của cqframework/cql-execution
Issue tương tự
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ManageIQ/manageiq-ui-service#2259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
electerious/Ackee#411 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[bug] 提瓦特记事本原石检测框宽度较窄Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
babalae/bettergi-scripts-list#3905 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] "Configure Colota" opens Colota with "Invalid configuration: No configuration data in URL"Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 87/100
dedicatedcode/reitti#1445 ·
Maintainer thường phản hồi trong vòng 1 ngày