-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: Improve sql_simple_queries
flag
#960
base: main
Are you sure you want to change the base?
Conversation
@@ -9,7 +9,7 @@ const iconv = require('iconv-lite') | |||
const { driver, prom, handleLevel } = require('./base') | |||
const { isDynatraceEnabled: dt_sdk_is_present, dynatraceClient: wrap_client } = require('./dynatrace') | |||
|
|||
if (cds.env.features.sql_simple_queries === 3) { | |||
if (cds.env.features.sql_simple_queries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's see:
features.sql_simple_queries: 1
: Patch not necessary, as always coming as boolean, right? And is default. Here we don't want to patch hdb here
features.sql_simple_queries: 2
: Does not make sense anymore at all, as not needed for HANA (sq3) and accepted for sqlite (sq1)
features.sql_simple_queries: 3
: Yes, here it should be applied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea is to set sql_simple_queries
once, being correct for all databases...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR achieves the same behavior for all databases without having to differ between sql_simple_queries:1|2|3
by having all databases return true
and false
for Booleans.
While generating the sql_simple_queries:2
SQL statements for HANA and patching the one driver which doesn't have native Boolean support. The original approach was to patch hdb
for sql_simple_queries:1
and not for sql_simple_queries:2
. This was not done, because @johannes-vogel had concerns about applications that would be using cds.UInt8
as these would now be returned as Booleans. My opinion on this is that these applications shouldn't use sql_simple_queries
. Or not use hdb
, but using @sap/hana-client
will have a more noticeable impact on the application performance then using the default JSON
queries. As HANA takes a whole 0.01ms to render a JSON row once the query is JIT compiled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR achieves the same behavior for all databases without having to differ between sql_simple_queries:1|2|3 by having all databases return true and false for Booleans.
Yes, that's good ! But I would not extra patch hdb
, when anyways the booleans come correctly from query ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't come correctly from the query when using hdb
as the protocol version it uses give the metadata as tinyint not as Boolean. That is why it is being patched instead of rendering json
queries.
I tried to find the place where hdb
defines the protocol version, but was not successful to change the behavior of HANA to match that for hana-client. A protocol upgrade probably comes with more features then just native Boolean support. So a feature request to hdb
will most definitely be rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that boolean comes from JSON function for simple_queries: 1
, isn't it?
cds.env.features.sql_simple_queries === 2 | ||
? undefined | ||
: expr => `CASE ${expr} when 1 then 'true' when 0 then 'false' END ->'$'`, | ||
boolean: expr => `CASE ${expr} when 1 then 'true' when 0 then 'false' END ->'$'`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
|
||
// REVISIT: Remove SELECT ${cols} by adjusting SELECT_columns | ||
let obj = `to_jsonb(${queryAlias}.*)` | ||
return `SELECT ${SELECT.one || isRoot ? obj : `coalesce(jsonb_agg (${obj}),'[]'::jsonb)` | ||
} as _json_ FROM (${subQuery}) as ${queryAlias}` | ||
return `SELECT ${SELECT.one || SELECT.expand === 'root' ? obj : `coalesce(jsonb_agg (${obj}),'[]'::jsonb)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot judge
sql_simple_queries
shouldn't exist.This change makes it so that only
HANA
knows about thesql_simple_queries
flag and it is no longer numeric. It now is eithertruthy
orfalsy
. There is a gap inhdb
which uses an older protocol version which usesTINYINT
as a fallback for the lack ofBOOLEAN
support when using@sap/hana-client
this limitation is no longer there.Which means that if applications have columns modeled as
cds.uint8
they are not allowed to usesql_simple_queries
andhdb
as driver. Either do the default behavior of not usingsql_simple_queries
or use@sap/hana-client
as driver.