Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-11-09 Thread Pavel Stehule
Hi

2017-11-06 14:00 GMT+01:00 Kyotaro HORIGUCHI <
horiguchi.kyot...@lab.ntt.co.jp>:

> Thank you for the new patch.
>
> - The latest patch is missing xpath_parser.h at least since
>   ns-3. That of the first (not-numbered) version was still
>   usable.
>
> - c29c578 conflicts on doc/src/sgml/func.sgml
>
>
> At Sun, 15 Oct 2017 12:06:11 +0200, Pavel Stehule 
> wrote in  b9efon...@mail.gmail.com>
> > 2017-10-02 12:22 GMT+02:00 Kyotaro HORIGUCHI <
> > horiguchi.kyot...@lab.ntt.co.jp>:
> >
> > > Hi, thanks for the new patch.
> > >
> > > # The patch is missing xpath_parser.h. That of the first patch was
> usable.
> > >
> > > At Thu, 28 Sep 2017 07:59:41 +0200, Pavel Stehule <
> pavel.steh...@gmail.com>
> > > wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-11-06 Thread Kyotaro HORIGUCHI
Thank you for the new patch.

- The latest patch is missing xpath_parser.h at least since
  ns-3. That of the first (not-numbered) version was still
  usable.

- c29c578 conflicts on doc/src/sgml/func.sgml


At Sun, 15 Oct 2017 12:06:11 +0200, Pavel Stehule  
wrote in 
> 2017-10-02 12:22 GMT+02:00 Kyotaro HORIGUCHI <
> horiguchi.kyot...@lab.ntt.co.jp>:
> 
> > Hi, thanks for the new patch.
> >
> > # The patch is missing xpath_parser.h. That of the first patch was usable.
> >
> > At Thu, 28 Sep 2017 07:59:41 +0200, Pavel Stehule 
> > wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-10-15 Thread Pavel Stehule
2017-10-02 12:22 GMT+02:00 Kyotaro HORIGUCHI <
horiguchi.kyot...@lab.ntt.co.jp>:

> Hi, thanks for the new patch.
>
> # The patch is missing xpath_parser.h. That of the first patch was usable.
>
> At Thu, 28 Sep 2017 07:59:41 +0200, Pavel Stehule 
> wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-10-03 Thread Kyotaro HORIGUCHI
At Mon, 2 Oct 2017 12:43:19 +0200, Pavel Stehule  
wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-10-02 Thread Pavel Stehule
2017-10-02 12:22 GMT+02:00 Kyotaro HORIGUCHI <
horiguchi.kyot...@lab.ntt.co.jp>:

> Hi, thanks for the new patch.
>
> # The patch is missing xpath_parser.h. That of the first patch was usable.
>
> At Thu, 28 Sep 2017 07:59:41 +0200, Pavel Stehule 
> wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-10-02 Thread Kyotaro HORIGUCHI
Hi, thanks for the new patch.

# The patch is missing xpath_parser.h. That of the first patch was usable.

At Thu, 28 Sep 2017 07:59:41 +0200, Pavel Stehule  
wrote in 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-09-28 Thread Pavel Stehule
Hi

now xpath and xpath_exists supports default namespace too

updated doc,
fixed all variants of expected result test file

Regards

Pavel
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 2f036015cc..610f709933 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -10477,7 +10477,8 @@ SELECT xml_is_well_formed_document('http://postgresql.org/stuf
  second the namespace URI. It is not required that aliases provided in
  this array be the same as those being used in the XML document itself (in
  other words, both in the XML document and in the xpath
- function context, aliases are local).
+ function context, aliases are local). Default namespace has
+ empty name (empty string) and should be only one.
 
 
 
