...
<property>
<name>hive.server2.authentication</name>
<value>nosasl</value>
</property>
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10000,
},
new hive.connections.TcpConnection(),
new hive.auth.NoSaslAuthentication()
).then(client => {
// ...
});
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10001,
options: {
path: '/hive'
}
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication()
).then(client => {
// ...
});
...
<property>
<name>hive.server2.authentication</name>
<value>none</value>
</property>
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10000,
},
new hive.connections.TcpConnection(),
new hive.auth.PlainTcpAuthentication()
).then(client => {
// ...
});
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10001,
options: {
path: '/hive'
}
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication()
).then(client => {
// ...
});
...
<property>
<name>hive.server2.authentication</name>
<value>ldap</value>
</property>
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10000,
},
new hive.connections.TcpConnection(),
new hive.auth.PlainTcpAuthentication({
username: 'admin',
password: '123456'
})
).then(client => {
// ...
});
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10001,
options: {
path: '/hive'
}
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication({
username: 'admin',
password: '123456'
})
).then(client => {
// ...
});
npm i kerberos
# *nix
kinit hive@KERBEROS.SERVER
# On windows client must be authorized by domain controller
...
<property>
<name>hive.server2.authentication</name>
<value>kerberos</value>
</property>
<property>
<name>hive.server2.thrift.sasl.qop</name>
<value>auth</value>
</property>
const kerberos = require('kerberos');
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10000,
},
new hive.connections.TcpConnection(),
new hive.auth.KerberosTcpAuthentication({
username: 'hive@KERBEROS.SERVER',
password: 'hive'
}, new auth.helpers.MongoKerberosAuthProcess({
fqdn: 'hive.driver',
service: 'hive'
}, kerberos)
).then(client => {
// ...
});
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'localhost',
port: 10001,
options: {
path: '/hive'
}
},
new hive.connections.HttpConnection(),
new auth.KerberosHttpAuthentication({
username: 'hive@KERBEROS.SERVER',
password: 'hive'
}, new auth.helpers.MongoKerberosAuthProcess({
fqdn: 'hive.driver',
service: 'hive'
}, kerberos))
).then(client => {
// ...
});
The driver is not able to connect to zookeeper directly. Zookeeper contains a list of hosts to hive clusters, so you can retrieve from zookeeper the list on your own and then connect to hive via hive-driver.
To connect to zookeeper you can use npm library zookeeper. To retrieve list of hive clusters you have to know host of the zookeeper server and namespace.
Host and namespace you can find in hive-site.xml in properties: hive.zookeeper.quorum (one host is enough) and hive.zookeeper.namespace (default: hiveserver2).
After that you should be able to connect to zookeeper and retrieve hive clusters. Here is an example, but your cases maybe different, at least parsing server uri may differ:
const ZooKeeper = require('zookeeper');
function parseServerUri(param) {
return param.replace(/^serverUri=/, '').split(';').shift();
}
async function getServerUri({ zookeeperQuorum, namespace }) {
return new Promise((resolve, reject) => {
const client = new ZooKeeper({
connect: zookeeperQuorum,
timeout: 5000,
debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
host_order_deterministic: false,
});
client.on('connect', async () => {
// getting list of clusters from zookeeper namespace
const clusters = await client.get_children(namespace);
// take random cluster and parse it
const serverUri = parseServerUri(clusters[Math.ceil((clusters.length - 1) * Math.random())]);
resolve(serverUri);
});
client.init();
});
};
const hiveHost = await getServerUri({ zookeeperQuorum: 'localhost:2181', namespace: '/hiveserver2' });
And when you get hive host you can connect with hive-driver:
async function connectToHive(host, port) {
const client = new hive.HiveClient(TCLIService, TCLIService_types);
const utils = new hive.HiveUtils(TCLIService_types);
client.connect(
{ host, port },
new hive.connections.TcpConnection(),
new hive.auth.NoSaslAuthentication()
).then(async client => {
// ... execute statements
await client.close();
});
}
const [host, port] = hiveHost.split(':');
await connectToHive(host, port);
You can find an example of the instance with zookeeper in .docker folder.
To run it execute following commands:
make up-zoo TYPE=tcp.nosasl.zoo
Via beeline you can connect as following:
docker-compose exec hive-server bin/beeline
!connect jdbc:hive2://zookeeper:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: '<cluster-name>.azurehdinsight.net',
port: 443,
options: {
path: '/hive2',
https: true
}
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication({
username: 'cluster-user',
password: 'cluster-password'
})
).then(client => {
// ...
});
For all kinds of connections the SSL settings are the same
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'host.name',
port: 10000,
options: {
ssl: true,
cert: fs.readFileSync('/path/to/cert.crt'),
key: fs.readFileSync('/path/to/cert.key'),
// in case of self-signed cert
ca: fs.readFileSync('/path/to/cert.ca')
}
},
new hive.connections.TcpConnection(),
new hive.auth.NoSaslAuthentication()
).then(client => {
// ...
});
const hive = require('hive-driver');
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'host.name',
port: 10001,
options: {
path: '/hive',
https: true,
cert: fs.readFileSync('/path/to/cert.crt'),
key: fs.readFileSync('/path/to/cert.key'),
// in case of self-signed cert
ca: fs.readFileSync('/path/to/cert.ca')
}
},
new hive.connections.HttpConnection(),
new hive.auth.PlainHttpAuthentication()
).then(client => {
// ...
});
npm i jks-js
const jks = require('jks-js');
const hive = require('hive-driver');
const keystore = jks.toPem(
fs.readFileSync('/path/to/keystore.jks'),
'keystore-password'
);
const client = new hive.HiveClient(
hive.thrift.TCLIService,
hive.thrift.TCLIService_types
);
client.connect(
{
host: 'host.name',
port: 10000,
options: {
ssl: true,
cert: keystore['alias'].cert,
key: keystore['alias'].key
}
},
new hive.connections.TcpConnection(),
new hive.auth.NoSaslAuthentication()
).then(client => {
// ...
});