Package org.apache.hadoop.hive.ql.parse

Examples of org.apache.hadoop.hive.ql.parse.ASTNode


    Assert.assertNull("Query without part location should not return location",
        partitionLocation);
  }
  @Test
  public void testAddPartitionWithLocation() throws Exception {
    ASTNode ast = parse("alter table parted add partition (day='Monday') location 'file:/'");
    LOG.info("AST: " + ast.toStringTree());
    AccessURI partitionLocation = HiveAuthzBindingHook.extractPartition(ast);
    Assert.assertNotNull("Query with part location must return location",
        partitionLocation);
    Assert.assertEquals("file:///", partitionLocation.getName());
  }
View Full Code Here


    Assert.assertEquals("file:///", partitionLocation.getName());
  }

  @Test
  public void testAddPartitionIfNotExists() throws Exception {
    ASTNode ast = parse("alter table parted add if not exists partition (day='Monday')");
    LOG.info("AST: " + ast.toStringTree());
    AccessURI partitionLocation = HiveAuthzBindingHook.extractPartition(ast);
    Assert.assertNull("Query without part location should not return location",
        partitionLocation);
  }
View Full Code Here

    Assert.assertNull("Query without part location should not return location",
        partitionLocation);
  }
  @Test
  public void testAddPartitionIfNotExistsWithLocation() throws Exception {
    ASTNode ast = parse("alter table parted add if not exists partition (day='Monday')" +
        " location 'file:/'");
    LOG.info("AST: " + ast.toStringTree());
    AccessURI partitionLocation = HiveAuthzBindingHook.extractPartition(ast);
    Assert.assertNotNull("Query with part location must return location",
        partitionLocation);
    Assert.assertEquals("file:///", partitionLocation.getName());
  }
View Full Code Here

  }

  @VisibleForTesting
  protected static AccessURI extractPartition(ASTNode ast) throws SemanticException {
    for (int i = 0; i < ast.getChildCount(); i++) {
      ASTNode child = (ASTNode)ast.getChild(i);
      if (child.getToken().getType() == HiveParser.TOK_PARTITIONLOCATION &&
          child.getChildCount() == 1) {
        return parseURI(BaseSemanticAnalyzer.
          unescapeSQLString(child.getChild(0).getText()));
      }
    }
    return null;
  }
View Full Code Here

    return createTask(new DDLWork(inputs, outputs, roleDesc));
  }
  @Override
  public Task<? extends Serializable> createShowRoleGrantTask(ASTNode ast, Path resultFile,
      HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException {
    ASTNode child = (ASTNode) ast.getChild(0);
    PrincipalType principalType = PrincipalType.USER;
    switch (child.getType()) {
    case HiveParser.TOK_USER:
      principalType = PrincipalType.USER;
      break;
    case HiveParser.TOK_GROUP:
      principalType = PrincipalType.GROUP;
      break;
    case HiveParser.TOK_ROLE:
      principalType = PrincipalType.ROLE;
      break;
    }
    if (principalType != PrincipalType.GROUP) {
      String msg = SentryHiveConstants.GRANT_REVOKE_NOT_SUPPORTED_FOR_PRINCIPAL + principalType;
      throw new SemanticException(msg);
    }
    String principalName = BaseSemanticAnalyzer.unescapeIdentifier(child.getChild(0).getText());
    RoleDDLDesc roleDesc = new RoleDDLDesc(principalName, principalType,
        RoleDDLDesc.RoleOperation.SHOW_ROLE_GRANT, null);
    roleDesc.setResFile(resultFile.toString());
    return createTask(new DDLWork(inputs, outputs,  roleDesc));
  }
View Full Code Here

        (ASTNode) ast.getChild(1));
    SentryHivePrivilegeObjectDesc privilegeObj = null;

    if (ast.getChildCount() > 2) {
      for (int i = 2; i < ast.getChildCount(); i++) {
        ASTNode astChild = (ASTNode) ast.getChild(i);
        if (astChild.getType() == HiveParser.TOK_GRANT_WITH_OPTION) {
          throw new SemanticException(SentryHiveConstants.GRANT_OPTION_NOT_SUPPORTED);
        } else if (astChild.getType() == HiveParser.TOK_PRIV_OBJECT) {
          privilegeObj = analyzePrivilegeObject(astChild);
        }
      }
    }
    String userName = null;
