Skip to content

Commit

Permalink
Merge pull request #40 from lyft/merge_apache_1cd0e7f
Browse files Browse the repository at this point in the history
Merge from apache master
  • Loading branch information
khtruong authored Jun 5, 2019
2 parents 55d85f3 + a6304d4 commit 8ae173c
Show file tree
Hide file tree
Showing 33 changed files with 299 additions and 85 deletions.
11 changes: 11 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage:
status:
project:
default:
# Commits pushed to master should not make the overall
# project coverage decrease:
target: auto
threshold: 0%
patch:
default:
threshold: 0%
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Superset can be used to visualize data out of most databases:
* Redshift
* Clickhouse
* Apache Kylin
* Apache Drill
* Google BigQuery
* **more!** look for the availability of a SQLAlchemy dialect for your database
to find out whether it will work with Superset
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ polyline==1.3.2
prison==0.1.0 # via flask-appbuilder
py==1.7.0 # via retry
pycparser==2.19 # via cffi
pydruid==0.5.2
pydruid==0.5.3
pyjwt==1.7.1 # via flask-appbuilder, flask-jwt-extended
pyrsistent==0.14.11 # via jsonschema
python-dateutil==2.6.1
Expand Down
1 change: 1 addition & 0 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def index(self):
base_template='superset/base.html',
indexview=MyIndexView,
security_manager_class=custom_sm,
update_perms=False, # Run `superset init` to update FAB's perms
)

security_manager = appbuilder.sm
Expand Down
14 changes: 13 additions & 1 deletion superset/assets/spec/javascripts/sqllab/SouthPane_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ import { shallow } from 'enzyme';
import { STATUS_OPTIONS } from '../../../src/SqlLab/constants';
import { initialState } from './fixtures';
import SouthPaneContainer, { SouthPane } from '../../../src/SqlLab/components/SouthPane';
import ResultSet from '../../../src/SqlLab/components/ResultSet';

