Hi,
I think this should also work:
IF(foo, 1, 0)
That said, the question was about the internal casting rules. As you've seen, a
BIT is actually stored as a 1-bit integer internally (via the BitVector). One
the one hand, it seems possible to add the needed implementations so that
casting works.
On the other hand, I wonder if that would cause undesired interference with the
SQL Boolean rules: maybe there is some place where the ability to treat a Bit
as both an INT and a BOOLEAN causes ambiguities in the planner or in run-time
type resolution code.
Still, easy enough to add the rule and rerun the unit tests to see what's what.
Thanks,
- Paul
On Wednesday, February 26, 2020, 6:16:52 AM PST, Charles Givre
<[email protected]> wrote:
Hi There,
Thanks for your interest in Drill. Can you please explain a bit more about
what you're trying to do? My intiial thought is to use a CASE statement rather
than a CAST function. IE:
SELECT ...
(CASE
WHEN foo = true THEN 1
ELSE 0
END)
FROM dfs...
Best,
--C
> On Feb 26, 2020, at 9:03 AM, Зиновьев Олег <[email protected]> wrote:
>
> Hello.
>
> I am confused with the implicit Drill cast rules for BIT data type. According
> to TypeCastRules.java there is the possibility of conversion between BIT and
> INT (and other number type), e.g. cast(true as int). However, when trying to
> perform such a conversion, the error "Missing function implementation:
> [castBIGINT (BIT-REQUIRED)]" occurs.
>
> As far as I understand, Drill scans the list of functions for conversion (in
> my case it is castINT) and tries to find the chain of transformations that is
> the least expensive. However, since there is no direct BIT -> INT conversion
> function, it selects the function with the least difference in
> ResolverTypePrecedence.precedenceMap and tries to add a additional cast for
> the argument (In my case it is [castINT (BIGINT-REQUIRED), since
> TypeCastRules.java also allows conversion BIT -> BIGINT). At the time of
> searching for the argument conversion function, the error mentioned above
> occurs.
>
> questions:
> 1) Is it correct that BIT -> Number conversions are allowed in TypeCastRules?
> 2) Was the conversion supposed to be done through TinyInt? However, for this
> type I could not find the conversion functions to other types of numbers.
> 3) the inability to convert BIT to number is an error? Or is this the correct
> behavior?