Search code examples
clouderaimpalahue

Impala add column with default value


I want to add a column to an existing impala table(and view) with a default value (so that the existing rows also have a value). The column should not allow null values.

ALTER TABLE dbName.tblName ADD COLUMNS (id STRING NOT NULL '-1')

I went through the docs but could not find an example that specifically does this. How do I do this in Impala? Hue underlines/does not recognize the NOT NULL command


Solution

  • Are you using Kudu as a storage layer for your table? Because if not, then according to Impala docs,

    Note: Impala only allows PRIMARY KEY clauses and NOT NULL constraints on columns for Kudu tables. These constraints are enforced on the Kudu side.

    ...

    For non-Kudu tables, Impala allows any column to contain NULL values, because it is not practical to enforce a "not null" constraint on HDFS data files that could be prepared using external tools and ETL processes.

    Impala's ALTER TABLE syntax also does not support specifying default column values (in general, non-Kudu).