nooberfsh / prusto

A presto/trino client library written in rust.
MIT License
37 stars 23 forks source link

An error occurred while connecting #43

Closed groobyming closed 4 months ago

groobyming commented 4 months ago

When I follow the official documentation example to connect to an existing trino server, I get the following error

HttpNotOk(401, "Basic authentication or X-Trino-User must be sent")

image

Here is my code:

ClientBuilder::new(user, host).port(port as u16).build().map_err(|e| {
            CustomError::ConnectOtherErr {message: e.to_string()}
})
nooberfsh commented 4 months ago

Please provide trino server version and the full example code.

groobyming commented 4 months ago

Please provide trino server version and the full example code.

@nooberfsh Thanks for your replay.

Trino version: 382

Example Code:

use prusto::{ClientBuilder, Presto};

  #[derive(Presto, Debug)]
    struct Foo {
        a: i64,
        b: f64,
        c: String,
    }
    #[tokio::test]
    async fn main() {
        let cli = ClientBuilder::new("user", "localhost")
            .port(8080)
            .catalog("iceberg")
            .build()
            .unwrap();

        let sql = "SELECT * FROM iceberg.iceberg_test.test_log  LIMIT 1";
        let result = cli.get_all::<Foo>(sql.to_string()).await.unwrap().into_vec();
    }
nooberfsh commented 4 months ago

I can see the server is running locally, can you confirm the server can be accessed through trino-cli or other database tools, such as DataGrip or dbeaver.

groobyming commented 4 months ago

I can see the server is running locally, can you confirm the server can be accessed through trino-cli or other database tools, such as DataGrip or dbeaver.

Connect success when using the idea database tool:

image
nooberfsh commented 4 months ago

It seems there is some error message in the background.

image

Can you run some simple query to see whether it is actually working?

groobyming commented 4 months ago

@nooberfsh I believe the issue is caused by different request headers in the Presto and Trino clients.

【Presto headers】: https://prestodb.io/docs/current/develop/client-protocol.html

image

【Trino headers】: https://trino.io/docs/current/develop/client-protocol.html

image

And In our project, we can only hardcode the Presto header. https://github.com/nooberfsh/prusto/blob/master/src/presto_header.rs

image

Is there any way to customize this header?

nooberfsh commented 4 months ago

prusto has two set of headers which is defined in header.rs and presto_header.rs, the default headers is trino, the presto header can be enabled by the presto feature.

As I said before, can you run some simple query in the IDE to see whether it is actually working?

groobyming commented 4 months ago

It seems there is some error message in the background. image Can you run some simple query to see whether it is actually working?

image

when I disable presto feature, it works for me

image
groobyming commented 4 months ago

prusto has two set of headers which is defined in header.rs and presto_header.rs, the default headers is trino, the presto header can be enabled by the presto feature.

As I said before, can you run some simple query in the IDE to see whether it is actually working?

image