* 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 "SubstraitParser.h"
#include "velox/core/Expressions.h"
#include "velox/type/StringView.h"
#include "velox/vector/ComplexVector.h"
#include "velox/vector/FlatVector.h"
using namespace facebook::velox;
namespace gluten {
class SubstraitVeloxExprConverter {
public:
explicit SubstraitVeloxExprConverter(
memory::MemoryPool* pool,
const std::unordered_map<uint64_t, std::string>& functionMap)
: pool_(pool), functionMap_(functionMap) {}
struct TypedVariant {
variant veloxVariant;
TypePtr variantType;
};
static std::shared_ptr<const core::FieldAccessTypedExpr> toVeloxExpr(
const ::substrait::Expression::FieldReference& substraitField,
const RowTypePtr& inputType);
core::TypedExprPtr toVeloxExpr(
const ::substrait::Expression::ScalarFunction& substraitFunc,
const RowTypePtr& inputType);
core::TypedExprPtr toVeloxExpr(
const ::substrait::Expression::SingularOrList& singularOrList,
const RowTypePtr& inputType);
core::TypedExprPtr toVeloxExpr(const ::substrait::Expression::Cast& castExpr, const RowTypePtr& inputType);
static core::TypedExprPtr toExtractExpr(const std::vector<core::TypedExprPtr>& params, const TypePtr& outputType);
std::shared_ptr<const core::ConstantTypedExpr> toVeloxExpr(const ::substrait::Expression::Literal& substraitLit);
core::TypedExprPtr toVeloxExpr(const ::substrait::Expression& substraitExpr, const RowTypePtr& inputType);
core::TypedExprPtr toVeloxExpr(const ::substrait::Expression::IfThen& substraitIfThen, const RowTypePtr& inputType);
std::shared_ptr<const core::ConstantTypedExpr> literalsToConstantExpr(
const std::vector<::substrait::Expression::Literal>& literals);
std::shared_ptr<const core::ITypedExpr> toLambdaExpr(
const ::substrait::Expression::ScalarFunction& substraitFunc,
const RowTypePtr& inputType);
private:
ArrayVectorPtr literalsToArrayVector(const ::substrait::Expression::Literal& literal);
MapVectorPtr literalsToMapVector(const ::substrait::Expression::Literal& literal);
VectorPtr literalsToVector(
const ::substrait::Expression::Literal& childLiteral,
vector_size_t childSize,
std::function<::substrait::Expression::Literal(vector_size_t )> elementAtFunc);
RowVectorPtr literalsToRowVector(const ::substrait::Expression::Literal& structLiteral);
memory::MemoryPool* pool_;
std::unordered_map<uint64_t, std::string> functionMap_;
static std::unordered_map<std::string, std::string> extractDatetimeFunctionMap_;
};
}