trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.27k stars 2.95k forks source link

Trino JDBC does not have support for prepareCall #5433

Open mhlaskar1991 opened 3 years ago

mhlaskar1991 commented 3 years ago

Presto JDBC does not have support for prepareCall which is required to call procedures

findepi commented 3 years ago

Currently available API is to call them via Statement:

For example

try (Connection connection = DriverManager.getConnection("jdbc:presto://localhost:8080/hive/default", "presto", "")) {
    try (Statement statement = connection.createStatement()) {
        boolean hasResultSet = statement.execute("CALL system.sync_partition_metadata('default', 'table_name', 'FULL')");
        verify(!hasResultSet, "unexpected resultSet");
    }
}

However, we should support prepareCall too.

Gentle-Chen commented 3 years ago

@findepi hihi, just want to ask if there is way that i can setup parameters by using createStatement to call procedure like system.create_empty_partition(?,?,?,?)

Gentle-Chen commented 3 years ago

I tried below code and it said io.prestosql.spi.PrestoException: line 1:1: Incorrect number of parameters: expected 0 but found 1

String sql = "CALL system.create_empty_partition(schema_name => 'test',table_name => 'test', " +
                "partition_columns => ARRAY['year','month','day','hour'], " +
                "?)";
        try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
                pstmt.setString(1, "partition_values => ARRAY['2021','06','16','00']");
                pstmt.execute();
        }
findepi commented 3 years ago

It seems ? parameters are not supported for CALL statement at all. cc @kasiafi

trino> PREPARE c FROM CALL system.runtime.kill_query(?, 'message');
PREPARE

Should list a parameter:

trino> DESCRIBE INPUT c;
 Position | Type
----------+------
(0 rows)

Should accept a parameter

trino> EXECUTE c USING 'query_id';
Query 20210616_150207_00006_x99jb failed: line 1:1: Incorrect number of parameters: expected 0 but found 1
io.trino.spi.TrinoException: line 1:1: Incorrect number of parameters: expected 0 but found 1
    at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:48)
    at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:43)
    at io.trino.execution.QueryPreparer.validateParameters(QueryPreparer.java:88)
    at io.trino.execution.QueryPreparer.prepareQuery(QueryPreparer.java:80)
    at io.trino.execution.QueryPreparer.prepareQuery(QueryPreparer.java:56)