Please ignore the question below. It seems like Virtuoso is sensitive to
"redundant" (extra) semi-colons. I was using an extra semi-colon at the end
of Q2 unknowingly, and so it was repeatedly giving a syntax error.

Without an extra semi-colon, Q2 now runs as expected without syntax error.


On Thu, Mar 5, 2015 at 2:05 PM, Medha Atre <medha.a...@gmail.com> wrote:

> Hi,
>
> I am trying to run some SPARQL queries translated to SQL on NATIVE
> Virtuoso columnstore, which involve combination of left join and UNION
> statements.
>
> A sample SPARQL query is given below:
>
> *Q1:*
>
> SPARQL SELECT * FROM <http://mytest.com>
> WHERE {
> ?a <http://ex.com/11> <http://ex.com/1> .
>     OPTIONAL {
>         {?a <http://ex.com/11> <http://ex.com/1> .
>             OPTIONAL {?a <http://ex.com/12> ?b .}
>         }
>         UNION
>         {?a <http://ex.com/11> <http://ex.com/1> .
>             OPTIONAL {?b <http://ex.com/11> ?a .}
>         }
>     }
> }
>
> Now, to run this as an SQL query, I stored the same data from the graph <
> http://mytest.com> in a 3-column table called "mytest", and translated
> the above query to SQL as below:
>
>
>
> *Q2:*SELECT * FROM
> (select s as a from mytest where p=11 and o=1) as t1
> left join
> (select t2.s as a, t3.o as b from
>      (select s from mytest where p=11 and o=1) as t2
>      left join
>      (select s, o from mytest where p=12) as t3
>      on t2.s=t3.s
>     UNION ALL
>     select t4.s as a, t5.s as b from
>      (select s from mytest where p=11 and o=1) as t4
>      left join
>      (select s, o from mytest where p=11) as t5
>      on t4.s=t5.o) t7
> on t1.a=t7.a;
>
> *The problem is* -- while Q1 runs fine on Virtuoso, Q2 keeps giving me
> syntax a error at the very last line (on t1.a=t7.a). I checked Virtuoso's
> SQL grammar at http://docs.openlinksw.com/virtuoso/SELECTSTMT.html as
> well as looked at the abstract representation of Q1 through "set explain
> on". But neither of this has helped me to know where I am going wrong.
>
> Any other SQL query with only left joins, without UNION statement run
> correctly, but as soon as do a left join over a UNION ALL statement, it
> gives a syntax error. To debug more, I tried running just the subquery of
> Q2 having only UNION ALL as
>
> *Q3:*
> select t2.s as a, t3.o as b from
>      (select s from mytest where p=11 and o=1) as t2
>      left join
>      (select s, o from mytest where p=12) as t3
>      on t2.s=t3.s
>     UNION ALL
>     select t4.s as a, t5.s as b from
>      (select s from mytest where p=11 and o=1) as t4
>      left join
>      (select s, o from mytest where p=11) as t5
>      on t4.s=t5.o) t7
>
> *Q3 runs correctly, but Q2 refuses to run by giving syntax error.*
>
> Can the Virtuoso support staff or the users let me know how to correctly
> write Q2 to make it run on the native SQL engine? *Please note* that I
> have to run the SQL format of the query to do some native SPARQL vs SQL
> experiments, so solutions like "just run the SPARQL query only" will not be
> useful!
>
> Thanks in anticipation.
>
> Medha
>
>
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to