hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r1043768 - in /hive/trunk: ./ common/src/java/org/apache/hadoop/hive/conf/ conf/ docs/stylesheets/ docs/xdocs/language_manual/ ql/src/java/org/apache/hadoop/hive/ql/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop...
Date Wed, 08 Dec 2010 23:27:03 GMT
Author: namit
Date: Wed Dec  8 23:27:02 2010
New Revision: 1043768

URL: http://svn.apache.org/viewvc?rev=1043768&view=rev
Log:
HIVE-1096 Hive variables (Edward Capriolo via namit)


Added:
    hive/trunk/docs/xdocs/language_manual/var_substitution.xml
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/VariableSubstitution.java
    hive/trunk/ql/src/test/queries/clientpositive/set_processor_namespaces.q
    hive/trunk/ql/src/test/results/clientpositive/set_processor_namespaces.q.out
Modified:
    hive/trunk/CHANGES.txt
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/conf/hive-default.xml
    hive/trunk/docs/stylesheets/project.xml
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java

Modified: hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hive/trunk/CHANGES.txt?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/CHANGES.txt (original)
+++ hive/trunk/CHANGES.txt Wed Dec  8 23:27:02 2010
@@ -119,6 +119,8 @@ Trunk -  Unreleased
     HIVE-1836 Extend CREATE DATABASE command with DBPROPERTIES
     (Ning Zhang via namit)
 
+    HIVE-1096 Hive variables (Edward Capriolo via namit)
+
   IMPROVEMENTS
 
     HIVE-1712. Migrating metadata from derby to mysql thrown NullPointerException (Jake Farrell
via pauly)

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Wed Dec  8 23:27:02
2010
@@ -314,6 +314,9 @@ public class HiveConf extends Configurat
     // Serde for FetchTask
     HIVEFETCHOUTPUTSERDE("hive.fetch.output.serde", "org.apache.hadoop.hive.serde2.DelimitedJSONSerDe"),
 
+    // Hive Variables
+    HIVEVARIABLESUBSTITUTE("hive.variable.substitute", true),
+
     SEMANTIC_ANALYZER_HOOK("hive.semantic.analyzer.hook",null),
     
     // Print column names in output
@@ -624,4 +627,5 @@ public class HiveConf extends Configurat
   public static String getColumnInternalName(int pos) {
     return "_col" + pos;
   }
+
 }

Modified: hive/trunk/conf/hive-default.xml
URL: http://svn.apache.org/viewvc/hive/trunk/conf/hive-default.xml?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/conf/hive-default.xml (original)
+++ hive/trunk/conf/hive-default.xml Wed Dec  8 23:27:02 2010
@@ -792,4 +792,10 @@
   <description>Default property values for newly created tables</description>
 </property>
 
+<property>
+  <name>hive.variable.substitute</name>
+  <value>true</value>
+  <description>This enables substitution using syntax like ${var} ${system:var} and
${env:var}.</description>
+</property>
+
 </configuration>

Modified: hive/trunk/docs/stylesheets/project.xml
URL: http://svn.apache.org/viewvc/hive/trunk/docs/stylesheets/project.xml?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/docs/stylesheets/project.xml (original)
+++ hive/trunk/docs/stylesheets/project.xml Wed Dec  8 23:27:02 2010
@@ -29,6 +29,7 @@
       <item name="Data Manipulation Statements" href="/language_manual/data-manipulation-statements.html"
/>
       <item name="Joins" href="/language_manual/joins.html" />
       <item name="Cli" href="/language_manual/cli.html" />
+      <item name="Var Substitution" href="/language_manual/var_substitution.html" />
     </menu>
     <menu name="Developer Guide">
       <item name="Issue Tracking (JIRA)" href="https://issues.apache.org/jira/browse/HIVE"/>

