Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

app: fix initial preview query #371

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/actions/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ export function getApacheDrillS3Keys(connectionId) {
);
}

export function previewTable (connectionId, dialect, table, database) {
export function previewTable(connectionId, connectionObject, table, elasticsearchIndex) {
const body = {
query: PREVIEW_QUERY(dialect, table, database)
query: PREVIEW_QUERY(connectionObject, table, elasticsearchIndex)
};
return apiThunk(
`connections/${connectionId}/query`,
Expand Down
2 changes: 1 addition & 1 deletion app/components/Settings/Preview/Preview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Preview extends Component {

const dialect = connectionObject.dialect;
const showEditor = propOr(true, 'showEditor')(preview);
const code = propOr(PREVIEW_QUERY(dialect, selectedTable), 'code')(preview);
const code = propOr(PREVIEW_QUERY(connectionObject, selectedTable), 'code')(preview);
propOr('', 'error')(preview);

// Surpressing ESLint cause restricting line length would harm JSX readability
Expand Down
6 changes: 3 additions & 3 deletions app/components/Settings/Settings.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function mapStateToProps(state) {
const preview = previews[selectedConnectionId] || {};
const connection = connections[selectedTab];
if (connection && !hasIn('code', preview)) {
preview.code = PREVIEW_QUERY(connection.dialect, selectedTable);
preview.code = PREVIEW_QUERY(connection, selectedTable);
}

return {
Expand Down Expand Up @@ -604,9 +604,9 @@ function mergeProps(stateProps, dispatchProps, ownProps) {
function boundPreviewTables() {
return dispatch(Actions.previewTable(
selectedConnectionId,
connectionObject.dialect,
connectionObject,
selectedTable,
connectionObject.database || selectedIndex
selectedIndex
));
}
function boundUpdatePreview(previewUpdateObject) {
Expand Down
9 changes: 4 additions & 5 deletions app/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ export const LOGOS = {
[DIALECTS.DATA_WORLD]: 'images/dataworld-logo.png'
};

export function PREVIEW_QUERY (dialect, table, database = '') {
switch (dialect) {
export function PREVIEW_QUERY(connection, table, elasticsearchIndex) {
switch (connection.dialect) {
case DIALECTS.IBM_DB2:
return `SELECT * FROM ${table} FETCH FIRST 1000 ROWS ONLY`;
case DIALECTS.APACHE_IMPALA:
Expand All @@ -228,11 +228,10 @@ export function PREVIEW_QUERY (dialect, table, database = '') {
case DIALECTS.REDSHIFT:
return `SELECT * FROM ${table} LIMIT 1000`;
case DIALECTS.MSSQL:
return 'SELECT TOP 1000 * FROM ' +
`${database}.dbo.${table}`;
return `SELECT TOP 1000 * FROM ${connection.database}.dbo.${table}`;
case DIALECTS.ELASTICSEARCH:
return JSON.stringify({
index: database || '_all',
index: elasticsearchIndex || '_all',
type: table || '_all',
body: {
query: { 'match_all': {} },
Expand Down