Author: xuefu
Date: Wed Jan 15 17:26:39 2014
New Revision: 1558476

URL: http://svn.apache.org/r1558476
Log:
HIVE-6174: Beeline 'set varible' doesn't show the value of the variable as Hive 
CLI

Modified:
    
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
    
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java
    
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java

Modified: 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java?rev=1558476&r1=1558475&r2=1558476&view=diff
==============================================================================
--- 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
 (original)
+++ 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java
 Wed Jan 15 17:26:39 2014
@@ -18,6 +18,10 @@
 
 package org.apache.hive.beeline;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -32,15 +36,12 @@ import java.util.List;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hive.beeline.BeeLine;
 import org.apache.hive.service.server.HiveServer2;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 /**
  * TestBeeLineWithArgs - executes tests of the command-line arguments to 
BeeLine
  *
@@ -282,6 +283,14 @@ public class TestBeeLineWithArgs {
     testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, 
getBaseArgs(JDBC_URL));
   }
 
+  @Test
+  public void testGetVariableValue() throws Throwable {
+    final String TEST_NAME = "testGetVariableValue";
+    final String SCRIPT_TEXT = "set env:TERM;";
+    final String EXPECTED_PATTERN = "env:TERM";
+    testScriptFile(TEST_NAME, SCRIPT_TEXT, EXPECTED_PATTERN, true, 
getBaseArgs(JDBC_URL));
+  }
+
   /**
    * Select null from table , check if setting null to empty string works.
    * Original beeline/sqlline used to print nulls as empty strings

Modified: 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java?rev=1558476&r1=1558475&r2=1558476&view=diff
==============================================================================
--- 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java
 (original)
+++ 
hive/trunk/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java
 Wed Jan 15 17:26:39 2014
@@ -30,6 +30,7 @@ import org.apache.hive.service.cli.Opera
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.SessionHandle;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -66,4 +67,14 @@ public class TestHiveServer2 {
     RowSet rowSet = serviceClient.fetchResults(opHandle);
     assertFalse(rowSet.numRows() == 0);
   }
+
+  @Test
+  public void testGetVariableValue() throws Exception {
+    CLIServiceClient serviceClient = miniHS2.getServiceClient();
+    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
+    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "set 
system:os.name", confOverlay);
+    RowSet rowSet = serviceClient.fetchResults(opHandle);
+    Assert.assertEquals(1, rowSet.numRows());
+  }
+
 }

Modified: 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java?rev=1558476&r1=1558475&r2=1558476&view=diff
==============================================================================
--- 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java 
(original)
+++ 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java 
Wed Jan 15 17:26:39 2014
@@ -99,6 +99,7 @@ public class SetProcessor implements Com
     }
   }
 
+  @Override
   public void init() {
   }
 
@@ -181,18 +182,18 @@ public class SetProcessor implements Com
   }
 
 
-  private CommandProcessorResponse getVariable(String varname){
+  private CommandProcessorResponse getVariable(String varname) {
     SessionState ss = SessionState.get();
     if (varname.equals("silent")){
       ss.out.println("silent" + "=" + ss.getIsSilent());
-      return new CommandProcessorResponse(0);
+      return createProcessorSuccessResponse();
     }
     if (varname.startsWith(SetProcessor.SYSTEM_PREFIX)){
       String propName = varname.substring(SetProcessor.SYSTEM_PREFIX.length());
       String result = System.getProperty(propName);
       if (result != null){
         ss.out.println(SetProcessor.SYSTEM_PREFIX+propName + "=" + result);
-        return new CommandProcessorResponse(0);
+        return createProcessorSuccessResponse();
       } else {
         ss.out.println( propName + " is undefined as a system property");
         return new CommandProcessorResponse(1);
@@ -201,7 +202,7 @@ public class SetProcessor implements Com
       String var = varname.substring(ENV_PREFIX.length());
       if (System.getenv(var)!=null){
         ss.out.println(SetProcessor.ENV_PREFIX+var + "=" + System.getenv(var));
-        return new CommandProcessorResponse(0);
+        return createProcessorSuccessResponse();
       } else {
         ss.out.println(varname + " is undefined as an environmental variable");
         return new CommandProcessorResponse(1);
@@ -210,7 +211,7 @@ public class SetProcessor implements Com
       String var = varname.substring(SetProcessor.HIVECONF_PREFIX.length());
       if (ss.getConf().get(var)!=null){
         ss.out.println(SetProcessor.HIVECONF_PREFIX+var + "=" + 
ss.getConf().get(var));
-        return new CommandProcessorResponse(0);
+        return createProcessorSuccessResponse();
       } else {
         ss.out.println(varname + " is undefined as a hive configuration 
variable");
         return new CommandProcessorResponse(1);
@@ -219,30 +220,34 @@ public class SetProcessor implements Com
       String var = varname.substring(SetProcessor.HIVEVAR_PREFIX.length());
       if (ss.getHiveVariables().get(var)!=null){
         ss.out.println(SetProcessor.HIVEVAR_PREFIX+var + "=" + 
ss.getHiveVariables().get(var));
-        return new CommandProcessorResponse(0);
+        return createProcessorSuccessResponse();
       } else {
         ss.out.println(varname + " is undefined as a hive variable");
         return new CommandProcessorResponse(1);
       }
     } else {
       dumpOption(varname);
-      return new CommandProcessorResponse(0, null, null, getSchema());
+      return createProcessorSuccessResponse();
     }
   }
 
+  private CommandProcessorResponse createProcessorSuccessResponse() {
+    return new CommandProcessorResponse(0, null, null, getSchema());
+  }
+
+  @Override
   public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
-    Schema sch = getSchema();
 
     String nwcmd = command.trim();
     if (nwcmd.equals("")) {
       dumpOptions(ss.getConf().getChangedProperties());
-      return new CommandProcessorResponse(0, null, null, sch);
+      return createProcessorSuccessResponse();
     }
 
     if (nwcmd.equals("-v")) {
       dumpOptions(ss.getConf().getAllProperties());
-      return new CommandProcessorResponse(0, null, null, sch);
+      return createProcessorSuccessResponse();
     }
 
     String[] part = new String[2];


Reply via email to