Skip to content

Commit

Permalink
add file
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchengchenghh committed May 15, 2024
1 parent 003eadb commit c90f078
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cpp/src/arrow/engine/substrait/extension_internal.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.

// This API is EXPERIMENTAL.

#include "arrow/engine/substrait/extension_internal.h"

#include "substrait/algebra.pb.h"

namespace arrow {
namespace engine {

Status FromProto(const substrait::extensions::AdvancedExtension& extension,
std::unordered_map<std::string, std::string>& out) {
if (!extension.has_enhancement()) {
return Status::Invalid("AdvancedExtension does not have enhancement");
}
const auto& enhancement = extension.enhancement();
substrait::Expression_Literal literal;

if (!enhancement.UnpackTo(&literal)) {
return Status::Invalid("Unpack the literal failed");
}

if (!literal.has_map()) {
return Status::Invalid("Literal does not have map");
}
auto literalMap = literal.map();
auto size = literalMap.key_values_size();
for (auto i = 0; i < size; i++) {
substrait::Expression_Literal_Map_KeyValue keyValue = literalMap.key_values(i);
out.emplace(keyValue.key().string(), keyValue.value().string());
}
}
} // namespace engine
} // namespace arrow
44 changes: 44 additions & 0 deletions cpp/src/arrow/engine/substrait/extension_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

// 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.

// This API is EXPERIMENTAL.

#pragma once

#include <memory>

#include "arrow/compute/type_fwd.h"
#include "arrow/engine/substrait/extension_set.h"
#include "arrow/engine/substrait/options.h"
#include "arrow/engine/substrait/relation.h"
#include "arrow/engine/substrait/visibility.h"
#include "arrow/result.h"
#include "arrow/status.h"

#include "substrait/extensions/extensions.pb.h" // IWYU pragma: export

namespace arrow {
namespace engine {

/// Convert a Substrait ExtendedExpression to a vector of expressions and output names
ARROW_ENGINE_EXPORT
Status FromProto(const substrait::extensions::AdvancedExtension& extension,
std::unordered_map<std::string, std::string>& out);

} // namespace engine
} // namespace arrow

0 comments on commit c90f078

Please sign in to comment.