You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/07/10 08:40:18 UTC

[GitHub] [hive] adesh-rao opened a new pull request #1237: Hive 23618: Enable event replication for default/check constraints

adesh-rao opened a new pull request #1237:
URL: https://github.com/apache/hive/pull/1237


   This also includes adding default/check constraint listener api in MetastoreEventListener.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r477220540



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3060,13 +3049,19 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 1);
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl8"));
+      assertEquals(dks.size(), 1);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string, price double CHECK (price > 0 AND price <= 1000))", driver);

Review comment:
       done.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494034968



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       I meant, use cols instead of addCheckConstraintEvent.getCheckConstraintCols().




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh merged pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh merged pull request #1237:
URL: https://github.com/apache/hive/pull/1237


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on pull request #1237:
URL: https://github.com/apache/hive/pull/1237#issuecomment-656653951


   @maheshk114  @pkumarsinha Can you please take a look at the PR? 


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494034909



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());

Review comment:
       I meant, use cols instead of addDefaultConstraintEvent.getDefaultConstraintCols().

##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       I meant, use cols instead of addDefaultConstraintEvent.getDefaultConstraintCols().

##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       I meant, use cols instead of addCheckConstraintEvent.getCheckConstraintCols().

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3236,13 +3236,29 @@ public void testConstraints() throws IOException {
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));
       assertEquals(nns.size(), 1);
       nnName = nns.get(0).getNn_name();
-      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl9"));
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName, "tbl9"));
       assertEquals(cks.size(), 2);
       ckName1 = cks.get(0).getDc_name();
       ckName2 = cks.get(1).getDc_name();
-      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl10"));
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName, "tbl10"));
       assertEquals(dks.size(), 1);
-      dkName = dks.get(0).getDc_name();
+      dkName1 = dks.get(0).getDc_name();
+    } catch (TException te) {
+      assertNull(te);
+    }
+
+    String dkName2 = "custom_dk_name";
+    String ckName3 = "customer_ck_name";
+    run("ALTER TABLE " + dbName+ ".tbl10 CHANGE COLUMN a a string CONSTRAINT " + ckName3 + " CHECK (a like 'a%')", driver);

Review comment:
       nit: Add space before "+" in both lines.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3265,13 +3283,15 @@ public void testConstraints() throws IOException {
       assertTrue(fks.isEmpty());
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));

Review comment:
       nit: Remove space before ","




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r492641417



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Alter table can either add or drop the constraints. Since the drop was already there, I have added through alter too.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r492640788



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());

Review comment:
       done. Thought changed it to `colsInMsg`

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Alter table can either add or drop the constraints. Since the drop was already there, I have added add through alter too.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Alter table constraints hive doc: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTableConstraints

##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       done as above.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494038041



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3265,13 +3283,15 @@ public void testConstraints() throws IOException {
       assertTrue(fks.isEmpty());
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));

Review comment:
       nit: Remove space before ","




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on pull request #1237:
URL: https://github.com/apache/hive/pull/1237#issuecomment-701430847


   +1, LGTM


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] pkumarsinha commented on pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
pkumarsinha commented on pull request #1237:
URL: https://github.com/apache/hive/pull/1237#issuecomment-662353656


   @adesh-rao Apologies, missed on this review request. @aasha is reviewing the patch.


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r477220458



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -31,20 +31,7 @@
 import org.apache.hadoop.hive.metastore.InjectableBehaviourObjectStore.BehaviourInjection;
 import org.apache.hadoop.hive.metastore.MetaStoreTestUtils;
 import org.apache.hadoop.hive.metastore.PersistenceManagerProvider;
-import org.apache.hadoop.hive.metastore.api.Database;
-import org.apache.hadoop.hive.metastore.api.ForeignKeysRequest;
-import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
-import org.apache.hadoop.hive.metastore.api.NotNullConstraintsRequest;
-import org.apache.hadoop.hive.metastore.api.NotificationEvent;
-import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
-import org.apache.hadoop.hive.metastore.api.Partition;
-import org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest;
-import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
-import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
-import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
-import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
-import org.apache.hadoop.hive.metastore.api.Table;
-import org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest;
+import org.apache.hadoop.hive.metastore.api.*;

