|
@@ -18,44 +18,46 @@ import $ from 'jquery';
|
|
|
|
|
|
|
|
import BaseStrategy from './baseStrategy';
|
|
import BaseStrategy from './baseStrategy';
|
|
|
import dataCatalog from 'catalog/dataCatalog';
|
|
import dataCatalog from 'catalog/dataCatalog';
|
|
|
-import sqlAutocompleteParser from 'parse/sql/hive/hiveAutocompleteParser';
|
|
|
|
|
|
|
+import sqlParserRepository from 'parse/sql/sqlParserRepository';
|
|
|
import I18n from 'utils/i18n';
|
|
import I18n from 'utils/i18n';
|
|
|
|
|
|
|
|
export default class LocalStrategy extends BaseStrategy {
|
|
export default class LocalStrategy extends BaseStrategy {
|
|
|
analyzeRisk(options) {
|
|
analyzeRisk(options) {
|
|
|
const snippet = JSON.parse(options.snippetJson);
|
|
const snippet = JSON.parse(options.snippetJson);
|
|
|
|
|
|
|
|
- // TODO: Get parser from repository, need to extract SqlFunctions dep first
|
|
|
|
|
- // to reduce size of main hue bundle
|
|
|
|
|
- // const parser = await sqlParserRepository.getAutocompleteParser(snippet.dialect);
|
|
|
|
|
- const sqlParseResult = sqlAutocompleteParser.parseSql(snippet.statement + ' ', '');
|
|
|
|
|
|
|
+ const deferred = $.Deferred();
|
|
|
|
|
+ sqlParserRepository
|
|
|
|
|
+ .getAutocompleteParser(this.connector.dialect)
|
|
|
|
|
+ .then(sqlAutocompleteParser => {
|
|
|
|
|
+ const sqlParseResult = sqlAutocompleteParser.parseSql(snippet.statement + ' ', '');
|
|
|
|
|
|
|
|
- const hasLimit = sqlParseResult.locations.some(
|
|
|
|
|
- location => location.type === 'limitClause' && !location.missing
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const hasLimit = sqlParseResult.locations.some(
|
|
|
|
|
+ location => location.type === 'limitClause' && !location.missing
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ deferred.resolve({
|
|
|
|
|
+ status: 0,
|
|
|
|
|
+ message: '',
|
|
|
|
|
+ query_complexity: {
|
|
|
|
|
+ hints: !hasLimit
|
|
|
|
|
+ ? [
|
|
|
|
|
+ {
|
|
|
|
|
+ riskTables: [],
|
|
|
|
|
+ riskAnalysis: I18n('Query has no limit'),
|
|
|
|
|
+ riskId: 22, // To change
|
|
|
|
|
+ risk: 'low',
|
|
|
|
|
+ riskRecommendation: I18n(
|
|
|
|
|
+ 'Append a limit clause to reduce the size of the result set'
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ : [],
|
|
|
|
|
+ noStats: true,
|
|
|
|
|
+ noDDL: false
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- const deferred = $.Deferred();
|
|
|
|
|
- deferred.resolve({
|
|
|
|
|
- status: 0,
|
|
|
|
|
- message: '',
|
|
|
|
|
- query_complexity: {
|
|
|
|
|
- hints: !hasLimit
|
|
|
|
|
- ? [
|
|
|
|
|
- {
|
|
|
|
|
- riskTables: [],
|
|
|
|
|
- riskAnalysis: I18n('Query has no limit'),
|
|
|
|
|
- riskId: 22, // To change
|
|
|
|
|
- risk: 'low',
|
|
|
|
|
- riskRecommendation: I18n(
|
|
|
|
|
- 'Append a limit clause to reduce the size of the result set'
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- : [],
|
|
|
|
|
- noStats: true,
|
|
|
|
|
- noDDL: false
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
return deferred.promise();
|
|
return deferred.promise();
|
|
|
}
|
|
}
|
|
|
|
|
|