westonpace commented on a change in pull request #12279: URL: https://github.com/apache/arrow/pull/12279#discussion_r799926600
########## File path: cpp/src/arrow/engine/substrait/relation_internal.cc ########## @@ -0,0 +1,202 @@ +// 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/engine/substrait/relation_internal.h" + +#include "arrow/compute/api_scalar.h" +#include "arrow/compute/exec/options.h" +#include "arrow/dataset/file_parquet.h" +#include "arrow/dataset/plan.h" +#include "arrow/dataset/scanner.h" +#include "arrow/engine/substrait/expression_internal.h" +#include "arrow/engine/substrait/type_internal.h" +#include "arrow/filesystem/localfs.h" + +namespace arrow { +namespace engine { + +template <typename RelMessage> +Status CheckRelCommon(const RelMessage& rel) { + if (rel.has_common()) { + if (rel.common().has_emit()) { + return Status::NotImplemented("substrait::RelCommon::Emit"); + } + if (rel.common().has_hint()) { + return Status::NotImplemented("substrait::RelCommon::Hint"); + } + if (rel.common().has_advanced_extension()) { + return Status::NotImplemented("substrait::RelCommon::advanced_extension"); + } + } + if (rel.has_advanced_extension()) { + return Status::NotImplemented("substrait AdvancedExtensions"); + } + return Status::OK(); +} + +Result<compute::Declaration> FromProto(const substrait::Rel& rel, + const ExtensionSet& ext_set) { + static bool dataset_init = false; + if (!dataset_init) { + dataset_init = true; + dataset::internal::Initialize(); + } + + switch (rel.rel_type_case()) { + case substrait::Rel::RelTypeCase::kRead: { + const auto& read = rel.read(); + RETURN_NOT_OK(CheckRelCommon(read)); + + ARROW_ASSIGN_OR_RAISE(auto base_schema, FromProto(read.base_schema(), ext_set)); + + auto scan_options = std::make_shared<dataset::ScanOptions>(); + + if (read.has_filter()) { + ARROW_ASSIGN_OR_RAISE(scan_options->filter, FromProto(read.filter(), ext_set)); + } Review comment: I don't think this will actually work quite right. We can't push every kind of filter down into the scanner (and some formats, e.g. CSV can't do any pushdown filtering). As a result we will probably need to implement this both with a pushdown filter and an actual filter node. Or we need to clarify this in the Substrait docs. I've opened substrait-io/substrait#137 to investigate. I've opened ARROW-15586 to track this in Arrow. -- 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