Apache Superset
Apache Superset is a modern data exploration and visualization platform. This article explains how to create visualizations using data stored in YDB.
Installation of dependencies
To connect to YDB from Superset, install the ydb-sqlalchemy driver.
The installation method depends on your Superset setup. For detailed instructions, see the official documentation.
Adding a database connection to YDB
There are two ways to connect to YDB:
- Native connection using the SQLAlchemy driver (starting from version 5.0.0)
- Connect using the PostgreSQL wire protocol
It is recommended to use a native connection whenever possible.
Native connection using SQLAlchemy driver
To connect to YDB from Apache Superset version 5.0.0 and higher, 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, choose YDB from the Supported databases list. If the YDB option is not available, make sure that all the steps from prerequisites are completed.
-
In Step 2 of the wizard, enter the YDB credentials in the corresponding fields:
- Display Name. The YDB connection name in Apache Superset.
- SQLAlchemy URI. A string in the format
ydb://{host}:{port}/{database_name}
, where host and port are parts of the endpoint of the YDB cluster to which the connection will be made, and database_name is the path to the database.
-
To enhance security, you can specify credentials parameters in the Secure Extra field under the Advanced / Security tab.
Define the parameters as follows:
PasswordAccess TokenService Account{ "credentials": { "username": "...", "password": "..." } }
{ "credentials": { "token": "...", } }
{ "credentials": { "service_account_json": { "id": "...", "service_account_id": "...", "created_at": "...", "key_algorithm": "...", "public_key": "...", "private_key": "..." } } }
-
Click CONNECT.
-
To save the database connection, click FINISH.
For more information about configuring a YDB connection, refer to the YDB section in the official documentation.
Connect using the PostgreSQL wire protocol
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 connect to.
- 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.
-
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.
Copied -