lenchv / hive-driver

Driver for connection to Apache Hive via Thrift API
MIT License
40 stars 9 forks source link

how to connect hive with specify database/schema. #59

Closed xunziheng closed 1 year ago

xunziheng commented 1 year ago

for example:

const client = await this.client.connect(
        {
          host: 'localhost',
          port: 10000,
          options: {
            database: 'test'
          }
        },
        new hive.connections.TcpConnection(),
        new hive.auth.PlainTcpAuthentication({
          username: 'root',
          password: 'root',
        })
);
lenchv commented 1 year ago

Hi @xunziheng! There is no such possibility atm. You can use "USE" statement after you open a session:

const dbName = `your_dbname`;
const client = await new hive.HiveClient(
    TCLIService,
    TCLIService_types
).connect(
    {
        host: 'localhost',
        port: 10000
    },
    new hive.connections.TcpConnection(),
    new hive.auth.NoSaslAuthentication()
);
const session = await client.openSession({
    client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
});
await session.executeStatement(`USE ${dbName}`);

The issue with setting db within the connection is that open session request is not documented well: https://github.com/lenchv/hive-driver/blob/master/thrift/TCLIService.thrift#L583

There is a configuration hash map, that overlaps Hive default configurations, so probably there is some config to do this, but the easiest is to use "USE" statement

xunziheng commented 1 year ago

Hi @lenchv ! Great to receive your reply, I got it, it's a good library that I already use in production and hope we can improve it better together.