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

Datatype returned as character instead of double since fix of issue #83 #90

Open
pascalgulikers opened this issue Apr 28, 2022 · 10 comments

Comments

@pascalgulikers
Copy link

pascalgulikers commented Apr 28, 2022

Since version 0.2-10 there are some issues with datatype conversion from SAP HANA tables. High precision 0 values return as character 0E-8 instead of double 0.0000000
RJDBC 0.2-08:
image

RJDBC 0.2-10
image

Possible fix in class.R line 454:

l[[i]] <- numeric()
cp <- .jcall(res@md, "I", "getPrecision", i)
if (cp > 15) {
l[[i]] <- character()
rts[i] <- 1L
}

@jesadrperez
Copy link

I am having a similar issue pulling data from a Denodo data virtualization server, in which NUMERIC fields are automatically converted to characters.

@pascalgulikers
Copy link
Author

@s-u What is your opinion on this issue?

@s-u
Copy link
Owner

s-u commented May 2, 2022

@pascalgulikers I don't have access to SAP so I would need more details on what exactly is the exact SQL type and what happens there. The report lacks any and all details (screenshots are not helpful, use R tools like str). Same goes for @jesadrperez - can you, please, be more specific exactly about the table schema, what is the expected value, what is the returned value in R?

@JeroenvdLogt
Copy link

@s-u can you say what information exact you need to investigate this issue. Then I can see if I can retrieve that information. I am a collegae of Pascal and have access to SAP HANA.

@JeroenvdLogt
Copy link

image
Datatype of field in QueryView in SAP HANA

@JeroenvdLogt
Copy link

require(devtools)
require(DescTools)
devtools::install_version("RJDBC", version = "0.2-08", repos = "http://cran.us.r-project.org")
test_query <- function() {
driver <- RJDBC::JDBC(driverClass = "com.sap.db.jdbc.Driver",
classPath = "/xxxxxx/xxxxx/xxxxxxx/Rlibs/xcxxxxx/java/ngdbc.jar",
identifier.quote = """)
connection_database <- RJDBC::dbConnect(drv = driver,"jdbc:sap://xxxxxxxxxx:xxxxx/",
hana_user,hana_pass)
output_data <- DBI::dbFetch(RJDBC::dbSendQuery(conn = connection_database,
statement = "select top 2 SJV_HOOG from "_SYS_BIC"."IT.Specifiek.Keten.NetPrognose.QV/NP_NETTOPOLOGIE""))
return(output_data)
}
test_08 <- test_query()

test_08$SJV_HOOG[[1]]
[1] 1083

class(test_08$SJV_HOOG[[1]])
[1] "numeric"
typeof(test_08$SJV_HOOG[[1]])
[1] "double"
DescTools::Str(test_08$SJV_HOOG[[1]])
num 1083


@JeroenvdLogt
Copy link

JeroenvdLogt commented May 3, 2022

devtools::install_version("RJDBC", version = "0.2-10", repos = "http://cran.us.r-project.org/")

test_10 <- test_query()
test_10
SJV_HOOG
1 1083
2 1475
class(test_10$SJV_HOOG[[1]])
[1] "character"
typeof(test_10$SJV_HOOG[[1]])
[1] "character"
DescTools::Str(test_10$SJV_HOOG[[1]])
chr "1083"

Note: Of course there are R packages which could convert strings into numeric. However, with high precision in HANA this results in incorrect values because of rounding differences.

@pascalgulikers
Copy link
Author

@s-u Do you have an update on this issue? Do you have enough information?

@s-u
Copy link
Owner

s-u commented Jun 9, 2022

@pascalgulikers The data type in the database is not representable as numeric in R, so the only type in R that can represent it without loss of precision is a string. Previous versions would incorrectly convert such numbers to numeric vectors, but that could cause loss of precision. So the current behavior is correct. You can use Rmpfr to deal with numbers that are beyond the IEEE double precision or if you are ok with losing precision you can use as.numeric(). However, if you are not concerned by precision, you should probably use a cast in your query to avoid the overhead of unrepresentable numbers (how big that overhead is depends on your database/drivers).

@florianWickler
Copy link

We have the same issue when querying columns with type BIGINT from Impala. we receive them as characters. But if we query columns of type DOUBLE we receive numeric values as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants