Example #1
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;
 }
Example #2
0
 public AbstractCubeTable getQueriedTable(String alias) {
   if (cube != null && cube.getName().equalsIgnoreCase(qb.getTabNameForAlias((alias)))) {
     return (AbstractCubeTable) cube;
   }
   for (Dimension dim : dimensions) {
     if (dim.getName().equalsIgnoreCase(qb.getTabNameForAlias(alias))) {
       return dim;
     }
   }
   return null;
 }
Example #3
0
 public String getAliasForTableName(String tableName) {
   for (String alias : qb.getTabAliases()) {
     String table = qb.getTabNameForAlias(alias);
     if (table != null && table.equalsIgnoreCase(tableName)) {
       return alias;
     }
   }
   // get alias from cubeTbls
   for (Map.Entry<String, AbstractCubeTable> cubeTblEntry : cubeTbls.entrySet()) {
     if (cubeTblEntry.getValue().getName().equalsIgnoreCase(tableName)) {
       return cubeTblEntry.getKey();
     }
   }
   return tableName.toLowerCase();
 }
Example #4
0
 private String getClause() {
   if (clauseName == null) {
     TreeSet<String> ks = new TreeSet<String>(qb.getParseInfo().getClauseNames());
     clauseName = ks.first();
   }
   return clauseName;
 }
Example #5
0
 private boolean addQueriedTable(String alias, boolean isOptional) throws LensException {
   String tblName = qb.getTabNameForAlias(alias);
   if (tblName == null) {
     tblName = alias;
   }
   boolean added = addQueriedTable(alias, tblName, isOptional, false);
   if (!added) {
     // try adding as joinchain
     added = addJoinChain(alias, isOptional);
   }
   return added;
 }
Example #6
0
 private void extractMetaTables() throws LensException {
   List<String> tabAliases = new ArrayList<String>(qb.getTabAliases());
   Set<String> missing = new HashSet<String>();
   for (String alias : tabAliases) {
     boolean added = addQueriedTable(alias);
     if (!added) {
       missing.add(alias);
     }
   }
   for (String alias : missing) {
     // try adding them as joinchains
     boolean added = addJoinChain(alias, false);
     if (!added) {
       log.info("Queried tables do not exist. Missing table:{}", alias);
       throw new LensException(LensCubeErrorCode.NEITHER_CUBE_NOR_DIMENSION.getLensErrorInfo());
     }
   }
 }
Example #7
0
 String getQBFromString(CandidateFact fact, Map<Dimension, CandidateDim> dimsToQuery)
     throws LensException {
   String fromString;
   if (getJoinAST() == null) {
     if (cube != null) {
       if (dimensions.size() > 0) {
         throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
       }
       fromString = fact.getStorageString(getAliasForTableName(cube.getName()));
     } else {
       if (dimensions.size() != 1) {
         throw new LensException(LensCubeErrorCode.NO_JOIN_CONDITION_AVAILABLE.getLensErrorInfo());
       }
       Dimension dim = dimensions.iterator().next();
       fromString = dimsToQuery.get(dim).getStorageString(getAliasForTableName(dim.getName()));
     }
   } else {
     StringBuilder builder = new StringBuilder();
     getQLString(qb.getQbJoinTree(), builder, fact, dimsToQuery);
     fromString = builder.toString();
   }
   return fromString;
 }
Example #8
0
 public void setLimitValue(Integer value) {
   qb.getParseInfo().setDestLimit(getClause(), value);
 }
Example #9
0
 public Integer getLimitValue() {
   return qb.getParseInfo().getDestLimit(getClause());
 }
Example #10
0
 public QBJoinTree getQBJoinTree() {
   return qb.getQbJoinTree();
 }
Example #11
0
 public ASTNode getJoinAST() {
   return qb.getParseInfo().getJoinExpr();
 }
