Ext func arg item seq can not be consumed 2 times

Bug #867262 reported by Gabriel Petrovay
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Released
High
Markos Zaharioudakis

Bug Description

If one tried to consume an external function argument item sequence 2 times, the 2nd time no more item is returned: next returns false and the item is NULL.

To reproduce, take any external module and in the "evaluate" implementation of a function do the following (make sure that the function receives a non non-empty sequence as the first parameter):

Item item;

Iterator_t iter = args[0]->getIterator();
iter->open();
iter->next(item);
iter->close();

// item is valid here

iter = args[0]->getIterator();
iter->open();
iter->next(item);
iter->close();

// item is NULL here

Tags: core-runtime
Revision history for this message
Gabriel Petrovay (gabipetrovay) wrote :

The problem might have to do with src\runtime\core\fncall_iterator.cpp:

10015 nbrinza is_open = true;
  9845 danielturcanu //if(open_count)
  9845 danielturcanu // theItemSequence->theChild->reset(theItemSequence->thePlanState);
  9845 danielturcanu open_count++;
  9845 danielturcanu }

...

 11584 markosza // theItemSequence->theChild->close(theItemSequence->thePlanState);

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Gabriel, would it be ok with your use case if instead of calling getIterator() a second time, you reused the same iterator? Basically, the code would look something like this:

Item item;
Iterator_t iter = args[0] ->getIterator( );
iter->open();
iter->next(item);
iter->close();

// iter = args[0] ->getIterator( );
iter->open();
iter->next(item);
iter->close();

The only difference between the above code and your example is that I have commented-out the 2nd call to getIterator().

In general, it doesn't make sense to have more than one iterator on a ExtFuncArgItemSequence, unless the sequence is materialized, and then you would get a performance hit.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

I think it's fine to restrict the API to only allow one iterator at a time. If the user has a use case
that requires two active iterators at a time, he should think about his use case and eventually
materialize in his code.

I'm going to approve the merge proposal.

Revision history for this message
Gabriel Petrovay (gabipetrovay) wrote :

What about this bug? Is it done?

Changed in zorba:
status: New → Fix Released
Changed in zorba:
status: Fix Released → Fix Committed
milestone: none → 2.1
Changed in zorba:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.