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.
Prerequisites
A MaxCompute data source is added to DataWorks and is associated with DataStudio.
Before you create an ODPS node to develop a MaxCompute task, you must add a MaxCompute project to your DataWorks workspace as a MaxCompute data source and associate the MaxCompute data source with DataStudio as an underlying engine for MaxCompute task development. For more information, see Add a MaxCompute data source and Environment preparation.
Create an ad hoc query node
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.
In the left-side navigation pane of the DataStudio page, click the
icon.
In the Ad Hoc Query pane, right-click Ad Hoc Query and choose
.In the Create Node dialog box, configure the Name parameter.
NoteThe node name cannot exceed 128 characters in length.
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.
When you run a MaxCompute task, the estimated fees are displayed on the page. The fees are included in the bills of MaxCompute. The estimation result is for reference only. You can view your bill for the actual costs. For more information, see Billable items and billing methods.
If an error is reported during fee estimation, a potential cause is that a desired table does not exist or you do not have the required permissions. You can ignore this error and run the node. Then, you can handle the error based on a reported error message.
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.