Merge lp:~zorba-coders/zorba/bug1064978 into lp:zorba

Proposed by Juan Zacarias
Status: Needs review
Proposed branch: lp:~zorba-coders/zorba/bug1064978
Merge into: lp:zorba
Diff against target: 367 lines (+202/-38)
11 files modified
include/zorba/static_context.h (+12/-0)
modules/xqxq/xqxq.xq (+18/-3)
modules/xqxq/xqxq.xq.src/xqxq.cpp (+47/-2)
modules/xqxq/xqxq.xq.src/xqxq.h (+56/-32)
src/api/dynamiccontextimpl.cpp (+0/-1)
src/api/staticcontextimpl.cpp (+46/-0)
src/api/staticcontextimpl.h (+3/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/variable-type-name.xml.res (+1/-0)
test/rbkt/Queries/zorba/xqxq/variable-type-name.xq (+13/-0)
test/rbkt/Queries/zorba/xqxq/variable-type-name2.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/variable-type-name2.xq (+5/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug1064978
Reviewer Review Type Date Requested Status
Matthias Brantner Needs Fixing
Sorin Marian Nasoi Approve
Chris Hillery Approve
Review via email: mp+150696@code.launchpad.net

Commit message

Implementation of features requested in bug1064978 xqxq: add new bind-variable signature
* Added to the DynamicContext API getVariableType function.
* Added xqxq module function xqxq:variable-type.
* Added xqxq module function xqxq:set-variable.

Description of the change

Implementation of features requested in bug1064978 xqxq: add new bind-variable signature
* Added to the DynamicContext API getVariableType function.
* Added xqxq module function xqxq:variable-type.
* Added xqxq module function xqxq:set-variable.

To post a comment you must log in.
Revision history for this message
Juan Zacarias (juan457) wrote :

This is a proposal for solving the requested issue with current bind-variables.

This new function called xqxq:set-variable($query-key as xs:anyURI, $var-name as xs:QName, $value as xs:string*)

fulfills the requested feature of casting an xs:string to the corresponding type of a defined external variable.
To be able to create this function a new function to the DynamicContext API had to be added, the function is called getValueType which returns a string of the type a given variable QName.
And then bringing this function to the xqxq module with the name xqxq:variable-type.

I am not sure about the name set-variable since is different from bind-variable. Would appreciate suggestions on how to name this new function.

Revision history for this message
Chris Hillery (ceejatec) wrote :

1. Need some test cases of this functionality, including error conditions, for both new functions.

2. For the element() case, I think you should use the x:parse() function in the built-in XML module (http://www.zorba-xquery.com/modules/xml) with the "parse-external-parsed-entity" option. I'm not sure it'll make a difference, honestly, but it's slightly more correct.

3. I agree set-variable() isn't a great name. It should be more explicit that it is doing casting. Maybe bind-cast-variable() ?

4. It'd be nice if you could support eg. xs:integer+, and all known schema simple types. I have a suggestion - in xqxq:bind-cast-variable(), first check for object/array/element/document-node, and then for any other type, use XQXQ to let XQuery itself do the casting. You'll need to first strip the quantifier from the type string, and then construct a query that does the casting. This should work:

  variable $unquanttype := fn:replace($type, "[*?+]$", "");
  variable $caster := xq := xqxq:prepare-main-module(
     fn:concat("declare variable $val as xs:string* external; ",
               "for $v in $val return $v cast as ",
               $unquanttype));
  xqxq:bind-variable($caster, xs:QName("val"), $value);
  xqxq:evaluate($caster)

The result of that will be the $casted-value. It'd probably be a good idea to explicitly call xqxq:delete-query($caster) also.

review: Needs Fixing
Revision history for this message
Juan Zacarias (juan457) wrote :

The changes suggested by Chris have been included can you review again?

Revision history for this message
Chris Hillery (ceejatec) wrote :

Looks good!

review: Approve
Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug1064978 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug1064978-2013-04-11T00-04-50.241Z is finished. The
  final status was:

  184 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

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

The attempt to merge lp:~zorba-coders/zorba/bug1064978 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job bug1064978-2013-04-11T16-31-07.189Z is finished. The
  final status was:

  184 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

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

I don't think the bind-cast-variable should go in this module. It's clearly a convenient function that the user can write as well. As such, it would be OK but it adds an XML dependency to the module which is something that we don't want.

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

From the documentation, it's not clear what format the outType is. Is it a QName, EQName, or even a sequence type? In either case, it should probably be of type Item or a TypeIdentifier.

review: Needs Information
Revision history for this message
Juan Zacarias (juan457) wrote :

So, should I remove the xml dependency from the function? or should I remove the whole function?
If we remove the function the user should be able to create the same function by themselves using xqxq:get-type-variable
I will make the changes to getVariableType so it returns a TypeIdentifier or Item and make the documentation clearer.

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

> So, should I remove the xml dependency from the function? or should I remove
> the whole function?
> If we remove the function the user should be able to create the same function
> by themselves using xqxq:get-type-variable
I think we should remove the entire function. It leaves to many unanswered questions. For example,
what if the user wants to pass other parameters to the parse-fragment function or what if the user wants to validate items before passing them as arguments?

lp:~zorba-coders/zorba/bug1064978 updated
11264. By Juan Zacarias

Changed implementation of Dynamic context function getVariableType to return an Item instead of a zorba::String, also updated function Documentation to make clear what it returns.

11265. By Juan Zacarias

Removed Implementation of xqxq function bind-cast-variable

Revision history for this message
Juan Zacarias (juan457) wrote :

> > So, should I remove the xml dependency from the function? or should I remove
> > the whole function?
> > If we remove the function the user should be able to create the same
> function
> > by themselves using xqxq:get-type-variable
> I think we should remove the entire function. It leaves to many unanswered
> questions. For example,
> what if the user wants to pass other parameters to the parse-fragment function
> or what if the user wants to validate items before passing them as arguments?

So I made the following changes:
*Removed the implementation of bind-cast-variable
*Changed the return value of getVariableType from zorba::String to a string Item since if the function returns a TypeIdentifier getting a legible type of the variable is lost, unless there is a way to get the schema String from a typeIdentifier?

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

> > > So, should I remove the xml dependency from the function? or should I
> remove
> > > the whole function?
> > > If we remove the function the user should be able to create the same
> > function
> > > by themselves using xqxq:get-type-variable
> > I think we should remove the entire function. It leaves to many unanswered
> > questions. For example,
> > what if the user wants to pass other parameters to the parse-fragment
> function
> > or what if the user wants to validate items before passing them as
> arguments?
>
> So I made the following changes:
> *Removed the implementation of bind-cast-variable
> *Changed the return value of getVariableType from zorba::String to a string
> Item since if the function returns a TypeIdentifier getting a legible type of
> the variable is lost, unless there is a way to get the schema String from a
> typeIdentifier?
I think a string item doesn't make a difference. The type of a variable is a sequence type that consists of a QName and an occurrence indicator. Just having the name doesn't really help. What do you think is missing from the TypeIdentifier? It allows you to retrieve the URI, local name, and quantifier. What am I missing?

Revision history for this message
Juan Zacarias (juan457) wrote :

> > > > So, should I remove the xml dependency from the function? or should I
> > remove
> > > > the whole function?
> > > > If we remove the function the user should be able to create the same
> > > function
> > > > by themselves using xqxq:get-type-variable
> > > I think we should remove the entire function. It leaves to many unanswered
> > > questions. For example,
> > > what if the user wants to pass other parameters to the parse-fragment
> > function
> > > or what if the user wants to validate items before passing them as
> > arguments?
> >
> > So I made the following changes:
> > *Removed the implementation of bind-cast-variable
> > *Changed the return value of getVariableType from zorba::String to a string
> > Item since if the function returns a TypeIdentifier getting a legible type
> of
> > the variable is lost, unless there is a way to get the schema String from a
> > typeIdentifier?
> I think a string item doesn't make a difference. The type of a variable is a
> sequence type that consists of a QName and an occurrence indicator. Just
> having the name doesn't really help. What do you think is missing from the
> TypeIdentifier? It allows you to retrieve the URI, local name, and quantifier.
> What am I missing?

There are 2 things I miss information about typeIdentifier:
1. how to create a TypeIdentifier from a XQType
2. The function of xqxq is supposed to return the string of type function so getVariableType is returning the XQType toSchemaString so that the user can actually use it to cast the values of the variable, now does a typeIdentifier has a value like that? Does the localname represents that?

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

> > > > > So, should I remove the xml dependency from the function? or should I
> > > remove
> > > > > the whole function?
> > > > > If we remove the function the user should be able to create the same
> > > > function
> > > > > by themselves using xqxq:get-type-variable
> > > > I think we should remove the entire function. It leaves to many
> unanswered
> > > > questions. For example,
> > > > what if the user wants to pass other parameters to the parse-fragment
> > > function
> > > > or what if the user wants to validate items before passing them as
> > > arguments?
> > >
> > > So I made the following changes:
> > > *Removed the implementation of bind-cast-variable
> > > *Changed the return value of getVariableType from zorba::String to a
> string
> > > Item since if the function returns a TypeIdentifier getting a legible type
> > of
> > > the variable is lost, unless there is a way to get the schema String from
> a
> > > typeIdentifier?
> > I think a string item doesn't make a difference. The type of a variable is a
> > sequence type that consists of a QName and an occurrence indicator. Just
> > having the name doesn't really help. What do you think is missing from the
> > TypeIdentifier? It allows you to retrieve the URI, local name, and
> quantifier.
> > What am I missing?
>
> There are 2 things I miss information about typeIdentifier:
> 1. how to create a TypeIdentifier from a XQType
Take a look at CollectionImpl::getType in src/api/collectionimpl.cpp.

> 2. The function of xqxq is supposed to return the string of type function so
> getVariableType is returning the XQType toSchemaString so that the user can
> actually use it to cast the values of the variable, now does a typeIdentifier
> has a value like that? Does the localname represents that?
The problem is that there is no representation of types in the data model. To answer the question we need to investigate the use case. I think the function should either (1) return a QName item that represents the name of the type (maybe renaming the function to getVariablePrimeType) or (2) return a string using the sequence-type syntax (e.g. xs:string*, xs:integer?, or Q{http://foo.bar}my-type*).

Revision history for this message
Juan Zacarias (juan457) wrote :
Download full text (3.3 KiB)

> > > > > > So, should I remove the xml dependency from the function? or should
> I
> > > > remove
> > > > > > the whole function?
> > > > > > If we remove the function the user should be able to create the same
> > > > > function
> > > > > > by themselves using xqxq:get-type-variable
> > > > > I think we should remove the entire function. It leaves to many
> > unanswered
> > > > > questions. For example,
> > > > > what if the user wants to pass other parameters to the parse-fragment
> > > > function
> > > > > or what if the user wants to validate items before passing them as
> > > > arguments?
> > > >
> > > > So I made the following changes:
> > > > *Removed the implementation of bind-cast-variable
> > > > *Changed the return value of getVariableType from zorba::String to a
> > string
> > > > Item since if the function returns a TypeIdentifier getting a legible
> type
> > > of
> > > > the variable is lost, unless there is a way to get the schema String
> from
> > a
> > > > typeIdentifier?
> > > I think a string item doesn't make a difference. The type of a variable is
> a
> > > sequence type that consists of a QName and an occurrence indicator. Just
> > > having the name doesn't really help. What do you think is missing from the
> > > TypeIdentifier? It allows you to retrieve the URI, local name, and
> > quantifier.
> > > What am I missing?
> >
> > There are 2 things I miss information about typeIdentifier:
> > 1. how to create a TypeIdentifier from a XQType
> Take a look at CollectionImpl::getType in src/api/collectionimpl.cpp.
>
> > 2. The function of xqxq is supposed to return the string of type function so
> > getVariableType is returning the XQType toSchemaString so that the user can
> > actually use it to cast the values of the variable, now does a
> typeIdentifier
> > has a value like that? Does the localname represents that?
> The problem is that there is no representation of types in the data model. To
> answer the question we need to investigate the use case. I think the function
> should either (1) return a QName item that represents the name of the type
> (maybe renaming the function to getVariablePrimeType) or (2) return a string
> using the sequence-type syntax (e.g. xs:string*, xs:integer?, or
> Q{http://foo.bar}my-type*).

As for the purpose of the function, is to allow the user a tool so he can cast a string value into the corresponding type of external variable, that's why we need the function to return something logical in string which in this case the schema string of the type fits perfectly, so an actual type representation of the function is not that helpful if is not usable to cast the variable.

So let me see if I understand your points the first one, is to rename the function (which is appropriate) and to instead of returning the string item with the value turn it into a QName my only question would be the namespace of this QName should it be the same of the external variable? or a new namespace referring to this primetype, also I am guessing that the localname would be the schema string of the type.
As for your second suggestion I don't understand what you mean by it, are you talking about the xqxq.xq description o...

Read more...

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :
Download full text (3.6 KiB)

> > > > > > > So, should I remove the xml dependency from the function? or
> should
> > I
> > > > > remove
> > > > > > > the whole function?
> > > > > > > If we remove the function the user should be able to create the
> same
> > > > > > function
> > > > > > > by themselves using xqxq:get-type-variable
> > > > > > I think we should remove the entire function. It leaves to many
> > > unanswered
> > > > > > questions. For example,
> > > > > > what if the user wants to pass other parameters to the parse-
> fragment
> > > > > function
> > > > > > or what if the user wants to validate items before passing them as
> > > > > arguments?
> > > > >
> > > > > So I made the following changes:
> > > > > *Removed the implementation of bind-cast-variable
> > > > > *Changed the return value of getVariableType from zorba::String to a
> > > string
> > > > > Item since if the function returns a TypeIdentifier getting a legible
> > type
> > > > of
> > > > > the variable is lost, unless there is a way to get the schema String
> > from
> > > a
> > > > > typeIdentifier?
> > > > I think a string item doesn't make a difference. The type of a variable
> is
> > a
> > > > sequence type that consists of a QName and an occurrence indicator. Just
> > > > having the name doesn't really help. What do you think is missing from
> the
> > > > TypeIdentifier? It allows you to retrieve the URI, local name, and
> > > quantifier.
> > > > What am I missing?
> > >
> > > There are 2 things I miss information about typeIdentifier:
> > > 1. how to create a TypeIdentifier from a XQType
> > Take a look at CollectionImpl::getType in src/api/collectionimpl.cpp.
> >
> > > 2. The function of xqxq is supposed to return the string of type function
> so
> > > getVariableType is returning the XQType toSchemaString so that the user
> can
> > > actually use it to cast the values of the variable, now does a
> > typeIdentifier
> > > has a value like that? Does the localname represents that?
> > The problem is that there is no representation of types in the data model.
> To
> > answer the question we need to investigate the use case. I think the
> function
> > should either (1) return a QName item that represents the name of the type
> > (maybe renaming the function to getVariablePrimeType) or (2) return a string
> > using the sequence-type syntax (e.g. xs:string*, xs:integer?, or
> > Q{http://foo.bar}my-type*).
>
> As for the purpose of the function, is to allow the user a tool so he can cast
> a string value into the corresponding type of external variable, that's why we
> need the function to return something logical in string which in this case the
> schema string of the type fits perfectly, so an actual type representation of
> the function is not that helpful if is not usable to cast the variable.
>
> So let me see if I understand your points the first one, is to rename the
> function (which is appropriate) and to instead of returning the string item
> with the value turn it into a QName my only question would be the namespace of
> this QName should it be the same of the external variable? or a new namespace
> referring to this primetype, also I am guessing that the localname would be
> the sc...

Read more...

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

I talked to Markos and there are some more issues here.

1. The function should probably go into the static context instead of the dynamic context.
2. It really depends on what you want to cast to. In general, the target type for casting is a sequence type (e.g. node()*, or xs:string?). As already mentioned, this cannot be returned as an item other than a string. If you did that, it pushes a lot of effort to the consumer because he needs to parse the sequence-type. There are two alternatives:
  - xqxq:variable-type-name($name as xs:QName) as xs:QName? which returns the name of type (e.g. no node()*)
  - xqxq:variable-sequence-type($name as xs:QName) as xs:string? which returns the sequence type as a string.

It really depends on exactly what the user needs. I would go with variable-type-name if that's sufficient for all FOTS use cases.

Revision history for this message
Juan Zacarias (juan457) wrote :

> I talked to Markos and there are some more issues here.
>
> 1. The function should probably go into the static context instead of the
> dynamic context.
But the Static context doesn't have functions to access the external variables, so if this function is to be implemented in the static context it would actually be using several functions of the dynamic context to work. Since the external variable are part of the Dynamic context isn't it better to just leave them there?

> 2. It really depends on what you want to cast to. In general, the target type
> for casting is a sequence type (e.g. node()*, or xs:string?). As already
> mentioned, this cannot be returned as an item other than a string. If you did
> that, it pushes a lot of effort to the consumer because he needs to parse the
> sequence-type. There are two alternatives:
> - xqxq:variable-type-name($name as xs:QName) as xs:QName? which returns the
> name of type (e.g. no node()*)
> - xqxq:variable-sequence-type($name as xs:QName) as xs:string? which returns
> the sequence type as a string.
>
> It really depends on exactly what the user needs. I would go with variable-
> type-name if that's sufficient for all FOTS use cases.
I will go ahead and make the change for it to return of a QName

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

> > I talked to Markos and there are some more issues here.
> >
> > 1. The function should probably go into the static context instead of the
> > dynamic context.
> But the Static context doesn't have functions to access the external
> variables, so if this function is to be implemented in the static context it
> would actually be using several functions of the dynamic context to work.
> Since the external variable are part of the Dynamic context isn't it better to
> just leave them there?
As I said, it doesn't belong there. If you want to have it in the dynamic context
you should only invoke it after execution.
I think you should use VarInfo* lookup_var(const store::Item* qname) const;
VarInfo contains the type of the variable.

>
> > 2. It really depends on what you want to cast to. In general, the target
> type
> > for casting is a sequence type (e.g. node()*, or xs:string?). As already
> > mentioned, this cannot be returned as an item other than a string. If you
> did
> > that, it pushes a lot of effort to the consumer because he needs to parse
> the
> > sequence-type. There are two alternatives:
> > - xqxq:variable-type-name($name as xs:QName) as xs:QName? which returns
> the
> > name of type (e.g. no node()*)
> > - xqxq:variable-sequence-type($name as xs:QName) as xs:string? which
> returns
> > the sequence type as a string.
> >
> > It really depends on exactly what the user needs. I would go with variable-
> > type-name if that's sufficient for all FOTS use cases.
> I will go ahead and make the change for it to return of a QName
Double check with Sorin whether he really doesn't need the occurrence indicator for casting.

lp:~zorba-coders/zorba/bug1064978 updated
11266. By Juan Zacarias

Renamed DynamicContext Function getVariableType to getVariablePrimeType it also returns a QName Item now.
XQXQ function xqxq:variable-type renamed to xqxq:variable-type-name it also returns a xs:QName.

Revision history for this message
Juan Zacarias (juan457) wrote :

> > > I talked to Markos and there are some more issues here.
> > >
> > > 1. The function should probably go into the static context instead of the
> > > dynamic context.
> > But the Static context doesn't have functions to access the external
> > variables, so if this function is to be implemented in the static context it
> > would actually be using several functions of the dynamic context to work.
> > Since the external variable are part of the Dynamic context isn't it better
> to
> > just leave them there?
> As I said, it doesn't belong there. If you want to have it in the dynamic
> context
> you should only invoke it after execution.
> I think you should use VarInfo* lookup_var(const store::Item* qname) const;
> VarInfo contains the type of the variable.
Oh that makes sense I will make it static context then.

>
> >
> > > 2. It really depends on what you want to cast to. In general, the target
> > type
> > > for casting is a sequence type (e.g. node()*, or xs:string?). As already
> > > mentioned, this cannot be returned as an item other than a string. If you
> > did
> > > that, it pushes a lot of effort to the consumer because he needs to parse
> > the
> > > sequence-type. There are two alternatives:
> > > - xqxq:variable-type-name($name as xs:QName) as xs:QName? which returns
> > the
> > > name of type (e.g. no node()*)
> > > - xqxq:variable-sequence-type($name as xs:QName) as xs:string? which
> > returns
> > > the sequence type as a string.
> > >
> > > It really depends on exactly what the user needs. I would go with
> variable-
> > > type-name if that's sufficient for all FOTS use cases.
> > I will go ahead and make the change for it to return of a QName
> Double check with Sorin whether he really doesn't need the occurrence
> indicator for casting.

The current implementation does return the occurrence indicator

lp:~zorba-coders/zorba/bug1064978 updated
11267. By Juan Zacarias

Changed DynamicContext getVariablePrimeType Function to the StaticContext.

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

the build doesn't work for me:

/home/mbrantner/zorba/sandbox/src/api/staticcontextimpl.cpp: In member function 'virtual zorba::Item zorba::StaticContextImpl::getVariablePrimeType(const zorba::Item&)':
/home/mbrantner/zorba/sandbox/src/api/staticcontextimpl.cpp:1808:12: error: could not convert 'type' from 'zorba::store::Item_t {aka zorba::store::ItemHandle<zorba::store::Item>}' to 'zorba::Item'

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

import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';

variable $queryID := xqxq:prepare-main-module('declare variable $ext2 external; $ext2');

fn:local-name-from-QName(xqxq:variable-type-name($queryID, xs:QName('ext2')))

returns xs:anyType. Shouldn't it be anyType? I think the QName is not constructed
correctly.

xs:anyType should not be a string constant in the code. I think this should come from the typemanager.

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

> the build doesn't work for me:
>
> /home/mbrantner/zorba/sandbox/src/api/staticcontextimpl.cpp: In member
> function 'virtual zorba::Item
> zorba::StaticContextImpl::getVariablePrimeType(const zorba::Item&)':
> /home/mbrantner/zorba/sandbox/src/api/staticcontextimpl.cpp:1808:12: error:
> could not convert 'type' from 'zorba::store::Item_t {aka
> zorba::store::ItemHandle<zorba::store::Item>}' to 'zorba::Item'

I pushed a fix for the build.

lp:~zorba-coders/zorba/bug1064978 updated
11268. By Matthias Brantner

fix build on linux

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

import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';

variable $queryID := xqxq:prepare-main-module('declare variable $ext2 as xs:integer? external; $ext2');

fn:local-name-from-QName(xqxq:variable-type-name($queryID, xs:QName('ext2')))

returns
xs:integer?.

That's not a local-name.

review: Needs Fixing
Revision history for this message
Juan Zacarias (juan457) wrote :

> import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
>
> variable $queryID := xqxq:prepare-main-module('declare variable $ext2
> external; $ext2');
>
> fn:local-name-from-QName(xqxq:variable-type-name($queryID, xs:QName('ext2')))
>
> returns xs:anyType. Shouldn't it be anyType? I think the QName is not
> constructed
> correctly.
What do you mean is not being constructed correctly?

>
> xs:anyType should not be a string constant in the code. I think this should
> come from the typemanager.
The thing with the variables that doesn't have a type specified in code when asked about the XQType of the variable using the function var->getType it returns a NULL pointer that is why a set a constant value of xs:anyType, now you don't want this to be constant what should I do then? create a new any type XQType variable using the TypeManager and return it's schemaString()?

lp:~zorba-coders/zorba/bug1064978 updated
11269. By Juan Zacarias

Static Context's getVariablePrimeType function removed constant string return when the requested variable has no type, the value comes now from the typemanager.

Revision history for this message
Juan Zacarias (juan457) wrote :

This changes remove the constant return String on xs:anyType it now uses the type manager to create an anyType item type and return it's string value.

With this change the query you mentioned using local-name-from-QName works correctly.

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

Why don't you use XQType::getQName to get the QName directly and return it?

Revision history for this message
Juan Zacarias (juan457) wrote :

> Why don't you use XQType::getQName to get the QName directly and return it?
Because if the type is not atomic, if it is an element or an object it throws a zorba exception.

Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) wrote :

Unmerged revisions

11269. By Juan Zacarias

Static Context's getVariablePrimeType function removed constant string return when the requested variable has no type, the value comes now from the typemanager.

11268. By Matthias Brantner

fix build on linux

11267. By Juan Zacarias

Changed DynamicContext getVariablePrimeType Function to the StaticContext.

11266. By Juan Zacarias

Renamed DynamicContext Function getVariableType to getVariablePrimeType it also returns a QName Item now.
XQXQ function xqxq:variable-type renamed to xqxq:variable-type-name it also returns a xs:QName.

11265. By Juan Zacarias

Removed Implementation of xqxq function bind-cast-variable

11264. By Juan Zacarias

Changed implementation of Dynamic context function getVariableType to return an Item instead of a zorba::String, also updated function Documentation to make clear what it returns.

11263. By Juan Zacarias

Fix for merging with trunk caused errors.

11262. By Juan Zacarias

merge with trunk

11261. By Juan Zacarias

Added new test for xqxq

11260. By Chris Hillery

Removing Windows linefeeds.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/zorba/static_context.h'
2--- include/zorba/static_context.h 2013-03-25 23:02:19 +0000
3+++ include/zorba/static_context.h 2013-04-30 19:07:30 +0000
4@@ -813,6 +813,18 @@
5 */
6 virtual bool
7 setDefaultFunctionNamespaces( const std::vector<String>& aURIs ) = 0;
8+
9+ /** \brief Returns the type of an external variable as a QName.
10+ *
11+ * The named external variable may be located in the main query or in any
12+ * modules imported directly or indirectly by the query.
13+ *
14+ * @param the variable's QName
15+ * @return the QName of the variable type if it has been retrieved successfully, a NULL Item otherwise.
16+ * @throw ZorbaException if an error occured.
17+ */
18+ virtual Item
19+ getVariablePrimeType(const Item& aQName) = 0;
20 };
21
22 } /* namespace zorba */
23
24=== modified file 'modules/xqxq/xqxq.xq'
25--- modules/xqxq/xqxq.xq 2013-04-09 14:22:41 +0000
26+++ modules/xqxq/xqxq.xq 2013-04-30 19:07:30 +0000
27@@ -285,7 +285,6 @@
28 declare %an:sequential function xqxq:bind-variable($query-key as xs:anyURI,
29 $var as xs:QName, $value as item()*) as empty-sequence() external ;
30
31-
32 (:~
33 : Evaluates the given prepared query and returns the result
34 : of the evaluation. The query must not be sequential or
35@@ -387,6 +386,23 @@
36 xs:QName) as item()* external;
37
38 (:~
39+ : This function returns the type of a variable that is bound in the
40+ : given query.
41+ :
42+ : @param $query-key the identifier of a compiled query.
43+ : @param $var-name the name of the variable whose value should be returned.
44+ :
45+ : @return the type of the given variable.
46+ :
47+ : @error xqxq:NoQueryMatch if no query with the given identifier
48+ : was prepared.
49+ : @error xqxq:UndeclaredVariable if the given variable is not declared
50+ : in the query.
51+ : @error xqxq:UnboundVariable if the given variable doesn't have a value.
52+ :)
53+declare function xqxq:variable-type-name($query-key as xs:anyURI, $var-name as
54+ xs:QName) as xs:QName external;
55+(:~
56 : Returns the compiled query identified by the given query-key
57 : as binary data.
58 :
59@@ -400,8 +416,7 @@
60 :)
61 declare function xqxq:query-plan($query-key as xs:anyURI)
62 as xs:base64Binary external;
63-
64-
65+
66 (:~
67 : The function loads a given XQuery program for execution from a
68 : xs:base64Binary query plan, obtained through the xqxq:query-plan function.
69
70=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
71--- modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-04-15 12:07:41 +0000
72+++ modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-04-30 19:07:30 +0000
73@@ -85,7 +85,11 @@
74 {
75 lFunc = new VariableValueFunction(this);
76 }
77- else if (localName == "query-plan")
78+ else if (localName == "variable-type-name")
79+ {
80+ lFunc = new VariableTypeFunction(this);
81+ }
82+ else if (localName == "query-plan")
83 {
84 lFunc = new QueryPlanFunction(this);
85 }
86@@ -975,6 +979,48 @@
87 /*******************************************************************************
88
89 ********************************************************************************/
90+zorba::ItemSequence_t VariableTypeFunction::evaluate(
91+ const Arguments_t& aArgs,
92+ const zorba::StaticContext* aSctx,
93+ const zorba::DynamicContext* aDctx) const
94+{
95+ String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
96+
97+ QueryMap* lQueryMap;
98+ if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
99+ {
100+ throwError("NoQueryMatch", "String identifying query does not exists.");
101+ }
102+
103+ XQuery_t lQuery = getQuery(aDctx, lQueryID);
104+
105+ Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
106+ zorba::StaticContext* lSctx = const_cast<StaticContext*>(lQuery->getStaticContext());
107+
108+ Item lType;
109+ try
110+ {
111+ lType = lSctx->getVariablePrimeType(lVarQName);
112+ if(lType.isNull())
113+ {
114+ std::ostringstream lMsg;
115+ lMsg << lVarQName.getLocalName() << ": variable not bound";
116+ XQXQFunction::throwError("UndeclaredVariable", lMsg.str());
117+ }
118+ }
119+ catch (ZorbaException& ze)
120+ {
121+ if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
122+ XQXQFunction::throwError("UndeclaredVariable", ze.what());
123+ throw; // should not happen
124+ }
125+ return ItemSequence_t(new SingletonItemSequence(lType));
126+}
127+
128+
129+/*******************************************************************************
130+
131+********************************************************************************/
132 zorba::ItemSequence_t QueryPlanFunction::evaluate(
133 const Arguments_t& aArgs,
134 const zorba::StaticContext* aSctx,
135@@ -999,7 +1045,6 @@
136
137 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createStreamableBase64Binary(*lExcPlan.release(), &streamReleaser)));
138 }
139-
140
141 /*******************************************************************************
142
143
144=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.h'
145--- modules/xqxq/xqxq.xq.src/xqxq.h 2013-04-15 12:07:41 +0000
146+++ modules/xqxq/xqxq.xq.src/xqxq.h 2013-04-30 19:07:30 +0000
147@@ -531,38 +531,62 @@
148 const zorba::DynamicContext*) const;
149 };
150
151- class VariableValueFunction : public XQXQFunction{
152- protected:
153- class ValueItemSequence : public ItemSequence
154- {
155- protected:
156- Iterator_t theIterator;
157-
158- public:
159- ValueItemSequence(Iterator_t& aIter)
160- : theIterator(aIter)
161- {
162- }
163-
164- virtual ~ValueItemSequence(){}
165-
166- Iterator_t
167- getIterator() { return theIterator; }
168-
169- };
170- public:
171- VariableValueFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
172-
173- virtual ~VariableValueFunction() {}
174-
175- virtual zorba::String
176- getLocalName() const {return "variable-value"; }
177-
178- virtual zorba::ItemSequence_t
179- evaluate(const Arguments_t&,
180- const zorba::StaticContext*,
181- const zorba::DynamicContext*) const;
182- };
183+
184+/*******************************************************************************
185+
186+********************************************************************************/
187+class VariableValueFunction : public XQXQFunction{
188+ protected:
189+ class ValueItemSequence : public ItemSequence
190+ {
191+ protected:
192+ Iterator_t theIterator;
193+
194+ public:
195+ ValueItemSequence(Iterator_t& aIter)
196+ : theIterator(aIter)
197+ {
198+ }
199+
200+ virtual ~ValueItemSequence(){}
201+
202+ Iterator_t
203+ getIterator() { return theIterator; }
204+
205+ };
206+ public:
207+ VariableValueFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
208+
209+ virtual ~VariableValueFunction() {}
210+
211+ virtual zorba::String
212+ getLocalName() const {return "variable-value"; }
213+
214+ virtual zorba::ItemSequence_t
215+ evaluate(const Arguments_t&,
216+ const zorba::StaticContext*,
217+ const zorba::DynamicContext*) const;
218+};
219+
220+
221+/*******************************************************************************
222+
223+********************************************************************************/
224+class VariableTypeFunction : public XQXQFunction
225+{
226+public:
227+ VariableTypeFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
228+
229+ virtual ~VariableTypeFunction() {}
230+
231+ virtual zorba::String
232+ getLocalName() const {return "variable-type-name"; }
233+
234+ virtual zorba::ItemSequence_t
235+ evaluate(const Arguments_t&,
236+ const zorba::StaticContext*,
237+ const zorba::DynamicContext*) const;
238+};
239
240 /*******************************************************************************
241
242
243=== modified file 'src/api/dynamiccontextimpl.cpp'
244--- src/api/dynamiccontextimpl.cpp 2013-04-25 20:41:11 +0000
245+++ src/api/dynamiccontextimpl.cpp 2013-04-30 19:07:30 +0000
246@@ -184,7 +184,6 @@
247 return var;
248 }
249
250-
251 /****************************************************************************//**
252
253 ********************************************************************************/
254
255=== modified file 'src/api/staticcontextimpl.cpp'
256--- src/api/staticcontextimpl.cpp 2013-03-25 23:02:19 +0000
257+++ src/api/staticcontextimpl.cpp 2013-04-30 19:07:30 +0000
258@@ -1769,5 +1769,51 @@
259 }
260 }
261
262+Item
263+StaticContextImpl::getVariablePrimeType(
264+ const Item& aQName)
265+{
266+ ZORBA_TRY
267+ {
268+ store::Item_t type;
269+
270+ store::Item_t lQname = Unmarshaller::getInternalItem(aQName);
271+ VarInfo* var = NULL;
272+
273+ try
274+ {
275+ var = theCtx->lookup_var(lQname);
276+ if (!var)
277+ return NULL;
278+ const XQType* varType = var->getType();
279+ zstring varTypeString;
280+ if (!varType)
281+ {
282+ xqtref_t lAnyType = theCtx->get_typemanager()->create_any_type();
283+ varTypeString = lAnyType->toSchemaString();
284+ }
285+ else
286+ varTypeString = varType->toSchemaString();
287+
288+ GENV_ITEMFACTORY->createQName(type, lQname->getNamespace(), zstring(), varTypeString);
289+ }
290+ catch (ZorbaException const& e)
291+ {
292+ // Normally, we should be throwing an exception if the variable has not
293+ // been declared inside the xquery program, but this cases many failures
294+ // with the w3c XQTS.
295+ if (e.diagnostic() == err::XPST0008)
296+ {
297+ return NULL;
298+ }
299+ throw;
300+ }
301+ return type.getp();
302+ }
303+ ZORBA_CATCH
304+ return NULL;
305+}
306+
307+
308 } /* namespace zorba */
309 /* vim:set et sw=2 ts=2: */
310
311=== modified file 'src/api/staticcontextimpl.h'
312--- src/api/staticcontextimpl.h 2013-03-25 23:02:19 +0000
313+++ src/api/staticcontextimpl.h 2013-04-30 19:07:30 +0000
314@@ -332,6 +332,9 @@
315 public:
316 virtual void
317 clearBaseURI();
318+
319+ virtual Item
320+ getVariablePrimeType(const Item& aQname);
321
322 };
323
324
325=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/variable-type-name.xml.res'
326--- test/rbkt/ExpQueryResults/zorba/xqxq/variable-type-name.xml.res 1970-01-01 00:00:00 +0000
327+++ test/rbkt/ExpQueryResults/zorba/xqxq/variable-type-name.xml.res 2013-04-30 19:07:30 +0000
328@@ -0,0 +1,1 @@
329+xs:integer xs:string xs:dateTime object() element(*, xs:anyType?)
330\ No newline at end of file
331
332=== added file 'test/rbkt/Queries/zorba/xqxq/variable-type-name.xq'
333--- test/rbkt/Queries/zorba/xqxq/variable-type-name.xq 1970-01-01 00:00:00 +0000
334+++ test/rbkt/Queries/zorba/xqxq/variable-type-name.xq 2013-04-30 19:07:30 +0000
335@@ -0,0 +1,13 @@
336+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
337+
338+variable $queryID := xqxq:prepare-main-module('declare variable $ext as xs:integer external; $ext');
339+variable $queryID2 := xqxq:prepare-main-module('declare variable $ext as xs:string external; $ext');
340+variable $queryID3 := xqxq:prepare-main-module('declare variable $ext as xs:dateTime external; $ext');
341+variable $queryID4 := xqxq:prepare-main-module('declare variable $ext as object() external; $ext');
342+variable $queryID5 := xqxq:prepare-main-module('declare variable $ext as element() external; $ext');
343+
344+xqxq:variable-type-name($queryID, xs:QName('ext')),
345+xqxq:variable-type-name($queryID2, xs:QName('ext')),
346+xqxq:variable-type-name($queryID3, xs:QName('ext')),
347+xqxq:variable-type-name($queryID4, xs:QName('ext')),
348+xqxq:variable-type-name($queryID5, xs:QName('ext'))
349\ No newline at end of file
350
351=== added file 'test/rbkt/Queries/zorba/xqxq/variable-type-name2.spec'
352--- test/rbkt/Queries/zorba/xqxq/variable-type-name2.spec 1970-01-01 00:00:00 +0000
353+++ test/rbkt/Queries/zorba/xqxq/variable-type-name2.spec 2013-04-30 19:07:30 +0000
354@@ -0,0 +1,1 @@
355+Error: http://www.zorba-xquery.com/modules/xqxq:UndeclaredVariable
356\ No newline at end of file
357
358=== added file 'test/rbkt/Queries/zorba/xqxq/variable-type-name2.xq'
359--- test/rbkt/Queries/zorba/xqxq/variable-type-name2.xq 1970-01-01 00:00:00 +0000
360+++ test/rbkt/Queries/zorba/xqxq/variable-type-name2.xq 2013-04-30 19:07:30 +0000
361@@ -0,0 +1,5 @@
362+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
363+
364+variable $queryID := xqxq:prepare-main-module('declare variable $ext as xs:integer external; $ext');
365+
366+xqxq:variable-type-name($queryID, xs:QName('ext2'))
367\ No newline at end of file

Subscribers

People subscribed via source and target branches