For the complete documentation index, see llms.txt. This page is also available as Markdown.

SQL Runner

A license is required to access Spark functionality on the DNAnexus Platform. Contact DNAnexus Sales for more information.

Overview

The Spark SQL Runner application starts a Spark cluster and executes your provided list of SQL queries. This is especially useful if you need to perform a sequence of queries multiple times. You can vary the size of your cluster to speed up your tasks.

How to Run Spark SQL Runner

Input:

  • sqlfile: (Required) SQL file containing an ordered list of SQL queries.

  • substitutions: JSON file containing variable substitutions.

  • user_config: JSON user configuration file to set or override specific Spark settings.

Other Options:

  • export: (boolean) default false. Exports output files with results for queries in sqlfile.

  • export_options: JSON file containing export configuration.

  • collect_logs: (boolean) default false. Collects cluster logs from all nodes.

  • executor_memory: (string) Amount of memory to use per executor process, in MiB unless otherwise specified. Common values include 2g or 8g. This is passed as --executor-memory to Spark submit.

  • executor_cores: (integer) Number of cores to use per executor process. This is passed as --executor-cores to Spark submit.

  • driver_memory: (string) Amount of memory to use for the driver process. Common values include 2g or 8g. This is passed as --driver-memory to Spark submit.

  • log_level: (string) default INFO. Logging level for both driver and executors. [ALL, TRACE, DEBUG, INFO]

Output:

  • output_files: Output files include a report SQL file and query export files.

Basic Run

Examples

sqlfile

How sqlfile is Processed

  1. The SQL runner extracts each command in sqlfile and runs them in sequential order.

  2. Every SQL command needs to be separated by a semicolon ;.

  3. Any command starting with -- is ignored (comments). Any comment within a command must be inside /*...*/. The following are examples of valid comments:

Variable Substitution

Variable substitution can be done by specifying the variables to replace in substitutions.

In this example, each reference to srcdb in sqlfile within ${...} is substituted with sskrdemo1. For example, select * from ${srcdb}.${patient_table};. The script adds the set command before executing any of the SQL commands in sqlfile. As a result, select * from ${srcdb}.${patient_table}; translates to:

Export

If enabled, the results of the SQL commands are exported to a CSV file. export_options defines an export configuration.

  1. num_files: default 1. This defines the maximum number of output files to generate. The number depends on how many executors are running in the cluster and how many partitions of this file exist in the system. Each output file corresponds to a part file in the CSV export.

  2. fileprefix: The filename prefix for every SQL output file. By default, output files are prefixed with query_id, which is the order in which the queries are listed in sqlfile (starting with 1), for example, 1-out.csv. If a prefix is specified, output files are named like <prefix>-1-out.csv.

  3. header: Default is true. If true, a header is added to each exported file.

User Configuration

Values in spark-defaults.conf override or add to the default Spark configuration.

Output Files

The export folder contains two generated files:

  • <JobId>-export.tar: Contains all the query results.

  • <JobId>-outfile.sql: SQL debug file.

Export Files

After extracting the export tar file, the structure appears as follows:

In this example, demo is the fileprefix used. The export produces one folder per query. Each folder contains a SQL file with the query executed and a .csv folder containing the result CSV.

SQL Report File

Every SQL run execution generates a SQL runner debug report file. This is a SQL file.

It lists all the queries executed and the status of the execution (Success or Fail). It also lists the name of the output file for that command and the time taken. If there are any failures, it reports the query and stops executing subsequent commands.

SQL Errors

During execution of the series of SQL commands, a command may fail (for example, due to an error or syntax issue). In that case, the app quits and uploads a SQL debug file to the project:

The output identifies the line with the SQL error and its response.

The query in the .sql file can be fixed, and this report file can be used as input for a subsequent run, allowing you to resume from where execution stopped.

Last updated

Was this helpful?