http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/java/org/apache/hadoop/hive/ql/io/orc/SchemaEvolution.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/SchemaEvolution.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/SchemaEvolution.java index 6747691..046665b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/SchemaEvolution.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/SchemaEvolution.java @@ -100,9 +100,11 @@ public class SchemaEvolution { break; case CHAR: case VARCHAR: + // HIVE-13648: Look at ORC data type conversion edge cases (CHAR, VARCHAR, DECIMAL) isOk = fileType.getMaxLength() == readerType.getMaxLength(); break; case DECIMAL: + // HIVE-13648: Look at ORC data type conversion edge cases (CHAR, VARCHAR, DECIMAL) // TODO we don't enforce scale and precision checks, but probably should break; case UNION: @@ -134,27 +136,20 @@ public class SchemaEvolution { throw new IllegalArgumentException("Unknown type " + readerType); } } else { - switch (fileType.getCategory()) { - case SHORT: - if (readerType.getCategory() != TypeDescription.Category.INT && - readerType.getCategory() != TypeDescription.Category.LONG) { - isOk = false; - } - break; - case INT: - if (readerType.getCategory() != TypeDescription.Category.LONG) { - isOk = false; - } - break; - default: - isOk = false; - } + /* + * Check for the few cases where will not convert.... + */ + + isOk = ConvertTreeReaderFactory.canConvert(fileType, readerType); } if (isOk) { readerToFile.put(readerType, fileType); } else { - throw new IOException("ORC does not support type conversion from " + - fileType + " to " + readerType); + throw new IOException( + String.format( + "ORC does not support type conversion from file type %s (%d) to reader type %s (%d)", + fileType.toString(), fileType.getId(), + readerType.toString(), readerType.getId())); } }
http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/java/org/apache/hadoop/hive/ql/io/orc/TreeReaderFactory.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/TreeReaderFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/TreeReaderFactory.java index 8ee8cd7..6d1c256 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/TreeReaderFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/TreeReaderFactory.java @@ -171,6 +171,12 @@ public class TreeReaderFactory { abstract void skipRows(long rows) throws IOException; + void readValuePresent() throws IOException { + if (present != null) { + valuePresent = present.next() == 1; + } + } + Object next(Object previous) throws IOException { if (present != null) { valuePresent = present.next() == 1; @@ -204,7 +210,7 @@ public class TreeReaderFactory { */ public void nextVector(ColumnVector previous, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { if (present != null || isNull != null) { // Set noNulls and isNull vector of the ColumnVector based on // present stream @@ -273,7 +279,7 @@ public class TreeReaderFactory { } @Override - public void nextVector(ColumnVector vector, boolean[] isNull, int size) { + public void nextVector(ColumnVector vector, boolean[] isNull, final int batchSize) { vector.noNulls = false; vector.isNull[0] = true; vector.isRepeating = true; @@ -337,7 +343,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -398,7 +404,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -480,7 +486,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -562,7 +568,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -645,7 +651,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -714,7 +720,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final DoubleColumnVector result = (DoubleColumnVector) previousVector; // Read present/isNull stream @@ -823,7 +829,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final DoubleColumnVector result = (DoubleColumnVector) previousVector; // Read present/isNull stream @@ -960,7 +966,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final BytesColumnVector result = (BytesColumnVector) previousVector; // Read present/isNull stream @@ -1125,7 +1131,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { TimestampColumnVector result = (TimestampColumnVector) previousVector; super.nextVector(previousVector, isNull, batchSize); @@ -1248,7 +1254,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final LongColumnVector result = (LongColumnVector) previousVector; // Read present/isNull stream @@ -1343,7 +1349,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final DecimalColumnVector result = (DecimalColumnVector) previousVector; // Read present/isNull stream @@ -1460,7 +1466,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { reader.nextVector(previousVector, isNull, batchSize); } @@ -1515,7 +1521,7 @@ public class TreeReaderFactory { IntegerReader lengths, LongColumnVector scratchlcv, BytesColumnVector result, - int batchSize) throws IOException { + final int batchSize) throws IOException { if (result.noNulls || !(result.isRepeating && result.isNull[0])) { byte[] allBytes = commonReadByteArrays(stream, lengths, scratchlcv, result, (int) batchSize); @@ -1626,7 +1632,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final BytesColumnVector result = (BytesColumnVector) previousVector; // Read present/isNull stream @@ -1798,7 +1804,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { final BytesColumnVector result = (BytesColumnVector) previousVector; int offset; int length; @@ -1915,7 +1921,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { // Get the vector of strings from StringTreeReader, then make a 2nd pass to // adjust down the length (right trim and truncate) if necessary. super.nextVector(previousVector, isNull, batchSize); @@ -1990,7 +1996,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { // Get the vector of strings from StringTreeReader, then make a 2nd pass to // adjust down the length (truncate) if necessary. super.nextVector(previousVector, isNull, batchSize); @@ -2034,18 +2040,18 @@ public class TreeReaderFactory { protected StructTreeReader(int columnId, TypeDescription readerSchema, - SchemaEvolution treeReaderSchema, + SchemaEvolution evolution, boolean[] included, boolean skipCorrupt) throws IOException { super(columnId); - TypeDescription fileSchema = treeReaderSchema.getFileType(readerSchema); + TypeDescription fileSchema = evolution.getFileType(readerSchema); List<TypeDescription> childrenTypes = readerSchema.getChildren(); this.fields = new TreeReader[childrenTypes.size()]; for (int i = 0; i < fields.length; ++i) { TypeDescription subtype = childrenTypes.get(i); - this.fields[i] = createTreeReader(subtype, treeReaderSchema, included, skipCorrupt); + this.fields[i] = createTreeReader(subtype, evolution, included, skipCorrupt); } } @@ -2097,7 +2103,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { super.nextVector(previousVector, isNull, batchSize); StructColumnVector result = (StructColumnVector) previousVector; if (result.noNulls || !(result.isRepeating && result.isNull[0])) { @@ -2142,7 +2148,7 @@ public class TreeReaderFactory { protected UnionTreeReader(int fileColumn, TypeDescription readerSchema, - SchemaEvolution treeReaderSchema, + SchemaEvolution evolution, boolean[] included, boolean skipCorrupt) throws IOException { super(fileColumn); @@ -2151,7 +2157,7 @@ public class TreeReaderFactory { this.fields = new TreeReader[fieldCount]; for (int i = 0; i < fieldCount; ++i) { TypeDescription subtype = childrenTypes.get(i); - this.fields[i] = createTreeReader(subtype, treeReaderSchema, included, skipCorrupt); + this.fields[i] = createTreeReader(subtype, evolution, included, skipCorrupt); } } @@ -2185,7 +2191,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previousVector, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { UnionColumnVector result = (UnionColumnVector) previousVector; super.nextVector(result, isNull, batchSize); if (result.noNulls || !(result.isRepeating && result.isNull[0])) { @@ -2237,12 +2243,12 @@ public class TreeReaderFactory { protected ListTreeReader(int fileColumn, TypeDescription readerSchema, - SchemaEvolution treeReaderSchema, + SchemaEvolution evolution, boolean[] included, boolean skipCorrupt) throws IOException { super(fileColumn); TypeDescription elementType = readerSchema.getChildren().get(0); - elementReader = createTreeReader(elementType, treeReaderSchema, included, + elementReader = createTreeReader(elementType, evolution, included, skipCorrupt); } @@ -2286,7 +2292,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previous, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { ListColumnVector result = (ListColumnVector) previous; super.nextVector(result, isNull, batchSize); // if we have some none-null values, then read them @@ -2347,14 +2353,14 @@ public class TreeReaderFactory { protected MapTreeReader(int fileColumn, TypeDescription readerSchema, - SchemaEvolution treeReaderSchema, + SchemaEvolution evolution, boolean[] included, boolean skipCorrupt) throws IOException { super(fileColumn); TypeDescription keyType = readerSchema.getChildren().get(0); TypeDescription valueType = readerSchema.getChildren().get(1); - keyReader = createTreeReader(keyType, treeReaderSchema, included, skipCorrupt); - valueReader = createTreeReader(valueType, treeReaderSchema, included, skipCorrupt); + keyReader = createTreeReader(keyType, evolution, included, skipCorrupt); + valueReader = createTreeReader(valueType, evolution, included, skipCorrupt); } @Override @@ -2390,7 +2396,7 @@ public class TreeReaderFactory { @Override public void nextVector(ColumnVector previous, boolean[] isNull, - int batchSize) throws IOException { + final int batchSize) throws IOException { MapColumnVector result = (MapColumnVector) previous; super.nextVector(result, isNull, batchSize); if (result.noNulls || !(result.isRepeating && result.isNull[0])) { @@ -2459,7 +2465,17 @@ public class TreeReaderFactory { (included != null && !included[readerType.getId()])) { return new NullTreeReader(0); } - switch (readerType.getCategory()) { + TypeDescription.Category readerTypeCategory = readerType.getCategory(); + if (!fileType.getCategory().equals(readerTypeCategory) && + (readerTypeCategory != TypeDescription.Category.STRUCT && + readerTypeCategory != TypeDescription.Category.MAP && + readerTypeCategory != TypeDescription.Category.LIST && + readerTypeCategory != TypeDescription.Category.UNION)) { + // We only convert complex children. + return ConvertTreeReaderFactory.createConvertTreeReader(readerType, evolution, + included, skipCorrupt); + } + switch (readerTypeCategory) { case BOOLEAN: return new BooleanTreeReader(fileType.getId()); case BYTE: @@ -2503,7 +2519,7 @@ public class TreeReaderFactory { evolution, included, skipCorrupt); default: throw new IllegalArgumentException("Unsupported type " + - readerType.getCategory()); + readerTypeCategory); } } } http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_replace_columns2.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_replace_columns2.q b/ql/src/test/queries/clientnegative/orc_replace_columns2.q index 2a50b94..9bf9c87 100644 --- a/ql/src/test/queries/clientnegative/orc_replace_columns2.q +++ b/ql/src/test/queries/clientnegative/orc_replace_columns2.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=true; + +-- Currently, string to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key tinyint, val string) stored as orc; -alter table src_orc replace columns (k smallint, val string); +alter table src_orc replace columns (k smallint, val int); http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_replace_columns2_acid.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_replace_columns2_acid.q b/ql/src/test/queries/clientnegative/orc_replace_columns2_acid.q index b1614e6..7b37757 100644 --- a/ql/src/test/queries/clientnegative/orc_replace_columns2_acid.q +++ b/ql/src/test/queries/clientnegative/orc_replace_columns2_acid.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=false; + +-- Currently, string to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key tinyint, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); -alter table src_orc replace columns (k smallint, val string); +alter table src_orc replace columns (k smallint, val int); http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_replace_columns3.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_replace_columns3.q b/ql/src/test/queries/clientnegative/orc_replace_columns3.q index b7b527f..c2564fb 100644 --- a/ql/src/test/queries/clientnegative/orc_replace_columns3.q +++ b/ql/src/test/queries/clientnegative/orc_replace_columns3.q @@ -1,4 +1,7 @@ SET hive.exec.schema.evolution=true; + +-- Currently, smallint to tinyint conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key smallint, val string) stored as orc; alter table src_orc replace columns (k int, val string, z smallint); alter table src_orc replace columns (k int, val string, z tinyint); http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_replace_columns3_acid.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_replace_columns3_acid.q b/ql/src/test/queries/clientnegative/orc_replace_columns3_acid.q index 89c04e6..e3cb819 100644 --- a/ql/src/test/queries/clientnegative/orc_replace_columns3_acid.q +++ b/ql/src/test/queries/clientnegative/orc_replace_columns3_acid.q @@ -1,4 +1,7 @@ SET hive.exec.schema.evolution=false; + +-- Currently, smallint to tinyint conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key smallint, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); alter table src_orc replace columns (k int, val string, z smallint); alter table src_orc replace columns (k int, val string, z tinyint); http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion1.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion1.q b/ql/src/test/queries/clientnegative/orc_type_promotion1.q index d7facc3..07a93d1 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion1.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion1.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=true; -create table src_orc (key tinyint, val string) stored as orc; -alter table src_orc change key key float; + +-- Currently, string to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. +create table src_orc (key string, val string) stored as orc; +alter table src_orc change key key int; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion1_acid.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion1_acid.q b/ql/src/test/queries/clientnegative/orc_type_promotion1_acid.q index b845bd6..3a8c08a 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion1_acid.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion1_acid.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=false; -create table src_orc (key tinyint, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); -alter table src_orc change key key float; + +-- Currently, string to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. +create table src_orc (key string, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); +alter table src_orc change key key int; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion2.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion2.q b/ql/src/test/queries/clientnegative/orc_type_promotion2.q index c4ee1b5..ddc3423 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion2.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion2.q @@ -1,4 +1,7 @@ SET hive.exec.schema.evolution=true; + +-- Currently, bigint to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key smallint, val string) stored as orc; desc src_orc; alter table src_orc change key key smallint; @@ -7,4 +10,4 @@ alter table src_orc change key key int; desc src_orc; alter table src_orc change key key bigint; desc src_orc; -alter table src_orc change val val char(100); +alter table src_orc change val val int; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion2_acid.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion2_acid.q b/ql/src/test/queries/clientnegative/orc_type_promotion2_acid.q index 5228cf8..1d24b1d 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion2_acid.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion2_acid.q @@ -1,4 +1,7 @@ SET hive.exec.schema.evolution=false; + +-- Currently, bigint to int conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. create table src_orc (key smallint, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); desc src_orc; alter table src_orc change key key smallint; @@ -7,4 +10,4 @@ alter table src_orc change key key int; desc src_orc; alter table src_orc change key key bigint; desc src_orc; -alter table src_orc change val val char(100); +alter table src_orc change val val int; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion3.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion3.q b/ql/src/test/queries/clientnegative/orc_type_promotion3.q index 3ee99ec..52b0ec7 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion3.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion3.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=true; -create table src_orc (key tinyint, val string) stored as orc; + +-- Currently, double to smallint conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. +create table src_orc (key double, val string) stored as orc; alter table src_orc change key key smallint; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientnegative/orc_type_promotion3_acid.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientnegative/orc_type_promotion3_acid.q b/ql/src/test/queries/clientnegative/orc_type_promotion3_acid.q index 79e5c84..83764e2 100644 --- a/ql/src/test/queries/clientnegative/orc_type_promotion3_acid.q +++ b/ql/src/test/queries/clientnegative/orc_type_promotion3_acid.q @@ -1,3 +1,6 @@ SET hive.exec.schema.evolution=false; -create table src_orc (key tinyint, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); + +-- Currently, double to smallint conversion is not supported because it isn't in the lossless +-- TypeIntoUtils.implicitConvertible conversions. +create table src_orc (key double, val string) clustered by (val) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true'); alter table src_orc change key key smallint; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientpositive/orc_int_type_promotion.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/orc_int_type_promotion.q b/ql/src/test/queries/clientpositive/orc_int_type_promotion.q index a5a2308..9be46f0 100644 --- a/ql/src/test/queries/clientpositive/orc_int_type_promotion.q +++ b/ql/src/test/queries/clientpositive/orc_int_type_promotion.q @@ -46,6 +46,8 @@ insert overwrite table alltypes_orc select * from alltypes; select * from alltypes_orc; +SET hive.exec.schema.evolution=true; + alter table alltypes_orc change si si int; select * from alltypes_orc; @@ -59,6 +61,8 @@ set hive.fetch.task.conversion=none; explain select ti, si, i, bi from alltypes_orc; select ti, si, i, bi from alltypes_orc; +SET hive.exec.schema.evolution=false; + set hive.exec.dynamic.partition.mode=nonstrict; create table src_part_orc (key int, value string) partitioned by (ds string) stored as orc; insert overwrite table src_part_orc partition(ds) select key, value, ds from srcpart where ds is not null; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientpositive/orc_schema_evolution.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/orc_schema_evolution.q b/ql/src/test/queries/clientpositive/orc_schema_evolution.q index 285acf4..c78cfe8 100644 --- a/ql/src/test/queries/clientpositive/orc_schema_evolution.q +++ b/ql/src/test/queries/clientpositive/orc_schema_evolution.q @@ -1,4 +1,6 @@ set hive.fetch.task.conversion=none; +SET hive.exec.schema.evolution=true; + create table src_orc (key smallint, val string) stored as orc; create table src_orc2 (key smallint, val string) stored as orc; http://git-wip-us.apache.org/repos/asf/hive/blob/a16058e1/ql/src/test/queries/clientpositive/schema_evol_orc_acid_mapwork_part.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/schema_evol_orc_acid_mapwork_part.q b/ql/src/test/queries/clientpositive/schema_evol_orc_acid_mapwork_part.q index 800c5f8..768d77d 100644 --- a/ql/src/test/queries/clientpositive/schema_evol_orc_acid_mapwork_part.q +++ b/ql/src/test/queries/clientpositive/schema_evol_orc_acid_mapwork_part.q @@ -2,172 +2,858 @@ set hive.mapred.mode=nonstrict; set hive.cli.print.header=true; set hive.support.concurrency=true; set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; +set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat; SET hive.exec.schema.evolution=false; -SET hive.vectorized.execution.enabled=false; +SET hive.vectorized.use.vectorized.input.format=true; +SET hive.vectorized.use.vector.serde.deserialize=false; +SET hive.vectorized.use.row.serde.deserialize=false; set hive.fetch.task.conversion=none; +SET hive.vectorized.execution.enabled=false; set hive.exec.dynamic.partition.mode=nonstrict; - +set hive.metastore.disallow.incompatible.col.type.changes=true; +set hive.default.fileformat=orc; -- SORT_QUERY_RESULTS -- -- FILE VARIATION: ORC, ACID Non-Vectorized, MapWork, Partitioned -- *IMPORTANT NOTE* We set hive.exec.schema.evolution=false above since schema evolution is always used for ACID. +-- Also, we don't do EXPLAINs on ACID files because the transaction id causes Q file statistics differences... -- +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE ADD COLUMNS -- --- SECTION VARIATION: ALTER TABLE ADD COLUMNS ... STATIC INSERT ---- -CREATE TABLE partitioned1(a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +-- +-- SUBSECTION: ALTER TABLE ADD COLUMNS: INT PERMUTE SELECT +-- +-- +CREATE TABLE part_add_int_permute_select(insert_num int, a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned1 partition(part=1) values(1, 'original'),(2, 'original'), (3, 'original'),(4, 'original'); +insert into table part_add_int_permute_select partition(part=1) + values (1, 1, 'original'), + (2, 2, 'original'), + (3, 3, 'original'), + (4, 4, 'original'); -- Table-Non-Cascade ADD COLUMNS ... -alter table partitioned1 add columns(c int, d string); +alter table part_add_int_permute_select add columns(c int); -insert into table partitioned1 partition(part=2) values(1, 'new', 10, 'ten'),(2, 'new', 20, 'twenty'), (3, 'new', 30, 'thirty'),(4, 'new', 40, 'forty'); +insert into table part_add_int_permute_select partition(part=2) + values (5, 1, 'new', 10), + (6, 2, 'new', 20), + (7, 3, 'new', 30), + (8, 4, 'new', 40); -insert into table partitioned1 partition(part=1) values(5, 'new', 100, 'hundred'),(6, 'new', 200, 'two hundred'); +insert into table part_add_int_permute_select partition(part=1) + values (9, 5, 'new', 100), + (10, 6, 'new', 200); -- SELECT permutation columns to make sure NULL defaulting works right -select part,a,b from partitioned1; -select part,a,b,c from partitioned1; -select part,a,b,c,d from partitioned1; -select part,a,c,d from partitioned1; -select part,a,d from partitioned1; -select part,c from partitioned1; -select part,d from partitioned1; +select insert_num,part,a,b from part_add_int_permute_select order by insert_num; +select insert_num,part,a,b,c from part_add_int_permute_select order by insert_num; +select insert_num,part,c from part_add_int_permute_select order by insert_num; + +drop table part_add_int_permute_select; + +-- SUBSECTION: ALTER TABLE ADD COLUMNS: INT, STRING, PERMUTE SELECT -- --- SECTION VARIATION: ALTER TABLE CHANGE COLUMN ... STATIC INSERT --- smallint = (2-byte signed integer, from -32,768 to 32,767) -- -CREATE TABLE partitioned2(a smallint, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +CREATE TABLE part_add_int_string_permute_select(insert_num int, a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_add_int_string_permute_select partition(part=1) + values (1, 1, 'original'), + (2, 2, 'original'), + (3, 3, 'original'), + (4, 4, 'original'); + +-- Table-Non-Cascade ADD COLUMNS ... +alter table part_add_int_string_permute_select add columns(c int, d string); + +insert into table part_add_int_string_permute_select partition(part=2) + values (5, 1, 'new', 10, 'ten'), + (6, 2, 'new', 20, 'twenty'), + (7, 3, 'new', 30, 'thirty'), + (8, 4, 'new', 40, 'forty'); + +insert into table part_add_int_string_permute_select partition(part=1) + values (9, 5, 'new', 100, 'hundred'), + (10, 6, 'new', 200, 'two hundred'); + +-- SELECT permutation columns to make sure NULL defaulting works right +select insert_num,part,a,b from part_add_int_string_permute_select order by insert_num; +select insert_num,part,a,b,c from part_add_int_string_permute_select order by insert_num; +select insert_num,part,a,b,c,d from part_add_int_string_permute_select order by insert_num; +select insert_num,part,a,c,d from part_add_int_string_permute_select order by insert_num; +select insert_num,part,a,d from part_add_int_string_permute_select order by insert_num; +select insert_num,part,c from part_add_int_string_permute_select order by insert_num; +select insert_num,part,d from part_add_int_string_permute_select order by insert_num; + +drop table part_add_int_string_permute_select; -insert into table partitioned2 partition(part=1) values(1000, 'original'),(6737, 'original'), ('3', 'original'),('4', 'original'); + + +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> DOUBLE +-- +-- +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> DOUBLE: (STRING, CHAR, VARCHAR) +-- +CREATE TABLE part_change_string_group_double(insert_num int, c1 STRING, c2 CHAR(50), c3 VARCHAR(50), b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_string_group_double partition(part=1) + values (1, '753.7028', '753.7028', '753.7028', 'original'), + (2, '-3651.672121', '-3651.672121', '-3651.672121', 'original'), + (3, '-29.0764', '-29.0764', '-29.0764', 'original'), + (4, '-10.3', '-10.3', '-10.3', 'original'); -- Table-Non-Cascade CHANGE COLUMNS ... -alter table partitioned2 change column a a int; +alter table part_change_string_group_double replace columns (insert_num int, c1 DOUBLE, c2 DOUBLE, c3 DOUBLE, b STRING); + +insert into table part_change_string_group_double partition(part=2) + values (5, 30.774, 30.774, 30.774, 'new'), + (6, 20.31, 20.31, 20.31, 'new'), + (7, 46114.284799488, 46114.284799488, 46114.284799488, 'new'), + (8, -66475.561431, -66475.561431, -66475.561431, 'new'); -insert into table partitioned2 partition(part=2) values(72909, 'new'),(200, 'new'), (32768, 'new'),(40000, 'new'); +insert into table part_change_string_group_double partition(part=1) + values (9, 17808.963785, 17808.963785, 17808.963785, 'new'), + (10, 9250340.75 , 9250340.75 , 9250340.75 , 'new'); -insert into table partitioned2 partition(part=1) values(5000, 'new'),(90000, 'new'); +select insert_num,part,c1,c2,c3,b from part_change_string_group_double order by insert_num; -select part,a,b from partitioned2; +drop table part_change_string_group_double; + + +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE CHANGE COLUMNS for DATE_GROUP -> STRING_GROUP -- -- --- SECTION VARIATION: ALTER TABLE ADD COLUMNS ... DYNAMIC INSERT ---- -CREATE TABLE partitioned3(a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for DATE_GROUP -> STRING_GROUP: TIMESTAMP, (STRING, CHAR, CHAR trunc, VARCHAR, VARCHAR trunc) +-- +CREATE TABLE part_change_date_group_string_group_timestamp(insert_num int, c1 TIMESTAMP, c2 TIMESTAMP, c3 TIMESTAMP, c4 TIMESTAMP, c5 TIMESTAMP, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned3 partition(part=1) values(1, 'original'),(2, 'original'), (3, 'original'),(4, 'original'); +insert into table part_change_date_group_string_group_timestamp partition(part=1) + values (1, '2000-12-18 08:42:30.000595596', '2000-12-18 08:42:30.000595596', '2000-12-18 08:42:30.000595596', '2000-12-18 08:42:30.000595596', '2000-12-18 08:42:30.000595596', 'original'), + (2, '2024-11-11 16:42:41.101', '2024-11-11 16:42:41.101', '2024-11-11 16:42:41.101', '2024-11-11 16:42:41.101', '2024-11-11 16:42:41.101', 'original'), + (3, '2021-09-24 03:18:32.413655165', '2021-09-24 03:18:32.413655165', '2021-09-24 03:18:32.413655165', '2021-09-24 03:18:32.413655165', '2021-09-24 03:18:32.413655165', 'original'); --- Table-Non-Cascade ADD COLUMNS ... -alter table partitioned3 add columns(c int, d string); +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_date_group_string_group_timestamp replace columns(insert_num int, c1 STRING, c2 CHAR(50), c3 CHAR(15), c4 VARCHAR(50), c5 VARCHAR(15), b STRING); -insert into table partitioned3 partition(part) values(1, 'new', 10, 'ten', 2),(2, 'new', 20, 'twenty', 2), (3, 'new', 30, 'thirty', 2),(4, 'new', 40, 'forty', 2), - (5, 'new', 100, 'hundred', 1),(6, 'new', 200, 'two hundred', 1); +insert into table part_change_date_group_string_group_timestamp partition(part=2) + values (4, '0004-09-22 18:26:29.519542222', '0004-09-22 18:26:29.519542222', '0004-09-22 18:26:29.519542222', '0004-09-22 18:26:29.519542222', '0004-09-22 18:26:29.519542222', 'new'), + (5, '1815-05-06 00:12:37.543584705', '1815-05-06 00:12:37.543584705', '1815-05-06 00:12:37.543584705', '1815-05-06 00:12:37.543584705', '1815-05-06 00:12:37.543584705', 'new'), + (6, '2007-02-09 05:17:29.368756876', '2007-02-09 05:17:29.368756876', '2007-02-09 05:17:29.368756876', '2007-02-09 05:17:29.368756876', '2007-02-09 05:17:29.368756876', 'new'), + (7, '2002-05-10 05:29:48.990818073', '2002-05-10 05:29:48.990818073', '2002-05-10 05:29:48.990818073', '2002-05-10 05:29:48.990818073', '2002-05-10 05:29:48.990818073', 'new'); +insert into table part_change_date_group_string_group_timestamp partition(part=1) + values (8, '6229-06-28 02:54:28.970117179', '6229-06-28 02:54:28.970117179', '6229-06-28 02:54:28.970117179', '6229-06-28 02:54:28.970117179', '6229-06-28 02:54:28.970117179', 'new'), + (9, '5966-07-09 03:30:50.597', '5966-07-09 03:30:50.597', '5966-07-09 03:30:50.597', '5966-07-09 03:30:50.597', '5966-07-09 03:30:50.597', 'new'); --- SELECT permutation columns to make sure NULL defaulting works right -select part,a,b from partitioned1; -select part,a,b,c from partitioned1; -select part,a,b,c,d from partitioned1; -select part,a,c,d from partitioned1; -select part,a,d from partitioned1; -select part,c from partitioned1; -select part,d from partitioned1; +select insert_num,part,c1,c2,c3,c4,c5,b from part_change_date_group_string_group_timestamp order by insert_num; + +drop table part_change_date_group_string_group_timestamp; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for DATE_GROUP -> STRING_GROUP: DATE, (STRING, CHAR, CHAR trunc, VARCHAR, VARCHAR trunc) +-- +CREATE TABLE part_change_date_group_string_group_date(insert_num int, c1 DATE, c2 DATE, c3 DATE, c4 DATE, c5 DATE, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_date_group_string_group_date partition(part=1) + values (1, '2000-12-18', '2000-12-18', '2000-12-18', '2000-12-18', '2000-12-18', 'original'), + (2, '2024-11-11', '2024-11-11', '2024-11-11', '2024-11-11', '2024-11-11', 'original'), + (3, '2021-09-24', '2021-09-24', '2021-09-24', '2021-09-24', '2021-09-24', 'original'); + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_date_group_string_group_date replace columns(insert_num int, c1 STRING, c2 CHAR(50), c3 CHAR(15), c4 VARCHAR(50), c5 VARCHAR(15), b STRING); + +insert into table part_change_date_group_string_group_date partition(part=2) + values (4, '0004-09-22', '0004-09-22', '0004-09-22', '0004-09-22', '0004-09-22', 'new'), + (5, '1815-05-06', '1815-05-06', '1815-05-06', '1815-05-06', '1815-05-06', 'new'), + (6, '2007-02-09', '2007-02-09', '2007-02-09', '2007-02-09', '2007-02-09', 'new'), + (7, '2002-05-10', '2002-05-10', '2002-05-10', '2002-05-10', '2002-05-10', 'new'), + (8, '6229-06-28', '6229-06-28', '6229-06-28', '6229-06-28', '6229-06-28', 'new'), + (9, '5966-07-09', '5966-07-09', '5966-07-09', '5966-07-09', '5966-07-09', 'new'); + +select insert_num,part,c1,c2,c3,c4,c5,b from part_change_date_group_string_group_date order by insert_num; + +drop table part_change_date_group_string_group_date; + + + +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP +-- +-- +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (TINYINT, SMALLINT, INT, BIGINT), STRING +-- +CREATE TABLE part_change_numeric_group_string_group_multi_ints_string(insert_num int, c1 tinyint, c2 smallint, c3 int, c4 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_multi_ints_string partition(part=1) + values (1, 45, 1000, 483777, -23866739993, 'original'), + (2, -2, -6737, 56, 28899333, 'original'), + (3, -255, 4957, 832222222, 9000000000, 'original'), + (4, 0, 20435, 847492223, -999999999999, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_string order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_multi_ints_string replace columns (insert_num int, c1 STRING, c2 STRING, c3 STRING, c4 STRING, b STRING) ; + +insert into table part_change_numeric_group_string_group_multi_ints_string partition(part) + values (5, '2000', '72909', '3244222', '-93222', 'new', 2), + (6, '1', '200', '2323322', '5430907', 'new', 2), + (7, '256', '32768', '31889', '470614135', 'new', 2), + (8, '5555', '40000', '-719017797', '810662019', 'new', 2), + (9, '100', '5000', '5443', '0', 'new', 1), + (10, '17', '90000', '754072151', '3289094', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_string order by insert_num; + +drop table part_change_numeric_group_string_group_multi_ints_string; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (TINYINT, SMALLINT, INT, BIGINT), CHAR +-- +CREATE TABLE part_change_numeric_group_string_group_multi_ints_char(insert_num int, c1 tinyint, c2 smallint, c3 int, c4 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_multi_ints_char partition(part=1) + values (1, 45, 1000, 483777, -23866739993, 'original'), + (2, -2, -6737, 56, 28899333, 'original'), + (3, -255, 4957, 832222222, 9000000000, 'original'), + (4, 0, 20435, 847492223, -999999999999, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_char order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_multi_ints_char replace columns (insert_num int, c1 CHAR(50), c2 CHAR(50), c3 CHAR(50), c4 CHAR(50), b STRING) ; + +insert into table part_change_numeric_group_string_group_multi_ints_char partition(part) + values (5, '2000', '72909', '3244222', '-93222', 'new', 2), + (6, '1', '200', '2323322', '5430907', 'new', 2), + (7, '256', '32768', '31889', '470614135', 'new', 2), + (8, '5555', '40000', '-719017797', '810662019', 'new', 2), + (9, '100', '5000', '5443', '0', 'new', 1), + (10, '17', '90000', '754072151', '3289094', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_char order by insert_num; + +drop table part_change_numeric_group_string_group_multi_ints_char; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (TINYINT, SMALLINT, INT, BIGINT), CHAR truncation +-- +CREATE TABLE part_change_numeric_group_string_group_multi_ints_char_trunc(insert_num int, c1 tinyint, c2 smallint, c3 int, c4 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_multi_ints_char_trunc partition(part=1) + values (1, 45, 1000, 483777, -23866739993, 'original'), + (2, -2, -6737, 56, 28899333, 'original'), + (3, -255, 4957, 832222222, 9000000000, 'original'), + (4, 0, 20435, 847492223, -999999999999, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_char_trunc order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_multi_ints_char_trunc replace columns (insert_num int, c1 CHAR(5), c2 CHAR(5), c3 CHAR(5), c4 CHAR(5), b STRING) ; + +insert into table part_change_numeric_group_string_group_multi_ints_char_trunc partition(part) + values (5, '2000', '72909', '3244222', '-93222', 'new', 2), + (6, '1', '200', '2323322', '5430907', 'new', 2), + (7, '256', '32768', '31889', '470614135', 'new', 2), + (8, '5555', '40000', '-719017797', '810662019', 'new', 2), + (9, '100', '5000', '5443', '0', 'new', 1), + (10, '17', '90000', '754072151', '3289094', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_char_trunc order by insert_num; + +drop table part_change_numeric_group_string_group_multi_ints_char_trunc; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (TINYINT, SMALLINT, INT, BIGINT), VARCHAR +-- +CREATE TABLE part_change_numeric_group_string_group_multi_ints_varchar(insert_num int, c1 tinyint, c2 smallint, c3 int, c4 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_multi_ints_varchar partition(part=1) + values (1, 45, 1000, 483777, -23866739993, 'original'), + (2, -2, -6737, 56, 28899333, 'original'), + (3, -255, 4957, 832222222, 9000000000, 'original'), + (4, 0, 20435, 847492223, -999999999999, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_varchar order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_multi_ints_varchar replace columns (insert_num int, c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50), c4 VARCHAR(50), b STRING) ; + +insert into table part_change_numeric_group_string_group_multi_ints_varchar partition(part) + values (5, '2000', '72909', '3244222', '-93222', 'new', 2), + (6, '1', '200', '2323322', '5430907', 'new', 2), + (7, '256', '32768', '31889', '470614135', 'new', 2), + (8, '5555', '40000', '-719017797', '810662019', 'new', 2), + (9, '100', '5000', '5443', '0', 'new', 1), + (10, '17', '90000', '754072151', '3289094', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_varchar order by insert_num; + +drop table part_change_numeric_group_string_group_multi_ints_varchar; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (TINYINT, SMALLINT, INT, BIGINT), VARCHAR truncation +-- +CREATE TABLE part_change_numeric_group_string_group_multi_ints_varchar_trunc(insert_num int, c1 tinyint, c2 smallint, c3 int, c4 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_multi_ints_varchar_trunc partition(part=1) + values (1, 45, 1000, 483777, -23866739993, 'original'), + (2, -2, -6737, 56, 28899333, 'original'), + (3, -255, 4957, 832222222, 9000000000, 'original'), + (4, 0, 20435, 847492223, -999999999999, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_varchar_trunc order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_multi_ints_varchar_trunc replace columns (insert_num int, c1 VARCHAR(5), c2 VARCHAR(5), c3 VARCHAR(5), c4 VARCHAR(5), b STRING) ; + +insert into table part_change_numeric_group_string_group_multi_ints_varchar_trunc partition(part) + values (5, '2000', '72909', '3244222', '-93222', 'new', 2), + (6, '1', '200', '2323322', '5430907', 'new', 2), + (7, '256', '32768', '31889', '470614135', 'new', 2), + (8, '5555', '40000', '-719017797', '810662019', 'new', 2), + (9, '100', '5000', '5443', '0', 'new', 1), + (10, '17', '90000', '754072151', '3289094', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_numeric_group_string_group_multi_ints_varchar_trunc order by insert_num; + +drop table part_change_numeric_group_string_group_multi_ints_varchar_trunc; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (DECIMAL, FLOAT, DOUBLE), STRING +-- +CREATE TABLE part_change_numeric_group_string_group_floating_string(insert_num int, c1 decimal(38,18), c2 float, c3 double, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_floating_string partition(part=1) + values (1, -23866739993, 753.7028, -3651.672121, 'original'), + (2, -10.3, -2, -29.0764, 'original'), + (3, - 832222222, 255, 4957,'original'), + (4, 847492223, 0, 20435, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_string order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_floating_string replace columns (insert_num int, c1 STRING, c2 STRING, c3 STRING, b STRING) ; + +insert into table part_change_numeric_group_string_group_floating_string partition(part) + values (5, '30.774', '20.31', '46114.284799488', 'new', 2), + (6, '-66475.561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_string order by insert_num; + +drop table part_change_numeric_group_string_group_floating_string; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (DECIMAL, FLOAT, DOUBLE), CHAR +-- +CREATE TABLE part_change_numeric_group_string_group_floating_char(insert_num int, c1 decimal(38,18), c2 float, c3 double, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_floating_char partition(part=1) + values (1, -23866739993, 753.7028, -3651.672121, 'original'), + (2, -10.3, -2, -29.0764, 'original'), + (3, 9000000000, -255, 4957,'original'), + (4, -999999999999, 0, 20435, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_char order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_floating_char replace columns (insert_num int, c1 CHAR(50), c2 CHAR(50), c3 CHAR(50), b STRING) ; + +insert into table part_change_numeric_group_string_group_floating_char partition(part) + values (5, '30.774', '20.31', '46114.284799488', 'new', 2), + (6, '-66475.561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_char order by insert_num; + +drop table part_change_numeric_group_string_group_floating_char; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (DECIMAL, FLOAT, DOUBLE), CHAR truncation +-- +CREATE TABLE part_change_numeric_group_string_group_floating_char_trunc(insert_num int, c1 decimal(38,18), c2 float, c3 double, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_floating_char_trunc partition(part=1) + values (1, -23866739993, 753.7028, -3651.672121, 'original'), + (2, -10.3, -2, -29.0764, 'original'), + (3, 832222222, -255, 4957, 'original'), + (4, 847492223, 0, 20435, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_char_trunc order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_floating_char_trunc replace columns (insert_num int, c1 CHAR(7), c2 CHAR(7), c3 CHAR(7), b STRING) ; + +insert into table part_change_numeric_group_string_group_floating_char_trunc partition(part) + values (5, '30.774', '20.31', '46114.284799488', 'new', 2), + (6, '-66475.561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_char_trunc order by insert_num; + +drop table part_change_numeric_group_string_group_floating_char_trunc; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (DECIMAL, FLOAT, DOUBLE), VARCHAR +-- +CREATE TABLE part_change_numeric_group_string_group_floating_varchar(insert_num int, c1 float, c2 double, c3 decimal(38,18), b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_floating_varchar partition(part=1) + values (1, -23866739993, 753.7028, -3651.672121, 'original'), + (2, -10.3, -2, -29.0764, 'original'), + (3, 9000000000, -255, 4957, 'original'), + (4, -999999999999, 0, 20435, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_varchar order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_floating_varchar replace columns (insert_num int, c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50), b STRING) ; + +insert into table part_change_numeric_group_string_group_floating_varchar partition(part) + values (5, '30.774', '20.31', '46114.284799488', 'new', 2), + (6, '-66475.561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_varchar order by insert_num; + +drop table part_change_numeric_group_string_group_floating_varchar; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for NUMERIC_GROUP -> STRING_GROUP: (DECIMAL, FLOAT, DOUBLE), VARCHAR truncation +-- +CREATE TABLE part_change_numeric_group_string_group_floating_varchar_trunc(insert_num int, c1 decimal(38,18), c2 float, c3 double, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_numeric_group_string_group_floating_varchar_trunc partition(part=1) + values (1, -23866739993, 753.7028, -3651.672121, 'original'), + (2, -10.3, -2, -29.0764, 'original'), + (3, 9000000000, -255, 4957, 'original'), + (4, -999999999999, 0, 20435, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_varchar_trunc order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_numeric_group_string_group_floating_varchar_trunc replace columns (insert_num int, c1 VARCHAR(7), c2 VARCHAR(7), c3 VARCHAR(7), b STRING) ; + +insert into table part_change_numeric_group_string_group_floating_varchar_trunc partition(part) + values (5, '30.774', '20.31', '46114.284799488', 'new', 2), + (6, '-66475.561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_numeric_group_string_group_floating_varchar_trunc order by insert_num; + +drop table part_change_numeric_group_string_group_floating_varchar_trunc; + + +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> STRING_GROUP +-- +-- +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> STRING_GROUP: STRING, (CHAR, CHAR trunc, VARCHAR, VARCHAR trunc) +-- +CREATE TABLE part_change_string_group_string_group_string(insert_num int, c1 string, c2 string, c3 string, c4 string, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_string_group_string_group_string partition(part=1) + values (1, 'escapist', 'escapist', 'escapist', 'escapist', 'original'), + (2, 'heartbeat', 'heartbeat', 'heartbeat', 'heartbeat', 'original'), + (3, 'dynamic reptile', 'dynamic reptile', 'dynamic reptile', 'dynamic reptile', 'original'), + (4, 'blank pads ', 'blank pads ', 'blank pads ', 'blank pads ', 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_string_group_string_group_string order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_string_group_string_group_string replace columns (insert_num int, c1 CHAR(50), c2 CHAR(9), c3 VARCHAR(50), c4 CHAR(9), b STRING) ; + +insert into table part_change_string_group_string_group_string partition(part) + values (5, 'junkyard', 'junkyard', 'junkyard', 'junkyard', 'new', 2), + (6, ' baffling ', ' baffling ', ' baffling ', ' baffling ', 'new', 2), + (7, ' featherweight ', ' featherweight ',' featherweight ',' featherweight ', 'new', 2), + (8, ' against', ' against', ' against', ' against', 'new', 2), + (9, 'hangar paralysed companion ', 'hangar paralysed companion ', 'hangar paralysed companion ', 'hangar paralysed companion ', 'new', 1), + (10, 'bottom ', 'bottom ', 'bottom ', 'bottom ', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_string_group_string_group_string order by insert_num; + +drop table part_change_string_group_string_group_string; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> STRING_GROUP: CHAR, (VARCHAR, VARCHAR trunc, STRING) +-- +CREATE TABLE part_change_string_group_string_group_char(insert_num int, c1 CHAR(50), c2 CHAR(50), c3 CHAR(50), b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_string_group_string_group_char partition(part=1) + values (1, 'escapist', 'escapist', 'escapist', 'original'), + (2, 'heartbeat', 'heartbeat', 'heartbeat', 'original'), + (3, 'dynamic reptile', 'dynamic reptile', 'dynamic reptile', 'original'), + (4, 'blank pads ', 'blank pads ', 'blank pads ', 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_string_group_string_group_char order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_string_group_string_group_char replace columns (insert_num int, c1 VARCHAR(50), c2 VARCHAR(9), c3 STRING, b STRING) ; + +insert into table part_change_string_group_string_group_char partition(part) + values (5, 'junkyard', 'junkyard', 'junkyard', 'new', 2), + (6, ' baffling ', ' baffling ', ' baffling ', 'new', 2), + (7, ' featherweight ', ' featherweight ',' featherweight ', 'new', 2), + (8, ' against', ' against', ' against', 'new', 2), + (9, 'hangar paralysed companion ', 'hangar paralysed companion ', 'hangar paralysed companion ', 'new', 1), + (10, 'bottom ', 'bottom ', 'bottom ', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_string_group_string_group_char order by insert_num; + +drop table part_change_string_group_string_group_char; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for STRING_GROUP -> STRING_GROUP: VARCHAR, (CHAR, CHAR trunc, STRING) +-- +CREATE TABLE part_change_string_group_string_group_varchar(insert_num int, c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50), b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_string_group_string_group_varchar partition(part=1) + values (1, 'escapist', 'escapist', 'escapist', 'original'), + (2, 'heartbeat', 'heartbeat', 'heartbeat', 'original'), + (3, 'dynamic reptile', 'dynamic reptile', 'dynamic reptile', 'original'), + (4, 'blank pads ', 'blank pads ', 'blank pads ', 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_string_group_string_group_varchar order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_string_group_string_group_varchar replace columns (insert_num int, c1 CHAR(50), c2 CHAR(9), c3 STRING, b STRING) ; + +insert into table part_change_string_group_string_group_varchar partition(part) + values (5, 'junkyard', 'junkyard', 'junkyard', 'new', 2), + (6, ' baffling ', ' baffling ', ' baffling ', 'new', 2), + (7, ' featherweight ', ' featherweight ',' featherweight ', 'new', 2), + (8, ' against', ' against', ' against', 'new', 2), + (9, 'hangar paralysed companion ', 'hangar paralysed companion ', 'hangar paralysed companion ', 'new', 1), + (10, 'bottom ', 'bottom ', 'bottom ', 'new', 1); +select insert_num,part,c1,c2,c3,b from part_change_string_group_string_group_varchar order by insert_num; +drop table part_change_string_group_string_group_varchar; + + + +------------------------------------------------------------------------------------------ +-- SECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP +-- +-- -- --- SECTION VARIATION: ALTER TABLE CHANGE COLUMN ... DYNAMIC INSERT --- smallint = (2-byte signed integer, from -32,768 to 32,767) +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: TINYINT, (SMALLINT, INT, BIGINT, DECIMAL, FLOAT, DOUBLE) -- -CREATE TABLE partitioned4(a smallint, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +CREATE TABLE part_change_lower_to_higher_numeric_group_tinyint(insert_num int, c1 tinyint, c2 tinyint, c3 tinyint, c4 tinyint, c5 tinyint, c6 tinyint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned4 partition(part=1) values(1000, 'original'),(6737, 'original'), ('3', 'original'),('4', 'original'); +insert into table part_change_lower_to_higher_numeric_group_tinyint partition(part=1) + values (1, 45, 45, 45, 45, 45, 45, 'original'), + (2, -2, -2, -2, -2, -2, -2, 'original'), + (3, -255, -255, -255, -255, -255, -255, 'original'), + (4, 100, 100, 100, 100, 100, 100, 'original'); + +select insert_num,part,c1,c2,c3,c4,c5,c6,b from part_change_lower_to_higher_numeric_group_tinyint order by insert_num; -- Table-Non-Cascade CHANGE COLUMNS ... -alter table partitioned4 change column a a int; +alter table part_change_lower_to_higher_numeric_group_tinyint replace columns (insert_num int, c1 SMALLINT, c2 INT, c3 BIGINT, c4 decimal(38,18), c5 FLOAT, c6 DOUBLE, b STRING) ; + +insert into table part_change_lower_to_higher_numeric_group_tinyint partition(part) + values (5, '774', '2031', '200', '12', '99', '0', 'new', 2), + (6, '561431', '52927714', '7203778961', '8', '7', '6', 'new', 2), + (7, '256', '32768', '31889', '300', '444', '506', 'new', 2), + (8, '5555', '40000', '-719017797', '45', '55', '65', 'new', 2), + (9, '100', '5000', '5443', '22', '2', '-2', 'new', 1), + (10, '17', '90000', '754072151', '95', '20', '18', 'new', 1); -insert into table partitioned4 partition(part) values(72909, 'new', 2),(200, 'new', 2), (32768, 'new', 2),(40000, 'new', 2), - (5000, 'new', 1),(90000, 'new', 1); +select insert_num,part,c1,c2,c3,c4,c5,c6,b from part_change_lower_to_higher_numeric_group_tinyint order by insert_num; -select part,a,b from partitioned4; +drop table part_change_lower_to_higher_numeric_group_tinyint; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: SMALLINT, (INT, BIGINT, DECIMAL, FLOAT, DOUBLE) +-- +CREATE TABLE part_change_lower_to_higher_numeric_group_smallint(insert_num int, c1 smallint, c2 smallint, c3 smallint, c4 smallint, c5 smallint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_lower_to_higher_numeric_group_smallint partition(part=1) + values (1, 2031, 2031, 2031, 2031, 2031, 'original'), + (2, -2, -2, -2, -2, -2, 'original'), + (3, -5000, -5000, -5000, -5000, -5000, 'original'), + (4, 100, 100, 100, 100, 100, 'original'); + +select insert_num,part,c1,c2,c3,c4,c5,b from part_change_lower_to_higher_numeric_group_smallint order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_lower_to_higher_numeric_group_smallint replace columns (insert_num int, c1 INT, c2 BIGINT, c3 decimal(38,18), c4 FLOAT, c5 DOUBLE, b STRING) ; + +insert into table part_change_lower_to_higher_numeric_group_smallint partition(part) + values (5, '774', '2031', '200', '12', '99', 'new', 2), + (6, '561431', '52927714', '7203778961', '8', '7', 'new', 2), + (7, '256', '32768', '31889', '300', '444', 'new', 2), + (8, '5555', '40000', '-719017797', '45', '55', 'new', 2), + (9, '100', '5000', '5443', '22', '2', 'new', 1), + (10, '17', '90000', '754072151', '95', '20', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,c5,b from part_change_lower_to_higher_numeric_group_smallint order by insert_num; + +drop table part_change_lower_to_higher_numeric_group_smallint; + + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: INT, (BIGINT, DECIMAL, FLOAT, DOUBLE) +-- +CREATE TABLE part_change_lower_to_higher_numeric_group_int(insert_num int, c1 int, c2 int, c3 int, c4 int, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_lower_to_higher_numeric_group_int partition(part=1) + values (1, 2031, 2031, 2031, 2031, 'original'), + (2, -2, -2, -2, -2, 'original'), + (3, -5000, -5000, -5000, -5000, 'original'), + (4, 52927714, 52927714, 52927714, 52927714, 'original'); + +select insert_num,part,c1,c2,c3,c4,b from part_change_lower_to_higher_numeric_group_int order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_lower_to_higher_numeric_group_int replace columns (insert_num int, c1 BIGINT, c2 decimal(38,18), c3 FLOAT, c4 DOUBLE, b STRING); + +insert into table part_change_lower_to_higher_numeric_group_int partition(part) + values (5, '774', '2031', '200', '12', 'new', 2), + (6, '561431', '52927714', '7203778961', '8', 'new', 2), + (7, '256', '32768', '31889', '300', 'new', 2), + (8, '5555', '40000', '-719017797', '45', 'new', 2), + (9, '100', '5000', '5443', '22', 'new', 1), + (10, '17', '90000', '754072151', '95', 'new', 1); + +select insert_num,part,c1,c2,c3,c4,b from part_change_lower_to_higher_numeric_group_int order by insert_num; + +drop table part_change_lower_to_higher_numeric_group_int; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: BIGINT, (DECIMAL, FLOAT, DOUBLE) +-- +CREATE TABLE part_change_lower_to_higher_numeric_group_bigint(insert_num int, c1 bigint, c2 bigint, c3 bigint, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_lower_to_higher_numeric_group_bigint partition(part=1) + values (1, 7203778961, 7203778961, 7203778961, 'original'), + (2, -2, -2, -2, 'original'), + (3, -5000, -5000, -5000, 'original'), + (4, 52927714, 52927714, 52927714, 'original'); + +select insert_num,part,c1,c2,c3,b from part_change_lower_to_higher_numeric_group_bigint order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_lower_to_higher_numeric_group_bigint replace columns (insert_num int, c1 decimal(38,18), c2 FLOAT, c3 DOUBLE, b STRING) ; + +insert into table part_change_lower_to_higher_numeric_group_bigint partition(part) + values (5, '774', '2031', '200', 'new', 2), + (6, '561431', '52927714', '7203778961', 'new', 2), + (7, '256', '32768', '31889', 'new', 2), + (8, '5555', '40000', '-719017797', 'new', 2), + (9, '100', '5000', '5443', 'new', 1), + (10, '17', '90000', '754072151', 'new', 1); + +select insert_num,part,c1,c2,c3,b from part_change_lower_to_higher_numeric_group_bigint order by insert_num; + +drop table part_change_lower_to_higher_numeric_group_bigint; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: DECIMAL, (FLOAT, DOUBLE) +-- +CREATE TABLE part_change_lower_to_higher_numeric_group_decimal(insert_num int, c1 decimal(38,18), c2 decimal(38,18), b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_lower_to_higher_numeric_group_decimal partition(part=1) + values (1, -29.0764, -29.0764, 'original'), + (2, 753.7028, 753.7028, 'original'), + (3, -5000, -5000, 'original'), + (4, 52927714, 52927714, 'original'); + +select insert_num,part,c1,b from part_change_lower_to_higher_numeric_group_decimal order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_lower_to_higher_numeric_group_decimal replace columns (insert_num int, c1 float, c2 double, b STRING) ; + +insert into table part_change_lower_to_higher_numeric_group_decimal partition(part) + values (5, '7.74', '22.3', 'new', 2), + (6, '56.1431', '90.9', 'new', 2), + (7, '2.56', '25.6', 'new', 2), + (8, '555.5', '55.55', 'new', 2), + (9, '10.0', '0.100', 'new', 1), + (10, '1.7', '17.8888', 'new', 1); + +select insert_num,part,c1,b from part_change_lower_to_higher_numeric_group_decimal order by insert_num; + +drop table part_change_lower_to_higher_numeric_group_decimal; + + +-- +-- SUBSECTION: ALTER TABLE CHANGE COLUMNS for "lower" type to "higher" NUMERIC_GROUP: FLOAT, (DOUBLE) +-- +CREATE TABLE part_change_lower_to_higher_numeric_group_float(insert_num int, c1 float, b STRING) PARTITIONED BY(part INT) clustered by (c1) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); + +insert into table part_change_lower_to_higher_numeric_group_float partition(part=1) + values (1, -29.0764, 'original'), + (2, 753.7028, 'original'), + (3, -5000, 'original'), + (4, 52927714, 'original'); + +select insert_num,part,c1,b from part_change_lower_to_higher_numeric_group_float order by insert_num; + +-- Table-Non-Cascade CHANGE COLUMNS ... +alter table part_change_lower_to_higher_numeric_group_float replace columns (insert_num int, c1 DOUBLE, b STRING) ; + +insert into table part_change_lower_to_higher_numeric_group_float partition(part) + values (5, '774', 'new', 2), + (6, '561431', 'new', 2), + (7, '256', 'new', 2), + (8, '5555', 'new', 2), + (9, '100', 'new', 1), + (10, '17', 'new', 1); + +select insert_num,part,c1,b from part_change_lower_to_higher_numeric_group_float order by insert_num; + +drop table part_change_lower_to_higher_numeric_group_float; -- -- -- SECTION VARIATION: ALTER TABLE ADD COLUMNS ... UPDATE New Columns --- -CREATE TABLE partitioned5(a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +CREATE TABLE partitioned_update_1(insert_num int, a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned5 partition(part=1) values(1, 'original'),(2, 'original'), (3, 'original'),(4, 'original'); +insert into table partitioned_update_1 partition(part=1) + values (1, 1, 'original'), + (2, 2, 'original'), + (3, 3, 'original'), + (4, 4, 'original'); -- Table-Non-Cascade ADD COLUMNS ... -alter table partitioned5 add columns(c int, d string); +alter table partitioned_update_1 add columns(c int, d string); -insert into table partitioned5 partition(part=2) values(1, 'new', 10, 'ten'),(2, 'new', 20, 'twenty'), (3, 'new', 30, 'thirty'),(4, 'new', 40, 'forty'); +insert into table partitioned_update_1 partition(part=2) + values (5, 1, 'new', 10, 'ten'), + (6, 2, 'new', 20, 'twenty'), + (7, 3, 'new', 30, 'thirty'), + (8, 4, 'new', 40, 'forty'); -insert into table partitioned5 partition(part=1) values(5, 'new', 100, 'hundred'),(6, 'new', 200, 'two hundred'); +insert into table partitioned_update_1 partition(part=1) + values (9, 5, 'new', 100, 'hundred'), + (10, 6, 'new', 200, 'two hundred'); -select part,a,b,c,d from partitioned5; +select insert_num,part,a,b,c,d from partitioned_update_1; -- UPDATE New Columns -update partitioned5 set c=99; +update partitioned_update_1 set c=99; -select part,a,b,c,d from partitioned5; +select insert_num,part,a,b,c,d from partitioned_update_1; -- -- -- SECTION VARIATION: ALTER TABLE ADD COLUMNS ... DELETE where old column --- -CREATE TABLE partitioned6(a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +CREATE TABLE partitioned_delete_1(insert_num int, a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned6 partition(part=1) values(1, 'original'),(2, 'original'), (3, 'original'),(4, 'original'); +insert into table partitioned_delete_1 partition(part=1) + values (1, 1, 'original'), + (2, 2, 'original'), + (3, 3, 'original'), + (4, 4, 'original'); -- Table-Non-Cascade ADD COLUMNS ... -alter table partitioned6 add columns(c int, d string); +alter table partitioned_delete_1 add columns(c int, d string); -insert into table partitioned6 partition(part=2) values(1, 'new', 10, 'ten'),(2, 'new', 20, 'twenty'), (3, 'new', 30, 'thirty'),(4, 'new', 40, 'forty'); +insert into table partitioned_delete_1 partition(part=2) + values (5, 1, 'new', 10, 'ten'), + (6, 2, 'new', 20, 'twenty'), + (7, 3, 'new', 30, 'thirty'), + (8, 4, 'new', 40, 'forty'); -insert into table partitioned6 partition(part=1) values(5, 'new', 100, 'hundred'),(6, 'new', 200, 'two hundred'); +insert into table partitioned_delete_1 partition(part=1) + values (9, 5, 'new', 100, 'hundred'), + (10, 6, 'new', 200, 'two hundred'); -select part,a,b,c,d from partitioned6; +select part,a,b,c,d from partitioned_delete_1; -- DELETE where old column -delete from partitioned6 where a = 2 or a = 4 or a = 6; +delete from partitioned_delete_1 where a = 2 or a = 4 or a = 6; -select part,a,b,c,d from partitioned6; + +select insert_num,part,a,b,c,d from partitioned_delete_1; -- -- -- SECTION VARIATION: ALTER TABLE ADD COLUMNS ... DELETE where new column --- -CREATE TABLE partitioned7(a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); +CREATE TABLE partitioned_delete_2(insert_num int, a INT, b STRING) PARTITIONED BY(part INT) clustered by (a) into 2 buckets STORED AS ORC TBLPROPERTIES ('transactional'='true'); -insert into table partitioned7 partition(part=1) values(1, 'original'),(2, 'original'), (3, 'original'),(4, 'original'); +insert into table partitioned_delete_2 partition(part=1) + values (1, 1, 'original'), + (2, 2, 'original'), + (3, 3, 'original'), + (4, 4, 'original'); -- Table-Non-Cascade ADD COLUMNS ... -alter table partitioned7 add columns(c int, d string); +alter table partitioned_delete_2 add columns(c int, d string); -insert into table partitioned7 partition(part=2) values(1, 'new', 10, 'ten'),(2, 'new', 20, 'twenty'), (3, 'new', 30, 'thirty'),(4, 'new', 40, 'forty'); +insert into table partitioned_delete_2 partition(part=2) + values (5, 1, 'new', 10, 'ten'), + (6, 2, 'new', 20, 'twenty'), + (7, 3, 'new', 30, 'thirty'), + (8, 4, 'new', 40, 'forty'); -insert into table partitioned7 partition(part=1) values(5, 'new', 100, 'hundred'),(6, 'new', 200, 'two hundred'); +insert into table partitioned_delete_2 partition(part=1) + values (9, 5, 'new', 100, 'hundred'), + (10, 6, 'new', 200, 'two hundred'); -select part,a,b,c,d from partitioned7; +select insert_num,part,a,b,c,d from partitioned_delete_2; -- DELETE where new column -delete from partitioned7 where a = 1 or c = 30 or c == 100; - -select part,a,b,c,d from partitioned7; +delete from partitioned_delete_2 where a = 1 or c = 30 or c == 100; +select insert_num,part,a,b,c,d from partitioned_delete_2; -DROP TABLE partitioned1; -DROP TABLE partitioned2; -DROP TABLE partitioned3; -DROP TABLE partitioned4; -DROP TABLE partitioned5; -DROP TABLE partitioned6; -DROP TABLE partitioned7; \ No newline at end of file +DROP TABLE partitioned_update_1; +DROP TABLE partitioned_delete_1; +DROP TABLE partitioned_delete_2; \ No newline at end of file
