private ASTNode getChildFromSubqueryAST(String errorMsg, int type) throws SemanticException { ASTNode childAST = (ASTNode) subQueryAST.getFirstChildWithType(type); if (childAST == null && errorMsg != null) { subQueryAST.setOrigin(originalSQASTOrigin); throw new SemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg( subQueryAST, errorMsg + " clause is missing in SubQuery.")); } return childAST; }
private ASTNode getChildFromSubqueryAST(String errorMsg, int type) throws SemanticException { ASTNode childAST = (ASTNode) subQueryAST.getFirstChildWithType(type); if (childAST == null && errorMsg != null) { subQueryAST.setOrigin(originalSQASTOrigin); throw new SemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg( subQueryAST, errorMsg + " clause is missing in SubQuery.")); } return childAST; }
private void analyzeDropTable(ASTNode ast, TableType expectedType) throws SemanticException { String tableName = getUnescapedName((ASTNode) ast.getChild(0)); boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null); // we want to signal an error if the table/view doesn't exist and we're // configured not to fail silently boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); ReplicationSpec replicationSpec = new ReplicationSpec(ast); Table tab = getTable(tableName, throwException); if (tab != null) { inputs.add(new ReadEntity(tab)); outputs.add(new WriteEntity(tab, WriteEntity.WriteType.DDL_EXCLUSIVE)); } boolean ifPurge = (ast.getFirstChildWithType(HiveParser.KW_PURGE) != null); DropTableDesc dropTblDesc = new DropTableDesc(tableName, expectedType, ifExists, ifPurge, replicationSpec); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), dropTblDesc))); }
private void analyzeDropTable(ASTNode ast, TableType expectedType) throws SemanticException { String tableName = getUnescapedName((ASTNode) ast.getChild(0)); boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null); // we want to signal an error if the table/view doesn't exist and we're // configured not to fail silently boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); ReplicationSpec replicationSpec = new ReplicationSpec(ast); Table tab = getTable(tableName, throwException); if (tab != null) { inputs.add(new ReadEntity(tab)); outputs.add(new WriteEntity(tab, WriteEntity.WriteType.DDL_EXCLUSIVE)); } boolean ifPurge = (ast.getFirstChildWithType(HiveParser.KW_PURGE) != null); DropTableDesc dropTblDesc = new DropTableDesc(tableName, expectedType, ifExists, ifPurge, replicationSpec); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), dropTblDesc), conf)); }
private void analyzeCreateFunction(ASTNode ast) throws SemanticException { // ^(TOK_CREATEFUNCTION identifier StringLiteral ({isTempFunction}? => TOK_TEMPORARY)) String functionName = ast.getChild(0).getText().toLowerCase(); boolean isTemporaryFunction = (ast.getFirstChildWithType(HiveParser.TOK_TEMPORARY) != null); String className = unescapeSQLString(ast.getChild(1).getText()); // Temp functions are not allowed to have qualified names. if (isTemporaryFunction && FunctionUtils.isQualifiedFunctionName(functionName)) { throw new SemanticException("Temporary function cannot be created with a qualified name."); } // find any referenced resources List<ResourceUri> resources = getResourceList(ast); if (!isTemporaryFunction && resources == null) { SESISON_STATE_LOG.warn("permanent functions created without USING clause will not be replicated."); } CreateFunctionDesc desc = new CreateFunctionDesc(functionName, isTemporaryFunction, className, resources, null); rootTasks.add(TaskFactory.get(new FunctionWork(desc))); addEntities(functionName, className, isTemporaryFunction, resources); }
private void analyzeAlterTableModifyCols(String[] qualified, ASTNode ast, HashMap<String, String> partSpec, AlterTableTypes alterType) throws SemanticException { String tblName = getDotName(qualified); List<FieldSchema> newCols = getColumns((ASTNode) ast.getChild(0)); boolean isCascade = false; if (null != ast.getFirstChildWithType(HiveParser.TOK_CASCADE)) { isCascade = true; } AlterTableDesc alterTblDesc = new AlterTableDesc(tblName, partSpec, newCols, alterType, isCascade); addInputsOutputsAlterTable(tblName, partSpec, alterTblDesc); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); }
private void analyzeCreateFunction(ASTNode ast) throws SemanticException { // ^(TOK_CREATEFUNCTION identifier StringLiteral ({isTempFunction}? => TOK_TEMPORARY)) String functionName = ast.getChild(0).getText().toLowerCase(); boolean isTemporaryFunction = (ast.getFirstChildWithType(HiveParser.TOK_TEMPORARY) != null); String className = unescapeSQLString(ast.getChild(1).getText()); // Temp functions are not allowed to have qualified names. if (isTemporaryFunction && FunctionUtils.isQualifiedFunctionName(functionName)) { throw new SemanticException("Temporary function cannot be created with a qualified name."); } // find any referenced resources List<ResourceUri> resources = getResourceList(ast); CreateFunctionDesc desc = new CreateFunctionDesc(functionName, isTemporaryFunction, className, resources); rootTasks.add(TaskFactory.get(new FunctionWork(desc), conf)); addEntities(functionName, isTemporaryFunction, resources); }
private void analyzeDropFunction(ASTNode ast) throws SemanticException { // ^(TOK_DROPFUNCTION identifier ifExists? $temp?) String functionName = ast.getChild(0).getText(); boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null); // we want to signal an error if the function doesn't exist and we're // configured not to ignore this boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); FunctionInfo info = FunctionRegistry.getFunctionInfo(functionName); if (info == null) { if (throwException) { throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(functionName)); } else { // Fail silently return; } } else if (info.isBuiltIn()) { throw new SemanticException(ErrorMsg.DROP_NATIVE_FUNCTION.getMsg(functionName)); } boolean isTemporaryFunction = (ast.getFirstChildWithType(HiveParser.TOK_TEMPORARY) != null); DropFunctionDesc desc = new DropFunctionDesc(functionName, isTemporaryFunction, null); rootTasks.add(TaskFactory.get(new FunctionWork(desc))); addEntities(functionName, info.getClassName(), isTemporaryFunction, null); }
boolean ifCascade = false; if (null != ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS)) { ifExists = true; if (null != ast.getFirstChildWithType(HiveParser.TOK_CASCADE)) { ifCascade = true;
private void analyzeAlterTableDropParts(String[] qualified, ASTNode ast, boolean expectView) throws SemanticException { boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null) || HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); boolean mustPurge = (ast.getFirstChildWithType(HiveParser.KW_PURGE) != null); ReplicationSpec replicationSpec = new ReplicationSpec(ast);
private void analyzeDropFunction(ASTNode ast) throws SemanticException { // ^(TOK_DROPFUNCTION identifier ifExists? $temp?) String functionName = ast.getChild(0).getText(); boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null); // we want to signal an error if the function doesn't exist and we're // configured not to ignore this boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); FunctionInfo info = FunctionRegistry.getFunctionInfo(functionName); if (info == null) { if (throwException) { throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(functionName)); } else { // Fail silently return; } } else if (info.isBuiltIn()) { throw new SemanticException(ErrorMsg.DROP_NATIVE_FUNCTION.getMsg(functionName)); } boolean isTemporaryFunction = (ast.getFirstChildWithType(HiveParser.TOK_TEMPORARY) != null); DropFunctionDesc desc = new DropFunctionDesc(functionName, isTemporaryFunction); rootTasks.add(TaskFactory.get(new FunctionWork(desc), conf)); addEntities(functionName, isTemporaryFunction, null); }
private void analyzeAlterTableUpdateColumns(ASTNode ast, String tableName, HashMap<String, String> partSpec) throws SemanticException { boolean isCascade = false; if (null != ast.getFirstChildWithType(HiveParser.TOK_CASCADE)) { isCascade = true; } AlterTableDesc alterTblDesc = new AlterTableDesc(AlterTableTypes.UPDATECOLUMNS); alterTblDesc.setOldName(tableName); alterTblDesc.setIsCascade(isCascade); alterTblDesc.setPartSpec(partSpec); Table tbl = getTable(tableName); if (AcidUtils.isTransactionalTable(tbl)) { setAcidDdlDesc(alterTblDesc); } rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); }
private List<ResourceUri> getResourceList(ASTNode ast) throws SemanticException { List<ResourceUri> resources = null; ASTNode resourcesNode = (ASTNode) ast.getFirstChildWithType(HiveParser.TOK_RESOURCE_LIST); if (resourcesNode != null) { resources = new ArrayList<ResourceUri>(); for (int idx = 0; idx < resourcesNode.getChildCount(); ++idx) { // ^(TOK_RESOURCE_URI $resType $resPath) ASTNode resNode = (ASTNode) resourcesNode.getChild(idx); if (resNode.getToken().getType() != HiveParser.TOK_RESOURCE_URI) { throw new SemanticException("Expected token type TOK_RESOURCE_URI but found " + resNode.getToken().toString()); } if (resNode.getChildCount() != 2) { throw new SemanticException("Expected 2 child nodes of TOK_RESOURCE_URI but found " + resNode.getChildCount()); } ASTNode resTypeNode = (ASTNode) resNode.getChild(0); ASTNode resUriNode = (ASTNode) resNode.getChild(1); ResourceType resourceType = getResourceType(resTypeNode); resources.add(new ResourceUri(resourceType, PlanUtils.stripQuotes(resUriNode.getText()))); } } return resources; }
private List<ResourceUri> getResourceList(ASTNode ast) throws SemanticException { List<ResourceUri> resources = null; ASTNode resourcesNode = (ASTNode) ast.getFirstChildWithType(HiveParser.TOK_RESOURCE_LIST); if (resourcesNode != null) { resources = new ArrayList<ResourceUri>(); for (int idx = 0; idx < resourcesNode.getChildCount(); ++idx) { // ^(TOK_RESOURCE_URI $resType $resPath) ASTNode resNode = (ASTNode) resourcesNode.getChild(idx); if (resNode.getToken().getType() != HiveParser.TOK_RESOURCE_URI) { throw new SemanticException("Expected token type TOK_RESOURCE_URI but found " + resNode.getToken().toString()); } if (resNode.getChildCount() != 2) { throw new SemanticException("Expected 2 child nodes of TOK_RESOURCE_URI but found " + resNode.getChildCount()); } ASTNode resTypeNode = (ASTNode) resNode.getChild(0); ASTNode resUriNode = (ASTNode) resNode.getChild(1); ResourceType resourceType = getResourceType(resTypeNode); resources.add(new ResourceUri(resourceType, PlanUtils.stripQuotes(resUriNode.getText()))); } } return resources; }
private void analyzeAlterTableModifyCols(String[] qualified, ASTNode ast, HashMap<String, String> partSpec, AlterTableTypes alterType) throws SemanticException { String tblName = getDotName(qualified); List<FieldSchema> newCols = getColumns((ASTNode) ast.getChild(0)); boolean isCascade = false; if (null != ast.getFirstChildWithType(HiveParser.TOK_CASCADE)) { isCascade = true; } AlterTableDesc alterTblDesc = new AlterTableDesc(tblName, partSpec, newCols, alterType, isCascade); Table table = getTable(tblName, true); if (AcidUtils.isTransactionalTable(table)) { setAcidDdlDesc(alterTblDesc); } addInputsOutputsAlterTable(tblName, partSpec, alterTblDesc); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc))); }
@SuppressWarnings("unchecked") private void analyzeDropMacro(ASTNode ast) throws SemanticException { String functionName = ast.getChild(0).getText(); boolean ifExists = (ast.getFirstChildWithType(TOK_IFEXISTS) != null); // we want to signal an error if the function doesn't exist and we're // configured not to ignore this boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); // Temp macros are not allowed to have qualified names. if (FunctionUtils.isQualifiedFunctionName(functionName)) { throw new SemanticException("Temporary macro name cannot be a qualified name."); } if (throwException && FunctionRegistry.getFunctionInfo(functionName) == null) { throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(functionName)); } DropMacroDesc desc = new DropMacroDesc(functionName); rootTasks.add(TaskFactory.get(new FunctionWork(desc))); addEntities(); }
@SuppressWarnings("unchecked") private void analyzeDropMacro(ASTNode ast) throws SemanticException { String functionName = ast.getChild(0).getText(); boolean ifExists = (ast.getFirstChildWithType(TOK_IFEXISTS) != null); // we want to signal an error if the function doesn't exist and we're // configured not to ignore this boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); // Temp macros are not allowed to have qualified names. if (FunctionUtils.isQualifiedFunctionName(functionName)) { throw new SemanticException("Temporary macro name cannot be a qualified name."); } if (throwException && FunctionRegistry.getFunctionInfo(functionName) == null) { throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(functionName)); } DropMacroDesc desc = new DropMacroDesc(functionName); rootTasks.add(TaskFactory.get(new FunctionWork(desc), conf)); addEntities(); }
@Override public Task<? extends Serializable> createRevokeTask(ASTNode ast, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException { List<PrivilegeDesc> privilegeDesc = analyzePrivilegeListDef((ASTNode) ast.getChild(0)); List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef((ASTNode) ast.getChild(1)); PrivilegeObjectDesc hiveObj = null; boolean grantOption = false; if (ast.getChildCount() > 2) { ASTNode astChild = (ASTNode) ast.getChild(2); hiveObj = analyzePrivilegeObject(astChild, outputs); if (null != ast.getFirstChildWithType(HiveParser.TOK_GRANT_OPTION_FOR)) { grantOption = true; } } RevokeDesc revokeDesc = new RevokeDesc(privilegeDesc, principalDesc, hiveObj, grantOption); return TaskFactory.get(new DDLWork(inputs, outputs, revokeDesc)); } @Override
@Override public Task<? extends Serializable> createRevokeTask(ASTNode ast, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException { List<PrivilegeDesc> privilegeDesc = analyzePrivilegeListDef((ASTNode) ast.getChild(0)); List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef((ASTNode) ast.getChild(1)); PrivilegeObjectDesc hiveObj = null; boolean grantOption = false; if (ast.getChildCount() > 2) { ASTNode astChild = (ASTNode) ast.getChild(2); hiveObj = analyzePrivilegeObject(astChild, outputs); if (null != ast.getFirstChildWithType(HiveParser.TOK_GRANT_OPTION_FOR)) { grantOption = true; } } RevokeDesc revokeDesc = new RevokeDesc(privilegeDesc, principalDesc, hiveObj, grantOption); return TaskFactory.get(new DDLWork(inputs, outputs, revokeDesc), conf); } @Override
private void analyzeDropIndex(ASTNode ast) throws SemanticException { String indexName = unescapeIdentifier(ast.getChild(0).getText()); String tableName = getUnescapedName((ASTNode) ast.getChild(1)); boolean ifExists = (ast.getFirstChildWithType(HiveParser.TOK_IFEXISTS) != null); // we want to signal an error if the index doesn't exist and we're // configured not to ignore this boolean throwException = !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); Table tbl = getTable(tableName, false); if (throwException && tbl == null) { throw new SemanticException(ErrorMsg.INVALID_TABLE.getMsg(tableName)); } try { Index idx = db.getIndex(tableName, indexName); } catch (HiveException e) { if (!(e.getCause() instanceof NoSuchObjectException)) { throw new SemanticException(ErrorMsg.CANNOT_DROP_INDEX.getMsg("dropping index"), e); } if (throwException) { throw new SemanticException(ErrorMsg.INVALID_INDEX.getMsg(indexName)); } } if (tbl != null) { inputs.add(new ReadEntity(tbl)); } DropIndexDesc dropIdxDesc = new DropIndexDesc(indexName, tableName, throwException); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), dropIdxDesc), conf)); }