|
| 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 | +  |
| 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 | +  |
| 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 | +  |
| 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**. |
0 commit comments