@@ -115,6 +115,75 @@ bool SubstraitToVeloxPlanValidator::validate(
115115 return false ;
116116}
117117
118+ bool SubstraitToVeloxPlanValidator::validate (
119+ const ::substrait::JoinRel& sJoin ) {
120+ if (sJoin .has_left () && !validate (sJoin .left ())) {
121+ return false ;
122+ }
123+ if (sJoin .has_right () && !validate (sJoin .right ())) {
124+ return false ;
125+ }
126+
127+ switch (sJoin .type ()) {
128+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_INNER:
129+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_OUTER:
130+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_LEFT:
131+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_RIGHT:
132+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_SEMI:
133+ case ::substrait::JoinRel_JoinType_JOIN_TYPE_ANTI:
134+ break ;
135+ default :
136+ return false ;
137+ }
138+
139+ // Validate input types.
140+ if (!sJoin .has_advanced_extension ()) {
141+ std::cout << " Input types are expected in JoinRel." << std::endl;
142+ return false ;
143+ }
144+
145+ const auto & extension = sJoin .advanced_extension ();
146+ std::vector<TypePtr> types;
147+ if (!validateInputTypes (extension, types)) {
148+ std::cout << " Validation failed for input types in JoinRel" << std::endl;
149+ return false ;
150+ }
151+
152+ int32_t inputPlanNodeId = 0 ;
153+ std::vector<std::string> names;
154+ names.reserve (types.size ());
155+ for (auto colIdx = 0 ; colIdx < types.size (); colIdx++) {
156+ names.emplace_back (subParser_->makeNodeName (inputPlanNodeId, colIdx));
157+ }
158+ auto rowType = std::make_shared<RowType>(std::move (names), std::move (types));
159+
160+ if (sJoin .has_expression ()) {
161+ std::vector<const ::substrait::Expression::FieldReference*> leftExprs,
162+ rightExprs;
163+ try {
164+ planConverter_->extractJoinKeys (
165+ sJoin .expression (), leftExprs, rightExprs);
166+ } catch (const VeloxException& err) {
167+ std::cout << " Validation failed for expression in JoinRel due to:"
168+ << err.message () << std::endl;
169+ return false ;
170+ }
171+ }
172+
173+ if (sJoin .has_post_join_filter ()) {
174+ try {
175+ auto expression =
176+ exprConverter_->toVeloxExpr (sJoin .post_join_filter (), rowType);
177+ exec::ExprSet exprSet ({std::move (expression)}, &execCtx_);
178+ } catch (const VeloxException& err) {
179+ std::cout << " Validation failed for expression in ProjectRel due to:"
180+ << err.message () << std::endl;
181+ return false ;
182+ }
183+ }
184+ return true ;
185+ }
186+
118187bool SubstraitToVeloxPlanValidator::validate (
119188 const ::substrait::AggregateRel& sAgg ) {
120189 if (sAgg .has_input () && !validate (sAgg .input ())) {
@@ -304,6 +373,9 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::Rel& sRel) {
304373 if (sRel .has_filter ()) {
305374 return validate (sRel .filter ());
306375 }
376+ if (sRel .has_join ()) {
377+ return validate (sRel .join ());
378+ }
307379 if (sRel .has_read ()) {
308380 return validate (sRel .read ());
309381 }
0 commit comments