Created on 09-07-2024 10:25 AM - last edited on 09-08-2024 11:47 PM by VidyaSargur
Hi Team,
Good Day..
I'm beginner in Node.JS trying to connect Hive DB using
I couldn't establish the db connection.
Any help would be much appreciated...
Note: Our Hive DB has ssl connection, jks trust store password, HTTP protocol , httppath=cliservice
NODE.JS SAMPLE CODE:
client.connect(
{
host: 'jdbc:hive2://abc.com:2181/dev_db;ssl=true;sslTrustStore=/etc/hive-jks/hivetrust.jks;trustStorePassword=pro@!23;transportMode=http;httpPath=cliservice;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2',
port: 2181
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication({
username: 'username',
password: 'password'
})
).then(async client => {
console.log(client);
const session = await client.openSession({
client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
});
}).catch(error => {
console.log(error);
});
when I console.log client It's printing but I tried to open client.open session I've been facing issues
Kindly check the host url string which I've given right or not.
Could you please help on this issue.
PFB Error.
Thank you..
Created 09-08-2024 01:44 AM
Adding message Tags to reach better view to get answer
Created 09-08-2024 11:46 PM
@Viki_Nodejs, Welcome to our community! To help you get the best possible answer, I have tagged our Hive experts @asish @smruti who may be able to assist you further.
Please feel free to provide any additional information or details about your query. We hope that you will find a satisfactory solution to your question.
Regards,
Vidya Sargur,Created 09-09-2024 12:36 AM
@Viki_Nodejs It seems like the hostname resolution fails. The url you have shared is rather jdbc compliant.
Could you give the following a try?
client.connect(
{
host: 'abc.com',
port: 2181
},
new hive.connections.HttpConnection({
transportMode: 'http',
httpPath: 'cliservice',
serviceDiscoveryMode: 'zooKeeper',
zooKeeperNamespace: 'hiveserver2'
}),
new hive.auth.PlainHttpAuthentication({
username: 'username',
password: 'password'
}),
{
ssl: true,
sslTrustStore: '/etc/hive-jks/hivetrust.jks',
trustStorePassword: 'pro@!23'
}
).then(async client => {
Created 09-09-2024 11:28 PM
Hi Smruti,
Thanks for your reply. I've used the above snippet. PFB Error
Created 09-10-2024 06:25 AM
Do we get this error after it gets connected? Could there be a socket timeout error set at client side? I am not aware if the hive driver has a default timeout value.
Instead of ZooKeeper, could you try connecting to HS2 directly.
e.g.
host: "hs2 node fqdn"
port: 10001
Remove
serviceDiscoveryMode: 'zooKeeper',
zooKeeperNamespace: 'hiveserver2'
Created 09-25-2024 12:11 PM
@Viki_Nodejs
Hi Viki, were you able to resolve the issue. I am also encountering same issue
Created 12-16-2024 01:30 AM
Hi sravansrk,
Still, the same issue persists.
Created 12-17-2024 10:14 AM
@Viki_Nodejs
if you haven't resolved this issue could you try the below steps and revert.
Use the hive-driver package for Node.js, which supports HiveServer2 over HTTP/HTTPS.
Ensure you have:
Here's an example of how to set up the connection using the hive-driver:
const { HiveClient, TCLIServiceTypes } = require('hive-driver');
async function connectToHive() {
const client = new HiveClient(TCLIServiceTypes);
// Configure the Hive connection
const connection = client.connect({
host: '<HIVE_SERVER_HOSTNAME>', // e.g., hive.example.com
port: 10001, // HiveServer2 port, typically 10001 for HTTPS
options: {
path: '/cliservice', // HTTP path to HiveServer2
ssl: true, // Enable SSL
sslOptions: {
rejectUnauthorized: true, // Ensure certificates are verified
ca: '<path/to/truststore.pem>' // Convert your JKS truststore to PEM format
},
// Authentication
username: '<YOUR_USERNAME>',
password: '<YOUR_PASSWORD>',
// You can add session configurations here
}
});
try {
// Open the connection
await connection.openSession();
console.log('Connected to Hive');
// Example query
const result = await connection.executeStatement('SELECT * FROM your_table LIMIT 10');
console.log(result);
// Close the session
await connection.closeSession();
} catch (error) {
console.error('Error connecting to Hive:', error);
} finally {
// Ensure the connection is closed
await connection.close();
}
}
connectToHive();
SSL Truststore [Very Important]