Examples of Hive


Examples of org.apache.hadoop.hive.ql.metadata.Hive

  }

  public int execute() {

    // Create the db
    Hive db;
    try {
      db = Hive.get(conf);

      createTableDesc crtTbl = work.getCreateTblDesc();
      if (crtTbl != null) {
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

    throws HiveException, AuthorizationException {
    HashSet<ReadEntity> inputs = sem.getInputs();
    HashSet<WriteEntity> outputs = sem.getOutputs();
    SessionState ss = SessionState.get();
    HiveOperation op = ss.getHiveOperation();
    Hive db = sem.getDb();
    if (op != null) {
      if (op.equals(HiveOperation.CREATETABLE_AS_SELECT)
          || op.equals(HiveOperation.CREATETABLE)) {
        ss.getAuthorizer().authorize(
            db.getDatabase(db.getCurrentDatabase()), null,
            HiveOperation.CREATETABLE_AS_SELECT.getOutputRequiredPrivileges());
      } else {
        if (op.equals(HiveOperation.IMPORT)) {
          ImportSemanticAnalyzer isa = (ImportSemanticAnalyzer) sem;
          if (!isa.existsTable()) {
            ss.getAuthorizer().authorize(
                db.getDatabase(db.getCurrentDatabase()), null,
                HiveOperation.CREATETABLE_AS_SELECT.getOutputRequiredPrivileges());
          }
        }
      }
      if (outputs != null && outputs.size() > 0) {
        for (WriteEntity write : outputs) {

          if (write.getType() == WriteEntity.Type.PARTITION) {
            Partition part = db.getPartition(write.getTable(), write
                .getPartition().getSpec(), false);
            if (part != null) {
              ss.getAuthorizer().authorize(write.getPartition(), null,
                      op.getOutputRequiredPrivileges());
              continue;
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

                               "IMPLICIT",
                               plan.getQueryStr());

      // Lock the database also
      try {
        Hive db = Hive.get(conf);
        lockObjects.add(new HiveLockObj(
                                        new HiveLockObject(db.getCurrentDatabase(), lockData),
                                        HiveLockMode.SHARED));
      } catch (HiveException e) {
        throw new SemanticException(e.getMessage());
      }
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

  private static HiveLockObject getLockObject(HiveConf conf, String path,
    HiveLockMode mode, HiveLockObjectData data,
    String parent, boolean verifyTablePartition)
      throws LockException {
    try {
      Hive db = Hive.get(conf);
      int indx = path.lastIndexOf("LOCK-" + mode.toString());
      String objName = path.substring(("/" + parent + "/").length(), indx-1);
      String[] names = objName.split("/");

      if (names.length < 2) {
        return null;
      }

      if (!verifyTablePartition) {
        return new HiveLockObject(names, data);
      }

      // do not throw exception if table does not exist
      Table tab = db.getTable(names[0], names[1], false);
      if (tab == null) {
        return null;
      }

      if (names.length == 2) {
        return new HiveLockObject(tab, data);
      }

      Map<String, String> partSpec = new HashMap<String, String>();
      for (indx = 2; indx < names.length; indx++) {
        String[] partVals = names[indx].split("=");
        partSpec.put(partVals[0], partVals[1]);
      }

      Partition partn;
      try {
        partn = db.getPartition(tab, partSpec, false);
      } catch (HiveException e) {
        partn = null;
      }

      if (partn == null) {
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

    @Override
    public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context, ASTNode ast)
        throws SemanticException {

        Hive db;
        try {
            db = context.getHive();
        } catch (HiveException e) {
            throw new SemanticException("Couldn't get Hive DB instance in semantic analysis phase.", e);
        }

        // Analyze and create tbl properties object
        int numCh = ast.getChildCount();

        databaseName = BaseSemanticAnalyzer.getUnescapedName((ASTNode) ast.getChild(0));

        for (int num = 1; num < numCh; num++) {
            ASTNode child = (ASTNode) ast.getChild(num);

            switch (child.getToken().getType()) {

            case HiveParser.TOK_IFNOTEXISTS:
                try {
                    List<String> dbs = db.getDatabasesByPattern(databaseName);
                    if (dbs != null && dbs.size() > 0) { // db exists
                        return ast;
                    }
                } catch (HiveException e) {
                    throw new SemanticException(e);
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

    @Override
    public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,
                              ASTNode ast) throws SemanticException {

        Hive db;
        try {
            db = context.getHive();
        } catch (HiveException e) {
            throw new SemanticException(
                "Couldn't get Hive DB instance in semantic analysis phase.",
                e);
        }

        // Analyze and create tbl properties object
        int numCh = ast.getChildCount();

        String inputFormat = null, outputFormat = null;
        tableName = BaseSemanticAnalyzer.getUnescapedName((ASTNode) ast
            .getChild(0));
        boolean likeTable = false;

        for (int num = 1; num < numCh; num++) {
            ASTNode child = (ASTNode) ast.getChild(num);

            switch (child.getToken().getType()) {

            case HiveParser.TOK_QUERY: // CTAS
                throw new SemanticException(
                    "Operation not supported. Create table as " +
                        "Select is not a valid operation.");

            case HiveParser.TOK_TABLEBUCKETS:
                break;

            case HiveParser.TOK_TBLSEQUENCEFILE:
                inputFormat = HCatConstants.SEQUENCEFILE_INPUT;
                outputFormat = HCatConstants.SEQUENCEFILE_OUTPUT;
                break;

            case HiveParser.TOK_TBLTEXTFILE:
                inputFormat = org.apache.hadoop.mapred.TextInputFormat.class.getName();
                outputFormat = org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat.class.getName();

                break;

            case HiveParser.TOK_LIKETABLE:
                likeTable = true;
                break;

            case HiveParser.TOK_IFNOTEXISTS:
                try {
                    List<String> tables = db.getTablesByPattern(tableName);
                    if (tables != null && tables.size() > 0) { // table
                        // exists
                        return ast;
                    }
                } catch (HiveException e) {
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

        if (!HiveConf.getBoolVar(context.getConf(),
            HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED)) {
            return;
        }

        Hive hive;
        try {
            hive = context.getHive();

            for (Task<? extends Serializable> task : rootTasks) {
                if (task.getWork() instanceof DDLWork) {
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

        }

        FsPermission perms = FsPermission.valueOf(permsStr);

        if (!tblName.isEmpty()) {
            Hive db = null;
            try {
                db = Hive.get();
                Table tbl = db.getTable(tblName);
                Path tblPath = tbl.getPath();

                FileSystem fs = tblPath.getFileSystem(conf);
                if (null != perms) {
                    fs.setPermission(tblPath, perms);
                }
                if (null != grp) {
                    fs.setOwner(tblPath, null, grp);
                }
                return 0;

            } catch (Exception e) {
                ss.err.println(String.format("Failed to set permissions/groups on TABLE: <%s> %s", tblName, e.getMessage()));
                try // We need to drop the table.
                    if (null != db) {
                        db.dropTable(tblName);
                    }
                } catch (HiveException he) {
                    ss.err.println(String.format("Failed to drop TABLE <%s> after failing to set permissions/groups on it. %s", tblName, e.getMessage()));
                }
                return 1;
            }
        } else {
            // looks like a db operation
            if (dbName.isEmpty() || dbName.equals(MetaStoreUtils.DEFAULT_DATABASE_NAME)) {
                // We dont set perms or groups for default dir.
                return 0;
            } else {
                try {
                    Hive db = Hive.get();
                    Path dbPath = new Warehouse(conf).getDatabasePath(db.getDatabase(dbName));
                    FileSystem fs = dbPath.getFileSystem(conf);
                    if (perms != null) {
                        fs.setPermission(dbPath, perms);
                    }
                    if (null != grp) {
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

    private List<String> getTableData(String table, String database) throws Exception {
        HiveConf conf = new HiveConf();
        conf.addResource("hive-site.xml");
        ArrayList<String> results = new ArrayList<String>();
        ArrayList<String> temp = new ArrayList<String>();
        Hive hive = Hive.get(conf);
        org.apache.hadoop.hive.ql.metadata.Table tbl = hive.getTable(database, table);
        FetchWork work;
        if (!tbl.getPartCols().isEmpty()) {
            List<Partition> partitions = hive.getPartitions(tbl);
            List<PartitionDesc> partDesc = new ArrayList<PartitionDesc>();
            List<String> partLocs = new ArrayList<String>();
            for (Partition part : partitions) {
                partLocs.add(part.getLocation());
                partDesc.add(Utilities.getPartitionDesc(part));
View Full Code Here

Examples of org.apache.hadoop.hive.ql.metadata.Hive

  @Override
  public int execute(DriverContext driverContext) {

    // Create the db
    Hive db;
    try {
      db = Hive.get(conf);

      CreateDatabaseDesc createDatabaseDesc = work.getCreateDatabaseDesc();
      if (null != createDatabaseDesc) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.