Repository: hive Updated Branches: refs/heads/branch-3 3d21bc383 -> baf513cfb
HIVE-18620: Improve error message while dropping a table that is part of a materialized view (Jesus Camacho Rodriguez, reviewed by Ashutosh Chauhan) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/baf513cf Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/baf513cf Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/baf513cf Branch: refs/heads/branch-3 Commit: baf513cfbd6b7ef93c432a2676cd32a8e4cd01af Parents: 3d21bc3 Author: Jesus Camacho Rodriguez <[email protected]> Authored: Tue Aug 14 16:38:16 2018 -0700 Committer: Jesus Camacho Rodriguez <[email protected]> Committed: Tue Aug 14 16:38:39 2018 -0700 ---------------------------------------------------------------------- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java | 9 +++++++++ .../test/results/clientnegative/drop_table_used_by_mv.q.out | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/baf513cf/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 9606f18..9fc2fb4 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -36,6 +36,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.nio.ByteBuffer; +import java.sql.SQLIntegrityConstraintViolationException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -71,6 +72,7 @@ import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.core.TableScan; import org.apache.calcite.rex.RexBuilder; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileStatus; @@ -1030,6 +1032,13 @@ public class Hive { if (!ignoreUnknownTab) { throw new HiveException(e); } + } catch (MetaException e) { + int idx = ExceptionUtils.indexOfType(e, SQLIntegrityConstraintViolationException.class); + if (idx != -1 && ExceptionUtils.getThrowables(e)[idx].getMessage().contains("MV_TABLES_USED")) { + throw new HiveException("Cannot drop table since it is used by at least one materialized view definition. " + + "Please drop any materialized view that uses the table before dropping it", e); + } + throw new HiveException(e); } catch (Exception e) { throw new HiveException(e); } http://git-wip-us.apache.org/repos/asf/hive/blob/baf513cf/ql/src/test/results/clientnegative/drop_table_used_by_mv.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientnegative/drop_table_used_by_mv.q.out b/ql/src/test/results/clientnegative/drop_table_used_by_mv.q.out index 635f31d..88e3b7d 100644 --- a/ql/src/test/results/clientnegative/drop_table_used_by_mv.q.out +++ b/ql/src/test/results/clientnegative/drop_table_used_by_mv.q.out @@ -32,4 +32,4 @@ PREHOOK: query: drop table mytable PREHOOK: type: DROPTABLE PREHOOK: Input: default@mytable PREHOOK: Output: default@mytable -FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Exception thrown flushing changes to datastore) +FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot drop table since it is used by at least one materialized view definition. Please drop any materialized view that uses the table before dropping it
