westonpace commented on a change in pull request #12279: URL: https://github.com/apache/arrow/pull/12279#discussion_r799928109
########## File path: cpp/src/arrow/engine/substrait/relation_internal.cc ########## @@ -0,0 +1,186 @@ +// 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)); + } + + if (read.has_projection()) { + return Status::NotImplemented("substrait::ReadRel::projection"); + } + + { + // just project all fields + std::vector<compute::Expression> expressions{base_schema->fields().size()}; + for (int i = 0; i < base_schema->num_fields(); ++i) { + expressions[i] = compute::field_ref(i); + } + scan_options->projection = + compute::call("make_struct", std::move(expressions), + compute::MakeStructOptions{base_schema->field_names()}); + } + + if (!read.has_local_files()) { + return Status::NotImplemented( + "substrait::ReadRel with read_type other than LocalFiles"); + } + + if (read.local_files().has_advanced_extension()) { + return Status::NotImplemented( + "substrait::ReadRel::LocalFiles::advanced_extension"); + } + + auto format = std::make_shared<dataset::ParquetFileFormat>(); + auto filesystem = std::make_shared<fs::LocalFileSystem>(); + std::vector<std::shared_ptr<dataset::FileFragment>> fragments; + + for (const auto& item : read.local_files().items()) { + if (!item.has_uri_file()) { + return Status::NotImplemented( + "substrait::ReadRel::LocalFiles::FileOrFiles with " + "path_type other than uri_file"); + } + + if (item.format() != + substrait::ReadRel::LocalFiles::FileOrFiles::FILE_FORMAT_PARQUET) { + return Status::NotImplemented( + "substrait::ReadRel::LocalFiles::FileOrFiles::format " + "other than FILE_FORMAT_PARQUET"); Review comment: ARROW-15588 and substrait-io/substrait#138 -- 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