Generating code from SQL
Use the Code wizard to generate the code that is used to get SQL access to data from your programs or applications.
Before you begin
Procedure
-
To launch the Code wizard from the Server tab,
right-click the virtual table or virtual view and select Generate Code From
SQL.
Alternatively, to compose and execute your SQL query directly from a selected SQL statement in the editor, right-click on the selected SQL statement and select Generate Code From SQL.
- On the SQL page, accept or change the file name that will be used to store the generated code.
-
Select from the following query options and click Next:
- Use Selected View – Creates a simple query. This is the default setting.
- Compose the SQL Statement – Selects all table columns and displays the resulting SQL statement. If necessary, you can choose to modify the resulting SQL statement before continuing to the next step.
- On the SQL Result Set page, review the result set and optionally rename variables, and click Next.
-
On the Code Generation page, choose the programming language that you
want to use to generate the SQL:
- Java JDBC Class
- Java Spark Application
- Scala Jupyter Notebook
- Scala Spark Application
- Python Jupyter Notebook
- VB.NET Class
- C# Class
- Other (Specify XSLT file)Note: The generated Scala Jupyter Notebook code provides a simple starter program showing you how to use the JDBC driver to load data into a Spark application. The wizard does not allow SQL parameter markers for this application type.
-
To finish generating the code, complete one of the following options:
- If you did not choose the Scala Jupyter Notebook option, click Finish.
- If you did chose the Scala Jupyter Notebook option, complete the following fields and click Finish:
Field Action Jupyter Kernel Name Enter the name of the kernel to use. Include additional Jars in the Generated Code Select to include additional JAR files when generating the code. This setting is optional and is only available after you set the Generate Code preferences to include additional Jar files. Leave credentials blank (use IOCTL) Select to use the IOCTL command call. Use the pandas API - Only for Python Notebook If you select Python Notebook, the dialog displays this option that let's you use the pandas API. Credentials processing in generated code Select from the following credential processing options: - Omit password text – the generated code will contain *** for the password variable, and will need to be updated manually.
- Use password text – the password is included in the generated code in hashed format.
- Use INI file – if this option is chosen, you must also specify the INI data set name to indicate that the DSN section in the INI file contains the user and password settings. Click Sample to generate and reference a sample INI file on your local system. This file must be available on the host where Jupyter Spark is running.
Preferences Click Preferences to review the default settings for code generation.
Results
The generated code is saved in your workspace and is accessible from the studio Client tab. The resulting file opens and can be modified in the editor if the Scala Jupyter Notebook option was not selected. Otherwise, the resulting file can be uploaded to Jupyter using the Jupyter Web UI.