Skip to content

fix: cast for recursive queries on sqlite #1172

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

etimr
Copy link
Contributor

@etimr etimr commented May 6, 2025

To have the same behaviour on SQLite as on HANA, computed fields like DistanceFromRoot and LimitedDescendantCount should be returned as integers casted as strings, for example "1".

@etimr etimr changed the title cast for recursive queries on sqlite fix: cast for recursive queries on sqlite May 7, 2025
@etimr etimr marked this pull request as ready for review May 7, 2025 13:27
@@ -238,14 +238,14 @@ SELECT

let Hierarchy = cds.ql(`
SELECT
HIERARCHY_LEVEL,
HIERARCHY_RANK,
CAST(HIERARCHY_LEVEL AS cds.Int64) AS HIERARCHY_LEVEL,
Copy link
Member

@patricebender patricebender May 7, 2025

Choose a reason for hiding this comment

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

if this change is for sqlite only, wouldn't it make sense to override the function in the sqlite/cql-functions.js? :)

If this is shared coding and it doesnt hurt for the other DBs, I'm fine with it!

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this is SQLite specific as Postgres will also require it. Rather the code is currently only being tested with SQLite and HANA. The tests cannot be added here yet as it requires @sap/cds@9 to function.

@danjoa
Copy link
Contributor

danjoa commented May 8, 2025

Also pls check this: If these fields are meant to be numbers they should always be returned as numbers, not always as strings, correct?

@etimr
Copy link
Contributor Author

etimr commented May 8, 2025

Also pls check this: If these fields are meant to be numbers they should always be returned as numbers, not always as strings, correct?

forgot to mention it in the description: we have strings only with the cds.env.features.ieee754compatible flag switched on, otherwise we are getting numbers.

Copy link
Contributor

@danjoa danjoa left a comment

Choose a reason for hiding this comment

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

I'd like to have this discussed in a review.
Why are these number Int64?
Do we really expect hierarchy levels or ranks > 4294967295 ?
And: Do we really always have to add such query clumsinesses ?

HIERARCHY_LEVEL,
HIERARCHY_RANK,
CAST(HIERARCHY_LEVEL AS cds.Int64) AS HIERARCHY_LEVEL,
HIERARCHY_RANK AS HIERARCHY_RANK,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bob is currently on vacation for the next two weeks, is it ok to have a review when he is back?

@cap-js cap-js deleted a comment from github-actions bot May 14, 2025
@johannes-vogel
Copy link
Contributor

johannes-vogel commented May 14, 2025

I'd like to have this discussed in a review. Why are these number Int64? Do we really expect hierarchy levels or ranks > 4294967295 ? And: Do we really always have to add such query clumsinesses ?

we currently always model it as int64 in our docs and samples. maybe also something to discuss tomorrow.

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.

6 participants