Review comment:
       done.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r488391678



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());

Review comment:
       Shall use "cols" here.

##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       Use "cols".

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/AddCheckConstraintEvent.java
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.events;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+
+import java.util.List;
+
+@InterfaceAudience.Public
+@InterfaceStability.Stable
+public class AddCheckConstraintEvent extends ListenerEvent {
+  private final List<SQLCheckConstraint> ds;

Review comment:
       nit: Use "cc" instead of "ds"

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageBuilder.java
##########
@@ -241,6 +247,16 @@ public AddNotNullConstraintMessage buildAddNotNullConstraintMessage(
     return new JSONAddNotNullConstraintMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, nns, now());
   }
 
+  public AddDefaultConstraintMessage buildAddDefaultConstraintMessage(
+    List<SQLDefaultConstraint> dcs) {
+    return new JSONAddDefaultConstraintMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, dcs, now());
+  }
+
+  public AddCheckConstraintMessage buildAddCheckConstraintMessage(
+    List<SQLCheckConstraint> dcs) {

Review comment:
       nit: "ccs" instead of "dcs".

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3243,6 +3265,15 @@ public void testConstraints() throws IOException {
       assertTrue(fks.isEmpty());
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));
       assertTrue(nns.isEmpty());
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl10"));
+      assertTrue(dks.isEmpty());
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl9"));
+      assertTrue(cks.isEmpty());
+      dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl12"));
+      assertTrue(dks.isEmpty());
+      cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl12"));

