superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] mistercrunch commented on a change in pull request #5358: basic elastic connector implementation
Date Tue, 17 Jul 2018 21:35:30 GMT
mistercrunch commented on a change in pull request #5358: basic elastic connector implementation
URL: https://github.com/apache/incubator-superset/pull/5358#discussion_r203186977
 
 

 ##########
 File path: superset/connectors/elastic/views.py
 ##########
 @@ -0,0 +1,294 @@
+# -*- coding: utf-8 -*-
+# pylint: disable=C,R,W
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from datetime import datetime
+import logging
+
+from flask import flash, Markup, redirect
+from flask_appbuilder import CompactCRUDMixin, expose
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+from flask_appbuilder.security.decorators import has_access
+from flask_babel import gettext as __
+from flask_babel import lazy_gettext as _
+import sqlalchemy as sqla
+
+from superset import appbuilder, db, security_manager, utils
+from superset.connectors.connector_registry import ConnectorRegistry
+from superset.views.base import BaseSupersetView
+from superset.views.base import (
+    DatasourceFilter, DeleteMixin, get_datasource_exist_error_mgs,
+    ListWidgetWithCheckboxes, SupersetModelView, validate_json)
+from . import models
+
+appbuilder.add_separator('Sources')
+
+
+class ElasticColumnInlineView(CompactCRUDMixin, SupersetModelView):  # noqa
+    datamodel = SQLAInterface(models.ElasticColumn)
+    edit_columns = [
+        'column_name', 'description', 'json', 'datasource',
+        'groupby', 'filterable', 'count_distinct', 'sum', 'min', 'max']
+    add_columns = edit_columns
+    list_columns = [
+        'column_name', 'type', 'groupby', 'filterable', 'count_distinct',
+        'sum', 'min', 'max']
+    can_delete = False
+    page_size = 500
+    label_columns = {
+        'column_name': _('Column'),
+        'type': _('Type'),
+        'datasource': _('Datasource'),
+        'groupby': _('Groupable'),
+        'filterable': _('Filterable'),
+        'count_distinct': _('Count Distinct'),
+        'sum': _('Sum'),
+        'min': _('Min'),
+        'max': _('Max'),
+    }
+    description_columns = {
+        'filterable': _(
+            'Whether this column is exposed in the `Filters` section '
+            'of the explore view.'),
+        'json': utils.markdown(
+            'this field can be used to specify  '
+            'a `dimensionSpec` as documented [here]'
+            '(http://elastic.io/docs/latest/querying/dimensionspecs.html). '
+            'Make sure to input valid JSON and that the '
+            '`outputName` matches the `column_name` defined '
+            'above.',
+            True),
+    }
+
+    def post_update(self, col):
+        col.generate_metrics()
+        utils.validate_json(col.json)
+
+    def post_add(self, col):
+        self.post_update(col)
+
+
+appbuilder.add_view_no_menu(ElasticColumnInlineView)
+
+
+class ElasticMetricInlineView(CompactCRUDMixin, SupersetModelView):  # noqa
+    datamodel = SQLAInterface(models.ElasticMetric)
+    list_columns = ['metric_name', 'verbose_name', 'metric_type']
+    edit_columns = [
+        'metric_name', 'description', 'verbose_name', 'metric_type', 'json',
+        'datasource', 'd3format', 'is_restricted']
+    add_columns = edit_columns
+    page_size = 500
+    validators_columns = {
+        'json': [validate_json],
+    }
+    description_columns = {
+        'metric_type': utils.markdown(
+            'use `postagg` as the metric type if you are defining a '
+            '[Elastic Post Aggregation]'
+            '(http://elastic.io/docs/latest/querying/post-aggregations.html)',
+            True),
+        'is_restricted': _('Whether the access to this metric is restricted '
+                           'to certain roles. Only roles with the permission '
+                           '\'metric access on XXX (the name of this metric)\' '
+                           'are allowed to access this metric'),
+    }
+    label_columns = {
+        'metric_name': _('Metric'),
+        'description': _('Description'),
+        'verbose_name': _('Verbose Name'),
+        'metric_type': _('Type'),
+        'json': _('JSON'),
+        'datasource': _('Elastic Datasource'),
+    }
+
+    def post_add(self, metric):
+        if metric.is_restricted:
+            security_manager.merge_perm('metric_access', metric.get_perm())
+
+    def post_update(self, metric):
+        if metric.is_restricted:
+            security_manager.merge_perm('metric_access', metric.get_perm())
+
+
+appbuilder.add_view_no_menu(ElasticMetricInlineView)
+
+
+class ElasticClusterModelView(SupersetModelView, DeleteMixin):  # noqa
+    datamodel = SQLAInterface(models.ElasticCluster)
+    add_columns = [
+        'cluster_name', 'hosts_json', 'cache_timeout',
+    ]
+    edit_columns = add_columns
+    list_columns = ['cluster_name', 'metadata_last_refreshed']
+    search_columns = ('cluster_name',)
+    label_columns = {
+        'cluster_name': _('Cluster'),
+        'hosts_json': _('Hosts JSON configuration'),
+    }
+    description_columns = {
+        'hosts_json': _(
+            'A JSON string that represents a host, and array of host, '
+            'or anything else that ``elasticsearch.Elasticsearch()`` will '
+            'be able to interpret'),
+    }
+
+    def pre_add(self, cluster):
+        security_manager.merge_perm('database_access', cluster.perm)
+
+    def pre_update(self, cluster):
+        self.pre_add(cluster)
+
+    def _delete(self, pk):
+        DeleteMixin._delete(self, pk)
+
+
+appbuilder.add_view(
+    ElasticClusterModelView,
+    name='Elastic Clusters',
+    label=__('Elastic Clusters'),
+    icon='fa-cubes',
+    category='Sources',
+    category_label=__('Sources'),
+    category_icon='fa-database')
+
+
+class ElasticDatasourceModelView(SupersetModelView, DeleteMixin):  # noqa
+    datamodel = SQLAInterface(models.ElasticDatasource)
+    list_widget = ListWidgetWithCheckboxes
+    list_columns = [
+        'datasource_link', 'cluster', 'changed_by_', 'modified']
+    order_columns = [
+        'datasource_link', 'changed_on_', 'offset']
+    related_views = [ElasticColumnInlineView, ElasticMetricInlineView]
+    edit_columns = [
+        'datasource_name', 'cluster', 'slices', 'description', 'owner',
+        'is_hidden',
+        'filter_select_enabled', 'fetch_values_from',
+        'default_endpoint', 'offset', 'cache_timeout']
+    search_columns = (
+        'datasource_name', 'cluster', 'description', 'owner',
+    )
+    add_columns = edit_columns
+    show_columns = add_columns + ['perm']
+    page_size = 500
+    base_order = ('datasource_name', 'asc')
+    description_columns = {
+        'slices': _(
+            'The list of slices associated with this table. By '
 
 Review comment:
   We don't use the term "slice" anymore and use "chart" instead. We haven't remove `slice`
references to object names and such, but from all user-facing terminology

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Mime
View raw message