Skip to content

Commit

Permalink
Documentation links for data sources (re getredash#6)
Browse files Browse the repository at this point in the history
(incorporates: show data source type when no doc link present (re getredash#46))
  • Loading branch information
Allen Short authored and Marina Samuel committed May 25, 2018
1 parent 3aad3c6 commit 7b85d06
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/app/pages/data-sources/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="database-source">
<a class="visual-card" ng-href="data_sources/{{dataSource.id}}" ng-repeat="dataSource in dataSources" title="{{dataSource.name}}">
<img ng-src="/static/images/db-logos/{{dataSource.type}}.png" alt="{{dataSource.name}}">
<h3>{{dataSource.name}}</h3>
<h3>{{dataSource.name}}</h3> - {{dataSource.type_name}}
</a>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ <h3>
<div class="col-xs-5 text-left">
<select class="form-control datasource-small" ng-disabled="!isQueryOwner || !sourceMode" ng-model="query.data_source_id" ng-change="updateDataSource()"
ng-options="ds.id as ds.name for ds in dataSources"></select>
<a ng-if="dataSource.options.doc_url != ''" ng-href={{dataSource.options.doc_url}}>{{dataSource.type_name}} documentation</a>
<span ng-if="dataSource.options.doc_url == ''">{{dataSource.type_name}}</span>
</div>

<div class="col-xs-7">
Expand Down
12 changes: 10 additions & 2 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,12 @@ def to_dict(self, all=False, with_permissions_for=None):
'type': self.type,
'syntax': self.query_runner.syntax,
'paused': self.paused,
'pause_reason': self.pause_reason
'pause_reason': self.pause_reason,
'type_name': self.query_runner.name(),
}

schema = get_configuration_schema_for_query_runner_type(self.type)
if all:
schema = get_configuration_schema_for_query_runner_type(self.type)
self.options.set_schema(schema)
d['options'] = self.options.to_dict(mask_secrets=True)
d['queue_name'] = self.queue_name
Expand All @@ -580,6 +581,11 @@ def to_dict(self, all=False, with_permissions_for=None):
DataSourceGroup.group == with_permissions_for,
DataSourceGroup.data_source == self).one()[0]

doc_url = self.options.get('doc_url', schema['properties'].get(
'doc_url', {}).get('default'))
if doc_url:
d['options'] = {'doc_url': doc_url}

return d

def __unicode__(self):
Expand Down Expand Up @@ -654,6 +660,8 @@ def add_group(self, group, view_only=False):
db.session.add(dsg)
return dsg

setattr(self, 'data_source_groups', dsg)

def remove_group(self, group):
db.session.query(DataSourceGroup).filter(
DataSourceGroup.group == group,
Expand Down
1 change: 1 addition & 0 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class NotSupported(Exception):

class BaseQueryRunner(object):
noop_query = None
default_doc_url = None

def __init__(self, configuration):
self.syntax = 'sql'
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _get_query_results(jobs, project_id, job_id, start_index):

class BigQuery(BaseQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://cloud.google.com/bigquery/docs/reference/legacy-sql"

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -117,6 +118,11 @@ def configuration_schema(cls):
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['jsonKeyFile', 'projectId'],
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def default(self, o):

class Cassandra(BaseQueryRunner):
noop_query = "SELECT dateof(now()) FROM system.local"
default_doc_url = "http://cassandra.apache.org/doc/latest/cql/index.html"

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -65,6 +66,11 @@ def configuration_schema(cls):
'type': 'number',
'title': 'Timeout',
'default': 10
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['keyspace', 'host']
Expand Down
8 changes: 8 additions & 0 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@


class DynamoDBSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://dql.readthedocs.io/en/latest/"

@classmethod
def configuration_schema(cls):
return {
Expand All @@ -47,6 +50,11 @@ def configuration_schema(cls):
},
"secret_key": {
"type": "string",
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["access_key", "secret_key"],
Expand Down
8 changes: 7 additions & 1 deletion redash/query_runner/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@


class BaseElasticSearch(BaseQueryRunner):
DEBUG_ENABLED = False
DEBUG_ENABLED = True
default_doc_url = "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html"

@classmethod
def configuration_schema(cls):
Expand All @@ -62,6 +63,11 @@ def configuration_schema(cls):
'basic_auth_password': {
'type': 'string',
'title': 'Basic Auth Password'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"secret": ["basic_auth_password"],
Expand Down
9 changes: 9 additions & 0 deletions redash/query_runner/google_spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def parse_worksheet(worksheet):
columns.append({
'name': column_name,
'friendly_name': column_name,

'type': TYPE_STRING
})

Expand Down Expand Up @@ -139,6 +140,9 @@ def request(self, *args, **kwargs):


class GoogleSpreadsheet(BaseQueryRunner):
default_doc_url = ("http://redash.readthedocs.io/en/latest/"
"datasources.html#google-spreadsheets")

@classmethod
def annotate_query(cls):
return False
Expand All @@ -159,6 +163,11 @@ def configuration_schema(cls):
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['jsonKeyFile'],
Expand Down
5 changes: 5 additions & 0 deletions redash/query_runner/graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def configuration_schema(cls):
'verify': {
'type': 'boolean',
'title': 'Verify SSL certificate'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url'],
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/hive_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class Hive(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = ("https://cwiki.apache.org/confluence/display/Hive/"
"LanguageManual")

@classmethod
def configuration_schema(cls):
Expand All @@ -53,6 +55,11 @@ def configuration_schema(cls):
},
"username": {
"type": "string"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["host"]
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/impala_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class Impala(BaseSQLQueryRunner):
noop_query = "show schemas"
default_doc_url = ("http://www.cloudera.com/documentation/enterprise/"
"latest/topics/impala_langref.html")

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -66,6 +68,11 @@ def configuration_schema(cls):
},
"timeout": {
"type": "number"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["host"],
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/influx_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _transform_result(results):

class InfluxDB(BaseQueryRunner):
noop_query = "show measurements limit 1"
default_doc_url = ("https://docs.influxdata.com/influxdb/v1.0/"
"query_language/spec/")

@classmethod
def configuration_schema(cls):
Expand All @@ -58,6 +60,11 @@ def configuration_schema(cls):
'properties': {
'url': {
'type': 'string'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url']
Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/jql.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def get_dict_output_field_name(cls,field_name, member_name):

class JiraJQL(BaseQueryRunner):
noop_query = '{"queryType": "count"}'
default_doc_url = ("https://confluence.atlassian.com/jirasoftwarecloud/"
"advanced-searching-764478330.html")

@classmethod
def configuration_schema(cls):
Expand All @@ -154,6 +156,11 @@ def configuration_schema(cls):
},
'password': {
'type': 'string'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['url', 'username', 'password'],
Expand Down
8 changes: 8 additions & 0 deletions redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def parse_results(results):


class MongoDB(BaseQueryRunner):
default_doc_url = ("https://docs.mongodb.com/manual/reference/operator/"
"query/")

@classmethod
def configuration_schema(cls):
return {
Expand All @@ -135,6 +138,11 @@ def configuration_schema(cls):
'type': 'string',
'title': 'Replica Set Name'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
'required': ['connectionString', 'dbName']
}
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def default(self, o):

class SqlServer(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://msdn.microsoft.com/en-us/library/bb510741.aspx"

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -68,6 +69,11 @@ def configuration_schema(cls):
"db": {
"type": "string",
"title": "Database Name"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["db"],
Expand Down
6 changes: 6 additions & 0 deletions redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

class Mysql(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = 'https://dev.mysql.com/doc/refman/5.7/en/'

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -79,6 +80,11 @@ def configuration_schema(cls):
'ssl_key': {
'type': 'string',
'title': 'Path to private key file (SSL)'
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
})

Expand Down
7 changes: 7 additions & 0 deletions redash/query_runner/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

logger = logging.getLogger(__name__)


class Oracle(BaseSQLQueryRunner):
noop_query = "SELECT 1 FROM dual"
default_doc_url = "http://docs.oracle.com/database/121/SQLRF/toc.htm"

@classmethod
def get_col_type(cls, col_type, scale):
Expand Down Expand Up @@ -65,6 +67,11 @@ def configuration_schema(cls):
"servicename": {
"type": "string",
"title": "DSN Service Name"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"required": ["servicename", "user", "password", "host", "port"],
Expand Down
14 changes: 14 additions & 0 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _wait(conn, timeout=None):

class PostgreSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://www.postgresql.org/docs/current/"

@classmethod
def configuration_schema(cls):
Expand Down Expand Up @@ -75,6 +76,11 @@ def configuration_schema(cls):
"type": "string",
"title": "SSL Mode",
"default": "prefer"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"order": ['host', 'port', 'user', 'password'],
Expand Down Expand Up @@ -179,6 +185,9 @@ def run_query(self, query, user):


class Redshift(PostgreSQL):
default_doc_url = ("http://docs.aws.amazon.com/redshift/latest/"
"dg/cm_chap_SQLCommandRef.html")

@classmethod
def type(cls):
return "redshift"
Expand Down Expand Up @@ -223,6 +232,11 @@ def configuration_schema(cls):
"type": "string",
"title": "SSL Mode",
"default": "prefer"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
}
},
"order": ['host', 'port', 'user', 'password'],
Expand Down
Loading

0 comments on commit 7b85d06

Please sign in to comment.