Review comment:
       nit: Remove extra space before ","

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AddCheckConstraintHandler.java
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.parse.repl.load.message;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+import org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * AddCheckConstraintHandler
+ * Target(Load) side handler for add check constraint event.
+ */
+public class AddCheckConstraintHandler extends AbstractMessageHandler {
+  @Override
+  public List<Task<?>> handle(Context context)
+    throws SemanticException {
+    AddCheckConstraintMessage msg = deserializer.getAddCheckConstraintMessage(context.dmd.getPayload());
+
+    List<SQLCheckConstraint> ccs;
+    try {
+      ccs = msg.getCheckConstraints();
+    } catch (Exception e) {
+      if (!(e instanceof SemanticException)){
+        throw new SemanticException("Error reading message members", e);
+      } else {
+        throw (SemanticException)e;
+      }
+    }
+
+    List<Task<?>> tasks = new ArrayList<Task<?>>();
+    if (ccs.isEmpty()) {
+      return tasks;
+    }
+
+    final String actualDbName = context.isDbNameEmpty() ? ccs.get(0).getTable_db() : context.dbName;
+    final String actualTblName = ccs.get(0).getTable_name();
+    final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
+
+    for (SQLCheckConstraint nn : ccs) {

Review comment:
       nit: Variable name can be uniform nn -> ck

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AddDefaultConstraintHandler.java
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.parse.repl.load.message;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint;
+import org.apache.hadoop.hive.metastore.messaging.AddDefaultConstraintMessage;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+/**
+ * AddDefaultConstraintHandler
+ * Target(Load) side handler for add default constraint event.
+ */
+public class AddDefaultConstraintHandler extends AbstractMessageHandler {
+  @Override
+  public List<Task<?>> handle(Context context)
+    throws SemanticException {
+    AddDefaultConstraintMessage msg = deserializer.getAddDefaultConstraintMessage(context.dmd.getPayload());
+
+    List<SQLDefaultConstraint> dcs;
+    try {
+      dcs = msg.getDefaultConstraints();
+    } catch (Exception e) {
+      if (!(e instanceof SemanticException)){
+        throw new SemanticException("Error reading message members", e);
+      } else {
+        throw (SemanticException)e;
+      }
+    }
+
+    List<Task<?>> tasks = new ArrayList<Task<?>>();
+    if (dcs.isEmpty()) {
+      return tasks;
+    }
+
+    final String actualDbName = context.isDbNameEmpty() ? dcs.get(0).getTable_db() : context.dbName;
+    final String actualTblName = dcs.get(0).getTable_name();
+    final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
+
+    for (SQLDefaultConstraint nn : dcs) {

Review comment:
       nit: nn -> dc

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Add ALTER operations to change the constraints and validate it for incremental repl.

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/messaging/MessageDeserializer.java
##########
@@ -62,6 +62,10 @@ public EventMessage getEventMessage(String eventTypeString, String messageBody)
       return getAddUniqueConstraintMessage(messageBody);
     case ADD_NOTNULLCONSTRAINT:
       return getAddNotNullConstraintMessage(messageBody);
+    case ADD_DEFAULTCONSTRAINT:
+      return getAddDefaultConstraintMessage(messageBody);
+      case ADD_CHECKCONSTRAINT:

Review comment:
       nit: Statement alignment.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3243,6 +3265,15 @@ public void testConstraints() throws IOException {
       assertTrue(fks.isEmpty());
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));
       assertTrue(nns.isEmpty());
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl10"));
+      assertTrue(dks.isEmpty());
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl9"));
+      assertTrue(cks.isEmpty());
+      dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl12"));

Review comment:
       nit: Remove extra space before ","




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494034909



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());

Review comment:
       I meant, use cols instead of addDefaultConstraintEvent.getDefaultConstraintCols().




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] aasha commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
aasha commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r458689209



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AddCheckConstraintHandler.java
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.parse.repl.load.message;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+import org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+public class AddCheckConstraintHandler extends AbstractMessageHandler {

Review comment:
       Please add comments and unit tests for these classes

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -31,20 +31,7 @@
 import org.apache.hadoop.hive.metastore.InjectableBehaviourObjectStore.BehaviourInjection;
 import org.apache.hadoop.hive.metastore.MetaStoreTestUtils;
 import org.apache.hadoop.hive.metastore.PersistenceManagerProvider;
-import org.apache.hadoop.hive.metastore.api.Database;
-import org.apache.hadoop.hive.metastore.api.ForeignKeysRequest;
-import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
-import org.apache.hadoop.hive.metastore.api.NotNullConstraintsRequest;
-import org.apache.hadoop.hive.metastore.api.NotificationEvent;
-import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
-import org.apache.hadoop.hive.metastore.api.Partition;
-import org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest;
-import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
-import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
-import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
-import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
-import org.apache.hadoop.hive.metastore.api.Table;
-import org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest;
+import org.apache.hadoop.hive.metastore.api.*;

Review comment:
       checkstyle error. Please fix

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3060,13 +3049,19 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));

Review comment:
       Add similar tests for external tables.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3060,13 +3049,19 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 1);
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl8"));
+      assertEquals(dks.size(), 1);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string, price double CHECK (price > 0 AND price <= 1000))", driver);

Review comment:
       Add multiple check constraints for the same table and test if all of them are replicated.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on pull request #1237:
URL: https://github.com/apache/hive/pull/1237#issuecomment-661742790


   @aasha Can you please look at this PR? 


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494034968



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       I meant, use cols instead of addDefaultConstraintEvent.getDefaultConstraintCols().




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] sankarh commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
sankarh commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r494037934



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3236,13 +3236,29 @@ public void testConstraints() throws IOException {
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl6"));
       assertEquals(nns.size(), 1);
       nnName = nns.get(0).getNn_name();
-      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl9"));
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName, "tbl9"));
       assertEquals(cks.size(), 2);
       ckName1 = cks.get(0).getDc_name();
       ckName2 = cks.get(1).getDc_name();
-      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl10"));
+      List<SQLDefaultConstraint> dks = metaStoreClientMirror.getDefaultConstraints(new DefaultConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName, "tbl10"));
       assertEquals(dks.size(), 1);
