IMPALA-4527: Columns in Kudu tables created from Impala default to "NULL"

This commit reverts the behavior introduced by IMPALA-3719 which used
the Kudu default behavior for column nullability if none was specified
in the CREATE TABLE statement. With this commit, non-key columns of Kudu
tables that are created from Impala are by default nullable unless
specified otherwise.

Change-Id: I950d9a9c64e3851e11a641573617790b340ece94
Reviewed-on: http://gerrit.cloudera.org:8080/5259
Reviewed-by: Alex Behm <alex.behm@cloudera.com>
Tested-by: Internal Jenkins
This commit is contained in:
Dimitris Tsirogiannis
2016-11-29 10:02:35 -08:00
committed by Internal Jenkins
parent b374061206
commit da34ce9780
3 changed files with 27 additions and 20 deletions

View File

@@ -97,6 +97,7 @@ public class KuduCatalogOpExecutor {
private static Schema createTableSchema(TCreateTableParams params)
throws ImpalaRuntimeException {
Set<String> keyColNames = new HashSet<>(params.getPrimary_key_column_names());
Preconditions.checkState(!keyColNames.isEmpty());
List<ColumnSchema> colSchemas = new ArrayList<>(params.getColumnsSize());
for (TColumn column: params.getColumns()) {
Type type = Type.fromThrift(column.getColumnType());
@@ -105,9 +106,15 @@ public class KuduCatalogOpExecutor {
// Create the actual column and check if the column is a key column
ColumnSchemaBuilder csb =
new ColumnSchemaBuilder(column.getColumnName(), kuduType);
Preconditions.checkState(column.isSetIs_key());
csb.key(keyColNames.contains(column.getColumnName()));
if (column.isSetIs_nullable()) csb.nullable(column.isIs_nullable());
boolean isKey = keyColNames.contains(column.getColumnName());
csb.key(isKey);
if (column.isSetIs_nullable()) {
csb.nullable(column.isIs_nullable());
} else if (!isKey) {
// Non-key columns are by default nullable unless the user explicitly sets their
// nullability.
csb.nullable(true);
}
if (column.isSetDefault_value()) {
csb.defaultValue(KuduUtil.getKuduDefaultValue(column.getDefault_value(), kuduType,
column.getColumnName()));
@@ -363,7 +370,7 @@ public class KuduCatalogOpExecutor {
Type type = Type.fromThrift(column.getColumnType());
Preconditions.checkState(type != null);
org.apache.kudu.Type kuduType = KuduUtil.fromImpalaType(type);
boolean isNullable = column.isSetIs_nullable() && column.isIs_nullable();
boolean isNullable = !column.isSetIs_nullable() ? true : column.isIs_nullable();
if (isNullable) {
if (column.isSetDefault_value()) {
// See KUDU-1747

View File

@@ -4,19 +4,19 @@ describe functional_kudu.alltypes
---- LABELS
NAME,TYPE,COMMENT,PRIMARY_KEY,NULLABLE,DEFAULT_VALUE,ENCODING,COMPRESSION,BLOCK_SIZE
---- RESULTS
'bigint_col','bigint','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'bool_col','boolean','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'date_string_col','string','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'double_col','double','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'float_col','float','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'bigint_col','bigint','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'bool_col','boolean','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'date_string_col','string','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'double_col','double','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'float_col','float','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'id','int','','true','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'int_col','int','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'month','int','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'smallint_col','smallint','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'string_col','string','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'timestamp_col','string','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'tinyint_col','tinyint','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'year','int','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'int_col','int','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'month','int','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'smallint_col','smallint','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'string_col','string','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'timestamp_col','string','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'tinyint_col','tinyint','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'year','int','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
---- TYPES
STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
====
@@ -27,7 +27,7 @@ create table describe_test
pk2 int,
pk3 string,
c1 string null default 'abc' comment 'testing',
c2 int default 100 encoding plain_encoding compression snappy,
c2 int not null default 100 encoding plain_encoding compression snappy,
c3 int null block_size 8388608,
primary key (pk1, pk2, pk3))
distribute by hash (pk1) into 3 buckets

View File

@@ -23,9 +23,9 @@ compute stats simple;
describe simple;
---- RESULTS
'id','int','','true','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'name','string','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'valf','float','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'vali','bigint','','false','false','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'name','string','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'valf','float','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
'vali','bigint','','false','true','','AUTO_ENCODING','DEFAULT_COMPRESSION','0'
---- TYPES
STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
====