druid icon indicating copy to clipboard operation
druid copied to clipboard

Handling cast boolean to integer

Open somu-imply opened this issue 1 year ago • 1 comments

Previously queries like SELECT CAST(TRUE as INTEGER) would throw errors. This PR aims to support it by allowing lenient conformance

This PR has:

  • [ ] been self-reviewed.
    • [ ] using the concurrency checklist (Remove this item if the PR doesn't have any relation to concurrency.)
  • [ ] added documentation for new or modified features or behaviors.
  • [ ] a release note entry in the PR description.
  • [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • [ ] added or updated version, license, or notice information in licenses.yaml
  • [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • [ ] added integration tests.
  • [ ] been tested in a test Druid cluster.

somu-imply avatar Feb 02 '24 22:02 somu-imply

Atm a query like this one throws an error

select STRLEN("dim3") from foo

Error: INVALID_INPUT

Cannot coerce field [v0] from type [java.util.ArrayList] to type [INTEGER]

This would allow the cast from array to string there by allowing these type of queries to run. This will lead to results which are incorrect as a MVD like [1,2] will have a length of 5 but the user would want the length of each individual values in MVD. Using a group by automatically does this and so does unnest. Anyways we are making a push for users to use Array columns and there is MV_TO_STRING to convert a MVD to string, so am not sure if this needs to be addressed. This issue is not a regression and is present in older versions like 28 as well

soumyava avatar Feb 28 '24 18:02 soumyava

I thinked this was merged a long time ago...forgot about this array coercion issue; maybe the tight coupling between the string2array and boolean coercion should refined: CALCITE-5662 renamed the allowCoercionStringToArray method and extended it to also handle boolean to numeric.

kgyrtkirk avatar Apr 11 '24 06:04 kgyrtkirk