140378476 opened a new issue #2132:
URL: https://github.com/apache/iotdb/issues/2132


   **Describe the bug**
   I got clearly incorrect results when retrieving data using method 
`getFloat`. 
   Addtionally, I can get a String representation of the data, which is highly 
inprecise and requires extra parsing.
   
   **To Reproduce**
   Steps to reproduce the behavior:
   1. Create timeseries: ` CREATE TIMESERIES root.t.d WITH DATATYPE=FLOAT, 
ENCODING=RLE`
   2. Insert data: `INSERT INTO root.t(timestamp,d) VALUES(1,1.23456789)`
   3. Retrieve data using JDBC: (mostly copied from the user guide and 
converted to Kotlin)
   ```
       fun getConnection(): Connection? {
           // JDBC driver name and database URL
           val driver = "org.apache.iotdb.jdbc.IoTDBDriver"
           val url = "jdbc:iotdb://127.0.0.1:6667/"
   
           // Database credentials
           val username = "root"
           val password = "root"
           var connection: Connection? = null
           try {
               Class.forName(driver)
               connection = DriverManager.getConnection(url, username, password)
           } catch (e: ClassNotFoundException) {
               e.printStackTrace()
           } catch (e: SQLException) {
               e.printStackTrace()
           }
           return connection
       }
   
       fun select(){
           val connection = getConnection()
           if (connection == null) {
               println("get connection defeat")
               return
           }
           val statement: Statement = connection.createStatement()
           statement.execute("SELECT d from root.test")
           val rs = statement.resultSet
           rs.next()
           println("String:")
           println(rs.getString(2))
           println("Float:")
           println(rs.getFloat(2))
       }
   ```
   
   
   4. The output is:
   ```
   String:
   1.23
   Float:
   1.06728262E9
   ```
   I got the approximately correct result from `getString()` but incorrect 
result from `getFloat()`.
   
   **Expected behavior**
   I should get a precise float result from `getFloat()`. 
   
   **Desktop (please complete the following information):**
    - OS: [e.g. iOS]
    - Browser [e.g. chrome, safari]
    - Version [e.g. 22]
   
   
   
   **Additional context**
   The inplementation in `IoTDBRpcDataSet.java` shows that it just converts 
   the bytes to float in the method, while the bytes are actually in the format 
of String.
   
   A further dig into the source code shows that all data are in the format of 
String except the timestamp.
   Therefore, a simple fix is not possible because the issue is that the raw 
data transferred from the 
   database is in the format of String.
   This can cause precision loss and significant performance issue(extra 
parsing and formatting, more transfer cost).
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to