Mailing list ARC-DEV: Archives

SPARQL UNION

From: Periklis Stavrou 
Subject: SPARQL UNION
Date: Tue, 21 Jul 2009 17:54:47 +0300


Hi all,

If 've been using ARC not long enough so I might be wrong. By the way 
it's really a great tool.

Trying to make some tests with BSBM  I saw that query 11 [1], which uses 
the following union, reports:

Error: The used SELECT statements have a different number of columns.

---------------------------------------------------
SELECT ?property ?hasValue ?isValueOf
WHERE {
{ %OfferXYZ% ?property ?hasValue }
UNION
{ ?isValueOf ?property %OfferXYZ% }
}
----------------------------------------------------
(SELECT
  T_0_0_0_0_0.p AS `property`,
    NULL AS `property lang_dt`,
  T_0_0_0_0_0.o AS `hasValue`,
    T_0_0_0_0_0.o_type AS `hasValue type`,
    T_0_0_0_0_0.o_lang_dt AS `hasValue lang_dt`,
  NULL AS `isValueOf`,
    NULL AS `isValueOf type`
FROM (sparql_triple T_0_0_0_0_0)
WHERE (T_0_0_0_0_0.s = 28611) /* 
http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor1/Offer1250 
*/
)
UNION ALL
(SELECT
  T_0_0_1_0_0.p AS `property`,
    NULL AS `property lang_dt`,
  NULL AS `hasValue`,
    NULL AS `hasValue type`,
    NULL AS `hasValue lang_dt`,
  T_0_0_1_0_0.s AS `isValueOf`,
    T_0_0_1_0_0.s_type AS `isValueOf type`,
    *NULL AS `isValueOf lang_dt`*
FROM (sparql_triple T_0_0_1_0_0)
WHERE (T_0_0_1_0_0.o = 0) /* 
http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor1/Offer1250 
*/
)
----------------------------------------------------
There is this in ARC2_StoreSelectQueryHandler:
 
  if ($tbl_alias == 'NULL') {
              $r .= (in_array($col, array('s', 'o'))) ? ', ' . $nl . 
'    ' .$tbl_alias . ' AS `' . $var_name . ' type`' : '';
              $r .= (in_array($col, array('o'))) ? ', ' . $nl . '    ' 
..$tbl_alias . ' AS `' . $var_name . ' lang_dt`' : '';
            }
            else {
              $r .= (in_array($col, array('s', 'o'))) ? ', ' . $nl . 
'    ' .$tbl_alias . '_type AS `' . $var_name . ' type`' : '';
              $r .= (in_array($col, array('o'))) ? ', ' . $nl . '    ' 
..$tbl_alias . '_lang_dt AS `' . $var_name . ' lang_dt`' : ', ' . $nl . 
'    *NULL AS `' . $var_name . ' lang_dt`' ;*
            }

Removing the bold part for the union (i don't know why it is used) it 
got me the result. I hope this help - if there was any bug :)

if ($this->is_union_query){
            if ($tbl_alias == 'NULL') {
              $r .= (in_array($col, array('s', 'o'))) ? ', ' . $nl . 
'    ' .$tbl_alias . ' AS `' . $var_name . ' type`' : '';
              $r .= (in_array($col, array('o'))) ? ', ' . $nl . '    ' 
..$tbl_alias . ' AS `' . $var_name . ' lang_dt`' : '';
            }
            else {
              $r .= (in_array($col, array('s', 'o'))) ? ', ' . $nl . 
'    ' .$tbl_alias . '_type AS `' . $var_name . ' type`' : '';
              $r .= (in_array($col, array('o'))) ? ', ' . $nl . '    ' 
..$tbl_alias . '_lang_dt AS `' . $var_name . ' lang_dt`' : '';
            }

            }else{the default}

1. 
http://www4.wiwiss.fu-berlin.de/bizer/BerlinSPARQLBenchmark/spec/index.html#queries



--
Periklis Stavrou
PhD Student

""" ;
         ns1:returnPath "<periklis.stavrou@cn.ntua.gr>" ;
         ns1:xOriginalTo "arc-dev@semsol.org" ;
         ns1:deliveredTo "web11p1@p15192371.pureserver.info" ;
         ns1:received """from [192.168.1.2] (athedsl-371313.home.otenet.gr [79.131.2.111])
	by psyche.cn.ece.ntua.gr (Postfix) with ESMTP id 53EB95C1F2
	for <arc-dev@semsol.org>; Tue, 21 Jul 2009 17:54:47 +0300 (EEST)""" ;
         ns1:messageID "<4A65D6B7.9090209@cn.ntua.gr>" ;
         ns1:date "Tue, 21 Jul 2009 17:54:47 +0300" ;
         ns1:from "Periklis Stavrou <periklis.stavrou@cn.ntua.gr>" ;
         ns1:userAgent "Thunderbird 2.0.0.22 (X11/20090608)" ;
         ns1:mIMEVersion "1.0" ;
         ns1:to "arc-dev@semsol.org" ;
         ns1:subject "SPARQL UNION" ;
         ns1:contentType "text/plain; charset=ISO-8859-1; format=flowed" ;
         ns1:contentTransferEncoding "7bit" ;
         ns1:xGreylist "Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (diomedes.noc.ntua.gr [147.102.222.220]); Tue, 21 Jul 2009 17:54:51 +0300 (EEST)" ;
         ns1:xVirusScanned "ClamAV version 0.94.2, clamav-milter version 0.94.2 on diomedes.noc.ntua.gr" ;
         ns1:xVirusStatus "Clean" ;
         ns1:xSpamCheckerVersion """SpamAssassin 2.64 (2004-01-11) on 
	p15192371.pureserver.info""" ;
         ns1:xSpamLevel "" ;
         ns1:xSpamStatus """No, hits=-0.5 required=5.0 tests=AWL,BAYES_10 autolearn=ham 
	version=2.64