Skip to content

In using SERVICE, "string" variables get retrieved as NULL #1278

@chapai2021

Description

@chapai2021

I was testing the federated SPARQL queries using "service". There are two issues:

  • only low-case "service" is accepted, i.e., SPARQL with "SERVICE" would fail. This was fixed for next release.
  • "string" variables get retrieved as null. This is new.

Sorry, I do not have time to create a small reproducible example.
Below, two examples of querying the same SPARQL endpoint, one with

from pandas import DataFrame
from rdflib.plugins.sparql.processor import SPARQLResult

def sparql_results_to_df(results: SPARQLResult) -> DataFrame:
return DataFrame(
data=([None if x is None else x.toPython() for x in row] for row in results),
columns=[str(x) for x in results.vars],
)

qf="""
PREFIX tsmodel: http://siemens.com/tsmodel/
PREFIX vobj: http://siemens.com/tsmodel/VAROBJECTS#

 SELECT ?x ?node_name ?idx 
 {      
    service <http://localhost:8080/sparql>
    {
        ?x a tsmodel:VAROBJECTS .
        ?x vobj:idx ?idx .
        ?x vobj:node_name ?node_name .
    }
  }

"""

results=graph.query(qf)
df=sparql_results_to_df(results)
df.head(20)

x node_name idx
0 http://siemens.com/tsmodel/VAROBJECTS/idx=1 None 1
1 http://siemens.com/tsmodel/VAROBJECTS/idx=2 None 2
2 http://siemens.com/tsmodel/VAROBJECTS/idx=3 None 3
3 http://siemens.com/tsmodel/VAROBJECTS/idx=4 None 4
4 http://siemens.com/tsmodel/VAROBJECTS/idx=5 None 5

import sparql_dataframe

endpoint = "http://localhost:8080/sparql"

q = """
PREFIX tsmodel: http://siemens.com/tsmodel/
PREFIX vobj: http://siemens.com/tsmodel/VAROBJECTS#

SELECT ?x ?node_name ?idx {
?x a tsmodel:VAROBJECTS .
?x vobj:idx ?idx .
?x vobj:node_name ?node_name .
}
"""

df = sparql_dataframe.get(endpoint, q)
df.head()

x	node_name	idx

0 http://siemens.com/tsmodel/VAROBJECTS/idx=1 ns=3;s="ultrasonicLeft" 1
1 http://siemens.com/tsmodel/VAROBJECTS/idx=2 ns=3;s="voltageL1-N" 2
2 http://siemens.com/tsmodel/VAROBJECTS/idx=3 ns=3;s="voltageL2-N" 3
3 http://siemens.com/tsmodel/VAROBJECTS/idx=4 ns=3;s="voltageL3-N" 4
4 http://siemens.com/tsmodel/VAROBJECTS/idx=5 ns=3;s="currentL1" 5

I do have more examples like this. As I have checked, "int", "float", "datetime" work fine. But, "string" variables are always get "NULL".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions