Java Code Examples for org.apache.hadoop.hive.ql.lib.Node

The following examples show how to use org.apache.hadoop.hive.ql.lib.Node. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Eagle   Source File: Parser.java    License: Apache License 2.0 6 votes vote down vote up
private void visitSubtree(ASTNode ast) {
  int len = ast.getChildCount();
  if (len > 0) {
    for (Node n : ast.getChildren()) {
      ASTNode asn = (ASTNode)n;
      switch (asn.getToken().getType()) {
      case HiveParser.TOK_TABNAME:
        tableSet.add(ast.getChild(0).getChild(0).getText());
        break;
      case HiveParser.TOK_SET_COLUMNS_CLAUSE:
        for (int i = 0; i < asn.getChildCount(); i++) {
          addToColumnSet((ASTNode)asn.getChild(i).getChild(0));
        }
      case HiveParser.TOK_FROM:
        parseFromClause((ASTNode)asn.getChild(0));
        break;
      case HiveParser.TOK_INSERT:
        for (int i = 0; i < asn.getChildCount(); i++) {
          parseInsertClause((ASTNode)asn.getChild(i));                           
        }
        break;
      case HiveParser.TOK_UNIONTYPE: 
        int childcount = asn.getChildCount();
        for (int i = 0; i < childcount; i++) {    
          parseQL((ASTNode)asn.getChild(i));
        }
        break;
      }
    }

    // Add tableSet and columnSet to tableColumnMap
    addTablesColumnsToMap(tableSet, columnSet);
  }
}
 
Example 2
Source Project: eagle   Source File: Parser.java    License: Apache License 2.0 6 votes vote down vote up
private void parseQueryClause(ASTNode ast) {
  int len = ast.getChildCount();
  if (len > 0) {
    for (Node n : ast.getChildren()) {
      ASTNode asn = (ASTNode) n;
      switch (asn.getToken().getType()) {
        case HiveParser.TOK_FROM:
          parseFromClause((ASTNode) asn.getChild(0));
          break;
        case HiveParser.TOK_INSERT:
          for (int i = 0; i < asn.getChildCount(); i++) {
            parseInsertClause((ASTNode) asn.getChild(i));
          }
          break;
      }
    }
  }
}
 
Example 3
Source Project: circus-train   Source File: TableProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object process(Node node, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs)
  throws SemanticException {
  ASTNode astNode = (ASTNode) node;
  if (astNode.getToken() != null && astNode.getToken().getText() != null) {
    if ("TOK_TABNAME".equals(astNode.getToken().getText())) {
      tables.add(extractTableName(astNode));
    }
  }
  return null;
}
 
Example 4
Source Project: circus-train   Source File: TableProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void typical() throws Exception {
  ArrayList<Node> children = new ArrayList<>();
  children.add(dbNode);
  children.add(tableNode);
  when(node.getChildren()).thenReturn(children);
  when(node.getChildCount()).thenReturn(children.size());
  when(node.getChild(0)).thenReturn(dbNode);
  when(node.getChild(1)).thenReturn(tableNode);
  when(node.getType()).thenReturn(HiveParser.TOK_TABNAME);
  when(token.getText()).thenReturn("TOK_TABNAME");
  processor.process(node, null, null);
  assertThat(processor.getTables(), is(Arrays.asList(DATABASE + "." + TABLE)));
}
 
Example 5
Source Project: circus-train   Source File: TableProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void unqualifiedTableName() throws Exception {
  ArrayList<Node> children = new ArrayList<>();
  children.add(tableNode);
  when(node.getChildren()).thenReturn(children);
  when(node.getChildCount()).thenReturn(children.size());
  when(node.getChild(0)).thenReturn(tableNode);
  when(node.getType()).thenReturn(HiveParser.TOK_TABNAME);
  when(token.getText()).thenReturn("TOK_TABNAME");
  when(SessionState.get()).thenReturn(sessionState);
  processor.process(node, null, null);
  assertThat(processor.getTables(), is(Arrays.asList(DEFAULT_DATABASE + "." + TABLE)));
}
 
Example 6
Source Project: circus-train   Source File: TableProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void unqualifiedTableNameFailsIsSessionIsNotSet() throws Exception {
  ArrayList<Node> children = new ArrayList<>();
  children.add(tableNode);
  when(node.getChildren()).thenReturn(children);
  when(node.getChildCount()).thenReturn(children.size());
  when(node.getChild(0)).thenReturn(tableNode);
  when(node.getType()).thenReturn(HiveParser.TOK_TABNAME);
  when(token.getText()).thenReturn("TOK_TABNAME");
  processor.process(node, null, null);
}
 
Example 7
Source Project: circus-train   Source File: HiveLanguageParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void typical() throws Exception {
  parser.parse(CREATE_TABLE_STATEMENT, nodeProcessor);
  verify(nodeProcessor, times(49)).process(any(Node.class), any(Stack.class), any(NodeProcessorCtx.class),
      anyVararg());
}
 
Example 8
Source Project: eagle   Source File: Parser.java    License: Apache License 2.0 5 votes vote down vote up
private void visitSubtree(ASTNode ast) {
  int len = ast.getChildCount();
  if (len > 0) {
    for (Node n : ast.getChildren()) {
      ASTNode asn = (ASTNode)n;
      switch (asn.getToken().getType()) {
        case HiveParser.TOK_TABNAME:
          //tableSet.add(ast.getChild(0).getChild(0).getText());
          parserContent.getTableColumnMap().put(ast.getChild(0).getChild(0).getText(), new HashSet<>(columnSet));
          break;
        case HiveParser.TOK_SET_COLUMNS_CLAUSE:
          for (int i = 0; i < asn.getChildCount(); i++) {
            addToColumnSet((ASTNode) asn.getChild(i).getChild(0));
          }
          break;
        case HiveParser.TOK_QUERY:
          parseQueryClause(asn);
          break;
        case HiveParser.TOK_UNIONTYPE:
        case HiveParser.TOK_UNIONALL:
        case HiveParser.TOK_UNIONDISTINCT:
          visitSubtree(asn);
          break;
      }
    }
    // Add tableSet and columnSet to tableColumnMap
    addTablesColumnsToMap(tableSet, columnSet);
  }
}