All Products
Search
Document Center

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

Last Updated:Nov 18, 2024

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

Create an ad hoc query node

  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 Governance > 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 of the DataStudio page, click the image icon.

  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 运行 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.估价估价

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

You can execute SQL statements that follow the SELECT syntax in the same way.