diff --git a/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp b/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp index da55fdb8..dc1a0b32 100644 --- a/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp +++ b/src/substrait/textplan/parser/SubstraitPlanRelationVisitor.cpp @@ -1953,10 +1953,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( @@ -1971,9 +1970,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.");