update js
This commit is contained in:
3382
lib/core/parse/generic/genericAutocompleteParser.js
Normal file
3382
lib/core/parse/generic/genericAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
3347
lib/core/parse/generic/genericSyntaxParser.js
Normal file
3347
lib/core/parse/generic/genericSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
1983
lib/core/parse/generic/sqlParseSupport.js
Normal file
1983
lib/core/parse/generic/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
5705
lib/core/parse/hive/hiveAutocompleteParser.js
Normal file
5705
lib/core/parse/hive/hiveAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
5644
lib/core/parse/hive/hiveSyntaxParser.js
Normal file
5644
lib/core/parse/hive/hiveSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
2208
lib/core/parse/hive/sqlParseSupport.js
Normal file
2208
lib/core/parse/hive/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
5407
lib/core/parse/impala/impalaAutocompleteParser.js
Normal file
5407
lib/core/parse/impala/impalaAutocompleteParser.js
Normal file
File diff suppressed because one or more lines are too long
5364
lib/core/parse/impala/impalaSyntaxParser.js
Normal file
5364
lib/core/parse/impala/impalaSyntaxParser.js
Normal file
File diff suppressed because one or more lines are too long
2289
lib/core/parse/impala/sqlParseSupport.js
Normal file
2289
lib/core/parse/impala/sqlParseSupport.js
Normal file
File diff suppressed because it is too large
Load Diff
4518
lib/core/parse/sqlFunctions.js
Normal file
4518
lib/core/parse/sqlFunctions.js
Normal file
File diff suppressed because it is too large
Load Diff
84
lib/core/parse/sqlParserRepository.js
Normal file
84
lib/core/parse/sqlParserRepository.js
Normal file
@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* AUTOCOMPLETE_MODULES and SYNTAX_MODULES are generated, do not edit manually, see tools/jison/generateParsers.js
|
||||
*/
|
||||
const AUTOCOMPLETE_MODULES = {
|
||||
calcite: require("calcite/calciteAutocompleteParser"),
|
||||
druid: require("druid/druidAutocompleteParser"),
|
||||
elasticsearch: require("elasticsearch/elasticsearchAutocompleteParser"),
|
||||
flink: require("flink/flinkAutocompleteParser"),
|
||||
generic: require("generic/genericAutocompleteParser"),
|
||||
hive: require("hive/hiveAutocompleteParser"),
|
||||
impala: require("impala/impalaAutocompleteParser"),
|
||||
ksql: require("ksql/ksqlAutocompleteParser"),
|
||||
phoenix: require("phoenix/phoenixAutocompleteParser"),
|
||||
presto: require("presto/prestoAutocompleteParser")
|
||||
};
|
||||
const SYNTAX_MODULES = {
|
||||
calcite: require("calcite/calciteSyntaxParser"),
|
||||
druid: require("druid/druidSyntaxParser"),
|
||||
elasticsearch: require("elasticsearch/elasticsearchSyntaxParser"),
|
||||
flink: require("flink/flinkSyntaxParser"),
|
||||
generic: require("generic/genericSyntaxParser"),
|
||||
hive: require("hive/hiveSyntaxParser"),
|
||||
impala: require("impala/impalaSyntaxParser"),
|
||||
ksql: require("ksql/ksqlSyntaxParser"),
|
||||
phoenix: require("phoenix/phoenixSyntaxParser"),
|
||||
presto: require("presto/prestoSyntaxParser")
|
||||
};
|
||||
/* eslint-enable */
|
||||
class SqlParserRepository {
|
||||
constructor() {
|
||||
this.modulePromises = {};
|
||||
}
|
||||
getParser(sourceType, parserType) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!this.modulePromises[sourceType + parserType]) {
|
||||
const modules = parserType === 'Autocomplete' ? AUTOCOMPLETE_MODULES : SYNTAX_MODULES;
|
||||
this.modulePromises[sourceType + parserType] = new Promise((resolve, reject) => {
|
||||
const targetModule = modules[sourceType] || modules.generic;
|
||||
resolve(targetModule);
|
||||
});
|
||||
}
|
||||
return this.modulePromises[sourceType + parserType];
|
||||
});
|
||||
}
|
||||
getAutocompleter(sourceType) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.getParser(sourceType, 'Autocomplete');
|
||||
});
|
||||
}
|
||||
getSyntaxParser(sourceType) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return this.getParser(sourceType, 'Syntax');
|
||||
});
|
||||
}
|
||||
}
|
||||
const sqlParserRepository = new SqlParserRepository();
|
||||
exports.default = sqlParserRepository;
|
75
lib/core/parse/stringDistance.js
Normal file
75
lib/core/parse/stringDistance.js
Normal file
@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
// Licensed to Cloudera, Inc. under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. Cloudera, Inc. licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* Calculates the Optimal String Alignment distance between two strings. Returns 0 when the strings are equal and the
|
||||
* distance when not, distances is less than or equal to the length of the longest string.
|
||||
*
|
||||
* @param strA
|
||||
* @param strB
|
||||
* @param [ignoreCase]
|
||||
* @returns {number} The similarity
|
||||
*/
|
||||
const stringDistance = function (strA, strB, ignoreCase) {
|
||||
if (ignoreCase) {
|
||||
strA = strA.toLowerCase();
|
||||
strB = strB.toLowerCase();
|
||||
}
|
||||
// TODO: Consider other algorithms for performance
|
||||
const strALength = strA.length;
|
||||
const strBLength = strB.length;
|
||||
if (strALength === 0) {
|
||||
return strBLength;
|
||||
}
|
||||
if (strBLength === 0) {
|
||||
return strALength;
|
||||
}
|
||||
const distances = new Array(strALength);
|
||||
let cost, deletion, insertion, substitution, transposition;
|
||||
for (let i = 0; i <= strALength; i++) {
|
||||
distances[i] = new Array(strBLength);
|
||||
distances[i][0] = i;
|
||||
for (let j = 1; j <= strBLength; j++) {
|
||||
if (!i) {
|
||||
distances[0][j] = j;
|
||||
}
|
||||
else {
|
||||
cost = strA[i - 1] === strB[j - 1] ? 0 : 1;
|
||||
deletion = distances[i - 1][j] + 1;
|
||||
insertion = distances[i][j - 1] + 1;
|
||||
substitution = distances[i - 1][j - 1] + cost;
|
||||
if (deletion <= insertion && deletion <= substitution) {
|
||||
distances[i][j] = deletion;
|
||||
}
|
||||
else if (insertion <= deletion && insertion <= substitution) {
|
||||
distances[i][j] = insertion;
|
||||
}
|
||||
else {
|
||||
distances[i][j] = substitution;
|
||||
}
|
||||
if (i > 1 && j > 1 && strA[i] === strB[j - 1] && strA[i - 1] === strB[j]) {
|
||||
transposition = distances[i - 2][j - 2] + cost;
|
||||
if (transposition < distances[i][j]) {
|
||||
distances[i][j] = transposition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return distances[strALength][strBLength];
|
||||
};
|
||||
exports.default = stringDistance;
|
Reference in New Issue
Block a user