mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
Bug fix: Datasource -> Slice relationship (#3011)
This commit is contained in:
parent
fdbb569c3e
commit
8dfe2b70b2
@ -1,15 +1,19 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
Column, Integer, String, Text, Boolean,
|
and_, Column, Integer, String, Text, Boolean,
|
||||||
)
|
)
|
||||||
|
from sqlalchemy.orm import foreign, relationship
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
|
||||||
from superset import utils
|
from superset import utils
|
||||||
|
from superset.models.core import Slice
|
||||||
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
||||||
|
|
||||||
|
|
||||||
class BaseDatasource(AuditMixinNullable, ImportMixin):
|
class BaseDatasource(AuditMixinNullable, ImportMixin):
|
||||||
|
"""A common interface to objects that are queryable
|
||||||
"""A common interface to objects that are queryable (tables and datasources)"""
|
(tables and datasources)"""
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# class attributes to define when deriving BaseDatasource
|
# class attributes to define when deriving BaseDatasource
|
||||||
@ -17,7 +21,6 @@ class BaseDatasource(AuditMixinNullable, ImportMixin):
|
|||||||
__tablename__ = None # {connector_name}_datasource
|
__tablename__ = None # {connector_name}_datasource
|
||||||
type = None # datasoure type, str to be defined when deriving this class
|
type = None # datasoure type, str to be defined when deriving this class
|
||||||
baselink = None # url portion pointing to ModelView endpoint
|
baselink = None # url portion pointing to ModelView endpoint
|
||||||
|
|
||||||
column_class = None # link to derivative of BaseColumn
|
column_class = None # link to derivative of BaseColumn
|
||||||
metric_class = None # link to derivative of BaseMetric
|
metric_class = None # link to derivative of BaseMetric
|
||||||
|
|
||||||
@ -39,6 +42,14 @@ class BaseDatasource(AuditMixinNullable, ImportMixin):
|
|||||||
params = Column(String(1000))
|
params = Column(String(1000))
|
||||||
perm = Column(String(1000))
|
perm = Column(String(1000))
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def slices(self):
|
||||||
|
return relationship(
|
||||||
|
'Slice',
|
||||||
|
primaryjoin=lambda: and_(
|
||||||
|
foreign(Slice.datasource_id) == self.id,
|
||||||
|
foreign(Slice.datasource_type) == self.type))
|
||||||
|
|
||||||
# placeholder for a relationship to a derivative of BaseColumn
|
# placeholder for a relationship to a derivative of BaseColumn
|
||||||
columns = []
|
columns = []
|
||||||
# placeholder for a relationship to a derivative of BaseMetric
|
# placeholder for a relationship to a derivative of BaseMetric
|
||||||
|
@ -342,11 +342,6 @@ class DruidDatasource(Model, BaseDatasource):
|
|||||||
'datasource_name', 'is_hidden', 'description', 'default_endpoint',
|
'datasource_name', 'is_hidden', 'description', 'default_endpoint',
|
||||||
'cluster_name', 'offset', 'cache_timeout', 'params'
|
'cluster_name', 'offset', 'cache_timeout', 'params'
|
||||||
)
|
)
|
||||||
slices = relationship(
|
|
||||||
'Slice',
|
|
||||||
primaryjoin=(
|
|
||||||
"DruidDatasource.id == foreign(Slice.datasource_id) and "
|
|
||||||
"Slice.datasource_type == 'druid'"))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def database(self):
|
def database(self):
|
||||||
|
@ -178,11 +178,6 @@ class SqlaTable(Model, BaseDatasource):
|
|||||||
foreign_keys=[database_id])
|
foreign_keys=[database_id])
|
||||||
schema = Column(String(255))
|
schema = Column(String(255))
|
||||||
sql = Column(Text)
|
sql = Column(Text)
|
||||||
slices = relationship(
|
|
||||||
'Slice',
|
|
||||||
primaryjoin=(
|
|
||||||
"SqlaTable.id == foreign(Slice.datasource_id) and "
|
|
||||||
"Slice.datasource_type == 'table'"))
|
|
||||||
|
|
||||||
baselink = "tablemodelview"
|
baselink = "tablemodelview"
|
||||||
export_fields = (
|
export_fields = (
|
||||||
|
Loading…
Reference in New Issue
Block a user