-      dkName = dks.get(0).getDc_name();
+      dkName1 = dks.get(0).getDc_name();
+    } catch (TException te) {
+      assertNull(te);
+    }
+
+    String dkName2 = "custom_dk_name";
+    String ckName3 = "customer_ck_name";
+    run("ALTER TABLE " + dbName+ ".tbl10 CHANGE COLUMN a a string CONSTRAINT " + ckName3 + " CHECK (a like 'a%')", driver);

Review comment:
       nit: Add space before "+" in both lines.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r492640788



##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());

Review comment:
       done. Thought changed it to `colsInMsg`

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Alter table can either add or drop the constraints. Since the drop was already there, I have added add through alter too.

##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3195,13 +3201,17 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));
+      assertEquals(cks.size(), 2);
     } catch (TException te) {
       assertNull(te);
     }
 
     run("CREATE TABLE " + dbName + ".tbl4(a string, b string, primary key (a, b) disable novalidate rely)", driver);
     run("CREATE TABLE " + dbName + ".tbl5(a string, b string, foreign key (a, b) references " + dbName + ".tbl4(a, b) disable novalidate)", driver);
     run("CREATE TABLE " + dbName + ".tbl6(a string, b string not null disable, unique (a) disable)", driver);
+    run("CREATE TABLE " + dbName + ".tbl9(a string CHECK (a like 'a%'), price double CHECK (price > 0 AND price <= 1000))", driver);
+    run("CREATE TABLE " + dbName + ".tbl10(a string, b int DEFAULT 0)", driver);

Review comment:
       Alter table constraints hive doc: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTableConstraints

##########
File path: hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java
##########
@@ -703,6 +709,49 @@ public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstrain
     }
   }
 
+  /***
+   * @param addDefaultConstraintEvent add default constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
+    List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
+    if (cols.size() > 0) {
+      AddDefaultConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddDefaultConstraintMessage(addDefaultConstraintEvent.getDefaultConstraintCols());
+      NotificationEvent event =
+        new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(),
+          msgEncoder.getSerializer().serialize(msg)
+        );
+      event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
+      event.setDbName(cols.get(0).getTable_db());
+      event.setTableName(cols.get(0).getTable_name());
+      process(event, addDefaultConstraintEvent);
+    }
+  }
+
+  /***
+   * @param addCheckConstraintEvent add check constraint event
+   * @throws MetaException
+   */
+  @Override
+  public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
+    LOG.info("Inside DBNotification listener for check constraint.");
+    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
+    if (cols.size() > 0) {
+      AddCheckConstraintMessage msg = MessageBuilder.getInstance()
+        .buildAddCheckConstraintMessage(addCheckConstraintEvent.getCheckConstraintCols());

Review comment:
       done as above.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] adesh-rao commented on a change in pull request #1237: HIVE-23618: Enable event replication for default/check constraints

Posted by GitBox <gi...@apache.org>.
adesh-rao commented on a change in pull request #1237:
URL: https://github.com/apache/hive/pull/1237#discussion_r477218017



##########
File path: itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java
##########
@@ -3060,13 +3049,19 @@ public void testConstraints() throws IOException {
       assertEquals(fks.size(), 2);
       List<SQLNotNullConstraint> nns = metaStoreClientMirror.getNotNullConstraints(new NotNullConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl3"));
       assertEquals(nns.size(), 1);
+      List<SQLCheckConstraint> cks = metaStoreClientMirror.getCheckConstraints(new CheckConstraintsRequest(DEFAULT_CATALOG_NAME, replDbName , "tbl7"));

Review comment:
       External tables don't support default/check constraints yet. So, skipped adding for external table.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AddCheckConstraintHandler.java
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.parse.repl.load.message;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+import org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+public class AddCheckConstraintHandler extends AbstractMessageHandler {

Review comment:
       Added comments.
   
   I couldn't find any existing unit tests for other *Handler classes, and since TestReplicationScenarios in itests is covering this end-to-end, I skipped unit tests.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org