Ejemplo n.º 1
0
    inline void execute(query_context& context) {
        if (m_random_seed != -1) {
            random::get_source().seed(m_random_seed + thread::thread_id());
        }
        while(1) {
            auto rows = context.get_next(0);
            if (rows == nullptr)
                break;
            auto output = context.get_output_buffer();
            output->resize(1, rows->num_rows());

            auto iter = rows->cbegin();
            auto output_iter = output->begin();
            while(iter != rows->cend()) {
                auto outval = m_transform_fn((*iter));
                if (m_output_type == flex_type_enum::UNDEFINED ||
                        outval.get_type() == m_output_type ||
                        outval.get_type() == flex_type_enum::UNDEFINED) {
                    (*output_iter)[0] = outval;
                } else {
                    flexible_type f(m_output_type);
                    f.soft_assign(outval);
                    (*output_iter)[0] = f;
                }
                ++output_iter;
                ++iter;
            }
            context.emit(output);
        }
    }
Ejemplo n.º 2
0
    inline void execute(query_context& context) {
        if (!m_reader) m_reader = m_source->get_reader();
        auto start = m_begin_index;
        auto block_size = context.block_size();
        bool skip_next_block = false;
        emit_state state = context.initial_state();

        while (start != m_end_index) {
            auto rows = context.get_output_buffer();
            auto end = std::min(start + block_size, m_end_index);
            if (skip_next_block == false) {
                m_reader->read_rows(start, end, *rows);
                state = context.emit(rows);
            } else {
                state = context.emit(nullptr);
            }
            skip_next_block = state == emit_state::SKIP_NEXT_BLOCK;
            start = end;
        }
    }
Ejemplo n.º 3
0
  inline void execute(query_context& context) {
    size_t i = 0;
    while(i < m_len) {
      auto ret = context.get_output_buffer();
      size_t len = std::min(m_len - i, context.block_size());

      ret->resize(1, len);
      for (auto& value: *(ret->get_columns()[0])) value = m_value;
      context.emit(ret);
      i += len;
    }
  }
Ejemplo n.º 4
0
 inline void execute(query_context& context) {
   while(1) {
     auto rows = context.get_next(0);
     if (rows == nullptr)
       break;
     for (const auto& row : *rows) {
       // TODO make add_element take a sframe_row::row_reference instead
       if (row.size() == 1) m_aggregator->add_element_simple(row[0]);
       else m_aggregator->add_element(std::vector<flexible_type>(row)); 
     }
   }
   auto out = context.get_output_buffer();
   out->resize(1, 1);
   (*out)[0][0] = m_aggregator->emit();
   context.emit(out);
 }
Ejemplo n.º 5
0
    inline void execute(query_context& context) {
        std::vector<std::shared_ptr<const sframe_rows> > input_v(num_inputs);

        std::vector<
        std::vector<
        std::shared_ptr<
        std::vector<graphlab::flexible_type> > > > input_columns(num_inputs);

        while(1) {
            bool all_null = true, any_null = false;
            for(size_t i = 0; i < num_inputs; ++i) {
                input_v[i] = context.get_next(i);
                if(input_v[i] == nullptr)
                    any_null = true;
                else
                    all_null = false;
            }

            if(any_null) {
                ASSERT_TRUE(all_null);
                break;
            }

            for(size_t i = 0; i < num_inputs; ++i) {
                input_columns[i] = std::move(input_v[i]->get_columns());
            }

            auto out = context.get_output_buffer();
            auto& out_columns = out->get_columns();
            out_columns.clear();

            for(const std::pair<size_t, size_t>& p : index_map) {
                out_columns.push_back(input_columns[p.first][p.second]);
            }

            context.emit(out);
        }
    }