You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2018/02/21 23:08:51 UTC
hive git commit: HIVE-18754 : REPL STATUS should support 'with'
clause ( mahesh kumar behera via Thejas Nair)
Repository: hive
Updated Branches:
refs/heads/master c544dae19 -> ad87176c7
HIVE-18754 : REPL STATUS should support 'with' clause ( mahesh kumar behera via Thejas Nair)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/ad87176c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/ad87176c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/ad87176c
Branch: refs/heads/master
Commit: ad87176c72e3a7d500cfdaad4ea7c84691157d0d
Parents: c544dae
Author: mahesh kumar behera <ma...@gmail.com>
Authored: Wed Feb 21 15:08:41 2018 -0800
Committer: Thejas M Nair <th...@hortonworks.com>
Committed: Wed Feb 21 15:08:41 2018 -0800
----------------------------------------------------------------------
.../apache/hadoop/hive/ql/parse/HiveParser.g | 5 ++-
.../ql/parse/ReplicationSemanticAnalyzer.java | 42 +++++++++++++++++---
.../parse/TestReplicationSemanticAnalyzer.java | 33 +++++++++++++++
3 files changed, 72 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/ad87176c/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
index e431271..733ec79 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
@@ -892,11 +892,12 @@ replConfigsList
;
replStatusStatement
-@init { pushMsg("replication load statement", state); }
+@init { pushMsg("replication status statement", state); }
@after { popMsg(state); }
: KW_REPL KW_STATUS
(dbName=identifier) (DOT tblName=identifier)?
- -> ^(TOK_REPL_STATUS $dbName $tblName?)
+ (KW_WITH replConf=replConfigs)?
+ -> ^(TOK_REPL_STATUS $dbName ^(TOK_TABNAME $tblName)? $replConf?)
;
ddlStatement
http://git-wip-us.apache.org/repos/asf/hive/blob/ad87176c/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
index c38f7dc..796ab0d 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ReplicationSemanticAnalyzer.java
@@ -48,6 +48,7 @@ import org.apache.hadoop.hive.ql.plan.DependencyCollectionWork;
import org.apache.hadoop.hive.ql.plan.PlanUtils;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.apache.hadoop.hive.ql.stats.StatsUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
import java.io.FileNotFoundException;
import java.io.Serializable;
@@ -81,6 +82,9 @@ public class ReplicationSemanticAnalyzer extends BaseSemanticAnalyzer {
// of any other queries running in the session
private HiveConf conf;
+ // This will be set to true only if repl-status is fired with "WITH" keyword
+ private boolean needNewdb;
+
private static String testInjectDumpDir = null; // unit tests can overwrite this to affect default dump behaviour
private static final String dumpSchema = "dump_dir,last_repl_id#string,string";
@@ -555,11 +559,29 @@ public class ReplicationSemanticAnalyzer extends BaseSemanticAnalyzer {
}
// REPL STATUS
- private void initReplStatus(ASTNode ast) {
- int numChildren = ast.getChildCount();
+ private void initReplStatus(ASTNode ast) throws SemanticException{
+ needNewdb = false;
dbNameOrPattern = PlanUtils.stripQuotes(ast.getChild(0).getText());
- if (numChildren > 1) {
- tblNameOrPattern = PlanUtils.stripQuotes(ast.getChild(1).getText());
+ int numChildren = ast.getChildCount();
+ for (int i = 1; i < numChildren; i++) {
+ ASTNode childNode = (ASTNode) ast.getChild(i);
+ switch (childNode.getToken().getType()) {
+ case TOK_TABNAME:
+ tblNameOrPattern = PlanUtils.stripQuotes(childNode.getChild(0).getText());
+ break;
+ case TOK_REPL_CONFIG:
+ Map<String, String> replConfigs
+ = DDLSemanticAnalyzer.getProps((ASTNode) childNode.getChild(0));
+ if (null != replConfigs) {
+ for (Map.Entry<String, String> config : replConfigs.entrySet()) {
+ conf.set(config.getKey(), config.getValue());
+ }
+ }
+ needNewdb = true;
+ break;
+ default:
+ throw new SemanticException("Unrecognized token in REPL STATUS statement");
+ }
}
}
@@ -570,9 +592,16 @@ public class ReplicationSemanticAnalyzer extends BaseSemanticAnalyzer {
String replLastId = null;
try {
+ Hive newDb;
+ if (needNewdb) {
+ newDb = Hive.get(conf, false);
+ } else {
+ newDb = db;
+ }
+
if (tblNameOrPattern != null) {
// Checking for status of table
- Table tbl = db.getTable(dbNameOrPattern, tblNameOrPattern);
+ Table tbl = newDb.getTable(dbNameOrPattern, tblNameOrPattern);
if (tbl != null) {
inputs.add(new ReadEntity(tbl));
Map<String, String> params = tbl.getParameters();
@@ -582,7 +611,8 @@ public class ReplicationSemanticAnalyzer extends BaseSemanticAnalyzer {
}
} else {
// Checking for status of a db
- Database database = db.getDatabase(dbNameOrPattern);
+
+ Database database = newDb.getDatabase(dbNameOrPattern);
if (database != null) {
inputs.add(new ReadEntity(database));
Map<String, String> params = database.getParameters();
http://git-wip-us.apache.org/repos/asf/hive/blob/ad87176c/ql/src/test/org/apache/hadoop/hive/ql/parse/TestReplicationSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestReplicationSemanticAnalyzer.java b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestReplicationSemanticAnalyzer.java
index 96e3fca..a034723 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestReplicationSemanticAnalyzer.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestReplicationSemanticAnalyzer.java
@@ -264,4 +264,37 @@ public class TestReplicationSemanticAnalyzer {
assertEquals(0, child.getChildCount());
}
}
+
+ public static class ReplStatus {
+
+ @Test
+ public void parseTargetDbName() throws ParseException {
+ ASTNode root = parse("repl status targetTestDbName");
+ assertTargetDatabaseName(root);
+ }
+
+ @Test
+ public void parseWithClause() throws ParseException {
+ ASTNode root = parse("repl status targetTestDbName with"
+ + "('hive.metastore.uris'='thrift://localhost:12341')");
+ assertTargetDatabaseName(root);
+
+ ASTNode child = (ASTNode) root.getChild(1);
+ assertEquals("TOK_REPL_CONFIG", child.getText());
+ assertEquals(1, child.getChildCount());
+ child = (ASTNode) child.getChild(0);
+ assertEquals("TOK_REPL_CONFIG_LIST", child.getText());
+ ASTNode configNode = (ASTNode) child.getChild(0);
+ assertEquals("TOK_TABLEPROPERTY", configNode.getText());
+ assertEquals(2, configNode.getChildCount());
+ assertEquals("'hive.metastore.uris'", configNode.getChild(0).getText());
+ assertEquals("'thrift://localhost:12341'", configNode.getChild(1).getText());
+ }
+
+ private void assertTargetDatabaseName(ASTNode root) {
+ ASTNode child = (ASTNode) root.getChild(0);
+ assertEquals("targetTestDbName", child.getText());
+ assertEquals(0, child.getChildCount());
+ }
+ }
}
\ No newline at end of file