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) {
   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.º 3
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);
        }
    }