Skip to content

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

Description

@HackPoint

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

Activity

  1. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

    Duplicate of apache/arrow#33475

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

  2. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    Duplicate of apache/arrow#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

  3. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

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

  4. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    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

  5. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

    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.

  6. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    `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)

  7. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

    Is the server implementation actually returning a parameter schema?

  8. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    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?

  9. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

    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

  10. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    parameter_schema

    Seems like it's empty: The calcite oriented db

    var preparedStatementResult = new ActionCreatePreparedStatementResult
            {
                DatasetSchema = schema.ToByteString(),
                ParameterSchema = ByteString.Empty,
  11. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

    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 #156

  12. HackPoint commented on Feb 18, 2024

    @HackPoint
    Author

    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 #156

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

  13. lidavidm commented on Feb 18, 2024

    @lidavidm
    Member

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

  14. MaoMiMao commented on Mar 12, 2024

    @MaoMiMao

    I encountered the same problem
    image

  15. transferred this issue fromapache/arrowon Nov 26, 2024
  16. Termainl commented on Jan 6, 2025

    @Termainl

    I encountered the same problem
    the version 15.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions