ropensci / redland-bindings

Redland librdf language bindings
http://librdf.org/bindings/
Other
17 stars 3 forks source link

Disable librdf warnings? #56

Open NovasTaylor opened 7 years ago

NovasTaylor commented 7 years ago

Is it possible to turn off (disable) warnings like: librdf warning ޱ - Variable p was bound but is unused in the query

from queries such as: SELECT (COUNT(?s) as ?sCount) WHERE { ?s ?p ?o }

gothub commented 7 years ago

@NovasTaylor the warning level is set in the Rasqal library function rasqal_world_set_warning_level which is not currently implemented in either the redland R code or the SWIG interface layer that is the bridge between the Redland libraries and R. This function would have to be added to both.

I'm leaving this issue open because this is something we should do, and it shouldn't be difficult to add another call to the library. We should also review other Redland library configuration functions that would be useful without potentially causing hard to debug problems.

NovasTaylor commented 7 years ago

Thanks, @gothub. This feature would be useful in production runs where we want to look for presence/absence of warnings. Just a thought - not critical at this point.

cboettig commented 6 years ago

👍 This would be great to address throughout. It would be great to be able to both handle these messages -- sometimes a large query can be slowed considerably (making RStudio unresponsive) because it is sending way too many messages to the console that aren't important; in other examples the warning or error messages can be pretty important and shouldn't be lost

cboettig commented 6 years ago

@gothub Any news on this? Is it possible to at least consider a more direct mechanism to at least capture or redirect stderr / stout ?

mbjones commented 6 years ago

This would be the header to be added to the IDL file:

int rasqal_world_set_warning_level(rasqal_world* world, unsigned int warning_level);

I'm not sure if other rasqal methods would be needed too to enable the settings and include an R method for it. If @gothub has the SWIG build working now (I don't), it should be a quick addition, and then the defaults could be set lower.

mbjones commented 6 years ago

@cboettig I just added PR #76 -- does that look like it would address the issue?

To release on CRAN, @gothub's magic documentation function would have to pull in the rasqal documentation. I'm not clear on how to run that. @gothub?

gothub commented 6 years ago

@mbjones @cboettig i'll have a look at the PR today. Regarding the rasqal document, the Redland RDF source trees have to be locally built, which I have on my machine, so I'll update the docs...

gothub commented 2 years ago

Fixed in commit 930c55b6852876bab76a1c9f402ca70ddd375dce

gothub commented 2 years ago

@mbjones - this issue is being re-opened as it's not clear to me that the changed code is having the desired affect of reducing the rasqal warning messages. After preparing release 1.0.17-16, I realized that I hadn't tested this, so I wrote the following script:

  library(redland)
  world <- new("World")
  storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'")
  model <- new("Model", world, storage, options="")
  stmt <- new("Statement", world=world, 
              subject="https://orcid.org/0000-0002-2192-403X",
              predicate="http://www.w3.org/ns/prov#Agent",
              object="slaughter", 
              objectType="literal", datatype_uri="http://www.w3.org/2001/XMLSchema#string")
  status <- addStatement(model, stmt)
  queryString <- paste("PREFIX orcid: <https://orcid.org/>",
                       "PREFIX dataone: <https://cn.dataone.org/cn/v1/resolve/>",
                       "PREFIX prov: <http://www.w3.org/ns/prov#>",
                       "SELECT (COUNT(?s) as ?sCount) WHERE { ?s ?p ?o }")
  query <- new("Query", world, queryString, base_uri=NULL, query_language="sparql", query_uri=NULL)
  results <- getResults(query, model, "rdfxml")
  grepl("sCount", results)

  # When the query object is no longer needed, the resources it had allocated can be freed.
  freeQuery(query)
  rm(query)
  freeStorage(storage)
  rm(storage)
  freeModel(model)
  rm(model)
  freeWorld(world)
  rm(world) 

This script was run 3 times, rebuilding the package after changing the warning level to 10, then 50, then 90 in World.R .

Each time the same warnings were printed:

librdf warning  - Variable p was bound but is unused in the query
librdf warning  - Variable o was bound but is unused in the query
librdf warning  - Variable s was bound but is unused in the query
librdf warning  - Variable p was bound but is unused in the query
librdf warning  - Variable o was bound but is unused in the query
librdf warning  - Variable $$agg$$0 was used but is not bound in the query

I've checked the return status of rasqal_world_set_warning_level in World.R, and it is 0 every time, which indicates success.

Is there something else I've missed?

mbjones commented 2 years ago

@gothub Did you try setting it to 0 and 1 to see how chatty the minimums would be?

gothub commented 2 years ago

@mbjones Setting the warning level to 0, 1 or 100 produces the same messages as show above.

mbjones commented 2 years ago

ok, then it seems that either I got the wrong warning function, or the code isn't fully instrumented to use its logging facility. My guess is that function only affects rasqal, and not all of librdf. I see that librdf_world also has API functions to override the logging facilities: https://librdf.org/docs/api/redland-world.html#librdf-world-set-logger That might prove to be more universal, but we'd have to provide a different logger function. Maybe we should just punt on this and get the release out without this PR for now.

mbjones commented 2 years ago

Also see: https://librdf.org/docs/api/redland-log.html

gothub commented 2 years ago

OK, i'll revert the commit (for the PR), rerun tests, then release.

mbjones commented 2 years ago

Looking at the librdf rdf_log.c implementation (and not just the API), I see that the way to override the logging is with three log handler implementations:

The code in rdf_log.c starting at line 89 (https://github.com/dajobe/librdf/blob/master/src/rdf_log.c#L89) uses the generic log handler if it is set, and which is used in preference to all of the others. The error handler and warning handler are only used if the generic logger is not set. If none are set, then the system falls through to logging to STDERR.

So, to squelch this output, I think we need to provide a generic error handler with the ability to be turned on or off based on a configurable setting for the log level to be logged.