BOOLEAN Data Type
A data type used in CREATE TABLE and ALTER TABLE statements, representing a single true/false choice.
In the column definition of a CREATE TABLE statement:
Range: TRUE or FALSE. Do not use quotation marks around the TRUE and FALSE literal values. You can write the literal values in uppercase, lowercase, or mixed case. The values queried from a table are always returned in lowercase, true or false.
Conversions: Impala does not automatically convert any other type to BOOLEAN. All conversions must use an explicit call to the CAST() function.
You can use CAST() to convert TINYINT, SMALLINT, INT, BIGINT, FLOAT, or DOUBLE BOOLEAN: a value of 0 represents false, and any non-zero value is converted to true.
You can cast DECIMAL values to BOOLEAN, with the same treatment of zero and non-zero values as the other numeric types. You cannot cast a BOOLEAN to a DECIMAL.
You cannot cast a STRING value to BOOLEAN, although you can cast a BOOLEAN value to STRING, returning '1' for true values and '0' for false values.
Although you can cast a TIMESTAMP to a BOOLEAN or a BOOLEAN to a TIMESTAMP, the results are unlikely to be useful. Any non-zero TIMESTAMP (that is, any value other than 1970-01-01 00:00:00) becomes TRUE when converted to BOOLEAN, while 1970-01-01 00:00:00 becomes FALSE. A value of FALSE becomes 1970-01-01 00:00:00 when converted to BOOLEAN, and TRUE becomes one second past this epoch date, that is, 1970-01-01 00:00:01.
NULL considerations: An expression of this type produces a NULL value if any argument of the expression is NULL.
Do not use a BOOLEAN column as a partition key. Although you can create such a table, subsequent operations produce errors:
[localhost:21000] > create table truth_table (assertion string) partitioned by (truth boolean); [localhost:21000] > insert into truth_table values ('Pigs can fly',false); ERROR: AnalysisException: INSERT into table with BOOLEAN partition column (truth) is not supported: partitioning.truth_table
SELECT 1 < 2; SELECT 2 = 5; SELECT 100 < NULL, 100 > NULL; CREATE TABLE assertions (claim STRING, really BOOLEAN); INSERT INTO assertions VALUES ("1 is less than 2", 1 < 2), ("2 is the same as 5", 2 = 5), ("Grass is green", true), ("The moon is made of green cheese", false);
HBase considerations: This data type is fully compatible with HBase tables.
Parquet considerations: This type is fully compatible with Parquet tables.
Text table considerations: Values of this type are potentially larger in text tables than in tables using Parquet or other binary formats.
Column statistics considerations: Because this type has a fixed size, the maximum and average size fields are always filled in for column statistics, even before you run the COMPUTE STATS statement.