describe('SouthPane', () => {
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
const store = mockStore(initialState);

const mockedProps = {
editorQueries: [],
editorQueries: [
{ cached: false, changedOn: 1559238552333, db: 'main', dbId: 1, id: 'LCly_kkIN' },
{ cached: false, changedOn: 1559238500401, db: 'main', dbId: 1, id: 'lXJa7F9_r' },
{ cached: false, changedOn: 1559238506925, db: 'main', dbId: 1, id: '2g2_iRFMl' },
{ cached: false, changedOn: 1559238516395, db: 'main', dbId: 1, id: 'erWdqEWPm' },
],
latestQueryId: 'LCly_kkIN',
dataPreviewQueries: [],
actions: {},
activeSouthPaneTab: '',
Expand All @@ -57,4 +64,9 @@ describe('SouthPane', () => {
wrapper.setProps({ offline: true });
expect(wrapper.find('.m-r-3').render().text()).toBe(STATUS_OPTIONS.offline);
});
it('should pass latest query down to ResultSet component', () => {
wrapper = getWrapper();
expect(wrapper.find(ResultSet)).toHaveLength(1);
expect(wrapper.find(ResultSet).props().query.id).toEqual(mockedProps.latestQueryId);
});
});
10 changes: 10 additions & 0 deletions superset/assets/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const EXPAND_TABLE = 'EXPAND_TABLE';
export const COLLAPSE_TABLE = 'COLLAPSE_TABLE';
export const QUERY_EDITOR_SETDB = 'QUERY_EDITOR_SETDB';
export const QUERY_EDITOR_SET_SCHEMA = 'QUERY_EDITOR_SET_SCHEMA';
export const QUERY_EDITOR_SET_SCHEMA_OPTIONS = 'QUERY_EDITOR_SET_SCHEMA_OPTIONS';
export const QUERY_EDITOR_SET_TABLE_OPTIONS = 'QUERY_EDITOR_SET_TABLE_OPTIONS';
export const QUERY_EDITOR_SET_TITLE = 'QUERY_EDITOR_SET_TITLE';
export const QUERY_EDITOR_SET_AUTORUN = 'QUERY_EDITOR_SET_AUTORUN';
export const QUERY_EDITOR_SET_SQL = 'QUERY_EDITOR_SET_SQL';
Expand Down Expand Up @@ -305,6 +307,14 @@ export function queryEditorSetSchema(queryEditor, schema) {
return { type: QUERY_EDITOR_SET_SCHEMA, queryEditor, schema };
}

export function queryEditorSetSchemaOptions(queryEditor, options) {
return { type: QUERY_EDITOR_SET_SCHEMA_OPTIONS, queryEditor, options };
}

export function queryEditorSetTableOptions(queryEditor, options) {
return { type: QUERY_EDITOR_SET_TABLE_OPTIONS, queryEditor, options };
}

export function queryEditorSetAutorun(queryEditor, autorun) {
return { type: QUERY_EDITOR_SET_AUTORUN, queryEditor, autorun };
}
Expand Down
28 changes: 24 additions & 4 deletions superset/assets/src/SqlLab/components/AceEditorWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const propTypes = {
actions: PropTypes.object.isRequired,
onBlur: PropTypes.func,
sql: PropTypes.string.isRequired,
schemas: PropTypes.array,
tables: PropTypes.array,
extendedTables: PropTypes.array,
queryEditor: PropTypes.object.isRequired,
height: PropTypes.string,
hotkeys: PropTypes.arrayOf(PropTypes.shape({
Expand All @@ -62,7 +64,9 @@ const propTypes = {
const defaultProps = {
onBlur: () => {},
onChange: () => {},
schemas: [],
tables: [],
extendedTables: [],
};

class AceEditorWrapper extends React.PureComponent {
Expand All @@ -80,7 +84,9 @@ class AceEditorWrapper extends React.PureComponent {
this.setAutoCompleter(this.props);
}
componentWillReceiveProps(nextProps) {
if (!areArraysShallowEqual(this.props.tables, nextProps.tables)) {
if (!areArraysShallowEqual(this.props.tables, nextProps.tables) ||
!areArraysShallowEqual(this.props.schemas, nextProps.schemas) ||
!areArraysShallowEqual(this.props.extendedTables, nextProps.extendedTables)) {
this.setAutoCompleter(nextProps);
}
if (nextProps.sql !== this.props.sql) {
Expand Down Expand Up @@ -126,20 +132,34 @@ class AceEditorWrapper extends React.PureComponent {
getCompletions(aceEditor, session, pos, prefix, callback) {
const completer = {
insertMatch: (editor, data) => {
if (data.meta === 'table') {
this.props.actions.addTable(
this.props.queryEditor,
data.value,
this.props.queryEditor.schema,
);
}
editor.completer.insertMatch({ value: data.caption + ' ' });
},
};
const words = this.state.words.map(word => ({ ...word, completer }));
callback(null, words);
}
setAutoCompleter(props) {
// Loading table and column names as auto-completable words
// Loading schema, table and column names as auto-completable words
let words = [];
const schemas = props.schemas || [];
schemas.forEach((s) => {
words.push({ name: s.label, value: s.value, score: 60, meta: 'schema' });
});
const columns = {};
const tables = props.tables || [];
const extendedTables = props.extendedTables || [];
tables.forEach((t) => {
words.push({ name: t.name, value: t.name, score: 55, meta: 'table' });
const cols = t.columns || [];
const tableName = t.value.table;
words.push({ name: t.label, value: tableName, score: 55, meta: 'table' });
const extendedTable = extendedTables.find(et => et.name === tableName);
const cols = extendedTable && extendedTable.columns || [];
cols.forEach((col) => {
columns[col.name] = null; // using an object as a unique set
});
Expand Down
4 changes: 3 additions & 1 deletion superset/assets/src/SqlLab/components/SouthPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TAB_HEIGHT = 44;
*/
const propTypes = {
editorQueries: PropTypes.array.isRequired,
latestQueryId: PropTypes.string.isRequired,
dataPreviewQueries: PropTypes.array.isRequired,
actions: PropTypes.object.isRequired,
activeSouthPaneTab: PropTypes.string,
Expand Down Expand Up @@ -82,7 +83,8 @@ export class SouthPane extends React.PureComponent {
let latestQuery;
const props = this.props;
if (props.editorQueries.length > 0) {
latestQuery = props.editorQueries[props.editorQueries.length - 1];
// get the latest query
latestQuery = props.editorQueries.find(q => q.id === this.props.latestQueryId);
}
let results;
if (latestQuery) {
Expand Down
13 changes: 8 additions & 5 deletions superset/assets/src/SqlLab/components/SqlEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ class SqlEditor extends React.PureComponent {
}
runQuery() {
if (this.props.database) {
this.startQuery(this.props.database.allow_run_async);
this.startQuery();
}
}
startQuery(runAsync = false, ctas = false) {
startQuery(ctas = false) {
const qe = this.props.queryEditor;
const query = {
dbId: qe.dbId,
Expand All @@ -256,7 +256,7 @@ class SqlEditor extends React.PureComponent {
tempTableName: ctas ? this.state.ctas : '',
templateParams: qe.templateParams,
queryLimit: qe.queryLimit || this.props.defaultQueryLimit,
runAsync,
runAsync: this.props.database ? this.props.database.allow_run_async : false,
ctas,
};
this.props.actions.runQuery(query);
Expand All @@ -268,7 +268,7 @@ class SqlEditor extends React.PureComponent {
}
}
createTableAs() {
this.startQuery(true, true);
this.startQuery(true);
}
ctasChanged(event) {
this.setState({ ctas: event.target.value });
Expand Down Expand Up @@ -298,14 +298,17 @@ class SqlEditor extends React.PureComponent {
onChange={this.onSqlChanged}
queryEditor={this.props.queryEditor}
sql={this.props.queryEditor.sql}
tables={this.props.tables}
schemas={this.props.queryEditor.schemaOptions}
tables={this.props.queryEditor.tableOptions}
extendedTables={this.props.tables}
height={`${aceEditorHeight}px`}
hotkeys={hotkeys}
/>
{this.renderEditorBottomBar(hotkeys)}
</div>
<SouthPane
editorQueries={this.props.editorQueries}
latestQueryId={this.props.latestQuery ? this.props.latestQuery.id : 0}
dataPreviewQueries={this.props.dataPreviewQueries}
actions={this.props.actions}
height={southPaneHeight}
Expand Down
10 changes: 10 additions & 0 deletions superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ export default class SqlEditorLeftBar extends React.PureComponent {
};
this.resetState = this.resetState.bind(this);
this.onSchemaChange = this.onSchemaChange.bind(this);
this.onSchemasLoad = this.onSchemasLoad.bind(this);
this.onTablesLoad = this.onTablesLoad.bind(this);
this.onDbChange = this.onDbChange.bind(this);
this.getDbList = this.getDbList.bind(this);
this.onTableChange = this.onTableChange.bind(this);
}
onSchemaChange(schema) {
this.props.actions.queryEditorSetSchema(this.props.queryEditor, schema);
}
onSchemasLoad(schemas) {
this.props.actions.queryEditorSetSchemaOptions(this.props.queryEditor, schemas);
}
onTablesLoad(tables) {
this.props.actions.queryEditorSetTableOptions(this.props.queryEditor, tables);
}
onDbChange(db) {
this.props.actions.queryEditorSetDb(this.props.queryEditor, db.id);
}
Expand Down Expand Up @@ -105,6 +113,8 @@ export default class SqlEditorLeftBar extends React.PureComponent {
schema={qe.schema}
onDbChange={this.onDbChange}
onSchemaChange={this.onSchemaChange}
onSchemasLoad={this.onSchemasLoad}
onTablesLoad={this.onTablesLoad}
getDbList={this.getDbList}
onTableChange={this.onTableChange}
tableNameSticky={false}
Expand Down
11 changes: 10 additions & 1 deletion superset/assets/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ export default function sqlLabReducer(state = {}, action) {
[actions.QUERY_EDITOR_SET_SCHEMA]() {
return alterInArr(state, 'queryEditors', action.queryEditor, { schema: action.schema });
},
[actions.QUERY_EDITOR_SET_SCHEMA_OPTIONS]() {
return alterInArr(state, 'queryEditors', action.queryEditor, { schemaOptions: action.options });
},
[actions.QUERY_EDITOR_SET_TABLE_OPTIONS]() {
return alterInArr(state, 'queryEditors', action.queryEditor, { tableOptions: action.options });
},
[actions.QUERY_EDITOR_SET_TITLE]() {
return alterInArr(state, 'queryEditors', action.queryEditor, { title: action.title });
},
Expand Down Expand Up @@ -322,7 +328,10 @@ export default function sqlLabReducer(state = {}, action) {
let queriesLastUpdate = state.queriesLastUpdate;
for (const id in action.alteredQueries) {
const changedQuery = action.alteredQueries[id];
if (!state.queries.hasOwnProperty(id) || state.queries[id].state !== 'stopped') {
if (
!state.queries.hasOwnProperty(id)
|| (state.queries[id].state !== 'stopped' && state.queries[id].state !== 'failed')
) {
if (changedQuery.changedOn > queriesLastUpdate) {
queriesLastUpdate = changedQuery.changedOn;
}
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/AnchorLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class AnchorLink extends React.PureComponent {
}

handleClickAnchorLink(ev) {
ev.preventDefault();
history.pushState(null, null, `#${this.props.anchorLinkId}`);
ev.stopPropagation();
}

render() {
Expand All @@ -76,6 +75,7 @@ class AnchorLink extends React.PureComponent {
<span
className="anchor-link-container"
id={anchorLinkId}
onClick={this.handleClickAnchorLink}
>
{showShortLinkButton &&
<URLShortLinkButton
Expand Down
41 changes: 18 additions & 23 deletions superset/assets/src/components/FilterableTable/FilterableTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class FilterableTable extends PureComponent {
constructor(props) {
super(props);
this.list = List(this.formatTableData(props.data));
this.headerRenderer = this.headerRenderer.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.rowClassName = this.rowClassName.bind(this);
this.sort = this.sort.bind(this);

Expand Down Expand Up @@ -139,27 +139,6 @@ export default class FilterableTable extends PureComponent {
return values.some(v => v.includes(lowerCaseText));
}

headerRenderer({ dataKey, label, sortBy, sortDirection }) {
return (
<TooltipWrapper label="header" tooltip={label}>
<div className="header-style">
<span
className={
this.props.expandedColumns.indexOf(label) > -1
? 'header-style-disabled'
: ''
}
>
{label}
</span>
{sortBy === dataKey &&
<SortIndicator sortDirection={sortDirection} />
}
</div>
</TooltipWrapper>
);
}

rowClassName({ index }) {
let className = '';
if (this.props.striped) {
Expand All @@ -172,6 +151,22 @@ export default class FilterableTable extends PureComponent {
this.setState({ sortBy, sortDirection });
}

renderHeader({ dataKey, label, sortBy, sortDirection }) {
const className = this.props.expandedColumns.indexOf(label) > -1
? 'header-style-disabled'
: 'header-style';
return (
<TooltipWrapper label="header" tooltip={label}>
<div className={className}>
{label}
{sortBy === dataKey &&
<SortIndicator sortDirection={sortDirection} />
}
</div>
</TooltipWrapper>
);
}

render() {
const { sortBy, sortDirection } = this.state;
const {
Expand Down Expand Up @@ -229,7 +224,7 @@ export default class FilterableTable extends PureComponent {
<Column
dataKey={columnKey}
disableSort={false}
headerRenderer={this.headerRenderer}
headerRenderer={this.renderHeader}
width={this.widthsForColumnsByKey[columnKey]}
label={columnKey}
key={columnKey}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@
white-space: nowrap;
}
.header-style-disabled {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #aaa;
}
Loading

0 comments on commit 8ae173c

Please sign in to comment.