View Full Code Here

      HashSet<WriteEntity> outputs) throws SemanticException {
    List<PrivilegeDesc> privilegeDesc = analyzePrivilegeListDef((ASTNode) ast.getChild(0));
    List<PrincipalDesc> principalDesc = analyzePrincipalListDef((ASTNode) ast.getChild(1));
    PrivilegeObjectDesc privilegeObj = null;
    if (ast.getChildCount() > 2) {
      ASTNode astChild = (ASTNode) ast.getChild(2);
      privilegeObj = analyzePrivilegeObject(astChild);
    }
    if (privilegeObj.getPartSpec() != null) {
      throw new SemanticException(SentryHiveConstants.PARTITION_PRIVS_NOT_SUPPORTED);
    }
View Full Code Here

  @Override
  public Task<? extends Serializable> createShowGrantTask(ASTNode ast, Path resultFile, HashSet<ReadEntity> inputs,
      HashSet<WriteEntity> outputs) throws SemanticException {
    PrivilegeObjectDesc privHiveObj = null;

    ASTNode principal = (ASTNode) ast.getChild(0);
    PrincipalType type = PrincipalType.USER;
    switch (principal.getType()) {
    case HiveParser.TOK_USER:
      type = PrincipalType.USER;
      break;
    case HiveParser.TOK_GROUP:
      type = PrincipalType.GROUP;
      break;
    case HiveParser.TOK_ROLE:
      type = PrincipalType.ROLE;
      break;
    }
    if (type != PrincipalType.ROLE) {
      String msg = SentryHiveConstants.GRANT_REVOKE_NOT_SUPPORTED_FOR_PRINCIPAL + type;
      throw new SemanticException(msg);
    }
    String principalName = BaseSemanticAnalyzer.unescapeIdentifier(principal.getChild(0).getText());
    PrincipalDesc principalDesc = new PrincipalDesc(principalName, type);

    //Column privileges and Partition privileges are not supported by Sentry
    if (ast.getChildCount() > 1) {
      ASTNode child = (ASTNode) ast.getChild(1);
      if (child.getToken().getType() == HiveParser.TOK_PRIV_OBJECT_COL) {
        privHiveObj = analyzePrivilegeObject(child);
      }else {
        throw new SemanticException("Unrecognized Token: " + child.getToken().getType());
      }
    }

    ShowGrantDesc showGrant = new ShowGrantDesc(resultFile.toString(),
        principalDesc, privHiveObj, null);
View Full Code Here

    SentryHivePrivilegeObjectDesc subject = new SentryHivePrivilegeObjectDesc();
    String privilegeObject = BaseSemanticAnalyzer.unescapeIdentifier(ast
        .getChild(0).getText());
    if (ast.getChildCount() > 1) {
      for (int i = 1; i < ast.getChildCount(); i++) {
        ASTNode astChild = (ASTNode) ast.getChild(i);
        if (astChild.getToken().getType() == HiveParser.TOK_PARTSPEC) {
          throw new SemanticException(SentryHiveConstants.PARTITION_PRIVS_NOT_SUPPORTED);
        } else if (astChild.getToken().getType() == HiveParser.TOK_TABCOLNAME) {
          throw new SemanticException(SentryHiveConstants.COLUMN_PRIVS_NOT_SUPPORTED);
        }else if (astChild.getToken().getType() == HiveParser.TOK_URI) {
          privilegeObject = privilegeObject.replaceAll("'", "").replaceAll("\"", "");
          subject.setUri(true);
        } else if (astChild.getToken().getType() == HiveParser.TOK_SERVER) {
          subject.setServer(true);
        } else {
          subject.setTable(true);
        }
      }
View Full Code Here

  }

  private List<PrincipalDesc> analyzePrincipalListDef(ASTNode node) {
    List<PrincipalDesc> principalList = new ArrayList<PrincipalDesc>();
    for (int i = 0; i < node.getChildCount(); i++) {
      ASTNode child = (ASTNode) node.getChild(i);
      PrincipalType type = null;
      switch (child.getType()) {
      case HiveParser.TOK_USER:
        type = PrincipalType.USER;
        break;
      case HiveParser.TOK_GROUP:
        type = PrincipalType.GROUP;
        break;
      case HiveParser.TOK_ROLE:
        type = PrincipalType.ROLE;
        break;
      }
      String principalName = BaseSemanticAnalyzer.unescapeIdentifier(child.getChild(0).getText());
      PrincipalDesc principalDesc = new PrincipalDesc(principalName, type);
      principalList.add(principalDesc);
    }
    return principalList;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.parse.ASTNode

Copyright © 2018 www.massapicom. 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.