Added: hive/trunk/docs/xdocs/language_manual/var_substitution.xml
URL: http://svn.apache.org/viewvc/hive/trunk/docs/xdocs/language_manual/var_substitution.xml?rev=1043768&view=auto
==============================================================================
--- hive/trunk/docs/xdocs/language_manual/var_substitution.xml (added)
+++ hive/trunk/docs/xdocs/language_manual/var_substitution.xml Wed Dec  8 23:27:02 2010
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<document>
+
+  <properties>
+    <title>Hadoop Hive- Variable Substitution</title>
+    <author email="hive-user@hadoop.apache.org">Hadoop Hive Documentation Team</author>
+  </properties>
+
+  <body>
+<h3>Hive Variable Substitution</h3>
+<section name="Introduction" href="Introduction">
+
+<p>Hive is used for both interactive queries as well as part. The hive variable substitution
mechanism was 
+designed to avoid some of the code that was getting baked into the scripting language ontop
of hive. For example:</p>
+
+<source><![CDATA[$ a=b
+$ hive -e " describe $a "
+]]></source>
+
+<p>
+are becoming common place. This is frustrating as hive becomes closely coupled with scripting
languages. The hive
+startup time of a couple seconds is non-trivial when doing thousands of manipulations multiple
hive -e invocations.</p>
+
+<p>
+Hive Variables combine the set capability you know and love with some limited yet powerful
(evil laugh) substitution 
+ability. For example:</p>
+
+<source><![CDATA[$ bin/hive -hiveconf a=b -e 'set a; set hiveconf:a; \
+create table if not exists b (col int); describe ${hiveconf:a}'
+]]></source>
+
+<p>Results in:</p>
+<source><![CDATA[Hive history file=/tmp/edward/hive_job_log_edward_201011240906_1463048967.txt
+a=b
+hiveconf:a=b
+OK
+Time taken: 5.913 seconds
+OK
+col	int	
+Time taken: 0.754 seconds
+]]></source>
+
+</section>
+
+<section name="Using variables" href="using_variables">
+
+<p>There are three namespaces for variables hiveconf,system, and env. hiveconf variables
are set as normal:</p>
+
+<source><![CDATA[set x=myvalue
+]]></source>
+
+<p>However they are retrieved using</p>
+
+<source><![CDATA[${hiveconf:x}
+]]></source>
+ 
+<p>Annotated examples of usage from the test case ql/src/test/queries/clientpositive/set_processor_namespaces.q</p>
+
+<source><![CDATA[set zzz=5;
+--  sets zzz=5
+set zzz;
+
+set system:xxx=5;
+set system:xxx;
+-- sets a system property xxx to 5
+
+set system:yyy=${system:xxx};
+set system:yyy;
+-- sets yyy with value of xxx
+
+set go=${hiveconf:zzz};
+set go;
+-- sets go base on value on zzz
+
+set hive.variable.substitute=false;
+set raw=${hiveconf:zzz};
+set raw;
+-- disable substitution set a value to the literal
+
+set hive.variable.substitute=true;
+
+EXPLAIN SELECT * FROM src where key=${hiveconf:zzz};
+SELECT * FROM src where key=${hiveconf:zzz};
+--use a variable in a query
+
+set a=1;
+set b=a;
+set c=${hiveconf:${hiveconf:b}};
+set c;
+--uses nested variables. 
+
+
+set jar=../lib/derby.jar;
+
+add file ${hiveconf:jar};
+list file;
+delete file ${hiveconf:jar};
+list file;
+]]></source>
+</section>
+
+<section name="Disabling" href="disable">
+  <p>Variable substitution is on by default. If this causes an issue with an already
existing script disable it.</p>
+
+<source><![CDATA[set hive.variable.substitute=false;
+]]></source>
+
+</section>
+
+</body>
+</document>

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java Wed Dec  8 23:27:02 2010
@@ -85,6 +85,7 @@ import org.apache.hadoop.hive.ql.parse.P
 import org.apache.hadoop.hive.ql.parse.ParseUtils;
 import org.apache.hadoop.hive.ql.parse.SemanticAnalyzerFactory;
 import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
 import org.apache.hadoop.hive.ql.plan.TableDesc;
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
@@ -312,6 +313,7 @@ public class Driver implements CommandPr
     TaskFactory.resetId();
 
     try {
+      command = new VariableSubstitution().substitute(conf,command);
       ctx = new Context(conf);
 
       ParseDriver pd = new ParseDriver();

Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/VariableSubstitution.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/VariableSubstitution.java?rev=1043768&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/VariableSubstitution.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/VariableSubstitution.java Wed Dec
 8 23:27:02 2010
@@ -0,0 +1,65 @@
+package org.apache.hadoop.hive.ql.parse;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hadoop.hive.ql.processors.SetProcessor;
+
+public class VariableSubstitution {
+
+  private static final Log l4j = LogFactory.getLog(VariableSubstitution.class);
+  protected static Pattern varPat = Pattern.compile("\\$\\{[^\\}\\$\u0020]+\\}");
+  protected static int MAX_SUBST = 40;
+
+  public String substitute (HiveConf conf, String expr) {
+
+    if (conf.getBoolVar(ConfVars.HIVEVARIABLESUBSTITUTE)){
+      l4j.debug("Substitution is on: "+expr);
+    } else {
+      return expr;
+    }
+    if (expr == null) {
+      return null;
+    }
+    Matcher match = varPat.matcher("");
+    String eval = expr;
+    for(int s=0; s<MAX_SUBST; s++) {
+      match.reset(eval);
+      if (!match.find()) {
+        return eval;
+      }
+      String var = match.group();
+      var = var.substring(2, var.length()-1); // remove ${ .. }
+      String val = null;
+      try {
+        if (var.startsWith(SetProcessor.SYSTEM_PREFIX)) {
+          val = System.getProperty(var.substring(SetProcessor.SYSTEM_PREFIX.length()));
+        }
+      } catch(SecurityException se) {
+        l4j.warn("Unexpected SecurityException in Configuration", se);
+      }
+      if (val ==null){
+        if (var.startsWith(SetProcessor.ENV_PREFIX)){
+          val = System.getenv(var.substring(SetProcessor.ENV_PREFIX.length()));
+        }
+      }
+      if (val == null) {
+        if (var.startsWith(SetProcessor.HIVECONF_PREFIX)){
+          val = conf.get(var.substring(SetProcessor.HIVECONF_PREFIX.length()));
+        }
+      }
+      if (val == null) {
+        l4j.debug("Interpolation result: "+eval);
+        return eval; // return literal ${var}: var is unbound
+      }
+      // substitute
+      eval = eval.substring(0, match.start())+val+eval.substring(match.end());
+    }
+    throw new IllegalStateException("Variable substitution depth too large: "
+                                    + MAX_SUBST + " " + expr);
+  }
+}

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
Wed Dec  8 23:27:02 2010
@@ -21,6 +21,7 @@ package org.apache.hadoop.hive.ql.proces
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 
@@ -39,6 +40,7 @@ public class AddResourceProcessor implem
 
   public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
+    command = new VariableSubstitution().substitute(ss.getConf(),command);
     String[] tokens = command.split("\\s+");
     SessionState.ResourceType t;
     if (tokens.length < 2

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
Wed Dec  8 23:27:02 2010
@@ -21,6 +21,7 @@ package org.apache.hadoop.hive.ql.proces
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 
@@ -38,6 +39,7 @@ public class DeleteResourceProcessor imp
 
   public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
+    command = new VariableSubstitution().substitute(ss.getConf(),command);
     String[] tokens = command.split("\\s+");
 
     SessionState.ResourceType t;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java?rev=1043768&r1=1043767&r2=1043768&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java Wed Dec
 8 23:27:02 2010
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FsShell;
+import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 
@@ -46,10 +47,13 @@ public class DfsProcessor implements Com
   }
 
   public CommandProcessorResponse run(String command) {
-    String[] tokens = command.split("\\s+");
+
 
     try {
       SessionState ss = SessionState.get();
+      command = new VariableSubstitution().substitute(ss.getConf(),command);
+
+      String[] tokens = command.split("\\s+");
       PrintStream oldOut = System.out;
 
       if (ss != null && ss.out != null) {

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=1043768&r1=1043767&r2=1043768&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 Dec
 8 23:27:02 2010
@@ -18,11 +18,12 @@
 
 package org.apache.hadoop.hive.ql.processors;
 
-import java.util.Properties;
 import java.util.Map;
+import java.util.Properties;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import org.apache.hadoop.hive.ql.parse.VariableSubstitution;
 import org.apache.hadoop.hive.ql.session.SessionState;
 
 /**
@@ -32,6 +33,9 @@ import org.apache.hadoop.hive.ql.session
 public class SetProcessor implements CommandProcessor {
 
   private static String prefix = "set: ";
+  public static final String ENV_PREFIX = "env:";
+  public static final String SYSTEM_PREFIX = "system:";
+  public static final String HIVECONF_PREFIX = "hiveconf:";
 
   public static boolean getBoolean(String value) {
     if (value.equals("on") || value.equals("true")) {
@@ -57,6 +61,16 @@ public class SetProcessor implements Com
     for (Map.Entry<String, String> entries : sortedMap.entrySet()) {
       ss.out.println(entries.getKey() + "=" + entries.getValue());
     }
+
+    for (Map.Entry<String, String> entry : mapToSortedMap(System.getenv()).entrySet())
{
+      ss.out.println(ENV_PREFIX+entry.getKey() + "=" + entry.getValue());
+    }
+
+    for (Map.Entry<String, String> entry :
+      propertiesToSortedMap(System.getProperties()).entrySet() ) {
+      ss.out.println(SYSTEM_PREFIX+entry.getKey() + "=" + entry.getValue());
+    }
+
   }
 
   private void dumpOption(Properties p, String s) {
@@ -72,6 +86,80 @@ public class SetProcessor implements Com
   public void init() {
   }
 
+  private CommandProcessorResponse setVariable(String varname, String varvalue){
+    SessionState ss = SessionState.get();
+    if (varname.startsWith(SetProcessor.ENV_PREFIX)){
+      ss.err.println("env:* variables can not be set.");
+      return new CommandProcessorResponse(1);
+    } else if (varname.startsWith(SetProcessor.SYSTEM_PREFIX)){
+      String propName = varname.substring(SetProcessor.SYSTEM_PREFIX.length());
+      System.getProperties().setProperty(propName, new VariableSubstitution().substitute(ss.getConf(),varvalue));
+      return new CommandProcessorResponse(0);
+    } else if (varname.startsWith(SetProcessor.HIVECONF_PREFIX)){
+      String propName = varname.substring(SetProcessor.HIVECONF_PREFIX.length());
+      ss.getConf().set(propName, new VariableSubstitution().substitute(ss.getConf(),varvalue));
+      return new CommandProcessorResponse(0);
+    } else {
+      ss.getConf().set(varname, new VariableSubstitution().substitute(ss.getConf(),varvalue)
);
+      return new CommandProcessorResponse(0);
+    }
+  }
+
+  private SortedMap<String,String> propertiesToSortedMap(Properties p){
+    SortedMap<String,String> sortedPropMap = new TreeMap<String,String>();
+    for (Map.Entry<Object, Object> entry :System.getProperties().entrySet() ){
+      sortedPropMap.put( (String) entry.getKey(), (String) entry.getValue());
+    }
+    return sortedPropMap;
+  }
+
+  private SortedMap<String,String> mapToSortedMap(Map<String,String> data){
+    SortedMap<String,String> sortedEnvMap = new TreeMap<String,String>();
+    sortedEnvMap.putAll( data );
+    return sortedEnvMap;
+  }
+
+
+  private CommandProcessorResponse getVariable(String varname){
+    SessionState ss = SessionState.get();
+    if (varname.equals("silent")){
+      ss.out.println("silent" + "=" + ss.getIsSilent());
+      return new CommandProcessorResponse(0);
+    }
+    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);
+      } else {
+        ss.out.println( propName + " is undefined as a system property");
+        return new CommandProcessorResponse(1);
+      }
+    } else if (varname.indexOf(SetProcessor.ENV_PREFIX)==0){
+      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);
+      } else {
+        ss.out.println(varname + " is undefined as an environmental variable");
+        return new CommandProcessorResponse(1);
+      }
+    } else if (varname.indexOf(SetProcessor.HIVECONF_PREFIX)==0) {
+      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);
+      } else {
+        ss.out.println(varname + " is undefined as a hive configuration variable");
+        return new CommandProcessorResponse(1);
+      }
+    } else {
+      dumpOption(ss.getConf().getAllProperties(), varname);
+      return new CommandProcessorResponse(0);
+    }
+  }
+
   public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
 
@@ -87,31 +175,24 @@ public class SetProcessor implements Com
     }
 
     String[] part = new String[2];
-
     int eqIndex = nwcmd.indexOf('=');
-    if (eqIndex == -1) {
-      // no equality sign - print the property out
-      dumpOption(ss.getConf().getAllProperties(), nwcmd);
-      return new CommandProcessorResponse(0);
-    } else if (eqIndex == nwcmd.length() - 1) {
-      part[0] = nwcmd.substring(0, nwcmd.length() - 1);
-      part[1] = "";
-    } else {
-      part[0] = nwcmd.substring(0, eqIndex).trim();
-      part[1] = nwcmd.substring(eqIndex + 1).trim();
-    }
 
-    try {
+    if (nwcmd.contains("=")){
+      if (eqIndex == nwcmd.length() - 1) { //x=
+        part[0] = nwcmd.substring(0, nwcmd.length() - 1);
+        part[1] = "";
+      } else { //x=y
+        part[0] = nwcmd.substring(0, eqIndex).trim();
+        part[1] = nwcmd.substring(eqIndex + 1).trim();
+      }
       if (part[0].equals("silent")) {
-        boolean val = getBoolean(part[1]);
-        ss.setIsSilent(val);
-      } else {
-        ss.getConf().set(part[0], part[1]);
+        ss.setIsSilent(getBoolean(part[1]));
+        return new CommandProcessorResponse(0);
       }
-    } catch (IllegalArgumentException err) {
-      ss.err.println(err.getMessage());
-      return new CommandProcessorResponse(1);
+      return setVariable(part[0],part[1]);
+    } else {
+      return getVariable(nwcmd);
     }
-    return new CommandProcessorResponse(0);
+
   }
 }

Added: hive/trunk/ql/src/test/queries/clientpositive/set_processor_namespaces.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/set_processor_namespaces.q?rev=1043768&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/set_processor_namespaces.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/set_processor_namespaces.q Wed Dec  8 23:27:02
2010
@@ -0,0 +1,32 @@
+set zzz=5;
+set zzz;
+
+set system:xxx=5;
+set system:xxx;
+
+set system:yyy=${system:xxx};
+set system:yyy;
+
+set go=${hiveconf:zzz};
+set go;
+
+set hive.variable.substitute=false;
+set raw=${hiveconf:zzz};
+set raw;
+
+set hive.variable.substitute=true;
+
+EXPLAIN SELECT * FROM src where key=${hiveconf:zzz};
+SELECT * FROM src where key=${hiveconf:zzz};
+
+set a=1;
+set b=a;
+set c=${hiveconf:${hiveconf:b}};
+set c;
+
+set jar=../lib/derby.jar;
+
+add file ${hiveconf:jar};
+list file;
+delete file ${hiveconf:jar};
+list file;

Added: hive/trunk/ql/src/test/results/clientpositive/set_processor_namespaces.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/set_processor_namespaces.q.out?rev=1043768&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/set_processor_namespaces.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/set_processor_namespaces.q.out Wed Dec 
8 23:27:02 2010
@@ -0,0 +1,63 @@
+zzz=5
+system:xxx=5
+system:yyy=5
+go=5
+raw=${hiveconf:zzz}
+PREHOOK: query: EXPLAIN SELECT * FROM src where key=5
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN SELECT * FROM src where key=5
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_TABREF src)) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE))
(TOK_SELECT (TOK_SELEXPR TOK_ALLCOLREF)) (TOK_WHERE (= (TOK_TABLE_OR_COL key) 5))))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        src 
+          TableScan
+            alias: src
+            Filter Operator
+              predicate:
+                  expr: (key = 5)
+                  type: boolean
+              Filter Operator
+                predicate:
+                    expr: (key = 5)
+                    type: boolean
+                Select Operator
+                  expressions:
+                        expr: key
+                        type: string
+                        expr: value
+                        type: string
+                  outputColumnNames: _col0, _col1
+                  File Output Operator
+                    compressed: false
+                    GlobalTableId: 0
+                    table:
+                        input format: org.apache.hadoop.mapred.TextInputFormat
+                        output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+
+
+PREHOOK: query: SELECT * FROM src where key=5
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/tmp/njain/hive_2010-12-08_15-23-53_839_6196969145923400160/-mr-10000
+POSTHOOK: query: SELECT * FROM src where key=5
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/tmp/njain/hive_2010-12-08_15-23-53_839_6196969145923400160/-mr-10000
+5	val_5
+5	val_5
+5	val_5
+c=1
+../lib/derby.jar



Mime
View raw message