diff --git a/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp b/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp index 05969fea..a67cd4a3 100644 --- a/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp +++ b/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp @@ -1954,10 +1954,9 @@ int SubstraitPlanRelationVisitor::findFieldReferenceByName( auto fieldPlacement = generatedField - relationData->generatedFieldReferences.rbegin(); return static_cast( - (relationData->generatedFieldReferences.size() - - fieldPlacement) & - std::numeric_limits::max()) - - 1 + fieldReferencesSize; + (fieldReferencesSize + relationData->generatedFieldReferences.size() - + fieldPlacement - 1) & + std::numeric_limits::max()); } auto field = std::find_if( @@ -1972,9 +1971,8 @@ int SubstraitPlanRelationVisitor::findFieldReferenceByName( if (field != relationData->fieldReferences.rend()) { auto fieldPlacement = field - relationData->fieldReferences.rbegin(); return static_cast( - (fieldReferencesSize - fieldPlacement) & - std::numeric_limits::max()) - - 1; + (fieldReferencesSize - fieldPlacement - 1) & + std::numeric_limits::max()); } errorListener_->addError(token, "Reference " + name + " does not exist.");