* 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.
*/
#pragma once
#include "substrait/algebra.pb.h"
#include "substrait/capabilities.pb.h"
#include "substrait/extensions/extensions.pb.h"
#include "substrait/function.pb.h"
#include "substrait/parameterized_types.pb.h"
#include "substrait/plan.pb.h"
#include "substrait/type.pb.h"
#include "substrait/type_expressions.pb.h"
#include <google/protobuf/wrappers.pb.h>
#include "velox/connectors/hive/TableHandle.h"
#include "velox/type/Type.h"
namespace gluten {
typedef ::facebook::velox::connector::hive::HiveColumnHandle::ColumnType ColumnType;
class SubstraitParser {
public:
static std::vector<facebook::velox::TypePtr> parseNamedStruct(
const ::substrait::NamedStruct& namedStruct,
bool asLowerCase = false);
static void parseColumnTypes(const ::substrait::NamedStruct& namedStruct, std::vector<ColumnType>& columnTypes);
static facebook::velox::TypePtr parseType(const ::substrait::Type& substraitType, bool asLowerCase = false);
static bool parseReferenceSegment(const ::substrait::Expression::ReferenceSegment& refSegment, uint32_t& fieldIndex);
static std::vector<std::string> makeNames(const std::string& prefix, int size);
static std::string makeNodeName(int nodeId, int colIdx);
static int getIdxFromNodeName(const std::string& nodeName);
static std::string findFunctionSpec(const std::unordered_map<uint64_t, std::string>& functionMap, uint64_t id);
static std::string getNameBeforeDelimiter(const std::string& signature, const std::string& delimiter = ":");
static std::vector<std::string> getSubFunctionTypes(const std::string& subFuncSpec);
static std::string findVeloxFunction(const std::unordered_map<uint64_t, std::string>& functionMap, uint64_t id);
static std::string mapToVeloxFunction(const std::string& substraitFunction, bool isDecimal);
static bool configSetInOptimization(const ::substrait::extensions::AdvancedExtension&, const std::string& config);
static std::vector<facebook::velox::TypePtr> sigToTypes(const std::string& functionSig);
template <typename T>
static T getLiteralValue(const ::substrait::Expression::Literal& );
private:
static std::unordered_map<std::string, std::string> substraitVeloxFunctionMap_;
static const std::unordered_map<std::string, std::string> typeMap_;
};
}