Example #1
0
  @Override
  public LogicalNode visitScan(
      CompilationContext context,
      LogicalPlan plan,
      LogicalPlan.QueryBlock block,
      ScanNode node,
      Stack<LogicalNode> stack)
      throws TajoException {

    compileProjectableNode(context, node.getInSchema(), node);
    compileSelectableNode(context, node.getInSchema(), node);

    return node;
  }
    public SystemPhysicalExec(TaskAttemptContext context, ScanNode scanNode) {
      super(context, scanNode.getInSchema(), scanNode.getOutSchema());
      this.scanNode = scanNode;

      if (this.scanNode.hasQual()) {
        this.qual = this.scanNode.getQual();
        this.qual.bind(null, inSchema);
      }

      cachedData = TUtil.newList();
      currentRow = 0;
      isClosed = false;

      projector = new Projector(context, inSchema, outSchema, scanNode.getTargets());
    }
    @Override
    public Tuple next() throws IOException {
      Tuple aTuple;
      Tuple outTuple = new VTuple(outColumnNum);

      if (isClosed) {
        return null;
      }

      if (cachedData.size() == 0) {
        rescan();
      }

      if (!scanNode.hasQual()) {
        if (currentRow < cachedData.size()) {
          aTuple = cachedData.get(currentRow++);
          projector.eval(aTuple, outTuple);
          outTuple.setOffset(aTuple.getOffset());
          return outTuple;
        }
        return null;
      } else {
        while (currentRow < cachedData.size()) {
          aTuple = cachedData.get(currentRow++);
          if (qual.eval(aTuple).isTrue()) {
            projector.eval(aTuple, outTuple);
            return outTuple;
          }
        }
        return null;
      }
    }
Example #4
0
  public void execSimpleQuery(
      QueryContext queryContext,
      Session session,
      String query,
      LogicalPlan plan,
      SubmitQueryResponse.Builder response)
      throws Exception {
    ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN);
    TableDesc desc = scanNode.getTableDesc();

    if (desc.hasPartition()) {
      scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN);
    }

    int maxRow = Integer.MAX_VALUE;
    if (plan.getRootBlock().hasNode(NodeType.LIMIT)) {
      LimitNode limitNode = plan.getRootBlock().getNode(NodeType.LIMIT);
      maxRow = (int) limitNode.getFetchFirstNum();
    }
    if (desc.getStats().getNumRows() == 0) {
      desc.getStats().setNumRows(TajoConstants.UNKNOWN_ROW_NUMBER);
    }

    QueryInfo queryInfo =
        context
            .getQueryJobManager()
            .createNewSimpleQuery(
                queryContext, session, query, (LogicalRootNode) plan.getRootBlock().getRoot());

    NonForwardQueryResultScanner queryResultScanner =
        new NonForwardQueryResultFileScanner(
            context.getConf(),
            session.getSessionId(),
            queryInfo.getQueryId(),
            scanNode,
            desc,
            maxRow);

    queryResultScanner.init();
    session.addNonForwardQueryResultScanner(queryResultScanner);

    response.setState(OK);
    response.setQueryId(queryInfo.getQueryId().getProto());
    response.setResultType(ResultType.ENCLOSED);
    response.setMaxRowNum(maxRow);
    response.setTableDesc(desc.getProto());
  }
    @Override
    public void rescan() throws IOException {
      cachedData.clear();
      cachedData.addAll(fetchSystemTable(scanNode.getTableDesc(), inSchema));

      tableStats = new TableStats();
      tableStats.setNumRows(cachedData.size());
    }
 @Override
 protected void compile() throws CompilationError {
   if (scanNode.hasQual()) {
     qual = context.getPrecompiledEval(inSchema, qual);
   }
 }