Code Samples
Python code snippets to carry out common operations on e6data
Best Practices
Environment Variables
Setting environment variables is encouraged over hardcoding authentication credentials or cluster details. The following environment variables can be configured before initializing the connection:
HOST_NAME — Hostname or IP address of the e6data cluster.
E6_USER — Username (email address) associated with your e6data account.
E6_TOKEN — Access token generated from the e6data Console under your user profile.
These environment variables are fetched dynamically using os.getenv() during connection setup.
import os
from e6data_python_connector import Connection
HOST_NAME = os.getenv("HOST_NAME")
E6_USER = os.getenv("E6_USER")
E6_TOKEN = os.getenv("E6_TOKEN")Usage:
from e6data_python_connector import ConnectionCreate Connection
Sample code for establishing a connection with an e6data cluster.
Switch Database in an Existing Connection
Perform Query & Get Results
Setting up the cursor allows you to execute queries and fetch results. The cursor supports:
fetchall()— fetch all results.fetchmany(limit)— fetch a limited number of rows.fetchone()— fetch a single row.fetchall_buffer()— memory-efficient streaming for large result sets.
To get all the results:
To get only one result (first row):
To limit the number of results:
To fetch all results in a memory-efficient way
Code Hygiene
It is recommended to clear the cursor, close the cursor and close the connection after running a function as a best practice. This enhances performance by clearing old data from memory.
Get Row Count
This code executes a query and returns the number of rows in the result set.
Fetching rowcount directly from the cursor is preferred over using fetchall() for performance and memory efficiency.
Get Query Execution Plan
The following code runs a query and returns the execution plan generated for the query by the e6data engine.
The execution plan data will be returned as a JSON string and should be parsed as JSON data.
Abort a Query
The following code aborts a query, referenced by the input Query ID. Refer Get Query ID for information on obtaining the Query ID.
Get Query Time Metrics
The following code runs a query and returns:
amount of time taken to execute the query in seconds
amount of time the query spent in the queue awaiting execution in seconds
amount of time taken to parse the query in seconds
Get Query ID
This code executes a query and returns the query ID.
Combine Multiple Functions
The following code is an example using multiple functions defined above to return:
Number of rows
The time taken to execute the query
Query results
Auto Resume
To enable Auto Resume while establishing a connection using the Python Connector, set auto_resume=True in the connection configuration. This ensures that the cluster resumes automatically when a query is executed, eliminating the need for manual intervention.
Last updated
