public Var setVariable(String name, Var value) {
    if (value == null || value == Var.Empty) {
      if (exec.stack.empty()) {
        return Var.Empty;
      }
      value = exec.stack.pop();
    }
    if (name.startsWith("hplsql.")) {
      exec.conf.setOption(name, value.toString());
      return Var.Empty;
    }
    Var var = findVariable(name);
    if (var != null) {
      var.cast(value);
    }
    else {
      var = new Var(value);
      var.setName(name);
      if(exec.currentScope != null && !exec.buildSql) {
        exec.currentScope.addVariable(var);
      }
    }    
    return var;
  }
Set a variable using a value from the parameter or the stack
hplsql/src/main/java/org/apache/hive/hplsql/Exec.java