* 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 "SubstraitToVeloxPlan.h"
#include "velox/core/QueryCtx.h"
namespace gluten {
class SubstraitToVeloxPlanValidator {
public:
SubstraitToVeloxPlanValidator(memory::MemoryPool* pool, core::ExecCtx* execCtx)
: pool_(pool), execCtx_(execCtx), planConverter_(pool_, confMap_, std::nullopt, true) {}
bool validate(const ::substrait::Plan& plan);
const std::vector<std::string>& getValidateLog() const {
return validateLog_;
}
private:
bool validate(const ::substrait::WriteRel& writeRel);
bool validate(const ::substrait::FetchRel& fetchRel);
bool validate(const ::substrait::TopNRel& topNRel);
bool validate(const ::substrait::ExpandRel& expandRel);
bool validate(const ::substrait::GenerateRel& generateRel);
bool validate(const ::substrait::SortRel& sortRel);
bool validate(const ::substrait::WindowRel& windowRel);
bool validate(const ::substrait::WindowGroupLimitRel& windowGroupLimitRel);
bool validate(const ::substrait::SetRel& setRel);
bool validate(const ::substrait::AggregateRel& aggRel);
bool validate(const ::substrait::ProjectRel& projectRel);
bool validate(const ::substrait::FilterRel& filterRel);
bool validate(const ::substrait::JoinRel& joinRel);
bool validate(const ::substrait::CrossRel& crossRel);
bool validate(const ::substrait::ReadRel& readRel);
bool validate(const ::substrait::Rel& rel);
bool validate(const ::substrait::RelRoot& relRoot);
memory::MemoryPool* pool_;
core::ExecCtx* execCtx_;
std::unordered_map<std::string, std::string> confMap_ = {};
SubstraitToVeloxPlanConverter planConverter_;
SubstraitVeloxExprConverter* exprConverter_ = nullptr;
std::vector<std::string> validateLog_;
bool parseVeloxType(const ::substrait::extensions::AdvancedExtension& extension, TypePtr& out);
bool flattenSingleLevel(const TypePtr& type, std::vector<TypePtr>& out);
bool flattenDualLevel(const TypePtr& type, std::vector<std::vector<TypePtr>>& out);
bool validateAggRelFunctionType(const ::substrait::AggregateRel& substraitAgg);
bool validateRound(const ::substrait::Expression::ScalarFunction& scalarFunction, const RowTypePtr& inputType);
bool validateExtractExpr(const std::vector<core::TypedExprPtr>& params);
bool validateRegexExpr(const std::string& name, const ::substrait::Expression::ScalarFunction& scalarFunction);
bool validateScalarFunction(
const ::substrait::Expression::ScalarFunction& scalarFunction,
const RowTypePtr& inputType);
bool validateCast(const ::substrait::Expression::Cast& castExpr, const RowTypePtr& inputType);
bool validateExpression(const ::substrait::Expression& expression, const RowTypePtr& inputType);
bool validateLiteral(const ::substrait::Expression_Literal& literal, const RowTypePtr& inputType);
bool validateIfThen(const ::substrait::Expression_IfThen& ifThen, const RowTypePtr& inputType);
bool validateSingularOrList(
const ::substrait::Expression::SingularOrList& singularOrList,
const RowTypePtr& inputType);
void logValidateMsg(const std::string& log) {
validateLog_.emplace_back(log);
}
};
}