@@ -10496,8 +10497,8 @@ SELECT xpath('/my:a/text()', 'http://example.com;>test',
 
  To deal with default (anonymous) namespaces, do something like this:
 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-09-27 Thread Pavel Stehule
Hi

2017-09-25 13:25 GMT+02:00 Kyotaro HORIGUCHI <
horiguchi.kyot...@lab.ntt.co.jp>:

> Hello, this patch have been ignored for a long time since its proposal...
>
> At Sat, 11 Mar 2017 20:44:31 +0100, Pavel Stehule 
> wrote in  com>
> > Hi
> >
> > This proposal is followup of implementation of XMLTABLE.
> >
> > Lot of XML documents has assigned document namespace.
> >
> > http://x.y;>10
> >
> > For these XML document any search path must use schema "http://x.y;.
> This
> > is not too intuitive, and from XMLTABLE usage is not too user friendly,
> > because the default column path (same like column name) cannot be used. A
> > solution of this issue is default namespace - defined in SQL/XML.
> >
> > example - related to previous xml
> >
> > without default namespace:
> > XMLTABLE(NAMESPACES('http://x.y' AS aux),
> > '/aux:rows/aux:row' PASSING ...
> > COLUMNS a int PATH 'aux:a')
> >
> > with default namespace
> > XMLTABLE(NAMESPACES(DEFAULT 'http://x.y'),
> > '/rows/row' PASSING ...
> > COLUMNS a int);
> >
> >
> > Unfortunately the libxml2 doesn't support default namespaces in XPath
> > expressions. Because the libxml2 functionality is frozen, there is not
> big
> > chance for support in near future. A implementation is not too hard -
> > although it requires simple XPath expressions state translator.
> >
> > The databases with XMLTABLE implementation supports default namespace for
> > XPath expressions.
> >
> > The patch for initial implementation is attached.
>
> The original message is a bit less informative for those who
> wants to review this but are not accustomed (like me) to this
> area. I try to augment this with a bit more information. (Perhaps)
>
> An example of this issue can be as follows.
>
> create table t1 (id int, doc xml);
> insert into t1
>   values
>   (1, 'http://x.y;>10'),
>   (2, 'http://x.y;>20'),
>   (3, 'http://x.y;>30'),
>   (4, 'http://x.y;>40');
> select x.* from t1, xmltable('/rows/row' passing t1.doc columns data int
> PATH 'a') as x;
> |  data
> | --
> | (0 rows)
> select x.* from t1, xmltable(XMLNAMESPACES('http://x.y' as n),
> '/n:rows/n:row' passing t1.doc columns data int PATH 'n:a') as x;
> |  data
> | --
> |10
> |20
> |30
> |40
> | (4 rows)
>
> But, currently the follwing command fails with error.
>
> select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.y'),
> '/rows/row' passing t1.doc columns data int PATH 'a') as x;
> | ERROR:  DEFAULT namespace is not supported
>
> This patch let PostgreSQL allow this syntax by transforming xpath
> string when DEFAULT namespace is defined.
>

> ===
> I have some review comments.
>
> This patch still applies with shifts and works as expected.
>
> 1. Uniformity among simliar features
>
>   As mentioned in the proposal, but it is lack of uniformity that
>   the xpath transformer is applied only to xmltable and not for
>   other xpath related functions.
>

I have to fix the XPath function. The SQL/XML function Xmlexists doesn't
support namespaces/

>
>
> 2. XML comformance
>
>I'm not yet sure this works for the all extent of the
>available syntax but at least fails for the following
>expression.
>
> (delete from t1;)
> insert into t1
>values
>(5, 'http://x.y;>50 rows>');
>
> select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.y'),
> '/rows/row' passing t1.doc columns data int PATH 'a[1][@hoge]') as x;
> >  data
> > --
> >
> > (1 row)
>
>
>   The following expression works.
>
> select x.* from t1, xmltable(XMLNAMESPACES('http://x.y' as x),
> '/x:rows/x:row' passing t1.doc columns data int PATH 'x:a[1][@hoge]') as x;
> >  data
> > --
> >50
> > (1 row)
>
>   The w3c says as follows.
>
>   https://www.w3.org/TR/xml-names/#defaulting
>   > The namespace name for an unprefixed attribute name always has no
> value.
>
>   We currently don't have a means to make sure that this works
>   correctly for the whole extent. More regression test helps?
>

I fixed this issue and I used your examples as regression tests

>
>
> 3. The predefined prefix for default namespace
>
>   The patch defines the name of the defaut namespace as
>   "pgdefnamespace". If a default namespace is defined, a
>   namespace is made with the name and with_default_ns is true. If
>   a namespace with the name is defined, a namespace is made also
>   with the same name but with_default_ns is false. This causes a
>   confused behavior.
>
> select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.x', '
> http://x.y' as pgdefnamespace), '/rows/row' passing t1.doc columns data
> int PATH 'a') as x;
> |  data
> | --
> |10
> |20
> |30
> |40
> | (4 rows)
>
>  The reason for the design is the fact that xmlXPathRegisterNs
>  doesn't accept NULL or empty string as a namespace prefix and it
>  only accepts 

Re: [HACKERS] proposal - Default namespaces for XPath expressions (PostgreSQL 11)

2017-09-25 Thread Kyotaro HORIGUCHI
Hello, this patch have been ignored for a long time since its proposal...

