All Products
Search
Document Center

DataWorks:Use an ad hoc query node to execute SQL statements (Optional)

Last Updated:Feb 19, 2025

DataWorks DataStudio's ad hoc query feature allows you to execute SQL statements within a MaxCompute project linked to your DataWorks workspace.

Prerequisites

The MaxCompute data source must be created and attached to Data Development (DataStudio).

Before developing MaxCompute tasks or creating related nodes, you must first establish a MaxCompute data source within the DataWorks workspace and attach it to Data Development (DataStudio), which serves as the underlying engine for developing MaxCompute tasks. For more information, see Create a MaxCompute data source and Environment preparation.

Enter ad hoc query

  1. Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose Data Development and O&M > Data Development. On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.

  2. In the left-side navigation pane, click the image icon.

  3. In the Ad Hoc Query panel, right-click Ad Hoc Query and select Create Node > ODPS SQL.

  4. In the Create Node dialog box, enter the Name.

    Note

    The node name must not exceed 128 characters.

  5. Click Confirm.

Execute SQL

You can now execute MaxCompute-supported SQL statements in the newly created ad hoc query node. For more information, see SQL overview.

Note
  • When executing MaxCompute tasks, a cost estimate is provided. This estimate is calculated by MaxCompute and is indicative only. The final cost will be reflected in your bill. For billing details, see MaxCompute billable items and billing method.

  • If an error occurs during cost estimation, it may be due to a non-existent table or insufficient permissions. You can disregard this error temporarily and address it after running the node based on the specific error message received.

For instance, to execute a DDL statement for table operations, input the table creation statement and click Run.

create table if not exists sale_detail
(
shop_name     string,
customer_id   string,
total_price   double
)
partitioned by (sale_date string,region string);
-- Create a partitioned table sale_detail

To view the cost estimate for this execution, click the Run option. In the Parameter pop-up, select the Run Resource Group and click Run.Cost EstimateCost Estimate

The execution details and results can be viewed in the Runtime Log section at the bottom of the configuration tab. If the SQL statement executes successfully, the result will display as OK.

This method can also be used to execute SELECT syntax.