dbt-labs / example-semantic-layer-clients

2 stars 0 forks source link

R Example does not work for legitimate queries #5

Open wtremml18 opened 1 month ago

wtremml18 commented 1 month ago

When I use the original project query, it generates an error '''The given input does not exactly match any known metrics.''' then lists the correct metrics in my project. So I am definitely connected to my project.

But when I change the metric to a legitimate metric, I get this:

Error in get_next(schema, validate = validate) : 
  array_stream->get_next(): [5] [FlightSQL]  (Unknown; DoGet: endpoint 0: [uri:"grpc+tls://semantic-layer.cloud.getdbt.com:443"])

I see that this is different than the commented host variable, but the query won't work at all if I use the commented variable directly.

I saw the documentation had a note that you may need to add &disableCertificateVerification=true to the url. I also tried: adbc.flight.sql.client_option.tls_skip_verify = "true". Neither of which worked.

Any idea why?

R 4.4.1 adbcdrivermanager 0.13.0 adbcflightsql 0.13.0.9000 arrow 16.1.0 httr2 1.0.2

wtremml18 commented 1 month ago

Update: I'm able to port the python example into R by using {reticulate}, so there's no issue with my DBT connection.

@aiguofer could you post the requirements.txt and validate the the R-native example is working?

library(reticulate)
use_virtualenv("r-dbtsl")

# py_install("os")
# py_install("sys")
# py_install("dataclasses")
# py_install("urllib")
# py_install("adbc_driver_flightsql")
# py_install("pandas")

#The python example code, with slightly adapted "execute_query" function
source_python("~/sl_query.py")

query <- "select * from {{ semantic_layer.metrics() }}"

# Execute the query
result <- execute_query(
  query = query
)

r_dataframe <- py_to_r(result) %>%
                as_tibble
aiguofer commented 1 month ago

Hi! sorry for some reason I was never notified of your initial issue!! I just saw the tagged comment today.

I tried re-running the example in R but I'm running into issues just installing the dependencies :(

The ADBC documentation says I should now be able to install.packages("adbcflightsql") but that doesn't work, and I'm having issues with pak

aiguofer commented 1 week ago

Ok, I finally had some time to fix my R and Go environments to build this and get it working.... and sure enough I ran into the same error as you.

The Python ADBC bindings and the JDBC driver both only use the PreparedStatement flow under the covers, so we've only implemented those endpoints. It looks like there was an update to the R bindings since I initially tested this that changed the backend to use regular Statements instead of using PreparedStatements, so the request to fetch the results fails.

It should theoretically be possible to use PreparedStatements through the R bindings, but looking through the R usage is a bit hard since I'm not really an R user.

I have added a task to our backlog to fix the regular Statement flow though, so hopefully that will be fixed within the next couple of sprints.