Skip to content

Commit

Permalink
Closes #537: Port datasource URL code to an extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Sep 12, 2018
1 parent 44bb2b5 commit b4209b1
Show file tree
Hide file tree
Showing 27 changed files with 534 additions and 661 deletions.
6 changes: 2 additions & 4 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ <h3>
{{ds.name}}
</ui-select-choices>
</ui-select>
<a ng-if="dataSource.options.doc_url != '' && dataSource.options.doc_url" ng-href={{dataSource.options.doc_url}}>{{dataSource.type_name}} documentation</a>
<span ng-if="dataSource.options.doc_url == '' || !dataSource.options.doc_url">{{ dataSource.type_name }} documentation</span>
<datasource-link datasource-id="query.data_source_id"></datasource-link>
<get-data-source-version id='data-source-version'></get-data-source-version>
</div>

Expand Down Expand Up @@ -171,8 +170,7 @@ <h3>
<select class="form-control datasource-small flex-fill w-100" 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>
<datasource-link datasource-id="query.data_source_id"></datasource-link>

<button class="btn btn-default m-l-5" ng-show="canEdit" ng-click="saveQuery()" title="Save" uib-tooltip-html="modKey + ' + S'"
tooltip-append-to-body="true">
Expand Down
9 changes: 4 additions & 5 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,13 @@ 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,
'type_name': self.query_runner.name(),
'pause_reason': self.pause_reason
}

schema = get_configuration_schema_for_query_runner_type(self.type)
self.options.set_schema(schema)
d['options'] = self.options.to_dict(mask_secrets=True)
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
d['scheduled_queue_name'] = self.scheduled_queue_name
d['groups'] = self.groups
Expand Down
62 changes: 32 additions & 30 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class NotSupported(Exception):

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

def __init__(self, configuration):
self.syntax = 'sql'
Expand All @@ -80,6 +80,12 @@ def annotate_query(cls):
def configuration_schema(cls):
return {}

@classmethod
def add_configuration_property(cls, property, value):
if cls.configuration_properties is None:
raise NotImplementedError()
cls.configuration_properties[property] = value

def get_data_source_version(self):
if self.data_source_version_query is None:
raise NotImplementedError
Expand Down Expand Up @@ -175,40 +181,36 @@ class BaseHTTPQueryRunner(BaseQueryRunner):
url_title = 'URL base path'
username_title = 'HTTP Basic Auth Username'
password_title = 'HTTP Basic Auth Password'
configuration_properties = {
'url': {
'type': 'string',
'title': url_title,
},
'username': {
'type': 'string',
'title': username_title,
},
'password': {
'type': 'string',
'title': password_title,
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": (
"This string will be used to toggle visibility of "
"tables in the schema browser when editing a query "
"in order to remove non-useful tables from sight."
),
}
}

@classmethod
def configuration_schema(cls):
schema = {
'type': 'object',
'properties': {
'url': {
'type': 'string',
'title': cls.url_title,
},
'username': {
'type': 'string',
'title': cls.username_title,
},
'password': {
'type': 'string',
'title': cls.password_title,
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url,
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": (
"This string will be used to toggle visibility of "
"tables in the schema browser when editing a query "
"in order to remove non-useful tables from sight."
),
}
},
'properties': cls.configuration_properties,
'required': ['url'],
'secret': ['password']
}
Expand Down
5 changes: 0 additions & 5 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ def configuration_schema(cls):
'type': 'boolean',
'title': 'Use Glue Data Catalog',
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
Expand Down
89 changes: 42 additions & 47 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,47 @@ def _get_query_results(jobs, project_id, location, job_id, start_index):

class BigQuery(BaseQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://cloud.google.com/bigquery/docs/reference/legacy-sql"
configuration_properties = {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
"default": "US",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
}

@classmethod
def enabled(cls):
Expand All @@ -93,52 +133,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
"default": "US",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
'properties': cls.configuration_properties,
'required': ['jsonKeyFile', 'projectId'],
"order": ['projectId', 'jsonKeyFile', 'loadSchema', 'useStandardSql', 'location', 'totalMBytesProcessedLimit', 'maximumBillingTier', 'userDefinedFunctionResourceUri'],
'secret': ['jsonKeyFile']
Expand Down
81 changes: 38 additions & 43 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,43 @@ 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"
configuration_properties = {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
}

@classmethod
def enabled(cls):
Expand All @@ -37,48 +73,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
'properties': cls.configuration_properties,
'required': ['keyspace', 'host']
}

Expand Down
43 changes: 19 additions & 24 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,30 @@

class DynamoDBSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
default_doc_url = "https://dql.readthedocs.io/en/latest/"
configuration_properties = {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
}

@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
},
"doc_url": {
"type": "string",
"title": "Documentation URL",
"default": cls.default_doc_url
},
"toggle_table_string": {
"type": "string",
"title": "Toggle Table String",
"default": "_v",
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
},
"properties": cls.configuration_properties,
"required": ["access_key", "secret_key"],
"secret": ["secret_key"]
}
Expand Down
Loading

0 comments on commit b4209b1

Please sign in to comment.