Skip to content

Commit

Permalink
Renaming Classes related to Druid
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 10, 2016
1 parent 460f6cb commit b18d117
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
16 changes: 8 additions & 8 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Slice(Model, AuditMixinNullable):
table = relationship(
'SqlaTable', foreign_keys=[table_id], backref='slices')
druid_datasource = relationship(
'Datasource', foreign_keys=[druid_datasource_id], backref='slices')
'DruidDatasource', foreign_keys=[druid_datasource_id], backref='slices')

def __repr__(self):
return self.slice_name
Expand Down Expand Up @@ -742,7 +742,7 @@ def isnum(self):
return self.type in ('LONG', 'DOUBLE', 'FLOAT')


class Cluster(Model, AuditMixinNullable):
class DruidCluster(Model, AuditMixinNullable):
__tablename__ = 'clusters'
id = Column(Integer, primary_key=True)
cluster_name = Column(String(250), unique=True)
Expand Down Expand Up @@ -772,10 +772,10 @@ def refresh_datasources(self):

datasources = json.loads(requests.get(endpoint).text)
for datasource in datasources:
Datasource.sync_to_db(datasource, self)
DruidDatasource.sync_to_db(datasource, self)


class Datasource(Model, AuditMixinNullable, Queryable):
class DruidDatasource(Model, AuditMixinNullable, Queryable):
type = "druid"

baselink = "datasourcemodelview"
Expand All @@ -792,7 +792,7 @@ class Datasource(Model, AuditMixinNullable, Queryable):
cluster_name = Column(
String(250), ForeignKey('clusters.cluster_name'))
cluster = relationship(
'Cluster', backref='datasources', foreign_keys=[cluster_name])
'DruidCluster', backref='datasources', foreign_keys=[cluster_name])
offset = Column(Integer, default=0)

@property
Expand Down Expand Up @@ -1059,7 +1059,7 @@ class Metric(Model):
datasource_name = Column(
String(250),
ForeignKey('datasources.datasource_name'))
datasource = relationship('Datasource', backref='metrics')
datasource = relationship('DruidDatasource', backref='metrics')
json = Column(Text)
description = Column(Text)

Expand All @@ -1072,13 +1072,13 @@ def json_obj(self):
return obj


class Column(Model, AuditMixinNullable):
class DruidColumn(Model, AuditMixinNullable):
__tablename__ = 'columns'
id = Column(Integer, primary_key=True)
datasource_name = Column(
String(250),
ForeignKey('datasources.datasource_name'))
datasource = relationship('Datasource', backref='columns')
datasource = relationship('DruidDatasource', backref='columns')
column_name = Column(String(256))
is_active = Column(Boolean, default=True)
type = Column(String(32))
Expand Down
2 changes: 1 addition & 1 deletion panoramix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def init():
table_perms = [
table.perm for table in session.query(models.SqlaTable).all()]
table_perms += [
table.perm for table in session.query(models.Datasource).all()]
table.perm for table in session.query(models.DruidDatasource).all()]
for table_perm in table_perms:
merge_perm(sm, 'datasource_access', table.perm)

Expand Down
28 changes: 14 additions & 14 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class TableColumnInlineView(CompactCRUDMixin, PanoramixModelView):

appbuilder.add_separator("Sources")

class ColumnInlineView(CompactCRUDMixin, PanoramixModelView):
datamodel = SQLAInterface(models.Column)
class DruidColumnInlineView(CompactCRUDMixin, PanoramixModelView):
datamodel = SQLAInterface(models.DruidColumn)
edit_columns = [
'column_name', 'description', 'datasource', 'groupby',
'count_distinct', 'sum', 'min', 'max']
Expand Down Expand Up @@ -185,8 +185,8 @@ def post_update(self, table):
appbuilder.add_separator("Sources")


class ClusterModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.Cluster)
class DruidClusterModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.DruidCluster)
add_columns = [
'cluster_name',
'coordinator_host', 'coordinator_port', 'coordinator_endpoint',
Expand All @@ -196,7 +196,7 @@ class ClusterModelView(PanoramixModelView, DeleteMixin):
list_columns = ['cluster_name', 'metadata_last_refreshed']

appbuilder.add_view(
ClusterModelView,
DruidClusterModelView,
"Druid Clusters",
icon="fa-cubes",
category="Sources",
Expand Down Expand Up @@ -277,14 +277,14 @@ class LogModelView(PanoramixModelView):
icon="fa-list-ol")


class DatasourceModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.Datasource)
class DruidDatasourceModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.DruidDatasource)
list_columns = [
'datasource_link', 'cluster', 'owner',
'created_by', 'created_on',
'changed_by_', 'changed_on',
'offset']
related_views = [ColumnInlineView, MetricInlineView]
related_views = [DruidColumnInlineView, MetricInlineView]
edit_columns = [
'datasource_name', 'cluster', 'description', 'owner',
'is_featured', 'is_hidden', 'default_endpoint', 'offset']
Expand All @@ -303,7 +303,7 @@ def post_update(self, datasource):
self.post_add(datasource)

appbuilder.add_view(
DatasourceModelView,
DruidDatasourceModelView,
"Druid Datasources",
category="Sources",
icon="fa-cube")
Expand Down Expand Up @@ -362,7 +362,7 @@ def explore(self, datasource_type, datasource_id):
else:
datasource = (
db.session
.query(models.Datasource)
.query(models.DruidDatasource)
.filter_by(id=datasource_id)
.first()
)
Expand Down Expand Up @@ -489,8 +489,8 @@ def checkbox(self, model_view, id_, attr, value):
model = None
if model_view == 'TableColumnInlineView':
model = models.TableColumn
elif model_view == 'ColumnInlineView':
model = models.Column
elif model_view == 'DruidColumnInlineView':
model = models.DruidColumn

obj = db.session.query(model).filter_by(id=id_).first()
if obj:
Expand Down Expand Up @@ -647,7 +647,7 @@ def runsql(self):
@expose("/refresh_datasources/")
def refresh_datasources(self):
session = db.session()
for cluster in session.query(models.Cluster).all():
for cluster in session.query(models.DruidCluster).all():
try:
cluster.refresh_datasources()
except Exception as e:
Expand Down Expand Up @@ -699,7 +699,7 @@ def featured_datasets(self):
session = db.session()
datasets_sqla = (session.query(models.SqlaTable)
.filter_by(is_featured=True).all())
datasets_druid = (session.query(models.Datasource)
datasets_druid = (session.query(models.DruidDatasource)
.filter_by(is_featured=True).all())
featured_datasets = datasets_sqla + datasets_druid
return self.render_template(
Expand Down
1 change: 1 addition & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_load_examples(self):
cli.load_examples(sample=True)

def test_slices(self):
# Testing by running all the examples
Slc = models.Slice
for slc in db.session.query(Slc).all():
print(slc)
Expand Down

0 comments on commit b18d117

Please sign in to comment.