ashish-kumar-sharma commented on a change in pull request #1419:
URL: https://github.com/apache/hive/pull/1419#discussion_r487367486
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
##########
@@ -5661,184 +5663,79 @@ public void dropConstraint(String dbName, String
tableName, String constraintNam
}
}
- public List<SQLDefaultConstraint> getDefaultConstraintList(String dbName,
String tblName) throws HiveException, NoSuchObjectException {
+ public SQLAllTableConstraints getTableConstraints(String dbName, String
tblName) throws HiveException, NoSuchObjectException {
try {
- return getMSC().getDefaultConstraints(new
DefaultConstraintsRequest(getDefaultCatalog(conf), dbName, tblName));
+ AllTableConstraintsRequest tableConstraintsRequest = new
AllTableConstraintsRequest();
+ tableConstraintsRequest.setDbName(dbName);
+ tableConstraintsRequest.setTblName(tblName);
+ tableConstraintsRequest.setCatName(getDefaultCatalog(conf));
+ return getMSC().getAllTableConstraints(tableConstraintsRequest);
} catch (NoSuchObjectException e) {
throw e;
} catch (Exception e) {
throw new HiveException(e);
}
}
-
- public List<SQLCheckConstraint> getCheckConstraintList(String dbName, String
tblName) throws HiveException, NoSuchObjectException {
- try {
- return getMSC().getCheckConstraints(new
CheckConstraintsRequest(getDefaultCatalog(conf),
- dbName, tblName));
- } catch (NoSuchObjectException e) {
- throw e;
- } catch (Exception e) {
- throw new HiveException(e);
- }
+ public TableConstraintsInfo getAllTableConstraints(String dbName, String
tblName) throws HiveException {
+ return getTableConstraints(dbName, tblName, false, false);
}
- /**
- * Get all primary key columns associated with the table.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Primary Key associated with the table.
- * @throws HiveException
- */
- public PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName) throws
HiveException {
- return getPrimaryKeys(dbName, tblName, false);
+ public TableConstraintsInfo getReliableAndEnableTableConstraints(String
dbName, String tblName) throws HiveException {
+ return getTableConstraints(dbName, tblName, true, true);
}
- /**
- * Get primary key columns associated with the table that are available for
optimization.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Primary Key associated with the table.
- * @throws HiveException
- */
- public PrimaryKeyInfo getReliablePrimaryKeys(String dbName, String tblName)
throws HiveException {
- return getPrimaryKeys(dbName, tblName, true);
- }
-
- private PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName, boolean
onlyReliable)
+ private TableConstraintsInfo getTableConstraints(String dbName, String
tblName, boolean reliable, boolean enable)
throws HiveException {
PerfLogger perfLogger = SessionState.getPerfLogger();
- perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_PK);
- try {
- List<SQLPrimaryKey> primaryKeys = getMSC().getPrimaryKeys(new
PrimaryKeysRequest(dbName, tblName));
- if (onlyReliable && primaryKeys != null && !primaryKeys.isEmpty()) {
- primaryKeys = primaryKeys.stream()
- .filter(pk -> pk.isRely_cstr())
- .collect(Collectors.toList());
- }
-
- return new PrimaryKeyInfo(primaryKeys, tblName, dbName);
- } catch (Exception e) {
- throw new HiveException(e);
- } finally {
- perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_PK, "HS2-cache");
- }
- }
-
- /**
- * Get all foreign keys associated with the table.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Foreign keys associated with the table.
- * @throws HiveException
- */
- public ForeignKeyInfo getForeignKeys(String dbName, String tblName) throws
HiveException {
- return getForeignKeys(dbName, tblName, false);
- }
-
- /**
- * Get foreign keys associated with the table that are available for
optimization.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Foreign keys associated with the table.
- * @throws HiveException
- */
- public ForeignKeyInfo getReliableForeignKeys(String dbName, String tblName)
throws HiveException {
- return getForeignKeys(dbName, tblName, true);
- }
-
- private ForeignKeyInfo getForeignKeys(String dbName, String tblName, boolean
onlyReliable)
- throws HiveException {
- PerfLogger perfLogger = SessionState.getPerfLogger();
- perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_FK);
- try {
- List<SQLForeignKey> foreignKeys = getMSC().getForeignKeys(new
ForeignKeysRequest(null, null, dbName, tblName));
- if (onlyReliable && foreignKeys != null && !foreignKeys.isEmpty()) {
- foreignKeys = foreignKeys.stream()
- .filter(fk -> fk.isRely_cstr())
- .collect(Collectors.toList());
+ perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_TABLE_CONSTRAINTS);
+ try {
+ SQLAllTableConstraints tableConstraints =
+ getMSC().getAllTableConstraints(new
AllTableConstraintsRequest(dbName, tblName));
+ if (reliable && tableConstraints != null) {
+ if (tableConstraints.getPrimaryKeys() != null &&
!tableConstraints.getPrimaryKeys().isEmpty()) {
+ tableConstraints.setPrimaryKeys(
+ tableConstraints.getPrimaryKeys().stream().filter(primaryKey ->
primaryKey.isRely_cstr())
+ .collect(Collectors.toList()));
+ }
+ if (tableConstraints.getForeignKeys() != null &&
!tableConstraints.getForeignKeys().isEmpty()) {
+ tableConstraints.setForeignKeys(
+ tableConstraints.getForeignKeys().stream().filter(foreignKey ->
foreignKey.isRely_cstr())
+ .collect(Collectors.toList()));
+ }
+ if (tableConstraints.getUniqueConstraints() != null &&
!tableConstraints.getUniqueConstraints().isEmpty()) {
+
tableConstraints.setUniqueConstraints(tableConstraints.getUniqueConstraints().stream()
+ .filter(uniqueConstraint ->
uniqueConstraint.isRely_cstr()).collect(Collectors.toList()));
+ }
+ if (tableConstraints.getNotNullConstraints() != null &&
!tableConstraints.getNotNullConstraints().isEmpty()) {
+
tableConstraints.setNotNullConstraints(tableConstraints.getNotNullConstraints().stream()
+ .filter(notNullConstraint ->
notNullConstraint.isRely_cstr()).collect(Collectors.toList()));
+ }
}
- return new ForeignKeyInfo(foreignKeys, tblName, dbName);
- } catch (Exception e) {
- throw new HiveException(e);
- } finally {
- perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_FK, "HS2-cache");
- }
- }
-
- /**
- * Get all unique constraints associated with the table.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Unique constraints associated with the table.
- * @throws HiveException
- */
- public UniqueConstraint getUniqueConstraints(String dbName, String tblName)
throws HiveException {
- return getUniqueConstraints(dbName, tblName, false);
- }
-
- /**
- * Get unique constraints associated with the table that are available for
optimization.
- *
- * @param dbName Database Name
- * @param tblName Table Name
- * @return Unique constraints associated with the table.
- * @throws HiveException
- */
- public UniqueConstraint getReliableUniqueConstraints(String dbName, String
tblName) throws HiveException {
- return getUniqueConstraints(dbName, tblName, true);
- }
-
- private UniqueConstraint getUniqueConstraints(String dbName, String tblName,
boolean onlyReliable)
- throws HiveException {
- PerfLogger perfLogger = SessionState.getPerfLogger();
- perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_UNIQ_CONSTRAINT);
- try {
- List<SQLUniqueConstraint> uniqueConstraints =
getMSC().getUniqueConstraints(
- new UniqueConstraintsRequest(getDefaultCatalog(conf), dbName,
tblName));
- if (onlyReliable && uniqueConstraints != null &&
!uniqueConstraints.isEmpty()) {
- uniqueConstraints = uniqueConstraints.stream()
- .filter(uk -> uk.isRely_cstr())
- .collect(Collectors.toList());
+ if (enable && tableConstraints != null) {
Review comment:
Yes, Ideally we can fetch all constraint on rely,enable and validate.
But in table.java we have chooses to pk,fk,unique and notnull as fetch based on
rely. Default and check constraints are fetch based on enable. this method is
tightly couple with Hive.java class that's why i have put everything is one
method as tableConstraints is single object. But yes we can have separate
function for both of them
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]