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

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

Open
HackPoint opened this issue Feb 18, 2024 · 14 comments

Comments

@HackPoint
Copy link

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

@lidavidm
Copy link
Member

Duplicate of #33475

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

@lidavidm lidavidm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
@HackPoint
Copy link
Author

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

@lidavidm
Copy link
Member

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

@HackPoint
Copy link
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

@lidavidm
Copy link
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.

@lidavidm lidavidm reopened this Feb 18, 2024
@HackPoint
Copy link
Author

HackPoint commented Feb 18, 2024

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

@lidavidm
Copy link
Member

Is the server implementation actually returning a parameter schema?

@HackPoint
Copy link
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?

@lidavidm
Copy link
Member

What server implementation are you using? It needs to fill in the parameter_schema in the CreatePreparedStatement response

arrow/format/FlightSql.proto

Lines 1524 to 1549 in a03d957

/*
* Wrap the result of a "CreatePreparedStatement" or "CreatePreparedSubstraitPlan" action.
*
* The resultant PreparedStatement can be closed either:
* - Manually, through the "ClosePreparedStatement" action;
* - Automatically, by a server timeout.
*
* The result should be wrapped in a google.protobuf.Any message.
*/
message ActionCreatePreparedStatementResult {
option (experimental) = true;
// Opaque handle for the prepared statement on the server.
bytes prepared_statement_handle = 1;
// If a result set generating query was provided, dataset_schema contains the
// schema of the result set. It should be an IPC-encapsulated Schema, as described in Schema.fbs.
// For some queries, the schema of the results may depend on the schema of the parameters. The server
// should provide its best guess as to the schema at this point. Clients must not assume that this
// schema, if provided, will be accurate.
bytes dataset_schema = 2;
// If the query provided contained parameters, parameter_schema contains the
// schema of the expected parameters. It should be an IPC-encapsulated Schema, as described in Schema.fbs.
bytes parameter_schema = 3;
}

@HackPoint
Copy link
Author

parameter_schema

Seems like it's empty: The calcite oriented db

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

@lidavidm
Copy link
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 #38585

@HackPoint
Copy link
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 #38585

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

@lidavidm
Copy link
Member

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

@MaoMiMao
Copy link

I encountered the same problem
image

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

No branches or pull requests

3 participants