Redash

更新时间:
复制 MD 格式

Redash is an open-source business intelligence (BI) tool that supports various data sources, such as MySQL and PostgreSQL. It provides an intuitive web interface to explore and visualize your data. This article shows how to connect Redash to AnalyticDB for MySQL.

Prerequisites

Connect to an AnalyticDB for MySQL endpoint

  1. After you start Redash, enter http://<IP address>:<port number> in your browser to open the Redash web interface.

    IP address: The IP address of the Redash server.

    Port number: The default port is 5000. If port 5000 is already in use, you can specify a different port when you start Redash.

  2. In the left navigation pane, click Settings. On the Data Sources tab, click +New Data Source.

  3. In the Create a New Data Source dialog box, configure the following parameters, and then click Create.

    Parameter

    Description

    Type Selection

    Select MySQL from the drop-down list.

    Configuration

    Name

    A custom name for the data source.

    Host

    The connection endpoint of your AnalyticDB for MySQL cluster.

    • If Redash is installed on an ECS instance in the same VPC as the AnalyticDB for MySQL cluster, enter the ECS.

    • If Redash is installed on a local server, enter the public endpoint.

    Port

    The port number. The value is fixed at 3306.

    User

    The database account for the AnalyticDB for MySQL cluster.

    Password

    The password for the AnalyticDB for MySQL database account.

    Database Name

    The database in the AnalyticDB for MySQL cluster.

  4. In the left navigation pane, click Create > New Query. In the editor, write a SQL statement and click Execute.

    If the query runs successfully, the results appear in a table below the editor. This confirms a successful connection to the AnalyticDB for MySQL endpoint.

  5. After the SQL statement runs, you can click + Add Visualization to create a visualization from the results. For more information, see the Redash official documentation.

    In the Visualization Editor dialog box, set Visualization Type to Chart and Chart Type to Bar. Configure the X Column (for example, name) and Y Columns (for example, age). A real-time preview of the bar chart appears on the right. After you confirm the settings, click Save.

Connect to a Spark JDBC endpoint

Prepare the environment

  1. (Optional) Copy the adb_spark.png file to the target path.

    • For a source code deployment of Redash, the target path is <root directory of the source code>/client/app/assets/images/db-logos/.

    • For a Docker image deployment of Redash, the target path is </app directory>/client/dist/images/db-logos/.

      Note

      The /app directory is in the redash_server, redash_scheduler, redash_adhoc_worker, and redash_scheduled_worker containers.

  2. Copy the adb_spark_ds.py file to the target path.

    • For a source code deployment of Redash, the target path is <root directory of the source code>/redash/query_runner/.

    • For a Docker image deployment of Redash, the target path is </app directory>/redash/query_runner/.

      Note

      The /app directory is in the redash_server, redash_scheduler, redash_adhoc_worker, and redash_scheduled_worker containers.

  3. Add the 'redash.query_runner.adb_spark_ds' configuration parameter to the __init__.py file.

    • Path of the __init__.py file:

      For a source code deployment of Redash, the target path is <root directory of the source code>/redash/settings/__init__.py.

      For a Docker image deployment of Redash, the target path is </app directory>/redash/settings/__init__.py.

      Note

      The /app directory is in the redash_server, redash_scheduler, redash_adhoc_worker, and redash_scheduled_worker containers.

    • The parameter format is as follows:

      default_query_runners = [
          'redash.query_runner.athena',
          'redash.query_runner.big_query',
          ........
          'redash.query_runner.uptycs',
          'redash.query_runner.adb_spark_ds'
      ]

Procedure

  1. Access the Redash web interface. In the left navigation pane, click Settings. On the Data Sources tab, click +New Data Source.

  2. In the Create a New Data Source dialog box, configure the following parameters, and then click Create.

    Parameter

    Description

    Type Selection

    Select ADB Spark from the drop-down list.

    Configuration

    Name

    A custom name for the data source.

    Host

    The connection endpoint for the Spark Interactive resource group. For information about how to obtain the endpoint, see Prepare the environment.

    Port

    The port number for the Spark Interactive resource group. The value is fixed at 10000.

    Database

    The database in the AnalyticDB for MySQL cluster.

    Username

    The database account for the AnalyticDB for MySQL cluster.

    Password

    The password for the AnalyticDB for MySQL database account.

    Resource Group

    The name of the Spark Interactive resource group.

  3. In the left navigation pane, click Create > > New Query. In the editor, write a SQL statement and click Execute.

    For example, run the query select * from test_db.test_tbl. If the query runs successfully, the results appear on the Table tab.

  4. After the SQL statement runs, you can click + Add Visualization to create a visualization from the results. For more information, see the Redash official documentation.

    In the Visualization Editor dialog box, set Visualization Type to Chart and Chart Type to Bar. For the X Column, select name, and for the Y Columns, select age. A preview of the bar chart appears on the right. After you confirm the settings, click Save.