arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[Java][FlightRPC] Flight SQL JDBC driver parameter getting an exception: parameter ordinal 1 out of range

Open HackPoint opened this issue 4 months ago • 14 comments

Describe the bug, including details regarding any error messages, version, and platform.

protected AvaticaParameter getParameter(int param) throws SQLException {
        try {
            return (AvaticaParameter)this.getSignature().parameters.get(param - 1);
        } catch (IndexOutOfBoundsException var3) {
            throw AvaticaConnection.HELPER.toSQLException(AvaticaConnection.HELPER.createException("parameter ordinal " + param + " out of range"));
        }
    }

Getting this exception

My code:

public static void handleSqlStatements() throws SQLException {
        String url = "jdbc:arrow-flight://localhost:5000;useEncryption=false;useServerPrepStmts=false;";
        String sql = "select * from MixedTypeDB.`Table` where OID=?"; // Example SQL query
        System.out.println("SQL query: " + sql); // Debugging: Log the query

        try (var connection = DriverManager.getConnection(url)) {
            ArrowFlightPreparedStatement pstmt = (ArrowFlightPreparedStatement)connection.prepareStatement(sql);
            ParameterMetaData metadata = pstmt.getParameterMetaData();
            pstmt.setInt(1, 12345); // crashing here

            System.out.println("Executing SQL query: " + sql);

            try (final ResultSet rs = pstmt.executeQuery()) {
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
}
<dependency>
            <groupId>org.apache.arrow</groupId>
            <artifactId>flight-sql-jdbc-driver</artifactId>
            <version>13.0.0</version>
        </dependency>

Component(s)

Java

HackPoint avatar Feb 18 '24 14:02 HackPoint

Duplicate of https://github.com/apache/arrow/issues/33475

This was fixed in 15.0.0, can you upgrade and try again?

lidavidm avatar Feb 18 '24 14:02 lidavidm

Duplicate of #33475

This was fixed in 15.0.0, can you upgrade and try again?

Have tried it with 15.0.0 and it's has the same issue

HackPoint avatar Feb 18 '24 14:02 HackPoint

Can you post all the details with 15.0.0 (stack trace, versions, etc)?

lidavidm avatar Feb 18 '24 15:02 lidavidm

Can you post all the details with 15.0.0 (stack trace, versions, etc)?

Sir, the error is still the same and the code is exactly the same, if you want I can repaste in here again , including the exception details. I can even add the project it self if needed. Which I will do. anybase-inspector-probe.zip

HackPoint avatar Feb 18 '24 15:02 HackPoint

I'm just asking for the stack trace, so I can take a quick look. While the project is appreciated, I don't have the time to build this from scratch.

lidavidm avatar Feb 18 '24 15:02 lidavidm

`image @lidavidm

Error executing SQL: parameter ordinal 1 out of range java.sql.SQLException: parameter ordinal 1 out of range at cfjd.org.apache.calcite.avatica.Helper.createException(Helper.java:60) at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.getParameter(AvaticaPreparedStatement.java:427) at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.getSite(AvaticaPreparedStatement.java:434) at cfjd.org.apache.calcite.avatica.AvaticaPreparedStatement.setInt(AvaticaPreparedStatement.java:174) at com.ge.core.SQLInterpreterWithParameters.setParameter(SQLInterpreterWithParameters.java:62) at com.ge.core.SQLInterpreterWithParameters.handleSqlStatements(SQLInterpreterWithParameters.java:38) at com.ge.grid.Main.main(Main.java:11)

HackPoint avatar Feb 18 '24 15:02 HackPoint

Is the server implementation actually returning a parameter schema?

lidavidm avatar Feb 18 '24 15:02 lidavidm

Is the server implementation actually returning a parameter schema?

all the column names are back other than that IDK, can you point me where to look please?

HackPoint avatar Feb 18 '24 15:02 HackPoint

What server implementation are you using? It needs to fill in the parameter_schema in the CreatePreparedStatement response https://github.com/apache/arrow/blob/a03d957b5b8d0425f9d5b6c98b6ee1efa56a1248/format/FlightSql.proto#L1524-L1549

lidavidm avatar Feb 18 '24 15:02 lidavidm

parameter_schema

Seems like it's empty: The calcite oriented db

var preparedStatementResult = new ActionCreatePreparedStatementResult
        {
            DatasetSchema = schema.ToByteString(),
            ParameterSchema = ByteString.Empty,

HackPoint avatar Feb 18 '24 15:02 HackPoint

The server needs to return the schema so that the driver knows how many and what type the parameters are. We could perhaps improve the error message on the client, or assume what the type/number of parameters are based on what the client does, but that is a duplicate of https://github.com/apache/arrow/issues/38585

lidavidm avatar Feb 18 '24 15:02 lidavidm

The server needs to return the schema so that the driver knows how many and what type the parameters are. We could perhaps improve the error message on the client, or assume what the type/number of parameters are based on what the client does, but that is a duplicate of #38585

I understand and already opened an issue in our code base, really appreciate you assistance. Awesome responsiveness.

HackPoint avatar Feb 18 '24 15:02 HackPoint

Sounds good. I'll leave this open and link it in that issue to track the error message improvement.

lidavidm avatar Feb 18 '24 17:02 lidavidm

I encountered the same problem image

MaoMiMao avatar Mar 12 '24 03:03 MaoMiMao