Query MaxCompute tables with SQL File

更新时间:
复制 MD 格式

DSW includes a built-in SQL File plugin for querying MaxCompute data sources with SQL—no Python code required.

Billing

SQL queries in DSW don't incur additional fees. You pay only for MaxCompute compute and storage costs.

Prerequisites

Before you begin, ensure the following:

  • MaxCompute is activated. For details, see Activate MaxCompute.

  • Your account must have MaxCompute project permissions. No additional authorization is required if you log in with your Alibaba Cloud account. For RAM users, follow the steps below to grant the necessary permissions.

    Steps

    1. Log in to the MaxCompute console with your Alibaba Cloud account, then select a region in the upper-left corner.

    2. In the left navigation pane, choose Workspace > Project management.

    3. On the Project management page, click Manage in the Actions column for the target project.

    4. On the Role permissions tab, find role_project_dev, click Member management, and add the RAM user.

    For more information about MaxCompute permission management, see Manage user permissions in the console.

Query MaxCompute data

  1. Open the DSW development environment.

    1. Log in to the PAI console.

    2. In the left navigation pane, click Workspaces. On the workspace list page, click the target workspace name.

    3. In the upper-left corner, select the region.

    4. In the left navigation pane, choose Model Training > Data Science Workshop (DSW).

    5. Optional: In the search box on the Data Science Workshop (DSW) page, enter an instance name or keyword to search for an instance.

    6. In the Actions column for the target instance, click Open.

  2. On the Notebook tab, on the Open page, click SQL File in the Text and terminal area to create a SQL query file.

    image

  3. Configure the MaxCompute data source:

    1. Click the data source button in the upper-right corner of the main workspace area.

    2. In the Data source settings panel, configure the parameters and click Select a node.

      Parameter

      Description

      MaxCompute Endpoint

      The endpoint for the region where your project is located. For details, see Endpoint. For example, the endpoint for China (Hangzhou) is http://service.cn-hangzhou.maxcompute.aliyun.com/api.

      Tunnel Endpoint

      The tunnel endpoint for the region where your project is located. For details, see Endpoint. For example, the endpoint for China (Hangzhou) is http://dt.cn-hangzhou.maxcompute.aliyun.com.

      MaxCompute project

      The MaxCompute project name.

  4. Enter your query in the SQL editor and run it to view the results.

    • Run code: Click the Run button to the left of the SQL statement to run it directly. To run a specific selection, select part of the code and click Run. After the run completes, view the results in the output area.

    • Format code: Click the format button to reformat your SQL code.

  5. View the query results.

    After the SQL statement runs successfully, perform the following operations on the query results:

    Feature

    Illustration

    Description

    View table data

    Table

    Displays the query results of the SQL statement.

    Visualize results as charts

    Chart visualization

    Supports visualizing query results as line charts, bar charts, horizontal bar charts, pie charts, and pivot tables. Drag fields to dimension or metric areas to create a chart, or click a field to change its data type or set an alias.

    View the SQL for the results

    SQL

    Displays the SQL for the current query results. Supports copying and inserting it into the code editor.

    View query operation logs

    Operation log

    Displays the operation log for the current SQL statement. If the statement fails, click the Logview link in the log to troubleshoot.

References

To read MaxCompute data using Python, use PyODPS instead of SQL File. For more information, see Read and write MaxCompute tables with PyODPS.