Skip to content

Commit

Permalink
[sql lab] option to disable cross schema search (apache#4551)
Browse files Browse the repository at this point in the history
* [sql lab] disable cross schema search

This is killing our metastore as people type it emits large
all-table-dump as they hit the keystroke. It never returns as it times
out and hammers the poor metastore.

Also some improvements around the disabling the table select on the left
panel and having the table name not be sticky.

* typo

(cherry picked from commit d522292)
  • Loading branch information
mistercrunch committed Mar 9, 2018
1 parent b95a1e9 commit dfb00ab
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class SqlEditor extends React.PureComponent {
>
<SqlEditorLeftBar
height={height}
database={this.props.database}
queryEditor={this.props.queryEditor}
tables={this.props.tables}
actions={this.props.actions}
Expand Down
14 changes: 11 additions & 3 deletions superset/assets/javascripts/SqlLab/components/SqlEditorLeftBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const propTypes = {
height: PropTypes.number.isRequired,
tables: PropTypes.array,
actions: PropTypes.object,
database: PropTypes.object,
};

const defaultProps = {
Expand Down Expand Up @@ -139,6 +140,14 @@ class SqlEditorLeftBar extends React.PureComponent {
render() {
const shouldShowReset = window.location.search === '?reset=1';
const tableMetaDataHeight = this.props.height - 130; // 130 is the height of the selects above
let tableSelectPlaceholder;
let tableSelectDisabled = false;
if (this.props.database && this.props.database.allow_multi_schema_metadata_fetch) {
tableSelectPlaceholder = t('Type to search ...');
} else {
tableSelectPlaceholder = t('Select table ');
tableSelectDisabled = true;
}
return (
<div className="clearfix sql-toolbar">
<div>
Expand Down Expand Up @@ -186,7 +195,6 @@ class SqlEditorLeftBar extends React.PureComponent {
name="select-table"
ref="selectTable"
isLoading={this.state.tableLoading}
value={this.state.tableName}
placeholder={t('Add a table (%s)', this.state.tableOptions.length)}
autosize={false}
onChange={this.changeTable.bind(this)}
Expand All @@ -199,8 +207,8 @@ class SqlEditorLeftBar extends React.PureComponent {
async
name="async-select-table"
ref="selectTable"
value={this.state.tableName}
placeholder={t('Type to search ...')}
placeholder={tableSelectPlaceholder}
disabled={tableSelectDisabled}
autosize={false}
onChange={this.changeTable.bind(this)}
loadOptions={this.getTableNamesBySubStr.bind(this)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('SqlEditorLeftBar', () => {
},
tables: [table],
queryEditor: defaultQueryEditor,
database: {},
height: 0,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('TabbedSqlEditors', () => {
tabHistory: initialState.tabHistory,
editorHeight: '',
getHeight: () => ('100px'),
database: {},
};
const getWrapper = () => (
shallow(<TabbedSqlEditors {...mockedProps} />, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""allow_multi_schema_metadata_fetch
Revision ID: e68c4473c581
Revises: e866bd2d4976
Create Date: 2018-03-06 12:24:30.896293
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'e68c4473c581'
down_revision = 'e866bd2d4976'


def upgrade():

op.add_column(
'dbs',
sa.Column(
'allow_multi_schema_metadata_fetch',
sa.Boolean(),
nullable=True,
default=True,
),
)


def downgrade():
op.drop_column('dbs', 'allow_multi_schema_metadata_fetch')
7 changes: 7 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ class Database(Model, AuditMixinNullable, ImportMixin):
allow_ctas = Column(Boolean, default=False)
allow_dml = Column(Boolean, default=False)
force_ctas_schema = Column(String(250))
allow_multi_schema_metadata_fetch = Column(Boolean, default=True)
extra = Column(Text, default=textwrap.dedent("""\
{
"metadata_params": {},
Expand All @@ -593,6 +594,8 @@ def data(self):
return {
'name': self.database_name,
'backend': self.backend,
'allow_multi_schema_metadata_fetch':
self.allow_multi_schema_metadata_fetch,
}

@property
Expand Down Expand Up @@ -736,6 +739,8 @@ def inspector(self):

def all_table_names(self, schema=None, force=False):
if not schema:
if not self.allow_multi_schema_metadata_fetch:
return []
tables_dict = self.db_engine_spec.fetch_result_sets(
self, 'table', force=force)
return tables_dict.get('', [])
Expand All @@ -744,6 +749,8 @@ def all_table_names(self, schema=None, force=False):

def all_view_names(self, schema=None, force=False):
if not schema:
if not self.allow_multi_schema_metadata_fetch:
return []
views_dict = self.db_engine_spec.fetch_result_sets(
self, 'view', force=force)
return views_dict.get('', [])
Expand Down
9 changes: 8 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ class DatabaseView(SupersetModelView, DeleteMixin, YamlExportMixin): # noqa
add_columns = [
'database_name', 'sqlalchemy_uri', 'cache_timeout', 'extra',
'expose_in_sqllab', 'allow_run_sync', 'allow_run_async',
'allow_ctas', 'allow_dml', 'force_ctas_schema', 'impersonate_user']
'allow_ctas', 'allow_dml', 'force_ctas_schema', 'impersonate_user',
'allow_multi_schema_metadata_fetch',
]
search_exclude_columns = (
'password', 'tables', 'created_by', 'changed_by', 'queries',
'saved_queries')
Expand Down Expand Up @@ -256,6 +258,10 @@ class DatabaseView(SupersetModelView, DeleteMixin, YamlExportMixin): # noqa
'If Hive and hive.server2.enable.doAs is enabled, will run the queries as '
'service account, but impersonate the currently logged on user '
'via hive.server2.proxy.user property.'),
'allow_multi_schema_metadata_fetch': _(
'Allow SQL Lab to fetch a list of all tables and all views across '
'all database schemas. For large data warehouse with thousands of '
'tables, this can be expensive and put strain on the system.'),
}
label_columns = {
'expose_in_sqllab': _('Expose in SQL Lab'),
Expand Down Expand Up @@ -312,6 +318,7 @@ class DatabaseAsync(DatabaseView):
'id', 'database_name',
'expose_in_sqllab', 'allow_ctas', 'force_ctas_schema',
'allow_run_async', 'allow_run_sync', 'allow_dml',
'allow_multi_schema_metadata_fetch',
]


Expand Down

0 comments on commit dfb00ab

Please sign in to comment.