Skip to content

Commit

Permalink
Merge branch 'master' into villebro/generator-plugin-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jan 17, 2022
2 parents f93a9aa + de8a1fa commit e240ab7
Show file tree
Hide file tree
Showing 64 changed files with 485 additions and 180 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ superset:
# Create an admin user in your metadata database
superset fab create-admin \
--username admin \
--firstname Admin \
--firstname "Admin I."\
--lastname Strator \
--email admin@superset.io \
--password general
Expand Down
91 changes: 83 additions & 8 deletions docs/src/pages/docs/Connecting to Databases/trino.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,95 @@ version: 1

## Trino

Supported trino version 352 and higher

The [sqlalchemy-trino](https://pypi.org/project/sqlalchemy-trino/) library is the recommended way to connect to Trino through SQLAlchemy.

The expected connection string is formatted as follows:
Superset supports Trino >=352 via SQLAlchemy by using the [sqlalchemy-trino](https://pypi.org/project/sqlalchemy-trino/) library.

### Connection String
The connection string format is as follows:
```
trino://{username}:{password}@{hostname}:{port}/{catalog}
```
If you are running trino with docker on local machine please use the following connection URL

If you are running Trino with docker on local machine, please use the following connection URL
```
trino://trino@host.docker.internal:8080
```

Reference:
[Trino-Superset-Podcast](https://trino.io/episodes/12.html)
### Authentications
#### 1. Basic Authentication
You can provide `username`/`password` in the connection string or in the `Secure Extra` field at `Advanced / Security`
* In Connection String
```
trino://{username}:{password}@{hostname}:{port}/{catalog}
```

* In `Secure Extra` field
```json
{
"auth_method": "basic",
"auth_params": {
"username": "<username>",
"password": "<password>"
}
}
```

NOTE: if both are provided, `Secure Extra` always takes higher priority.

#### 2. Kerberos Authentication
In `Secure Extra` field, config as following example:
```json
{
"auth_method": "kerberos",
"auth_params": {
"service_name": "superset",
"config": "/path/to/krb5.config",
...
}
}
```

All fields in `auth_params` are passed directly to the [`KerberosAuthentication`](https://github.com/trinodb/trino-python-client/blob/0.306.0/trino/auth.py#L40) class.

#### 3. JWT Authentication
Config `auth_method` and provide token in `Secure Extra` field
```json
{
"auth_method": "jwt",
"auth_params": {
"token": "<your-jwt-token>"
}
}
```

#### 4. Custom Authentication
To use custom authentication, first you need to add it into
`ALLOWED_EXTRA_AUTHENTICATIONS` allow list in Superset config file:
```python
from your.module import AuthClass
from another.extra import auth_method

ALLOWED_EXTRA_AUTHENTICATIONS: Dict[str, Dict[str, Callable[..., Any]]] = {
"trino": {
"custom_auth": AuthClass,
"another_auth_method": auth_method,
},
}
```

Then in `Secure Extra` field:
```json
{
"auth_method": "custom_auth",
"auth_params": {
...
}
}
```

You can also use custom authentication by providing reference to your `trino.auth.Authentication` class
or factory function (which returns an `Authentication` instance) to `auth_method`.

All fields in `auth_params` are passed directly to your class/function.

**Reference**:
* [Trino-Superset-Podcast](https://trino.io/episodes/12.html)
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ werkzeug==1.0.1
# via
# flask
# flask-jwt-extended
wrapt==1.12.1
# via -r requirements/base.in
wtforms==2.3.3
# via
# flask-appbuilder
Expand Down
1 change: 1 addition & 0 deletions requirements/testing.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ statsd
pytest-mock
# DB dependencies
-e file:.[bigquery]
-e file:.[trino]
10 changes: 5 additions & 5 deletions requirements/testing.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:9658361c2ab00a6b27c5875b7b3557c2999854ba
# SHA1:7a8e256097b4758bdeda2529d3d4d31e421e1a3c
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -11,8 +11,6 @@
# via
# -r requirements/base.in
# -r requirements/testing.in
appnope==0.1.2
# via ipython
astroid==2.6.6
# via pylint
backcall==0.2.0
Expand Down Expand Up @@ -166,20 +164,22 @@ requests-oauthlib==1.3.0
# via google-auth-oauthlib
rsa==4.7.2
# via google-auth
sqlalchemy-trino==0.4.1
# via apache-superset
statsd==3.3.0
# via -r requirements/testing.in
traitlets==5.0.5
# via
# ipython
# matplotlib-inline
trino==0.306
# via sqlalchemy-trino
typing-inspect==0.7.1
# via libcst
wcwidth==0.2.5
# via prompt-toolkit
websocket-client==1.2.0
# via docker
wrapt==1.12.1
# via astroid

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
27 changes: 14 additions & 13 deletions superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React from 'react';
import { t } from '@superset-ui/core';
import {
ControlPanelsContainerProps,
ControlSetItem,
ControlSetRow,
sharedControls,
} from '@superset-ui/chart-controls';
Expand All @@ -29,7 +30,7 @@ import { DEFAULT_FORM_DATA } from './Timeseries/types';
const { legendMargin, legendOrientation, legendType, showLegend } =
DEFAULT_LEGEND_FORM_DATA;

const showLegendControl = {
const showLegendControl: ControlSetItem = {
name: 'show_legend',
config: {
type: 'CheckboxControl',
Expand All @@ -40,7 +41,7 @@ const showLegendControl = {
},
};

const legendMarginControl = {
const legendMarginControl: ControlSetItem = {
name: 'legendMargin',
config: {
type: 'TextControl',
Expand All @@ -54,7 +55,7 @@ const legendMarginControl = {
},
};

const legendTypeControl = {
const legendTypeControl: ControlSetItem = {
name: 'legendType',
config: {
type: 'SelectControl',
Expand All @@ -72,7 +73,7 @@ const legendTypeControl = {
},
};

const legendOrientationControl = {
const legendOrientationControl: ControlSetItem = {
name: 'legendOrientation',
config: {
type: 'SelectControl',
Expand All @@ -92,15 +93,15 @@ const legendOrientationControl = {
},
};

export const legendSection = [
export const legendSection: ControlSetRow[] = [
[<h1 className="section-header">{t('Legend')}</h1>],
[showLegendControl],
[legendTypeControl],
[legendOrientationControl],
[legendMarginControl],
];

const showValueControl = {
const showValueControl: ControlSetItem = {
name: 'show_value',
config: {
type: 'CheckboxControl',
Expand All @@ -111,7 +112,7 @@ const showValueControl = {
},
};

const stackControl = {
const stackControl: ControlSetItem = {
name: 'stack',
config: {
type: 'CheckboxControl',
Expand All @@ -122,7 +123,7 @@ const stackControl = {
},
};

const onlyTotalControl = {
const onlyTotalControl: ControlSetItem = {
name: 'only_total',
config: {
type: 'CheckboxControl',
Expand All @@ -137,7 +138,7 @@ const onlyTotalControl = {
},
};

const percentageThresholdControl = {
const percentageThresholdControl: ControlSetItem = {
name: 'percentage_threshold',
config: {
type: 'TextControl',
Expand All @@ -155,14 +156,14 @@ const percentageThresholdControl = {
},
};

export const showValueSection = [
export const showValueSection: ControlSetRow[] = [
[showValueControl],
[stackControl],
[onlyTotalControl],
[percentageThresholdControl],
];

const richTooltipControl = {
const richTooltipControl: ControlSetItem = {
name: 'rich_tooltip',
config: {
type: 'CheckboxControl',
Expand All @@ -175,7 +176,7 @@ const richTooltipControl = {
},
};

const tooltipTimeFormatControl = {
const tooltipTimeFormatControl: ControlSetItem = {
name: 'tooltipTimeFormat',
config: {
...sharedControls.x_axis_time_format,
Expand All @@ -185,7 +186,7 @@ const tooltipTimeFormatControl = {
},
};

const tooltipSortByMetricControl = {
const tooltipSortByMetricControl: ControlSetItem = {
name: 'tooltipSortByMetric',
config: {
type: 'CheckboxControl',
Expand Down
8 changes: 4 additions & 4 deletions superset/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
from flask_appbuilder.api import BaseApi
from flask_appbuilder.api.manager import resolver

import superset.utils.database as database_utils
from superset import app, appbuilder, config, security_manager
from superset.extensions import celery_app, db
from superset.utils import core as utils
from superset.utils.celery import session_scope
from superset.utils.encrypt import SecretsMigrator
from superset.utils.urls import get_url_path
Expand Down Expand Up @@ -120,7 +120,7 @@ def load_examples_run(
if only_metadata:
print("Loading examples metadata")
else:
examples_db = utils.get_example_database()
examples_db = database_utils.get_example_database()
print(f"Loading examples metadata and related data into {examples_db}")

# pylint: disable=import-outside-toplevel
Expand Down Expand Up @@ -227,7 +227,7 @@ def import_directory(directory: str, overwrite: bool, force: bool) -> None:
)
def set_database_uri(database_name: str, uri: str, skip_create: bool) -> None:
"""Updates a database connection URI"""
utils.get_or_create_db(database_name, uri, not skip_create)
database_utils.get_or_create_db(database_name, uri, not skip_create)


@superset.command()
Expand Down Expand Up @@ -768,7 +768,7 @@ def load_test_users_run() -> None:

sm = security_manager

examples_db = utils.get_example_database()
examples_db = database_utils.get_example_database()

examples_pv = sm.add_permission_view_menu("database_access", examples_db.perm)

Expand Down
3 changes: 2 additions & 1 deletion superset/commands/importers/v1/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
from superset.datasets.commands.importers.v1.utils import import_dataset
from superset.datasets.schemas import ImportV1DatasetSchema
from superset.models.dashboard import dashboard_slices
from superset.utils.core import get_example_database, get_example_default_schema
from superset.utils.core import get_example_default_schema
from superset.utils.database import get_example_database


class ImportExamplesCommand(ImportModelsCommand):
Expand Down

0 comments on commit e240ab7

Please sign in to comment.