@Override public ArrayList<Node> getChildren() { if (super.getChildCount() == 0) { return null; } ArrayList<Node> ret_vec = new ArrayList<Node>(); for (int i = 0; i < super.getChildCount(); ++i) { ret_vec.add((Node) super.getChild(i)); } return ret_vec; }
private boolean isExtractDatePartNode(CommonTree node) { if (node.parent != null) { //date part of EXTRACT expression if (node.childIndex >= 1) { Tree extractNode = node.parent.getChild(node.childIndex - 1); if ("extract(".equalsIgnoreCase(extractNode.getText())) { return true; } } } return false; }
@Override public ArrayList<Node> getChildren() { if (super.getChildCount() == 0) { return null; } ArrayList<Node> ret_vec = new ArrayList<Node>(); for (int i = 0; i < super.getChildCount(); ++i) { ret_vec.add((Node) super.getChild(i)); } return ret_vec; }
/** * Get the partition specs from the tree. * * @param ast * Tree to extract partitions from. * @return A list of partition name to value mappings. * @throws SemanticException */ private List<Map<String, String>> getPartitionSpecs(Table tbl, CommonTree ast) throws SemanticException { List<Map<String, String>> partSpecs = new ArrayList<Map<String, String>>(); int childIndex = 0; // get partition metadata if partition specified for (childIndex = 0; childIndex < ast.getChildCount(); childIndex++) { ASTNode partSpecNode = (ASTNode)ast.getChild(childIndex); // sanity check if (partSpecNode.getType() == HiveParser.TOK_PARTSPEC) { Map<String,String> partSpec = getValidatedPartSpec(tbl, partSpecNode, conf, false); partSpecs.add(partSpec); } } return partSpecs; }
/** * Get the partition specs from the tree. * * @param ast * Tree to extract partitions from. * @return A list of partition name to value mappings. * @throws SemanticException */ private List<Map<String, String>> getPartitionSpecs(Table tbl, CommonTree ast) throws SemanticException { List<Map<String, String>> partSpecs = new ArrayList<Map<String, String>>(); int childIndex = 0; // get partition metadata if partition specified for (childIndex = 0; childIndex < ast.getChildCount(); childIndex++) { ASTNode partSpecNode = (ASTNode)ast.getChild(childIndex); // sanity check if (partSpecNode.getType() == HiveParser.TOK_PARTSPEC) { Map<String,String> partSpec = getValidatedPartSpec(tbl, partSpecNode, conf, false); partSpecs.add(partSpec); } } return partSpecs; }
private void findTableNames(final Object obj, final Set<TableName> tableNames) { if (!(obj instanceof CommonTree)) { return; } final CommonTree tree = (CommonTree) obj; final int childCount = tree.getChildCount(); if ("TOK_TABNAME".equals(tree.getText())) { final TableName tableName; final boolean isInput = "TOK_TABREF".equals(tree.getParent().getText()); switch (childCount) { case 1 : tableName = new TableName(null, tree.getChild(0).getText(), isInput); break; case 2: tableName = new TableName(tree.getChild(0).getText(), tree.getChild(1).getText(), isInput); break; default: throw new IllegalStateException("TOK_TABNAME does not have expected children, childCount=" + childCount); } // If parent is TOK_TABREF, then it is an input table. tableNames.add(tableName); return; } for (int i = 0; i < childCount; i++) { findTableNames(tree.getChild(i), tableNames); } }
private void findTableNames(final Object obj, final Set<TableName> tableNames) { if (!(obj instanceof CommonTree)) { return; } final CommonTree tree = (CommonTree) obj; final int childCount = tree.getChildCount(); if ("TOK_TABNAME".equals(tree.getText())) { final TableName tableName; final boolean isInput = "TOK_TABREF".equals(tree.getParent().getText()); switch (childCount) { case 1 : tableName = new TableName(null, tree.getChild(0).getText(), isInput); break; case 2: tableName = new TableName(tree.getChild(0).getText(), tree.getChild(1).getText(), isInput); break; default: throw new IllegalStateException("TOK_TABNAME does not have expected children, childCount=" + childCount); } // If parent is TOK_TABREF, then it is an input table. tableNames.add(tableName); return; } for (int i = 0; i < childCount; i++) { findTableNames(tree.getChild(i), tableNames); } }
repair = ast.getChild(0).getType() == HiveParser.KW_REPAIR; if (!repair) { tableName = getUnescapedName((ASTNode) ast.getChild(0)); addPartitions = isMsckAddPartition(ast.getChild(1).getType()); dropPartitions = isMsckDropPartition(ast.getChild(1).getType()); tableName = getUnescapedName((ASTNode) ast.getChild(1)); addPartitions = isMsckAddPartition(ast.getChild(2).getType()); dropPartitions = isMsckDropPartition(ast.getChild(2).getType());
/** * Verify that the information in the metastore matches up with the data on * the fs. * * @param ast * Query tree. * @throws SemanticException */ private void analyzeMetastoreCheck(CommonTree ast) throws SemanticException { String tableName = null; boolean repair = false; if (ast.getChildCount() > 0) { repair = ast.getChild(0).getType() == HiveParser.KW_REPAIR; if (!repair) { tableName = getUnescapedName((ASTNode) ast.getChild(0)); } else if (ast.getChildCount() > 1) { tableName = getUnescapedName((ASTNode) ast.getChild(1)); } } Table tab = getTable(tableName); List<Map<String, String>> specs = getPartitionSpecs(tab, ast); outputs.add(new WriteEntity(tab, WriteEntity.WriteType.DDL_SHARED)); MsckDesc checkDesc = new MsckDesc(tableName, specs, ctx.getResFile(), repair); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), checkDesc), conf)); }
if (!next.visited) { if (next.parent != null && next.parent.getChildCount() > 1 && next != next.parent.getChild(0)) { rootNode.addtoMemoizedString(" ");
if (!next.visited) { if (next.parent != null && next.parent.getChildCount() > 1 && next != next.parent.getChild(0)) { rootNode.addtoMemoizedString(" ");
new HashMap<Integer, List<ExprNodeGenericFuncDesc>>(); for (int childIndex = 0; childIndex < ast.getChildCount(); childIndex++) { Tree partSpecTree = ast.getChild(childIndex); if (partSpecTree.getType() != HiveParser.TOK_PARTSPEC) { continue; CommonTree partSpecSingleKey = (CommonTree) partSpecTree.getChild(i); assert (partSpecSingleKey.getType() == HiveParser.TOK_PARTVAL); String key = stripIdentifierQuotes(partSpecSingleKey.getChild(0).getText()).toLowerCase(); String operator = partSpecSingleKey.getChild(1).getText(); ASTNode partValNode = (ASTNode)partSpecSingleKey.getChild(2); TypeCheckCtx typeCheckCtx = new TypeCheckCtx(null); ExprNodeConstantDesc valExpr = (ExprNodeConstantDesc)TypeCheckProcFactory
new HashMap<Integer, List<ExprNodeGenericFuncDesc>>(); for (int childIndex = 0; childIndex < ast.getChildCount(); childIndex++) { Tree partSpecTree = ast.getChild(childIndex); if (partSpecTree.getType() != HiveParser.TOK_PARTSPEC) continue; ExprNodeGenericFuncDesc expr = null; CommonTree partSpecSingleKey = (CommonTree) partSpecTree.getChild(i); assert (partSpecSingleKey.getType() == HiveParser.TOK_PARTVAL); String key = stripIdentifierQuotes(partSpecSingleKey.getChild(0).getText()).toLowerCase(); String operator = partSpecSingleKey.getChild(1).getText(); ASTNode partValNode = (ASTNode)partSpecSingleKey.getChild(2); TypeCheckCtx typeCheckCtx = new TypeCheckCtx(null); ExprNodeConstantDesc valExpr = (ExprNodeConstantDesc)TypeCheckProcFactory
boolean ifNotExists = ast.getChild(0).getType() == HiveParser.TOK_IFNOTEXISTS; new AddPartitionDesc(tab.getDbName(), tab.getTableName(), ifNotExists); for (int num = start; num < numCh; num++) { ASTNode child = (ASTNode) ast.getChild(num); switch (child.getToken().getType()) { case HiveParser.TOK_PARTSPEC:
boolean ifNotExists = ast.getChild(0).getType() == HiveParser.TOK_IFNOTEXISTS; new AddPartitionDesc(tab.getDbName(), tab.getTableName(), ifNotExists); for (int num = start; num < numCh; num++) { ASTNode child = (ASTNode) ast.getChild(num); switch (child.getToken().getType()) { case HiveParser.TOK_PARTSPEC:
public static String collapseStringChildren(CommonTree tree) { StringBuilder builder = new StringBuilder(); for (int childIndex = 0; childIndex < tree.getChildCount(); childIndex++) { CommonTree child = (CommonTree) tree.getChild(childIndex); builder.append(child.getText()); } return builder.toString(); } }
private void handleDropIndex() throws SqlJetException { CommonTree options = (CommonTree) ast.getChild(0); boolean ifExists = options.getChildCount() > 0 && "exists".equalsIgnoreCase(options.getChild(0).getText()); String indexName = ast.getChild(1).getText(); if (db.getSchema().getIndex(indexName) != null) { db.dropIndex(indexName); } else if (!ifExists) { throw new SqlJetException(SqlJetErrorCode.ERROR, "Index does not exists."); } }
@Override public int getCharPositionInLine() { if ( token==null || token.getCharPositionInLine()==-1 ) { if ( getChildCount()>0 ) { return getChild(0).getCharPositionInLine(); } return 0; } return token.getCharPositionInLine(); }