jvanstraten commented on a change in pull request #12279: URL: https://github.com/apache/arrow/pull/12279#discussion_r796507162
########## File path: cpp/examples/arrow/engine_substrait_consumption.cc ########## @@ -0,0 +1,187 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <arrow/api.h> +#include <arrow/compute/api.h> +#include <arrow/compute/exec/options.h> +#include <arrow/engine/substrait/serde.h> + +#include <cstdlib> +#include <iostream> +#include <memory> +#include <vector> + +namespace eng = ::arrow::engine; +namespace cp = ::arrow::compute; + +#define ABORT_ON_FAILURE(expr) \ + do { \ + arrow::Status status_ = (expr); \ + if (!status_.ok()) { \ + std::cerr << status_.message() << std::endl; \ + abort(); \ + } \ + } while (0); + +arrow::Future<std::shared_ptr<arrow::Buffer>> GetSubstraitFromServer(); + +class IgnoringConsumer : public cp::SinkNodeConsumer { + public: + explicit IgnoringConsumer(size_t tag) : tag_{tag} {} + + arrow::Status Consume(cp::ExecBatch batch) override { + // Consume a batch of data + // (just print its row count to stdout) + std::cout << "-" << tag_ << " consumed " << batch.length << " rows" << std::endl; + return arrow::Status::OK(); + } + + arrow::Future<> Finish() override { + // Signal to the consumer that the last batch has been delivered + // (we don't do any real work in this consumer so mark it finished immediately) + // + // The returned future should only finish when all outstanding tasks have completed + // (after this method is called Consume is guaranteed not to be called again) + std::cout << "-" << tag_ << " finished" << std::endl; + return arrow::Future<>::MakeFinished(); + } + + private: + size_t tag_; +}; + +int main(int argc, char** argv) { + // Plans arrive at the consumer serialized in a substrait-formatted Buffer Review comment: See d64d53b -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org