Virtual graph + `NOW()` results in error

I encountered an issue using the NOW() clause with a virtual graph.

If I execute the following SPARQL query:

PREFIX : <urn:customer-journey:model:>

SELECT ?dat_0
FROM <virtual://dev-graph>
    ?sub a :organization .
    ?sub :begin_date ?dat_0 . 

    BIND(NOW() AS ?current_time) .
    FILTER (?dat_0 <= ?current_time) .

Produces the error:

Failed to run query: com.complexible.stardog.plan.eval.ExecutionException: Failed to translate SPARQL expression: "2023-07-18T20:37:58.854Z"^^

Also, if I remove the FILTER clause the same error results.

However, the following executes successfully:

PREFIX test: <>
PREFIX owl: <>
PREFIX xsd: <>
PREFIX rdfs: <>

    :A a owl:Class .
    :date a owl:DatatypeProperty ;
          rdfs:domain :A ;
          rdfs:range xsd:dateTime .
    :i a :A ;
       :date "2023-08-18T14:10:46+06:00"^^xsd:dateTime .
    :j a :A ;
       :date "2021-05-18T14:10:46+06:00"^^xsd:dateTime .

    ?s test:date ?o
    BIND(NOW() AS ?current_time)
    FILTER(?o <= ?current_time)



Hi Jamie,

While attempting to reproduce your error I did encounter some cases where I could get this translation error, but not when including the NOW() function in a VG. If I take the value returned by NOW() and include it as a literal, then I could get the error depending on how I formatted the timezone and the data type of the literal. I created a ticket for those (PLAT-5974 for cross referencing with the release notes) but I'm concerned I am seeing a different problem.

What version are you using and what is the database type that the VG is built on?


p.s. The reason this is working for me is that NOW() is not a function that we translate to SQL, so that operation gets pulled out of the virtual portion of the plan. The resulting query works but is slow because the FILTER is executed on the Stardog side. Here's my plan:

From <virtual://nowtest>
Slice(offset=0, limit=1000) [#3]
`─ Projection(?s, ?o, ?now) [#3]
   `─ Filter(?o < ?now) [#3]
      `─ Bind(NOW() AS ?now) [#6]
         `─ VirtualGraphSql<virtual://pjacks_concat> [#6] {
            +─ RelNode=
            +─    LogicalProject(emp_no=[$0], hire_date=[$5])
            +─      JdbcTableScan(table=[[hive_metastore, default, employees]])
            +─ Query=
            +─    SELECT `emp_no`, `hire_date`
            +─    FROM `hive_metastore`.`default`.`employees` -- No WHERE clause
            +─ Vars=
            +─    ?s <- TEMPLATE({emp_no/0})
            +─    ?o <- COLUMN($1)^^xsd:date
            } [#6]

Hi Paul,

Apologies for the delay in reply. I executed that query using the Studio IDE in Stardog Cloud (server version 9.1.0). The database type is a delta table (stored in parquet files) accessed via a Databricks Spark SQL.

1 Like