Skip to content

Commit a12e1a8

Browse files
Added an article on using YDB with Apache Superset (#8801)
Co-authored-by: Ivan Blinkov <ivan@ydb.tech>
1 parent ac9f050 commit a12e1a8

File tree

12 files changed

+249
-4
lines changed

12 files changed

+249
-4
lines changed
Loading
Loading
Loading

ydb/docs/en/core/integrations/visualization/_includes/toc-table.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
| Environment | Compatibility Level | Instruction |
44
| --- | :---: | --- |
5+
| [Apache Superset](https://superset.apache.org) | [PostgreSQL wire protocol](../../../postgresql/intro.md) | [Instruction](../superset.md) |
56
| [Grafana](https://grafana.com) | Full| [Instruction](../grafana.md) |
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Apache Superset
2+
3+
Apache Superset is a modern data exploration and data visualization platform.
4+
5+
[PostgreSQL compatibility mode in {{ ydb-short-name }}](../../postgresql/intro.md) enables the use of [Apache Superset](https://superset.apache.org/) to query and visualize data from {{ ydb-short-name }}. In this case Apache Superset works with {{ ydb-short-name }} just like with PostgreSQL.
6+
7+
8+
## Adding a database connection to {{ ydb-short-name }} {#add-database-connection}
9+
10+
To connect to {{ ydb-short-name }} from Apache Superset using the PostgreSQL wire protocol, follow these steps:
11+
12+
1. In the Apache Superset toolbar, hover over **Settings** and select **Database Connections**.
13+
14+
1. Click the **+ DATABASE** button.
15+
16+
The **Connect a database** wizard will appear.
17+
18+
1. In **Step 1** of the wizard, click the **PostgreSQL** button.
19+
20+
1. In **Step 2** of the wizard, enter the {{ ydb-short-name }} credentials in the corresponding fields:
21+
22+
* **HOST**. The [endpoint](https://ydb.tech/docs/en/concepts/connect#endpoint) of the {{ ydb-short-name }} cluster to which the connection will be made.
23+
24+
* **PORT**. The port of the {{ ydb-short-name }} endpoint.
25+
26+
* **DATABASE NAME**. The path to the [database](../../concepts/glossary.md#database) in the {{ ydb-short-name }} cluster where queries will be executed.
27+
28+
* **USERNAME**. The login for connecting to the {{ ydb-short-name }} database.
29+
30+
* **PASSWORD**. The password for connecting to the {{ ydb-short-name }} database.
31+
32+
* **DISPLAY NAME**. The { ydb-short-name }} connection name in Apache Superset.
33+
34+
![](_assets/superset-ydb-connection-details.png =400x)
35+
36+
1. Click **CONNECT**.
37+
38+
1. To save the database connection, click **FINISH**.
39+
40+
## Creating a dataset {#create-dataset}
41+
42+
To create a dataset for a {{ ydb-short-name }} table, follow these steps:
43+
44+
1. In the Apache Superset toolbar, hover over the **+** button and select **SQL query**.
45+
46+
1. In the **DATABASE** drop-down list, select the {{ ydb-short-name }} database connection.
47+
48+
1. In the **SCHEMA** drop-down list, select `public`.
49+
50+
{% note alert %}
51+
52+
{{ ydb-short-name }} 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.
53+
54+
{% endnote %}
55+
56+
4. Enter the SQL query in the right section of the page. For example, `SELECT * FROM <ydb_table_name>`.
57+
58+
{% note tip %}
59+
60+
To create a dataset for a table located in a subdirectory of a {{ ydb-short-name }} database, specify the table path in the table name. For example:
61+
62+
```yql
63+
SELECT * FROM "<path/to/subdirectory/table_name>";
64+
```
65+
66+
{% endnote %}
67+
68+
1. Click **RUN** to test the SQL query.
69+
70+
![](_assets/superset-sql-query.png)
71+
72+
1. Click the down arrow next to the **SAVE** button, then click **Save dataset**.
73+
74+
The **Save or Overwrite Dataset** dialog box appears.
75+
76+
1. In the **Save or Overwrite Dataset** dialog box, select **Save as new**, enter the dataset name, and click **SAVE & EXPLORE**.
77+
78+
After creating datasets, you can use data from {{ ydb-short-name }} to create charts in Apache Superset. For more information, refer to the [Apache Superset](https://superset.apache.org/docs/intro/) documentation.
79+
80+
81+
## Creating a chart {#create-chart}
82+
83+
Let's create a sample chart with the dataset from the `episodes` table that is described in the [YQL tutorial](../../dev/yql-tutorial/index.md).
84+
85+
The table contains the following columns:
86+
* series_id
87+
* season_id
88+
* episode_id
89+
* title
90+
* air_date
91+
92+
Let's say that we want to make a pie chart to show how many episodes each season contains.
93+
94+
To create a chart, follow these steps:
95+
96+
1. In the Apache Superset toolbar, hover over the **+** button and select **Chart**.
97+
98+
1. In the **Choose a dataset** drop-down list, select a dataset for the `episodes` table.
99+
100+
1. In the **Choose chart type** pane, select `Pie chart`.
101+
102+
1. Click **CREATE NEW CHART**.
103+
104+
1. In the **Query** pane, configure the chart:
105+
106+
* In the **DIMENSIONS** drop-down list, select the `season_id` column.
107+
108+
* In the **METRIC** field, specify the `COUNT(title)` function.
109+
110+
* In the **FILTERS** field, specify the `series_id in (2)` filter.
111+
112+
1. Click **CREATE CHART**.
113+
114+
The pie chart will appear in the preview pane on the right.
115+
116+
![](_assets/superset-sample-chart.png)
117+
118+
1. Click **SAVE**.
119+
120+
The **Save chart** dialog box will appear.
121+
122+
1. In the **Save chart** dialog box, in the **CHART NAME** field, enter the chart name.
123+
124+
1. Click **SAVE**.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
items:
2+
- name: Apache Superset
3+
href: superset.md
24
- name: Grafana data source
35
href: grafana.md
Loading
Loading
Loading

ydb/docs/ru/core/integrations/visualization/_includes/toc-table.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
| Среда | Уровень поддержки | Инструкция |
44
| --- | :---: | --- |
55
{% if ydb-datalens %}
6-
| [{{ datalens-name }}](https://datalens.tech/ru) | Полный | [Инструкция](../datalens.md) |
7-
{% endif %}
8-
{% if ydb-superset %}
96

10-
| [Apache Superset](https://superset.apache.org) | Через [PostgreSQL-совместимость](https://ydb.tech/docs/ru/postgresql/intro) | [Инструкция](../superset.md) |
7+
| [{{ datalens-name }}](https://datalens.tech/ru) | Полный | [Инструкция](../datalens.md) |
118

129
{% endif %}
10+
| [Apache Superset](https://superset.apache.org) | Через [PostgreSQL-совместимость](../../../postgresql/intro) | [Инструкция](../superset.md) |
1311
{% if ydb-finebi %}
1412

1513
| [FineBI](https://intl.finebi.com) | Через [PostgreSQL-совместимость](https://ydb.tech/docs/ru/postgresql/intro) | [Инструкция](./finebi.md) |
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Apache Superset
2+
3+
Apache Superset — это современная платформа для анализа и визуализации данных.
4+
5+
[Режим совместимости с PostgreSQL в {{ ydb-short-name }}](../../postgresql/intro.md) позволяет использовать [Apache Superset](https://superset.apache.org/) для выполнения запросов и визуализации данных из {{ ydb-short-name }}. В этом случае Apache Superset работает с {{ ydb-short-name }} как с PostgreSQL.
6+
7+
8+
## Создание подключения к {{ ydb-short-name }} {#add-database-connection}
9+
10+
Чтобы создать подключение к {{ ydb-short-name }} из Apache Superset с использованием сетевого протокола PostgreSQL, выполните следующие шаги:
11+
12+
1. В верхнем меню Apache Superset наведите курсор на **Settings** и выберите в выпадающем списке пункт **Database Connections**.
13+
14+
1. Нажмите кнопку **+ DATABASE**.
15+
16+
Откроется окно мастера **Connect a database**.
17+
18+
1. На первом шаге мастера нажмите кнопку **PostgreSQL**.
19+
20+
1. На втором шаге мастера введите данные для подключения к {{ ydb-short-name }} в следующие поля:
21+
22+
* **HOST**[эндпоинт](../../concepts/connect.md#endpoint) кластера {{ ydb-short-name }}, к которому осуществляется подключение.
23+
* **PORT** — порт эндпоинта {{ ydb-short-name }}.
24+
* **DATABASE NAME** — путь к [базе данных](../../concepts/glossary.md#database) в кластере {{ ydb-short-name }}, к которой будут выполняться запросы.
25+
* **USERNAME** — логин для подключения к базе данных {{ ydb-short-name }}.
26+
* **PASSWORD** — пароль для подключения к базе данных {{ ydb-short-name }}.
27+
* **DISPLAY NAME** — наименование соединения с {{ ydb-short-name }} в Apache Superset.
28+
29+
![](_assets/superset-ydb-connection-details.png =400x)
30+
31+
1. Нажмите кнопку **CONNECT**.
32+
33+
1. Нажмите кнопку **FINISH**, чтобы сохранить подключение.
34+
35+
## Создание набора данных (dataset) {#create-dataset}
36+
37+
Чтобы создать набор данных из таблицы {{ ydb-short-name }}, выполните следующие шаги:
38+
39+
1. В верхнем меню Apache Superset наведите курсор на кнопку **+** и выберите в выпадающем списке пункт **SQL query**.
40+
41+
1. В выпадающем списке **DATABASE** выберите подключение к {{ ydb-short-name }}.
42+
43+
1. В выпадающем меню **SCHEMA** выберите `public`.
44+
45+
{% note alert %}
46+
47+
В настоящее время {{ ydb-short-name }} не предоставляет схемы таблиц через сетевой протокол PostgreSQL. Поэтому выбор таблицы в выпадающем списке **SEE TABLE SCHEMA** можно пропустить.
48+
49+
{% endnote %}
50+
51+
1. Введите текст SQL-запроса в правой части страницы. Например, `SELECT * FROM <наименование_таблицы>`.
52+
53+
{% note tip %}
54+
55+
Если вы хотите создать набор данных из таблицы, которая расположена в поддиректории {{ ydb-short-name }}, необходимо указать путь к таблице в самом наименовании таблицы. Например:
56+
57+
```yql
58+
SELECT * FROM "<путь/к/таблице/наименование_таблицы>";
59+
```
60+
61+
{% endnote %}
62+
63+
1. Нажмите кнопку **RUN**, чтобы проверить SQL-запрос.
64+
65+
![](_assets/superset-sql-query.png)
66+
67+
1. Нажмите на стрелку рядом с кнопкой **SAVE** и выберите **Save dataset** в выпадающем списке.
68+
69+
Откроется диалоговое окно **Save or Overwrite Dataset**.
70+
71+
1. В открывшемся окне **Save or Overwrite Dataset** выберите **Save as new**, введите наименование набора данных и нажмите **SAVE & EXPLORE**.
72+
73+
После создания наборов данных вы можете использовать данные из {{ ydb-short-name }} для создания диаграмм в Apache Superset. См. документацию [Apache Superset](https://superset.apache.org/docs/intro/).
74+
75+
## Создание диаграммы {#create-chart}
76+
77+
Теперь давайте создадим пример диаграммы с использованием набора данных из таблицы `episodes`, которая описана в [Туториале по YQL](../../dev/yql-tutorial/index.md).
78+
79+
Таблица `episodes` содержит следующие колонки:
80+
* series_id;
81+
* season_id;
82+
* episode_id;
83+
* title;
84+
* air_date.
85+
86+
Предположим, что мы хотим построить круговую диаграмму, в которой бы было видно, сколько серий содержит каждый сезон сериала.
87+
88+
Чтобы создать диаграмму, выполните следующие шаги:
89+
90+
1. В верхнем меню Apache Superset наведите курсор на **+** и выберите в выпадающем списке пункт **Chart**.
91+
92+
1. В выпадающем списке **Choose a dataset**, выберите набор данных из таблицы `episodes`.
93+
94+
1. На панели **Choose chart type**, выберите тип диаграммы `Pie chart`.
95+
96+
1. Нажмите кнопку **CREATE NEW CHART**.
97+
98+
1. На панели **Query** настройте диаграмму:
99+
100+
* В выпадающем списке **DIMENSIONS** выберите колонку `season_id`.
101+
102+
* В поле **METRIC** введите функцию `COUNT(title)`.
103+
104+
* В поле **FILTERS** введите фильтр `series_id in (2)`.
105+
106+
1. Нажмите кнопку **CREATE CHART**.
107+
108+
Круговая диаграмма появится на панели справа.
109+
110+
![](_assets/superset-sample-chart.png)
111+
112+
1. Нажмите кнопку **SAVE**.
113+
114+
Откроется диалоговое окно **Save chart**.
115+
116+
1. В открывшемся окне **Save chart** в поле **CHART NAME** введите наименование диаграммы.
117+
118+
1. Нажмите кнопку **SAVE**.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
items:
2+
- name: Apache Superset
3+
href: superset.md
24
- name: Grafana data source
35
href: grafana.md

0 commit comments

Comments
 (0)