|
|
@@ -19,25 +19,22 @@ import $ from 'jquery';
|
|
|
import BaseStrategy from './baseStrategy';
|
|
|
import dataCatalog from 'catalog/dataCatalog';
|
|
|
import sqlAutocompleteParser from 'parse/sql/hive/hiveAutocompleteParser';
|
|
|
+import I18n from 'utils/i18n';
|
|
|
|
|
|
export default class LocalStrategy extends BaseStrategy {
|
|
|
analyzeRisk(options) {
|
|
|
const snippet = JSON.parse(options.snippetJson);
|
|
|
|
|
|
- const beforeCursor = snippet.statement + ' '; // Note trailing space
|
|
|
- const afterCursor = '';
|
|
|
- const dialect = snippet.dialect;
|
|
|
- const debug = false;
|
|
|
+ // TODO: Get parser from repository, need to extract SqlFunctions dep first
|
|
|
+ // to reduce size of main hue bundle
|
|
|
+ // const parser = await sqlParserRepository.getAutocompleter(snippet.dialect);
|
|
|
+ const sqlParseResult = sqlAutocompleteParser.parseSql(snippet.statement + ' ', '');
|
|
|
|
|
|
- const hasLimit =
|
|
|
- sqlAutocompleteParser
|
|
|
- .parseSql(beforeCursor, afterCursor, dialect, debug)
|
|
|
- .locations.filter(token => {
|
|
|
- return token.type == 'limitClause' && !token.missing;
|
|
|
- }).length > 0;
|
|
|
+ const hasLimit = sqlParseResult.locations.some(
|
|
|
+ location => location.type === 'limitClause' && !location.missing
|
|
|
+ );
|
|
|
|
|
|
const deferred = $.Deferred();
|
|
|
-
|
|
|
deferred.resolve({
|
|
|
status: 0,
|
|
|
message: '',
|
|
|
@@ -46,10 +43,12 @@ export default class LocalStrategy extends BaseStrategy {
|
|
|
? [
|
|
|
{
|
|
|
riskTables: [],
|
|
|
- riskAnalysis: 'Query has no limits',
|
|
|
+ riskAnalysis: I18n('Query has no limit'),
|
|
|
riskId: 22, // To change
|
|
|
risk: 'low',
|
|
|
- riskRecommendation: 'Append a limit clause to reduce size of the result set'
|
|
|
+ riskRecommendation: I18n(
|
|
|
+ 'Append a limit clause to reduce the size of the result set'
|
|
|
+ )
|
|
|
}
|
|
|
]
|
|
|
: [],
|
|
|
@@ -57,7 +56,6 @@ export default class LocalStrategy extends BaseStrategy {
|
|
|
noDDL: false
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
return deferred.promise();
|
|
|
}
|
|
|
|
|
|
@@ -67,8 +65,8 @@ export default class LocalStrategy extends BaseStrategy {
|
|
|
|
|
|
dataCatalog
|
|
|
.getEntry({
|
|
|
- sourceType: self.connector ? self.connector.type : '9',
|
|
|
- connector: self.connector,
|
|
|
+ sourceType: this.connector.type,
|
|
|
+ connector: this.connector,
|
|
|
path: path,
|
|
|
namespace: { id: 'default' }
|
|
|
})
|