bit functions

107 views
Skip to first unread message

tdingus

unread,
May 17, 2018, 5:13:22 PM5/17/18
to ClickHouse
According to the document about Bit functions,
"Bit functions work for any pair of types from UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, or Float64"

CREATE TABLE bit_func(c1 UInt8, c2 UInt32) ENGINE = Memory

INSERT INTO bit_func (c1, c2) VALUES (3, 4);

<<case one: if I cast both to uin8, it works OK>>
SELECT c1, c2 FROM bit_func WHERE bitAnd(toUInt8(c2), toUInt8(4));
┌─c1─┬─c2─┐
│  3 │  4 │
└────┴────┘

<<case two: if I case the second argument to UInt32, it does not work>>
SELECT c1, c2 FROM bit_func WHERE bitAnd(c2, toUInt32(4));
Received exception from server:
Code: 59. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Illegal type ColumnVector<UInt32> of column for filter. Must be ColumnUInt8 or ColumnConstUInt8 or Nullable variants of them.. 

This is not according to the document cited above. Or, did I do anything incorrect here?

Thanks

Alexey Milovidov

unread,
May 19, 2018, 11:48:53 AM5/19/18
to tdingus, ClickHouse
The documentation says "The result type is an integer with bits equal to the maximum bits of its arguments."
The function returns UInt32 in your case. And the only possible types in WHERE condition are UInt8 or Nullable(UInt8).

You may write:

WHERE bitAnd(c2, 4) != 0;


--
You received this message because you are subscribed to the Google Groups "ClickHouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clickhouse+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clickhouse/df0d8396-9de1-46e9-b45e-173ab1c2dee8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages