Ad-hoc query
You can use natural language commands to instruct code agents, such as Qoder and CodeX, to run a one-time SQL query or script, query metadata, and retrieve the results without creating a persistent task. This document describes the capability's features, prerequisites, usage examples, and execution results, and provides a list of input parameters in the appendix.
Overview
The ad-hoc query feature lets you use natural language commands to run one-time SQL queries, scripts, or metadata queries and receive immediate results. This process does not create a persistent, scheduled task in your project. It supports a wide range of task types, including MaxCompute SQL, relational database SQL (for databases like MySQL, Oracle, PostgreSQL, and SQLServer), Hologres, StarRocks, Shell, and Python. After you submit a task, you can check its run status, get the results, and view its logs.
Use cases:
-
Temporarily verify the output of a SQL query or script without creating a formal task.
-
Perform one-time operations, such as creating tables, querying data, or fetching metadata.
-
Query the table schema and column details in a specific database or data source.
-
Verify your logic with an ad-hoc query before implementing it as a persistent task.
Ad-hoc queries are for one-time execution and do not create scheduled tasks. For long-running or recurring jobs, create and submit an offline computing task after your logic is verified. The number of rows returned in a single query may be limited by your service version. For queries that return a large amount of data, use a standard persistent task.
Prerequisites
-
You must be a member of an existing Dataphin project.
-
Have your SQL statement or script ready.
-
When running SQL for a relational database (such as MySQL, Oracle, PostgreSQL, or SQLServer), you must specify the target data source and the corresponding database name or schema. For task types like MaxCompute SQL, Shell, or Python, you typically only need to specify the project.
Usage examples
Describe your request to the code agent in natural language. You can copy the following example prompts:
-
"Run a MaxCompute SQL query in this project:
SELECT COUNT(*) FROM my_table." -
"Show me the column schema of the
companytable in thepublicdatabase of this MySQL data source." -
"Temporarily run this Shell command:
echo hello world, and return the output." -
"Run this SQL as an ad-hoc query in the production environment. After it finishes, paste the results here."
Interaction steps:
-
The code agent typically confirms the runtime environment, target project, task type, and the code to execute. If any information is missing, it will ask you for it.
-
When executing a relational database SQL query, the code agent usually confirms the target data source and database name or schema before submitting the query.
-
After submission, the code agent waits for the task to complete before retrieving the results.
-
If the result set is empty or an error occurs, the code agent typically checks the run status and logs to determine if the task succeeded before responding to you.
Execution results
After the operation completes, you receive the following:
-
Return content: Query tasks return structured data, typically with column headers in the first row followed by data rows. Script tasks return the runtime output.
-
Completion status: After a task is submitted and accepted, it begins running. Results are available upon successful completion. There might be a slight delay in retrieving results immediately after completion, and the code agent will typically retry or check the run status.
-
Review and verification: You can compare the returned results with your expectations. If you need to troubleshoot an error, you can ask the code agent to check the run logs to identify the cause.
A success message from the command line only indicates that the request has been accepted. The actual results returned and the status displayed in the Dataphin UI should be considered the definitive source of truth.
Appendix: Input parameters
The following table lists the parameters for running an ad-hoc query. This is for reference only. In practice, the code agent automatically identifies the necessary information from your command and will prompt you if anything is missing. You do not need to provide items marked as "No", as the system generates them automatically.
|
Parameter |
Required |
Description |
Example |
|
tenant ID |
Yes |
The ID of the Dataphin tenant. |
1234567890123456789 |
|
project ID |
Yes |
The Dataphin project where the query runs. |
— |
|
runtime environment |
No |
The development ( |
PROD |
|
task type |
Yes |
The type of query or script to execute, such as MaxCompute SQL, relational database SQL, Shell, or Python. |
MaxCompute SQL |
|
execution code |
Yes |
The SQL statement or script content to run. |
|
|
data source |
Conditionally Required |
Required when running relational database SQL. Specifies the target data source for the query. |
— |
|
database name/schema |
Conditionally Required |
Required when running relational database SQL. Specifies the target database or schema. |
public |
|
runtime parameters |
No |
Key-value pairs for variables used in the code, such as the business date. |
|