示例#1
0
  public CubeQueryContext(ASTNode ast, QB qb, Configuration queryConf, HiveConf metastoreConf)
      throws LensException {
    this.ast = ast;
    this.qb = qb;
    this.conf = queryConf;
    this.clauseName = getClause();
    this.timeRanges = new ArrayList<TimeRange>();
    try {
      metastoreClient = CubeMetastoreClient.getInstance(metastoreConf);
    } catch (HiveException e) {
      throw new LensException(e);
    }
    if (qb.getParseInfo().getWhrForClause(clauseName) != null) {
      this.whereAST = qb.getParseInfo().getWhrForClause(clauseName);
    }
    if (qb.getParseInfo().getHavingForClause(clauseName) != null) {
      this.havingAST = qb.getParseInfo().getHavingForClause(clauseName);
    }
    if (qb.getParseInfo().getOrderByForClause(clauseName) != null) {
      this.orderByAST = qb.getParseInfo().getOrderByForClause(clauseName);
    }
    if (qb.getParseInfo().getGroupByForClause(clauseName) != null) {
      this.groupByAST = qb.getParseInfo().getGroupByForClause(clauseName);
    }
    if (qb.getParseInfo().getSelForClause(clauseName) != null) {
      this.selectAST = qb.getParseInfo().getSelForClause(clauseName);
    }

    for (ASTNode aggrTree : qb.getParseInfo().getAggregationExprsForClause(clauseName).values()) {
      String aggr = HQLParser.getString(aggrTree);
      aggregateExprs.add(aggr);
    }

    extractMetaTables();
  }
示例#2
0
 public String getInsertClause() {
   String insertString = "";
   ASTNode destTree = qb.getParseInfo().getDestForClause(clauseName);
   if (destTree != null
       && ((ASTNode) (destTree.getChild(0))).getToken().getType() != TOK_TMP_FILE) {
     insertString =
         "INSERT OVERWRITE" + HQLParser.getString(qb.getParseInfo().getDestForClause(clauseName));
   }
   return insertString;
 }
示例#3
0
 private void addRangeClauses(CandidateFact fact) throws LensException {
   if (fact != null) {
     // resolve timerange positions and replace it by corresponding where clause
     for (TimeRange range : getTimeRanges()) {
       for (Map.Entry<String, String> entry :
           fact.getRangeToStorageWhereMap().get(range).entrySet()) {
         String table = entry.getKey();
         String rangeWhere = entry.getValue();
         if (!StringUtils.isBlank(rangeWhere)) {
           ASTNode rangeAST = HQLParser.parseExpr(rangeWhere);
           range.getParent().setChild(range.getChildIndex(), rangeAST);
         }
         fact.getStorgeWhereClauseMap().put(table, getWhereTree());
       }
     }
   }
 }
示例#4
0
  boolean isCubeMeasure(ASTNode node) {
    String tabname = null;
    String colname;
    int nodeType = node.getToken().getType();
    if (!(nodeType == HiveParser.TOK_TABLE_OR_COL || nodeType == HiveParser.DOT)) {
      return false;
    }

    if (nodeType == HiveParser.TOK_TABLE_OR_COL) {
      colname = ((ASTNode) node.getChild(0)).getText();
    } else {
      // node in 'alias.column' format
      ASTNode tabident = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier);
      ASTNode colIdent = (ASTNode) node.getChild(1);

      colname = colIdent.getText();
      tabname = tabident.getText();
    }

    String msrname = StringUtils.isBlank(tabname) ? colname : tabname + "." + colname;

    return isCubeMeasure(msrname);
  }
示例#5
0
 public String getOrderByTree() {
   if (orderByAST != null) {
     return HQLParser.getString(orderByAST);
   }
   return null;
 }
示例#6
0
 public String getHavingTree() {
   if (havingAST != null) {
     return HQLParser.getString(havingAST);
   }
   return null;
 }
示例#7
0
 public String getGroupByTree() {
   if (groupByAST != null) {
     return HQLParser.getString(groupByAST);
   }
   return null;
 }
示例#8
0
 public String getWhereTree() {
   if (whereAST != null) {
     return HQLParser.getString(whereAST);
   }
   return null;
 }
示例#9
0
 public String getSelectTree() {
   return HQLParser.getString(selectAST);
 }
示例#10
0
 public void addExprToAlias(ASTNode expr, ASTNode alias) {
   exprToAlias.put(HQLParser.getString(expr).trim(), alias.getText().toLowerCase());
 }