diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index 3d1c67f97c..6c5d90c554 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -1124,6 +1124,11 @@ public void createTable(Table tbl) throws InvalidObjectException, MetaException MTable mtbl = convertToMTable(tbl); pm.makePersistent(mtbl); + if (tbl.getCreationMetadata() != null) { + MCreationMetadata mcm = convertToMCreationMetadata(tbl.getCreationMetadata()); + pm.makePersistent(mcm); + } + PrincipalPrivilegeSet principalPrivs = tbl.getPrivileges(); List toPersistPrivObjs = new ArrayList<>(); if (principalPrivs != null) { @@ -1234,11 +1239,9 @@ public boolean dropTable(String dbName, String tableName) throws MetaException, preDropStorageDescriptor(tbl.getSd()); - if (tbl.getCreationMetadata() != null) { - // Remove creation metadata - MCreationMetadata mcm = tbl.getCreationMetadata(); - tbl.setCreationMetadata(null); - pm.deletePersistent(mcm); + if (materializedView) { + dropCreationMetadata( + tbl.getDatabase().getName(), tbl.getTableName()); } // then remove the table @@ -1257,6 +1260,25 @@ public boolean dropTable(String dbName, String tableName) throws MetaException, return success; } + private boolean dropCreationMetadata(String dbName, String tableName) throws MetaException, + NoSuchObjectException, InvalidObjectException, InvalidInputException { + boolean success = false; + try { + openTransaction(); + MCreationMetadata mcm = getCreationMetadata(dbName, tableName); + pm.retrieve(mcm); + if (mcm != null) { + pm.deletePersistentAll(mcm); + } + success = commitTransaction(); + } finally { + if (!success) { + rollbackTransaction(); + } + } + return success; + } + private List listAllTableConstraintsWithOptionalConstraintName (String dbName, String tableName, String constraintname) { dbName = normalizeIdentifier(dbName); @@ -1309,6 +1331,11 @@ public Table getTable(String dbName, String tableName) throws MetaException { try { openTransaction(); tbl = convertToTable(getMTable(dbName, tableName)); + // Retrieve creation metadata if needed + if (tbl != null && TableType.MATERIALIZED_VIEW.toString().equals(tbl.getTableType())) { + tbl.setCreationMetadata( + convertToCreationMetadata(getCreationMetadata(dbName, tableName))); + } commited = commitTransaction(); } finally { if (!commited) { @@ -1557,11 +1584,6 @@ private AttachedMTableInfo getMTable(String db, String table, boolean retrieveCD pm.retrieveAll(mtbl.getSd().getCD()); nmtbl.mcd = mtbl.getSd().getCD(); } - // Retrieve creation metadata if needed - if (mtbl != null && - TableType.MATERIALIZED_VIEW.toString().equals(mtbl.getTableType())) { - mtbl.setCreationMetadata(getCreationMetadata(db, table)); - } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); @@ -1665,7 +1687,6 @@ private Table convertToTable(MTable mtbl) throws MetaException { .getRetention(), convertToStorageDescriptor(mtbl.getSd()), convertToFieldSchemas(mtbl.getPartitionKeys()), convertMap(mtbl.getParameters()), mtbl.getViewOriginalText(), mtbl.getViewExpandedText(), tableType); - t.setCreationMetadata(convertToCreationMetadata(mtbl.getCreationMetadata())); t.setRewriteEnabled(mtbl.isRewriteEnabled()); return t; } @@ -1705,7 +1726,7 @@ private MTable convertToMTable(Table tbl) throws InvalidObjectException, .getCreateTime(), tbl.getLastAccessTime(), tbl.getRetention(), convertToMFieldSchemas(tbl.getPartitionKeys()), tbl.getParameters(), tbl.getViewOriginalText(), tbl.getViewExpandedText(), tbl.isRewriteEnabled(), - convertToMCreationMetadata(tbl.getCreationMetadata()), tableType); + tableType); } private List convertToMFieldSchemas(List keys) { @@ -3713,10 +3734,14 @@ public void alterTable(String dbname, String name, Table newTable) oldt.setViewOriginalText(newt.getViewOriginalText()); oldt.setViewExpandedText(newt.getViewExpandedText()); oldt.setRewriteEnabled(newt.isRewriteEnabled()); - registerCreationSignature = newt.getCreationMetadata() != null; + registerCreationSignature = newTable.getCreationMetadata() != null; if (registerCreationSignature) { - oldt.getCreationMetadata().setTables(newt.getCreationMetadata().getTables()); - oldt.getCreationMetadata().setTxnList(newt.getCreationMetadata().getTxnList()); + // Update creation metadata + MCreationMetadata newMcm = convertToMCreationMetadata( + newTable.getCreationMetadata()); + MCreationMetadata mcm = getCreationMetadata(dbname, name); + mcm.setTables(newMcm.getTables()); + mcm.setTxnList(newMcm.getTxnList()); } // commit the changes diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MTable.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MTable.java index aea16ade7d..a38a1250e0 100644 --- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MTable.java +++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/model/MTable.java @@ -35,7 +35,6 @@ private String viewOriginalText; private String viewExpandedText; private boolean rewriteEnabled; - private MCreationMetadata creationMetadata; private String tableType; public MTable() {} @@ -57,8 +56,7 @@ public MTable() {} public MTable(String tableName, MDatabase database, MStorageDescriptor sd, String owner, int createTime, int lastAccessTime, int retention, List partitionKeys, Map parameters, String viewOriginalText, String viewExpandedText, - boolean rewriteEnabled, MCreationMetadata creationMetadata, - String tableType) { + boolean rewriteEnabled, String tableType) { this.tableName = tableName; this.database = database; this.sd = sd; @@ -71,7 +69,6 @@ public MTable(String tableName, MDatabase database, MStorageDescriptor sd, Strin this.viewOriginalText = viewOriginalText; this.viewExpandedText = viewExpandedText; this.rewriteEnabled = rewriteEnabled; - this.creationMetadata = creationMetadata; this.tableType = tableType; } @@ -173,20 +170,6 @@ public void setRewriteEnabled(boolean rewriteEnabled) { this.rewriteEnabled = rewriteEnabled; } - /** - * @return the metadata information related to a materialized view creation - */ - public MCreationMetadata getCreationMetadata() { - return creationMetadata; - } - - /** - * @param creationMetadata the metadata information to set - */ - public void setCreationMetadata(MCreationMetadata creationMetadata) { - this.creationMetadata = creationMetadata; - } - /** * @return the owner */