mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Adding indexes to table metadata (#1160)
This commit is contained in:
parent
5a0e06e7a2
commit
f1e80a8e1b
@ -102,22 +102,27 @@ class SqlEditorTopToolbar extends React.Component {
|
|||||||
const tableName = tableOpt.value;
|
const tableName = tableOpt.value;
|
||||||
const qe = this.props.queryEditor;
|
const qe = this.props.queryEditor;
|
||||||
const url = `/caravel/table/${qe.dbId}/${tableName}/${qe.schema}/`;
|
const url = `/caravel/table/${qe.dbId}/${tableName}/${qe.schema}/`;
|
||||||
|
|
||||||
|
this.setState({ tableLoading: true });
|
||||||
$.get(url, (data) => {
|
$.get(url, (data) => {
|
||||||
this.props.actions.addTable({
|
this.props.actions.addTable({
|
||||||
id: shortid.generate(),
|
id: shortid.generate(),
|
||||||
dbId: this.props.queryEditor.dbId,
|
dbId: this.props.queryEditor.dbId,
|
||||||
queryEditorId: this.props.queryEditor.id,
|
queryEditorId: this.props.queryEditor.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
indexes: data.indexes,
|
||||||
schema: qe.schema,
|
schema: qe.schema,
|
||||||
columns: data.columns,
|
columns: data.columns,
|
||||||
expanded: true,
|
expanded: true,
|
||||||
});
|
});
|
||||||
|
this.setState({ tableLoading: false });
|
||||||
})
|
})
|
||||||
.fail(() => {
|
.fail(() => {
|
||||||
this.props.actions.addAlert({
|
this.props.actions.addAlert({
|
||||||
msg: 'Error occurred while fetching metadata',
|
msg: 'Error occurred while fetching metadata',
|
||||||
bsStyle: 'danger',
|
bsStyle: 'danger',
|
||||||
});
|
});
|
||||||
|
this.setState({ tableLoading: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
@ -5,6 +5,7 @@ import { connect } from 'react-redux';
|
|||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import * as Actions from '../actions';
|
import * as Actions from '../actions';
|
||||||
import shortid from 'shortid';
|
import shortid from 'shortid';
|
||||||
|
import ModalTrigger from '../../components/ModalTrigger.jsx';
|
||||||
|
|
||||||
class TableElement extends React.Component {
|
class TableElement extends React.Component {
|
||||||
setSelectStar() {
|
setSelectStar() {
|
||||||
@ -86,6 +87,27 @@ class TableElement extends React.Component {
|
|||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let keyLink;
|
||||||
|
if (this.props.table.indexes && this.props.table.indexes.length > 0) {
|
||||||
|
keyLink = (
|
||||||
|
<ModalTrigger
|
||||||
|
modalTitle={
|
||||||
|
<div>
|
||||||
|
Keys for table <strong>{this.props.table.name}</strong>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
modalBody={
|
||||||
|
<pre>{JSON.stringify(this.props.table.indexes, null, 4)}</pre>
|
||||||
|
}
|
||||||
|
triggerNode={
|
||||||
|
<Link
|
||||||
|
className="fa fa-key pull-left m-l-2"
|
||||||
|
tooltip={`View indexes (${this.props.table.indexes.length})`}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="clearfix">
|
<div className="clearfix">
|
||||||
@ -94,6 +116,7 @@ class TableElement extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="pull-right">
|
<div className="pull-right">
|
||||||
<ButtonGroup className="ws-el-controls pull-right">
|
<ButtonGroup className="ws-el-controls pull-right">
|
||||||
|
{keyLink}
|
||||||
<Link
|
<Link
|
||||||
className="fa fa-pencil pull-left m-l-2"
|
className="fa fa-pencil pull-left m-l-2"
|
||||||
onClick={this.setSelectStar.bind(this)}
|
onClick={this.setSelectStar.bind(this)}
|
||||||
|
@ -633,6 +633,9 @@ class Database(Model, AuditMixinNullable):
|
|||||||
def get_columns(self, table_name, schema=None):
|
def get_columns(self, table_name, schema=None):
|
||||||
return self.inspector.get_columns(table_name, schema)
|
return self.inspector.get_columns(table_name, schema)
|
||||||
|
|
||||||
|
def get_indexes(self, table_name, schema=None):
|
||||||
|
return self.inspector.get_indexes(table_name, schema)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sqlalchemy_uri_decrypted(self):
|
def sqlalchemy_uri_decrypted(self):
|
||||||
conn = sqla.engine.url.make_url(self.sqlalchemy_uri)
|
conn = sqla.engine.url.make_url(self.sqlalchemy_uri)
|
||||||
|
@ -1527,9 +1527,11 @@ class Caravel(BaseCaravelView):
|
|||||||
schema = None if schema in ('null', 'undefined') else schema
|
schema = None if schema in ('null', 'undefined') else schema
|
||||||
mydb = db.session.query(models.Database).filter_by(id=database_id).one()
|
mydb = db.session.query(models.Database).filter_by(id=database_id).one()
|
||||||
cols = []
|
cols = []
|
||||||
|
indexes = []
|
||||||
t = mydb.get_columns(table_name, schema)
|
t = mydb.get_columns(table_name, schema)
|
||||||
try:
|
try:
|
||||||
t = mydb.get_columns(table_name, schema)
|
t = mydb.get_columns(table_name, schema)
|
||||||
|
indexes = mydb.get_indexes(table_name, schema)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response(
|
return Response(
|
||||||
json.dumps({'error': utils.error_msg_from_exception(e)}),
|
json.dumps({'error': utils.error_msg_from_exception(e)}),
|
||||||
@ -1548,6 +1550,7 @@ class Caravel(BaseCaravelView):
|
|||||||
tbl = {
|
tbl = {
|
||||||
'name': table_name,
|
'name': table_name,
|
||||||
'columns': cols,
|
'columns': cols,
|
||||||
|
'indexes': indexes,
|
||||||
}
|
}
|
||||||
return Response(json.dumps(tbl), mimetype="application/json")
|
return Response(json.dumps(tbl), mimetype="application/json")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user