public static boolean isPartitionLevelStats(ASTNode tree) { boolean isPartitioned = false; ASTNode child = (ASTNode) tree.getChild(0); if (child.getChildCount() > 1) { child = (ASTNode) child.getChild(1); if (child.getToken().getType() == HiveParser.TOK_PARTSPEC) { isPartitioned = true; } } return isPartitioned; }
public static VarcharTypeInfo getVarcharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type varchar"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getVarcharTypeInfo(Integer.parseInt(lengthStr)); }
public static List<PrincipalDesc> analyzePrincipalListDef(ASTNode node) { List<PrincipalDesc> principalList = new ArrayList<PrincipalDesc>(); for (int i = 0; i < node.getChildCount(); i++) { principalList.add(getPrincipalDesc((ASTNode) node.getChild(i))); } return principalList; }
private void analyzeDropTrigger(ASTNode ast) throws SemanticException { if (ast.getChildCount() != 2) { throw new SemanticException("Invalid syntax for drop trigger."); } String rpName = unescapeIdentifier(ast.getChild(0).getText()); String triggerName = unescapeIdentifier(ast.getChild(1).getText()); DropWMTriggerDesc desc = new DropWMTriggerDesc(rpName, triggerName); addServiceOutput(); rootTasks.add(TaskFactory.get( new DDLWork(getInputs(), getOutputs(), desc))); }
private Task<? extends Serializable> analyzeGrantRevokeRole(boolean isGrant, ASTNode ast, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) { List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef( (ASTNode) ast.getChild(0)); //check if admin option has been specified int rolesStartPos = 1; ASTNode wAdminOption = (ASTNode) ast.getChild(1); boolean isAdmin = false; if((isGrant && wAdminOption.getToken().getType() == HiveParser.TOK_GRANT_WITH_ADMIN_OPTION) || (!isGrant && wAdminOption.getToken().getType() == HiveParser.TOK_ADMIN_OPTION_FOR)){ rolesStartPos = 2; //start reading role names from next position isAdmin = true; } List<String> roles = new ArrayList<String>(); for (int i = rolesStartPos; i < ast.getChildCount(); i++) { roles.add(BaseSemanticAnalyzer.unescapeIdentifier(ast.getChild(i).getText())); } String roleOwnerName = SessionState.getUserFromAuthenticator(); //until change is made to use the admin option. Default to false with V2 authorization GrantRevokeRoleDDL grantRevokeRoleDDL = new GrantRevokeRoleDDL(isGrant, roles, principalDesc, roleOwnerName, PrincipalType.USER, isAdmin); return TaskFactory.get(new DDLWork(inputs, outputs, grantRevokeRoleDDL)); }
private void analyzeAlterTableAddConstraint(ASTNode ast, String tableName) throws SemanticException { ASTNode parent = (ASTNode) ast.getParent(); ASTNode child = (ASTNode) ast.getChild(0); List<SQLPrimaryKey> primaryKeys = new ArrayList<SQLPrimaryKey>(); List<SQLForeignKey> foreignKeys = new ArrayList<SQLForeignKey>(); if (child.getToken().getType() == HiveParser.TOK_PRIMARY_KEY) { BaseSemanticAnalyzer.processPrimaryKeys(parent, child, primaryKeys); } else if (child.getToken().getType() == HiveParser.TOK_FOREIGN_KEY) { BaseSemanticAnalyzer.processForeignKeys(parent, child, foreignKeys); } AlterTableDesc alterTblDesc = new AlterTableDesc(tableName, primaryKeys, foreignKeys); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); }
/** * Analyze list bucket column names * * @param skewedColNames * @param child * @return * @throws SemanticException */ protected List<String> analyzeSkewedTablDDLColNames(List<String> skewedColNames, ASTNode child) throws SemanticException { Tree nNode = child.getChild(0); if (nNode == null) { throw new SemanticException(ErrorMsg.SKEWED_TABLE_NO_COLUMN_NAME.getMsg()); } else { ASTNode nAstNode = (ASTNode) nNode; if (nAstNode.getToken().getType() != HiveParser.TOK_TABCOLNAME) { throw new SemanticException(ErrorMsg.SKEWED_TABLE_NO_COLUMN_NAME.getMsg()); } else { skewedColNames = getColumnNames(nAstNode); } } return skewedColNames; }
private static void assertConfig(ASTNode replConfigList, int atIndex, String expectedKey, String expectedValue) { ASTNode configOne = (ASTNode) replConfigList.getChild(atIndex); assertEquals("TOK_TABLEPROPERTY", configOne.getText()); assertEquals(2, configOne.getChildCount()); assertEquals(expectedKey, configOne.getChild(0).getText()); assertEquals(expectedValue, configOne.getChild(1).getText()); }
private static int getLine(ASTNode tree) { if (tree.getChildCount() == 0) { return tree.getToken().getLine(); } return getLine((ASTNode) tree.getChild(0)); }
private String buildTriggerActionExpression(ASTNode ast) throws SemanticException { switch (ast.getType()) { case HiveParser.KW_KILL: return "KILL"; case HiveParser.KW_MOVE: if (ast.getChildCount() != 1) { throw new SemanticException("Invalid move to clause in trigger action."); } String poolPath = poolPath(ast.getChild(0)); return "MOVE TO " + poolPath; default: throw new SemanticException("Unknown token in action clause: " + ast.getType()); } }
private PartitionSpec processPartitionSpec(ASTNode node) { PartitionSpec pSpec = new PartitionSpec(); int exprCnt = node.getChildCount(); for(int i=0; i < exprCnt; i++) { PartitionExpression exprSpec = new PartitionExpression(); exprSpec.setExpression((ASTNode) node.getChild(i)); pSpec.addExpression(exprSpec); } return pSpec; }
private void processQueryWindowClause(WindowingSpec spec, ASTNode node) throws SemanticException { ASTNode nameNode = (ASTNode) node.getChild(0); ASTNode wsNode = (ASTNode) node.getChild(1); if(spec.getWindowSpecs() != null && spec.getWindowSpecs().containsKey(nameNode.getText())){ throw new SemanticException(generateErrorMessage(nameNode, "Duplicate definition of window " + nameNode.getText() + " is not allowed")); } WindowSpec ws = processWindowSpec(wsNode); spec.addWindowSpec(nameNode.getText(), ws); }
private void analyzeDropPool(ASTNode ast) throws SemanticException { if (ast.getChildCount() != 2) { throw new SemanticException("Invalid syntax for drop pool."); } String rpName = unescapeIdentifier(ast.getChild(0).getText()); String poolPath = poolPath(ast.getChild(1)); DropWMPoolDesc desc = new DropWMPoolDesc(rpName, poolPath); addServiceOutput(); rootTasks.add(TaskFactory.get( new DDLWork(getInputs(), getOutputs(), desc))); }
public static boolean isPartitionLevelStats(ASTNode tree) { boolean isPartitioned = false; ASTNode child = (ASTNode) tree.getChild(0); if (child.getChildCount() > 1) { child = (ASTNode) child.getChild(1); if (child.getToken().getType() == HiveParser.TOK_PARTSPEC) { isPartitioned = true; } } return isPartitioned; }
public static CharTypeInfo getCharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type char"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getCharTypeInfo(Integer.parseInt(lengthStr)); }
private Task<? extends Serializable> analyzeGrantRevokeRole(boolean isGrant, ASTNode ast, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) { List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef( (ASTNode) ast.getChild(0)); //check if admin option has been specified int rolesStartPos = 1; ASTNode wAdminOption = (ASTNode) ast.getChild(1); boolean isAdmin = false; if((isGrant && wAdminOption.getToken().getType() == HiveParser.TOK_GRANT_WITH_ADMIN_OPTION) || (!isGrant && wAdminOption.getToken().getType() == HiveParser.TOK_ADMIN_OPTION_FOR)){ rolesStartPos = 2; //start reading role names from next position isAdmin = true; } List<String> roles = new ArrayList<String>(); for (int i = rolesStartPos; i < ast.getChildCount(); i++) { roles.add(BaseSemanticAnalyzer.unescapeIdentifier(ast.getChild(i).getText())); } String roleOwnerName = SessionState.getUserFromAuthenticator(); //until change is made to use the admin option. Default to false with V2 authorization GrantRevokeRoleDDL grantRevokeRoleDDL = new GrantRevokeRoleDDL(isGrant, roles, principalDesc, roleOwnerName, PrincipalType.USER, isAdmin); return TaskFactory.get(new DDLWork(inputs, outputs, grantRevokeRoleDDL), conf); }
public static List<PrincipalDesc> analyzePrincipalListDef(ASTNode node) { List<PrincipalDesc> principalList = new ArrayList<PrincipalDesc>(); for (int i = 0; i < node.getChildCount(); i++) { principalList.add(getPrincipalDesc((ASTNode) node.getChild(i))); } return principalList; }
private static void assertTableName(ASTNode root) { ASTNode child = (ASTNode) root.getChild(1); assertEquals("TOK_TABNAME", child.getText()); assertEquals(1, child.getChildCount()); assertEquals("test_table", child.getChild(0).getText()); }