1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
class MyAddTransformer : public IProcessor { public: String getName() const override { return "MyAddTransformer"; }
MyAddTransformer() : IProcessor( {Block({ColumnWithTypeAndName{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "number"}})}, {Block({ColumnWithTypeAndName{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "number"}})}) , input(inputs.front()) , output(outputs.front()) { }
Status prepare() override { if (output.isFinished()) { input.close(); return Status::Finished; }
if (!output.canPush()) { input.setNotNeeded(); return Status::PortFull; }
if (has_process_data) { output.push(std::move(current_chunk)); has_process_data = false; }
if (input.isFinished()) { output.finish(); return Status::Finished; }
if (!input.hasData()) { input.setNeeded(); return Status::NeedData; } current_chunk = input.pull(false); return Status::Ready; }
void work() override { auto num_rows = current_chunk.getNumRows(); auto result_columns = current_chunk.cloneEmptyColumns(); auto columns = current_chunk.detachColumns(); for (auto i = 0U; i < num_rows; i++) { auto val = columns[0]->getUInt(i); result_columns[0]->insert(val+1); } current_chunk.setColumns(std::move(result_columns), num_rows); has_process_data = true; }
InputPort & getInputPort() { return input; } OutputPort & getOutputPort() { return output; }
protected: bool has_input = false; bool has_process_data = false; Chunk current_chunk; InputPort & input; OutputPort & output; };
|