Example #12
0
  public void print() {
    if (!log.isDebugEnabled()) {
      return;
    }
    StringBuilder builder = new StringBuilder();
    builder.append("ASTNode:" + ast.dump() + "\n");
    builder.append("QB:");
    builder.append("\n numJoins:" + qb.getNumJoins());
    builder.append("\n numGbys:" + qb.getNumGbys());
    builder.append("\n numSels:" + qb.getNumSels());
    builder.append("\n numSelDis:" + qb.getNumSelDi());
    builder.append("\n aliasToTabs:");
    Set<String> tabAliases = qb.getTabAliases();
    for (String alias : tabAliases) {
      builder.append("\n\t" + alias + ":" + qb.getTabNameForAlias(alias));
    }
    builder.append("\n aliases:");
    for (String alias : qb.getAliases()) {
      builder.append(alias);
      builder.append(", ");
    }
    builder.append("id:" + qb.getId());
    builder.append("isQuery:" + qb.getIsQuery());
    builder.append("\n QBParseInfo");
    QBParseInfo parseInfo = qb.getParseInfo();
    builder.append("\n isSubQ: " + parseInfo.getIsSubQ());
    builder.append("\n alias: " + parseInfo.getAlias());
    if (parseInfo.getJoinExpr() != null) {
      builder.append("\n joinExpr: " + parseInfo.getJoinExpr().dump());
    }
    builder.append("\n hints: " + parseInfo.getHints());
    builder.append("\n aliasToSrc: ");
    for (String alias : tabAliases) {
      builder.append("\n\t" + alias + ": " + parseInfo.getSrcForAlias(alias).dump());
    }
    TreeSet<String> clauses = new TreeSet<String>(parseInfo.getClauseNames());
    for (String clause : clauses) {
      builder.append("\n\t" + clause + ": " + parseInfo.getClauseNamesForDest());
    }
    String clause = clauses.first();
    if (parseInfo.getWhrForClause(clause) != null) {
      builder.append("\n whereexpr: " + parseInfo.getWhrForClause(clause).dump());
    }
    if (parseInfo.getGroupByForClause(clause) != null) {
      builder.append("\n groupby expr: " + parseInfo.getGroupByForClause(clause).dump());
    }
    if (parseInfo.getSelForClause(clause) != null) {
      builder.append("\n sel expr: " + parseInfo.getSelForClause(clause).dump());
    }
    if (parseInfo.getHavingForClause(clause) != null) {
      builder.append("\n having expr: " + parseInfo.getHavingForClause(clause).dump());
    }
    if (parseInfo.getDestLimit(clause) != null) {
      builder.append("\n limit: " + parseInfo.getDestLimit(clause));
    }
    if (parseInfo.getAllExprToColumnAlias() != null
        && !parseInfo.getAllExprToColumnAlias().isEmpty()) {
      builder.append("\n exprToColumnAlias:");
      for (Map.Entry<ASTNode, String> entry : parseInfo.getAllExprToColumnAlias().entrySet()) {
        builder.append("\n\t expr: " + entry.getKey().dump() + " ColumnAlias: " + entry.getValue());
      }
    }
    if (parseInfo.getAggregationExprsForClause(clause) != null) {
      builder.append("\n aggregateexprs:");
      for (Map.Entry<String, ASTNode> entry :
          parseInfo.getAggregationExprsForClause(clause).entrySet()) {
        builder.append("\n\t key: " + entry.getKey() + " expr: " + entry.getValue().dump());
      }
    }
    if (parseInfo.getDistinctFuncExprsForClause(clause) != null) {
      builder.append("\n distinctFuncExprs:");
      for (ASTNode entry : parseInfo.getDistinctFuncExprsForClause(clause)) {
        builder.append("\n\t expr: " + entry.dump());
      }
    }

    if (qb.getQbJoinTree() != null) {
      builder.append("\n\n JoinTree");
      QBJoinTree joinTree = qb.getQbJoinTree();
      printJoinTree(joinTree, builder);
    }

    if (qb.getParseInfo().getDestForClause(clause) != null) {
      builder.append("\n Destination:");
      builder.append("\n\t dest expr:" + qb.getParseInfo().getDestForClause(clause).dump());
    }
    log.debug(builder.toString());
  }
Example #13
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();
  }