All Products
Search
Document Center

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

Last Updated:Aug 17, 2023

You can use the ad hoc query feature provided by DataWorks DataStudio to execute SQL statements in the MaxCompute project associated with your DataWorks workspace.

Create an ad hoc query node

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

  2. In the left-side navigation pane of the DataStudio page, click Ad Hoc Query.

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

  4. In the Create Node dialog box, configure the Name parameter.

    Note

    The node name cannot exceed 128 characters in length.

  5. Click Confirm.

Execute SQL statements

After the ad hoc query node is created, you can execute SQL statements supported by MaxCompute in the node. For more information, see Overview of MaxCompute SQL.

For example, to Table operations, enter the following statement and click the Run icon in the top toolbar of the configuration tab of the node.

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 named sale_detail.

You can view the estimated cost for the statement execution. In detail, you can click the Run icon in the top toolbar, select a resource group that you want to use in the Parameters dialog box, and then click Run. In the Estimate MaxCompute Computing Cost dialog box, you can view the estimated cost. Estimate MaxCompute Computing CostParameters

View the execution details and result in the Runtime Log section of the lower part of the configuration tab. If the SQL statement is successfully executed, the result is shown as OK.

You can execute SELECT syntax in the same way.