scruz-denodo commented on PR #1407:
URL: https://github.com/apache/arrow-java/pull/1407#issuecomment-6956232217
Hi, I modified the attached class for accessing to a table instead of
passing the number as argument with the `cast`. For removing noise with the
prepared statement.
I tested also with Oracle. Both of them (Postgresql and Oracle) return `0.1`
values with the different number types and methods.
I paste the output and the modified code:
### Postgresql
Table
``` sql
create table test_float (
c_decimal decimal(4, 2),
c_real real,
c_double double precision
);
insert into test_float (c_decimal, c_real, c_double) values (0.1, 0.1, 0.1);
```
Output
```
c_decimal
....................
getString() 0.10
getObject() 0.10
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.10
c_real
....................
getString() 0.10
getObject() 0.10
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.10
c_double
....................
getString() 0.10
getObject() 0.10
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.10
```
### Oracle
Table
``` sql
create table test_float (
c_number number(4, 2),
c_float float,
c_binary_float binary_float,
c_binary_double binary_double,
c_double double precision,
c_real real
);
insert into test_float (c_number, c_float, c_binary_float, c_binary_double,
c_double, c_real) values (0.1, 0.1, 0.1, 0.1, 0.1, 0.1);
```
```
C_NUMBER
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
C_FLOAT
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
C_BINARY_FLOAT
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
C_BINARY_DOUBLE
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
C_DOUBLE
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
C_REAL
....................
getString() 0.1
getObject() 0.1
getFloat() 0.1
getDouble() 0.1
getBigDecimal() 0.1
```
And the modified Java code:
``` java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
public class PgjdbcFloatReproducer {
public static void main(String[] args) throws Exception {
if (args.length != 3) {
throw new IllegalArgumentException(
"Usage: PgjdbcFloatReproducer <jdbc-url> <username>
<password>");
}
Properties properties = new Properties();
properties.setProperty("user", args[1]);
properties.setProperty("password", args[2]);
try (Connection connection = DriverManager.getConnection(args[0],
properties);
PreparedStatement statement =
connection.prepareStatement("SELECT * from test_float");
ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
for (int i=1;i<=rs.getMetaData().getColumnCount();i++) {
System.out.println(rs.getMetaData().getColumnName(i));
System.out.println("....................");
System.out.println("\tgetString() " + rs.getString(1));
System.out.println("\tgetObject() " + rs.getObject(1));
System.out.println("\tgetFloat() " + rs.getFloat(1));
System.out.println("\tgetDouble() " + rs.getDouble(1));
System.out.println("\tgetBigDecimal() " +
rs.getBigDecimal(1) + "\n");
}
}
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]