Transpose select results rows into columns

Ok, here is another Tableau developer request. The sparql select query returns just four columns and and lots of rows. The last two columns are called key and value - which is actually a property (such as book:title, book:description) and object (such as "A book title", "a sample book description"). I have lots of properties so I am am trying to avoid a very long sparql query.

  • How do I re-write the sparql query without including variable for each property type?
    (I understand that such sparql query will return lots of NULLS wich Tableau is ok with)

If my question is not clear enough I can provide an example.

BTW:

  • What is the Stardog limitation of sparql query length?

Re gads,
Radu

Thinking aloud now. What if we use the following as a subquery that feeds into main query:

select distinct ?p where {?s ?p ?o}

The above returns a list of distinct properties.

Hi Radu,

Could you please provide an example?

Thank you!

Then you still just have the same columns as before, just a column p in the final result.

What I understand, you have lets say 3 columns, first column s denoting the entity and two columns c1 and c2 for key and value

+----+----+----+
| s  | c1 | c2 |
+----+----+----+
| s1 | p1 | v1 |
| s1 | p1 | v2 |
| s1 | p2 | v3 |
| s2 | p1 | v4 |
| .. | .. | .. |
+----+----+----+

and you want

+----+----+----+----+----+
| s  | p1 | p2 | .. | pn |
+----+----+----+----+----+
| s1 | v1 | v3 |    |    |
| s1 | v1 | v3 |    |    |
| s2 | v4 |    |    |    |
| .. | .. | .. |    |    |
+----+----+----+----+----+

If that's not what you meant, please provide an example.

If that is a correct example, short answer: You can't create columns from variables in SPARQL. That is impossible, at least in standard SPARQL. All columns have to be specified in the projection part of a query.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.