Ready to get started?

Learn more about CData Cloud Hub or sign up for a free trial:

Learn More

Query Presto Data as a MySQL Database in Node.js

Execute MySQL queries against Presto data from Node.js.

You can use the CData Cloud Hub to query Presto data through a MySQL interface. Follow the procedure below to create a virtual database for Presto in the Cloud Hub and start querying using Node.js.

The CData Cloud Hub provides a pure MySQL, cloud-to-cloud interface for Presto, allowing you to easily query live Presto data in Node.js — without replicating the data to a natively supported database. As you query data in Node.js, the CData Cloud Hub pushes all supported SQL operations (filters, JOINs, etc) directly to Presto, leveraging server-side processing to quickly return Presto data.

Create a Virtual MySQL Database for Presto Data

CData Cloud Hub uses a straightforward, point-and-click interface to connect to data sources and generate APIs.

  1. Login to Cloud Hub and click Databases.
  2. Select "Presto" from Available Data Sources.
  3. Enter the necessary authentication properties to connect to Presto.

    Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.

    To enable TLS/SSL, set UseSSL to true.

    Authenticating with LDAP

    In order to authenticate with LDAP, set the following connection properties:

    • AuthScheme: Set this to LDAP.
    • User: The username being authenticated with in LDAP.
    • Password: The password associated with the User you are authenticating against LDAP with.

    Authenticating with Kerberos

    In order to authenticate with KERBEROS, set the following connection properties:

    • AuthScheme: Set this to KERBEROS.
    • KerberosKDC: The Kerberos Key Distribution Center (KDC) service used to authenticate the user.
    • KerberosRealm: The Kerberos Realm used to authenticate the user with.
    • KerberosSPN: The Service Principal Name for the Kerberos Domain Controller.
    • KerberosKeytabFile: The Keytab file containing your pairs of Kerberos principals and encrypted keys.
    • User: The user who is authenticating to Kerberos.
    • Password: The password used to authenticate to Kerberos.
  4. Click Test Database.
  5. Click Privileges -> Add and add the new user (or an existing user) with the appropriate permissions.

With the virtual database created, you are ready to connect to Presto data from any MySQL client.

Query Presto from Node.js

The following example shows how to define a connection and execute queries to Presto with the MySQL module. You will need the following information:

  • Host name, or address, and port: The address of your instance of the Cloud Hub (myinstance.cdatacloud.net) and the port (3306)
  • Username and password: The username and password of a user you authorized on the Cloud Hub
  • Database name: The database you configured for Presto (prestodb)

Connect to Presto data and start executing queries with the code below:

var mysql      = require('mysql');
var fs         = require('fs');
var connection = mysql.createConnection({
  host     : 'myinstance.cdatacloud.net',
  database : 'prestodb',
  port	   : '3306',
  user     : 'admin',
  password : 'password',
  ssl      : {
    ca : fs.readFileSync('C:/certs/myCA.pem')
  }
});
connection.connect();
connection.query('SELECT * FROM Customer', function(err, rows, fields) {
  if (err) throw err;
  console.log(rows);
});

connection.end();