Apache Superset

Apache Superset is a modern data exploration and data visualization platform.

PostgreSQL compatibility mode in YDB enables the use of Apache Superset to query and visualize data from YDB. In this case Apache Superset works with YDB just like with PostgreSQL.

Adding a database connection to YDB

To connect to YDB from Apache Superset using the PostgreSQL wire protocol, follow these steps:

  1. In the Apache Superset toolbar, hover over Settings and select Database Connections.

  2. Click the + DATABASE button.

    The Connect a database wizard will appear.

  3. In Step 1 of the wizard, click the PostgreSQL button.

  4. In Step 2 of the wizard, enter the YDB credentials in the corresponding fields:

    • HOST. The endpoint of the YDB cluster to which the connection will be made.

    • PORT. The port of the YDB endpoint.

    • DATABASE NAME. The path to the database in the YDB cluster where queries will be executed.

    • USERNAME. The login for connecting to the YDB database.

    • PASSWORD. The password for connecting to the YDB database.

    • DISPLAY NAME. The { ydb-short-name }} connection name in Apache Superset.

  5. Click CONNECT.

  6. To save the database connection, click FINISH.

Creating a dataset

To create a dataset for a YDB table, follow these steps:

  1. In the Apache Superset toolbar, hover over the + button and select SQL query.

  2. In the DATABASE drop-down list, select the YDB database connection.

  3. In the SCHEMA drop-down list, select public.

    Alert

    YDB currently does not provide table schema information via the PostgreSQL protocol. You can skip selecting a table in the SEE TABLE SCHEMA drop-down list.

  4. Enter the SQL query in the right section of the page. For example, SELECT * FROM <ydb_table_name>.

    Tip

    To create a dataset for a table located in a subdirectory of a YDB database, specify the table path in the table name. For example:

    SELECT * FROM "<path/to/subdirectory/table_name>";
    
  1. Click RUN to test the SQL query.

  2. Click the down arrow next to the SAVE button, then click Save dataset.

    The Save or Overwrite Dataset dialog box appears.

  3. In the Save or Overwrite Dataset dialog box, select Save as new, enter the dataset name, and click SAVE & EXPLORE.

After creating datasets, you can use data from YDB to create charts in Apache Superset. For more information, refer to the Apache Superset documentation.

Creating a chart

Let's create a sample chart with the dataset from the episodes table that is described in the YQL tutorial.

The table contains the following columns:

  • series_id
  • season_id
  • episode_id
  • title
  • air_date

Let's say that we want to make a pie chart to show how many episodes each season contains.

To create a chart, follow these steps:

  1. In the Apache Superset toolbar, hover over the + button and select Chart.

  2. In the Choose a dataset drop-down list, select a dataset for the episodes table.

  3. In the Choose chart type pane, select Pie chart.

  4. Click CREATE NEW CHART.

  5. In the Query pane, configure the chart:

    • In the DIMENSIONS drop-down list, select the season_id column.

    • In the METRIC field, specify the COUNT(title) function.

    • In the FILTERS field, specify the series_id in (2) filter.

  6. Click CREATE CHART.

    The pie chart will appear in the preview pane on the right.

  7. Click SAVE.

    The Save chart dialog box will appear.

  8. In the Save chart dialog box, in the CHART NAME field, enter the chart name.

  9. Click SAVE.