At Sat, 11 Mar 2017 20:44:31 +0100, Pavel Stehule  
wrote in 
> Hi
> 
> This proposal is followup of implementation of XMLTABLE.
> 
> Lot of XML documents has assigned document namespace.
> 
> http://x.y;>10
> 
> For these XML document any search path must use schema "http://x.y;. This
> is not too intuitive, and from XMLTABLE usage is not too user friendly,
> because the default column path (same like column name) cannot be used. A
> solution of this issue is default namespace - defined in SQL/XML.
> 
> example - related to previous xml
> 
> without default namespace:
> XMLTABLE(NAMESPACES('http://x.y' AS aux),
> '/aux:rows/aux:row' PASSING ...
> COLUMNS a int PATH 'aux:a')
> 
> with default namespace
> XMLTABLE(NAMESPACES(DEFAULT 'http://x.y'),
> '/rows/row' PASSING ...
> COLUMNS a int);
> 
> 
> Unfortunately the libxml2 doesn't support default namespaces in XPath
> expressions. Because the libxml2 functionality is frozen, there is not big
> chance for support in near future. A implementation is not too hard -
> although it requires simple XPath expressions state translator.
> 
> The databases with XMLTABLE implementation supports default namespace for
> XPath expressions.
> 
> The patch for initial implementation is attached.

The original message is a bit less informative for those who
wants to review this but are not accustomed (like me) to this
area. I try to augment this with a bit more information. (Perhaps)

An example of this issue can be as follows.

create table t1 (id int, doc xml);
insert into t1 
  values
  (1, 'http://x.y;>10'),
  (2, 'http://x.y;>20'),
  (3, 'http://x.y;>30'),
  (4, 'http://x.y;>40');
select x.* from t1, xmltable('/rows/row' passing t1.doc columns data int PATH 
'a') as x;
|  data 
| --
| (0 rows)
select x.* from t1, xmltable(XMLNAMESPACES('http://x.y' as n), '/n:rows/n:row' 
passing t1.doc columns data int PATH 'n:a') as x;
|  data 
| --
|10
|20
|30
|40
| (4 rows)

But, currently the follwing command fails with error.

select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.y'), '/rows/row' 
passing t1.doc columns data int PATH 'a') as x;
| ERROR:  DEFAULT namespace is not supported

This patch let PostgreSQL allow this syntax by transforming xpath
string when DEFAULT namespace is defined.

===
I have some review comments.

This patch still applies with shifts and works as expected.

1. Uniformity among simliar features

  As mentioned in the proposal, but it is lack of uniformity that
  the xpath transformer is applied only to xmltable and not for
  other xpath related functions.


2. XML comformance

   I'm not yet sure this works for the all extent of the
   available syntax but at least fails for the following
   expression.

(delete from t1;)
insert into t1 
   values
   (5, 'http://x.y;>50');

select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.y'), '/rows/row' 
passing t1.doc columns data int PATH 'a[1][@hoge]') as x;
>  data 
> --
>  
> (1 row)


  The following expression works.

select x.* from t1, xmltable(XMLNAMESPACES('http://x.y' as x), '/x:rows/x:row' 
passing t1.doc columns data int PATH 'x:a[1][@hoge]') as x;
>  data 
> --
>50
> (1 row)

  The w3c says as follows.

  https://www.w3.org/TR/xml-names/#defaulting
  > The namespace name for an unprefixed attribute name always has no value.  

  We currently don't have a means to make sure that this works
  correctly for the whole extent. More regression test helps?
  

3. The predefined prefix for default namespace

  The patch defines the name of the defaut namespace as
  "pgdefnamespace". If a default namespace is defined, a
  namespace is made with the name and with_default_ns is true. If
  a namespace with the name is defined, a namespace is made also
  with the same name but with_default_ns is false. This causes a
  confused behavior.

select x.* from t1, xmltable(XMLNAMESPACES(DEFAULT 'http://x.x', 'http://x.y' 
as pgdefnamespace), '/rows/row' passing t1.doc columns data int PATH 'a') as x;
|  data 
| --
|10
|20
|30
|40
| (4 rows)

 The reason for the design is the fact that xmlXPathRegisterNs
 doesn't accept NULL or empty string as a namespace prefix and it
 only accepts a string consists of valid XML caharacters.

 Even if we are to live with such restriction and such name is
 hardly used, a namespace prefix with the name should be
 rejected.


4. A mistake in the documentaion ?

 The documentaion says about the XMLNAMESPACES clause as the
 folows.

https://www.postgresql.org/docs/10/static/functions-xml.html
> The optional XMLNAMESPACES clause is a comma-separated list of
> namespaces. It specifies the XML namespaces used in the document
> and their aliases.

As