Skip to content
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

string filter issue using odbc with SAP HANA ODBC Drivers #3343

Closed
washcycle opened this issue Feb 6, 2018 · 3 comments
Closed

string filter issue using odbc with SAP HANA ODBC Drivers #3343

washcycle opened this issue Feb 6, 2018 · 3 comments

Comments

@washcycle
Copy link

The issue:

The Goal:

I want the sql generated to have this form or equivalent:

SELECT COLUMN1
FROM SCHEMA.TABLE
WHERE (LOCATE(COLUMN1, 'pattern') = 1) 
LIMIT 6;

I am trying to find strings that start with a specific pattern.

** The Issue**

If I use a dplyr filter(...) these solutions don't work...

stringr::str_locate, string::str_detect I tried a whole slew of things, these all create some malformed SQL.

str_detect gets translated into INSTR which is a MySQL specific function from what I can tell.

<SQL>
SELECT *
FROM SCHEMA.TABLE
WHERE (INSTR('pattern', "COLUMN") > 0)
LIMIT 6

This last one below will work, but isn't documented; I found it by trying things until something worked.

locate(COLUMN, 'pattern') this translates into the expected LOCATE

I am not even sure how this works because locate isn't a function from what I can tell.

library(DBI)                                                     
library(dplyr)                                                   
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(dbplyr)                                                  
#> 
#> Attaching package: 'dbplyr'
#> The following objects are masked from 'package:dplyr':
#> 
#>     ident, sql
library(readr)                                                   
                                                                 
con <- DBI::dbConnect(odbc::odbc(),                              
driver = "/Applications/sap/hdbclient/libodbcHDB.dylib",         
servernode = "host:port",                                        
uid = rstudioapi::askForPassword("UID"),                         
pwd = rstudioapi::askForPassword("PWD"),                         
CHAR_AS_UTF8 = TRUE # need this set because ASCII default is dumb
)                                                                
#> Error: RStudio not running
                                                                 
tbl_ref <- tbl(con, in_schema("schema","table"))                 
#> Error in tbl(con, in_schema("schema", "table")): object 'con' not found
                                                                 
tbl_ref %>%                                                      
filter(stringr::str_locate(COLUMN1, "pattern") == 1) %>%                      
head() %>% show_query()                                      
#> Error in eval(lhs, parent, parent): object 'tbl_ref' not found

Database is SAP HANA, there is a free version now if you wanted to replicate down to the database layer.
https://www.sap.com/developer/topics/sap-hana-express.html

Thanks,
Matt

@edgararuiz-zz
Copy link

Hi @washcycle ,this makes sense since there are no HANA specific translations yet in dbplyr. Also, your workaround makes sense, and it's probably the best way going forward until we have a customization for HANA. At this point, a new page in the site, which contains the workaround, is the best short-term solution, until we can get a customization for this connection.

@washcycle
Copy link
Author

washcycle commented Feb 11, 2018 via email

@hadley hadley closed this as completed May 20, 2018
@lock
Copy link

lock bot commented Nov 16, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants