Merge lp:~zorba-coders/zorba/fix-fncall-iterator into lp:zorba

Proposed by Federico Cavalieri
Status: Merged
Merged at revision: 11714
Proposed branch: lp:~zorba-coders/zorba/fix-fncall-iterator
Merge into: lp:zorba
Diff against target: 336 lines (+136/-122)
4 files modified
src/runtime/core/fncall_iterator.cpp (+126/-122)
src/runtime/core/fncall_iterator.h (+5/-0)
test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines-2.xml.res (+1/-0)
test/rbkt/Queries/zorba/file/file_read_text_lines-2.xq (+4/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/fix-fncall-iterator
Reviewer Review Type Date Requested Status
Federico Cavalieri Approve
Matthias Brantner Approve
Review via email: mp+215934@code.launchpad.net

Commit message

Fixed external functions skip iterator

Description of the change

Fixed external functions skip iterator

To post a comment you must log in.
Revision history for this message
Federico Cavalieri (fcavalieri) wrote :

I found a regression, investigating

11714. By Federico Cavalieri

Fixed external functions skip iterator

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~zorba-coders/zorba/fix-fncall-iterator/+merge/215934 :
Votes: {'Approve': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/fix-fncall-iterator/+merge/215934

Stage "CommitZorba" failed.

Check console output at http://jenkins.lambda.nu:8180/job/CommitZorba/316/console to view the results.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~zorba-coders/zorba/fix-fncall-iterator/+merge/215934 :
Votes: {'Approve': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/fix-fncall-iterator/+merge/215934

Stage "CommitZorba" failed.

Check console output at http://jenkins.lambda.nu:8180/job/CommitZorba/317/console to view the results.

Revision history for this message
Federico Cavalieri (fcavalieri) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/runtime/core/fncall_iterator.cpp'
--- src/runtime/core/fncall_iterator.cpp 2014-02-25 03:58:17 +0000
+++ src/runtime/core/fncall_iterator.cpp 2014-04-15 19:36:22 +0000
@@ -773,7 +773,8 @@
773/*******************************************************************************773/*******************************************************************************
774774
775********************************************************************************/775********************************************************************************/
776ExtFunctionCallIteratorState::ExtFunctionCallIteratorState()776ExtFunctionCallIteratorState::ExtFunctionCallIteratorState():
777 theIsEvaluated(false)
777{778{
778}779}
779780
@@ -796,6 +797,7 @@
796 PlanIteratorState::reset(planState);797 PlanIteratorState::reset(planState);
797 theResultIter = NULL;798 theResultIter = NULL;
798 theResult = NULL;799 theResult = NULL;
800 theIsEvaluated = false;
799}801}
800802
801803
@@ -951,48 +953,43 @@
951 STACK_END( state );953 STACK_END( state );
952}954}
953955
954bool ExtFunctionCallIterator::skip( int64_t count,956bool ExtFunctionCallIterator::skip(int64_t count, PlanState &planState) const
955 PlanState &planState ) const {957{
958 if (count == 0)
959 return true;
960
956 ItemSequence_t api_seq;961 ItemSequence_t api_seq;
957 bool more_items;962 bool more_items;
958963 ExtFunctionCallIteratorState *state =
959 ExtFunctionCallIteratorState *state;964 StateTraitsImpl<ExtFunctionCallIteratorState>::getState(planState, this->theStateOffset);
960 DEFAULT_STACK_INIT( ExtFunctionCallIteratorState, state, planState );965
961966 try
962 try {967 {
963 if ( theFunction->isContextual() ) {968 ZORBA_ASSERT(!state->theIsEvaluated);
964 ContextualExternalFunction const *const f =969 evaluate(state, planState);
965 dynamic_cast<ContextualExternalFunction const*>( theFunction );970
966 ZORBA_ASSERT( f );971 if ( !state->theResult.isNull() )
967 StaticContextImpl sctx(972 {
968 theModuleSctx,973 state->theResultIter = state->theResult->getIterator();
969 planState.theQuery ?974 state->theResultIter->open();
970 planState.theQuery->getRegisteredDiagnosticHandlerNoSync() :975 more_items = state->theResultIter->skip( count );
971 nullptr976 if (!more_items)
972 );977 state->theResultIter->close();
973 DynamicContextImpl dctx(
974 nullptr, planState.theGlobalDynCtx, theModuleSctx
975 );
976 api_seq = f->evaluate( state->m_extArgs, &sctx, &dctx );
977 } else {
978 NonContextualExternalFunction const *const f =
979 dynamic_cast<NonContextualExternalFunction const*>( theFunction );
980 ZORBA_ASSERT( f );
981 api_seq = f->evaluate( state->m_extArgs );
982 }
983 if ( !!api_seq ) {
984 Iterator_t api_iter( api_seq->getIterator() );
985 api_iter->open();
986 more_items = api_iter->skip( count );
987 api_iter->close();
988 }978 }
989 }979 }
990 catch ( ZorbaException &e ) {980 catch ( ZorbaException &e )
981 {
991 set_source( e, loc );982 set_source( e, loc );
992 throw;983 throw;
993 }984 }
994 STACK_PUSH( more_items, state );985 catch (std::exception const& e)
995 STACK_END( state );986 {
987 throw XQUERY_EXCEPTION(
988 zerr::ZXQP0001_DYNAMIC_RUNTIME_ERROR,
989 ERROR_PARAMS(e.what()),
990 ERROR_LOC(loc));
991 }
992 return more_items;
996}993}
997994
998bool ExtFunctionCallIterator::nextImpl(995bool ExtFunctionCallIterator::nextImpl(
@@ -1000,102 +997,109 @@
1000 PlanState& planState) const997 PlanState& planState) const
1001{998{
1002 Item lOutsideItem;999 Item lOutsideItem;
1003 const NonContextualExternalFunction* lPureFct = 0;
1004 const ContextualExternalFunction* lNonePureFct = 0;
10051000
1006 ExtFunctionCallIteratorState* state;1001 ExtFunctionCallIteratorState* state;
1007 DEFAULT_STACK_INIT(ExtFunctionCallIteratorState, state, planState);1002 DEFAULT_STACK_INIT(ExtFunctionCallIteratorState, state, planState);
10081003
1009 try1004 if (!state->theIsEvaluated)
1010 {
1011 if (!theFunction->isContextual())
1012 {
1013 lPureFct = dynamic_cast<const NonContextualExternalFunction*>(theFunction);
1014 ZORBA_ASSERT(lPureFct);
1015
1016 state->theResult = lPureFct->evaluate(state->m_extArgs);
1017 if(state->theResult.get() != NULL)
1018 state->theResultIter = state->theResult->getIterator();
1019 }
1020 else
1021 {
1022 lNonePureFct = dynamic_cast<const ContextualExternalFunction*>(theFunction);
1023 ZORBA_ASSERT(lNonePureFct);
1024
1025 // The planState.theQuery maybe null, e.g. in the case of constant-folding
1026 // of global variable expressions
1027 StaticContextImpl theSctxWrapper(theModuleSctx,
1028 (planState.theQuery == NULL?
1029 NULL :
1030 planState.theQuery->getRegisteredDiagnosticHandlerNoSync()));
1031
1032 DynamicContextImpl theDctxWrapper(NULL,
1033 planState.theGlobalDynCtx,
1034 theModuleSctx);
1035
1036 state->theResult = lNonePureFct->evaluate(state->m_extArgs,
1037 &theSctxWrapper,
1038 &theDctxWrapper);
1039
1040 if(state->theResult.get() != NULL)
1041 state->theResultIter = state->theResult->getIterator();
1042 } // if (!theFunction->isContextual())
1043 }
1044 catch (ZorbaException& e)
1045 {
1046 set_source( e, loc );
1047 throw;
1048 }
1049 catch (std::exception const& e)
1050 {
1051 throw XQUERY_EXCEPTION(
1052 zerr::ZXQP0001_DYNAMIC_RUNTIME_ERROR,
1053 ERROR_PARAMS(e.what()),
1054 ERROR_LOC(loc));
1055 }
1056
1057
1058 if(state->theResult.get() != NULL)
1059 {
1060 state->theResultIter->open();
1061 }
1062 while (true)
1063 {1005 {
1064 try1006 try
1065 {1007 {
1066 if (state->theResult.get() == NULL) // This will happen if the user's external function returns a zorba::ItemSequence_t(NULL)1008 evaluate(state, planState);
1067 break;1009
10681010 if (state->theResult.get() != NULL)
1069 if (!state->theResultIter->next(lOutsideItem))1011 {
1070 {1012 state->theResultIter = state->theResult->getIterator();
1071 state->theResultIter->close();1013 state->theResultIter->open();
1072 break;1014 }
1073 }1015 }
1074 }1016 catch (ZorbaException& e)
1075 catch (XQueryException& e)1017 {
1076 {1018 set_source( e, loc );
1077 set_source( e, loc );1019 throw;
1078 throw;1020 }
1079 }1021 catch (std::exception const& e)
10801022 {
1081 result = Unmarshaller::getInternalItem(lOutsideItem);1023 throw XQUERY_EXCEPTION(
10821024 zerr::ZXQP0001_DYNAMIC_RUNTIME_ERROR,
1083 if (theIsUpdating)1025 ERROR_PARAMS(e.what()),
1084 {1026 ERROR_LOC(loc));
1085 if (!result->isPul())1027 }
1086 throw XQUERY_EXCEPTION(err::XUDY0019, ERROR_LOC(loc));1028 }
1087 }1029
1088 else1030 if (!state->theResult.isNull() && //The external function returns zorba::ItemSequence_t(NULL)
1089 {1031 state->theResultIter->isOpen()) //The iterator has not been skipped past its end
1090 if (result->isPul())1032 {
1091 throw XQUERY_EXCEPTION(err::XUDY0018, ERROR_LOC(loc));1033 while (true)
1092 }1034 {
1093 STACK_PUSH(true, state);1035 try
1094 }1036 {
10951037 if (!state->theResultIter->next(lOutsideItem))
1038 {
1039 state->theResultIter->close();
1040 break;
1041 }
1042 }
1043 catch (XQueryException& e)
1044 {
1045 set_source( e, loc );
1046 throw;
1047 }
1048 catch (std::exception const& e)
1049 {
1050 throw XQUERY_EXCEPTION(
1051 zerr::ZXQP0001_DYNAMIC_RUNTIME_ERROR,
1052 ERROR_PARAMS(e.what()),
1053 ERROR_LOC(loc));
1054 }
1055
1056 result = Unmarshaller::getInternalItem(lOutsideItem);
1057
1058 if (theIsUpdating)
1059 {
1060 if (!result->isPul())
1061 throw XQUERY_EXCEPTION(err::XUDY0019, ERROR_LOC(loc));
1062 }
1063 else
1064 {
1065 if (result->isPul())
1066 throw XQUERY_EXCEPTION(err::XUDY0018, ERROR_LOC(loc));
1067 }
1068 STACK_PUSH(true, state);
1069 }
1070 }
1096 STACK_END (state);1071 STACK_END (state);
1097}1072}
10981073
1074void ExtFunctionCallIterator::evaluate(ExtFunctionCallIteratorState* state, PlanState& planState) const
1075{
1076 if ( theFunction->isContextual() )
1077 {
1078 ContextualExternalFunction const *const lFunction =
1079 dynamic_cast<ContextualExternalFunction const*>( theFunction );
1080 ZORBA_ASSERT( lFunction );
1081
1082 StaticContextImpl lSctx(theModuleSctx,
1083 planState.theQuery ?
1084 planState.theQuery->getRegisteredDiagnosticHandlerNoSync():
1085 nullptr);
1086
1087 DynamicContextImpl lDctx(nullptr,
1088 planState.theGlobalDynCtx,
1089 theModuleSctx);
1090
1091 state->theResult = lFunction->evaluate( state->m_extArgs, &lSctx, &lDctx );
1092 }
1093 else
1094 {
1095 NonContextualExternalFunction const *const lFunction =
1096 dynamic_cast<NonContextualExternalFunction const*>( theFunction );
1097 ZORBA_ASSERT( lFunction );
1098
1099 state->theResult = lFunction->evaluate( state->m_extArgs );
1100 }
1101 state->theIsEvaluated = true;
1102}
10991103
1100NARY_ACCEPT(ExtFunctionCallIterator);1104NARY_ACCEPT(ExtFunctionCallIterator);
11011105
11021106
=== modified file 'src/runtime/core/fncall_iterator.h'
--- src/runtime/core/fncall_iterator.h 2014-02-12 02:25:45 +0000
+++ src/runtime/core/fncall_iterator.h 2014-04-15 19:36:22 +0000
@@ -215,6 +215,7 @@
215 std::vector<ItemSequence*> m_extArgs;215 std::vector<ItemSequence*> m_extArgs;
216 ItemSequence_t theResult;216 ItemSequence_t theResult;
217 Iterator_t theResultIter;217 Iterator_t theResultIter;
218 bool theIsEvaluated;
218219
219 ExtFunctionCallIteratorState();220 ExtFunctionCallIteratorState();
220221
@@ -265,7 +266,11 @@
265 bool nextImpl(store::Item_t& result, PlanState& planState) const;266 bool nextImpl(store::Item_t& result, PlanState& planState) const;
266267
267 bool count(store::Item_t& result, PlanState& planState) const;268 bool count(store::Item_t& result, PlanState& planState) const;
269
268 bool skip(int64_t count, PlanState &planState) const;270 bool skip(int64_t count, PlanState &planState) const;
271
272private:
273 void evaluate(ExtFunctionCallIteratorState* state, PlanState& planState) const;
269};274};
270275
271}276}
272277
=== added file 'test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines-2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines-2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/file/file_read_text_lines-2.xml.res 2014-04-15 19:36:22 +0000
@@ -0,0 +1,1 @@
1&lt;products&gt; &lt;product&gt;
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/file/file_read_text_lines-2.xq'
--- test/rbkt/Queries/zorba/file/file_read_text_lines-2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/file/file_read_text_lines-2.xq 2014-04-15 19:36:22 +0000
@@ -0,0 +1,4 @@
1import module namespace file = "http://expath.org/ns/file";
2
3file:read-text-lines(fn:resolve-uri("mydata.xml"))[1],
4file:read-text-lines(fn:resolve-uri("mydata.xml"))[2]

Subscribers

People subscribed via source and target branches