Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cast expressions correctly #1751

Merged
merged 5 commits into from
Feb 4, 2025

Conversation

RobinTF
Copy link
Collaborator

@RobinTF RobinTF commented Feb 3, 2025

Add the cast expressions xsd:boolean(?something) and xsd:string(?something) .
Also add xsd:float which just does the same as xsd:double as QLever currently doesn't distinguish between these operations.
Also support exponential notation like "1E04" for the xsd:double cast.

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mostly three comments

  1. Tests missing
  2. The failure of the xsd:string test case is not yours, but a bug in the parser
  3. We have to analyze and then decide on the behavior for xsd:double(3E4) and xsd::boolean(3) and xsd:boolean(3.3) (the first being relevant for this PR)

Comment on lines +92 to +95
return Id::makeFromBool(std::get<int64_t>(value) != 0);
} else if (std::holds_alternative<double>(value)) {
return Id::makeFromBool(std::get<double>(value) != 0);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to check again whether that is the correct/intended behavior.

Comment on lines 73 to +75
using ToDouble = NARY<1, FV<ToNumericImpl<double>, ToNumericValueGetter>>;
using ToDecimal =
NARY<1, FV<ToNumericImpl<double, false>, ToNumericValueGetter>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you verified, that this is indeed a subtle difference between double and decimal?
Even if, I am still not sure whether it currently is a good idea to treat them differently in this single function, when we implement them the same in all other cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared the SPARQL grammar for decimal and yes, this is the difference:
decimal double grammar difference

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.99%. Comparing base (5550d1d) to head (2c6834e).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1751      +/-   ##
==========================================
+ Coverage   89.97%   89.99%   +0.01%     
==========================================
  Files         395      395              
  Lines       37667    37743      +76     
  Branches     4236     4250      +14     
==========================================
+ Hits        33891    33965      +74     
- Misses       2478     2479       +1     
- Partials     1298     1299       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RobinTF RobinTF marked this pull request as ready for review February 3, 2025 18:25
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final state of discussions:)

Comment on lines 1134 to 1140
// These test cases should technically not result in undefined, but
// they are parsed into actual float values, so the corresponding
// SPARQL compliance test cases pass regardless.
lit("0E1", absl::StrCat("^^<", XSD_PREFIX.second, "float>")),
lit("1E0", absl::StrCat("^^<", XSD_PREFIX.second, "float>")),
lit("1.25", absl::StrCat("^^<", XSD_PREFIX.second, "float>")),
lit("-7.875", absl::StrCat("^^<", XSD_PREFIX.second, "float>"))}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the comment. Do you mean "the compliance tests suggest, that no floating point value (even if it is exactly zero or "exactly" one can be converted to xsd::boolean directly?

@sparql-conformance
Copy link

Conformance check passed ✅

Test Status Changes 📊

Number of Tests Previous Status Current Status
4 Failed Intended

Details: https://qlever.cs.uni-freiburg.de/sparql-conformance-ui?cur=2c6834e10c6f97dac08c69c8b073568e5870c666&prev=db6825c3c3769836056106b7dd2ac23f7bdc19d0

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, I will wait for the tests to pass and then merge it.

Copy link

sonarqubecloud bot commented Feb 4, 2025

@joka921 joka921 merged commit be240ab into ad-freiburg:master Feb 4, 2025
24 checks passed
@RobinTF RobinTF deleted the implement-cast-correctly branch February 4, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants