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.
Warning
At the moment, YDB's compatibility with PostgreSQL is under development, so not all PostgreSQL constructs and functions are supported yet. PostgreSQL compatibility is available for testing in the form of a Docker container, which can be deployed by following these instructions.
Adding a database connection to YDB
To connect to YDB from Apache Superset using the PostgreSQL wire protocol, follow these steps:
-
In the Apache Superset toolbar, hover over Settings and select Database Connections.
-
Click the + DATABASE button.
The Connect a database wizard will appear.
-
In Step 1 of the wizard, click the PostgreSQL button.
-
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 connection name in Apache Superset.
-
Click CONNECT.
-
To save the database connection, click FINISH.
Creating a dataset
To create a dataset for a YDB table, follow these steps:
-
In the Apache Superset toolbar, hover over the + button and select SQL query.
-
In the DATABASE drop-down list, select the YDB database connection.
-
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.
-
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>";
-
Click RUN to test the SQL query.
-
Click the down arrow next to the SAVE button, then click Save dataset.
The Save or Overwrite Dataset dialog box appears.
-
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:
-
In the Apache Superset toolbar, hover over the + button and select Chart.
-
In the Choose a dataset drop-down list, select a dataset for the
episodes
table. -
In the Choose chart type pane, select
Pie chart
. -
Click CREATE NEW CHART.
-
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.
- In the DIMENSIONS drop-down list, select the
-
Click CREATE CHART.
The pie chart will appear in the preview pane on the right.
-
Click SAVE.
The Save chart dialog box will appear.
-
In the Save chart dialog box, in the CHART NAME field, enter the chart name.
-
Click SAVE.
-