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

Incorrect result returned by getFloat in JDBC. #2132

Closed
140378476 opened this issue Nov 26, 2020 · 5 comments · Fixed by #2167
Closed

Incorrect result returned by getFloat in JDBC. #2132

140378476 opened this issue Nov 26, 2020 · 5 comments · Fixed by #2167
Labels
bug Something isn't working

Comments

@140378476
Copy link

140378476 commented Nov 26, 2020

Describe the bug
I got clearly incorrect results when retrieving data using method getFloat.

To Reproduce
Steps to reproduce the behavior:

  1. Create timeseries: CREATE TIMESERIES root.t.d WITH DATATYPE=FLOAT, ENCODING=GORILLA
  2. Insert data: INSERT INTO root.t(timestamp,d) VALUES(1,1.2345678)
  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))
    }
  1. The output is:
String:
1.2345678
Float:
1.0673209E9

I got incorrect result from getFloat().

Expected behavior
I should get a correct result from getFloat().

Desktop (please complete the following information):

  • Version 0.10.1

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.
I presume that the raw data transferred from the database is in the format of String.
This may cause performance issue(extra parsing and formatting, more transfer cost).

@HTHou
Copy link
Contributor

HTHou commented Nov 26, 2020

Hi, same reason of your last question. Try to use encoding type GORILLA ?

@140378476
Copy link
Author

Using encoding type GORILLA did fix the precision loss issue, but the method getFloat still return
incorrect values.

I will try to make a simple fix for the latter problem.

@qiaojialin
Copy link
Member

Hi, thanks for your detailed description, and welcome to contribute 👍

@Alima777
Copy link
Contributor

Hi, I checked the code and found it's a typo mistake: It's in 326 line of AbstractIoTDBJDBCResultSet.

Thanks for your detailed description!! If you don't mind, welcome to pull a PR to fix it :D

@HTHou
Copy link
Contributor

HTHou commented Dec 5, 2020

The bug is fixed. I'll close this issue.

@HTHou HTHou closed this as completed Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants