-
Notifications
You must be signed in to change notification settings - Fork 20
Better parsing errors #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
DoD:
|
Parse JSON with duckdb, don't need jsonlite as dependency. |
library(DBI)
con <- dbConnect(duckdb::duckdb())
sql <- "SELECT count(*), date FROM SELECT CAST(time AS date), count(*) GROUP by date;"
dbGetQuery(con, sql)
#> Error: {"exception_type":"Parser","exception_message":"syntax error at or near \"SELECT\"","position":"27","error_subtype":"SYNTAX_ERROR"}
e <- tryCatch(
dbGetQuery(con, sql),
error = identity
)
msg <- conditionMessage(e)
dbExecute(con, "LOAD json")
#> [1] 0
out <- dbGetQuery(con, "SELECT json_transform(?, json_structure(?)) AS msg", params = list(msg, msg))
as.list(out[[1]])
#> $exception_type
#> [1] "Parser"
#>
#> $exception_message
#> [1] "syntax error at or near \"SELECT\""
#>
#> $position
#> [1] "27"
#>
#> $error_subtype
#> [1] "SYNTAX_ERROR"
dbDisconnect(con) Created on 2024-10-26 with reprex v2.1.1 |
Currently on my machine: library(DBI)
con <- dbConnect(duckdb::duckdb())
sql <- "SELECT count(*), date FROM SELECT CAST(time AS date), count(*) GROUP by date;"
dbGetQuery(con, sql)
#> Error in `dbSendQuery()` at DBI/R/dbGetQuery_DBIConnection_character.R:5:3:
#> ! syntax error at or near "SELECT"
#> ℹ exception_type: Parser
#> ℹ position: 27
#> ℹ error_subtype: SYNTAX_ERROR
rlang::last_error()
#> Error: Can't show last error because no error was recorded yet Created on 2024-10-26 with reprex v2.1.1 |
Oh, it's a reprex thing, it's shown in the default backtrace. |
We can parse JSON, but this is really needed only for uncaught duckdb exceptions. We get much better results here with catching and adding context in the C++ glue: library(DBI)
con <- dbConnect(duckdb::duckdb())
sql <- "SELECT count(*), date FROM SELECT CAST(time AS date), count(*) GROUP by date;"
dbGetQuery(con, sql)
#> Error in `dbSendQuery()` at DBI/R/dbGetQuery_DBIConnection_character.R:5:3:
#> ! rapi_prepare: Failed to extract statements:
#> Parser Error: syntax error at or near "SELECT"
#> LINE 1: SELECT count(*), date FROM SELECT CAST(time AS date), count(*) GRO...
#> ^ Created on 2024-10-26 with reprex v2.1.1 I keep the JSON parsing code, but it will only be in effect when exceptions come through unfiltered. We could use JSON everywhere, though: duckdb/duckdb-r#519. |
The JSON parsing now adds little extra value, I can't even test it. Whenever we see a JSON string on the R side, we want to catch and rethrow in C++. Much later, we can think about JSONifying everything in duckdb/duckdb-r#519. |
Would be nicer as:
Or similar
The text was updated successfully, but these errors were encountered: