Skip to content

Commit

Permalink
[autocomplete] Revert pluggable autocompleter as it's causing build i…
Browse files Browse the repository at this point in the history
…ssues

This reverts commit 25b30d1.
  • Loading branch information
JohanAhlen committed May 26, 2022
1 parent 357fa6c commit 8f24a01
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 533 deletions.
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ commands:
cp ~/repo/package.json .
rm -f package-lock.json
cp ~/repo/package-lock.json .
cd /usr/share/hue/tools/jison && npm install && node generateParserModuleImports.js
cd /usr/share/hue
npm install
npm i eslint-plugin-jest@latest --save-dev # Seems to not be found otherwise
npm run webpack
Expand Down
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
/desktop/core/src/desktop/js/parse/sql/dasksql/dasksqlAutocompleteParser.js
/desktop/core/src/desktop/js/parse/sql/dasksql/dasksqlSyntaxParser.js
/desktop/core/src/desktop/js/parse/sql/dasksql/spec/dasksqlAutocompleteParser_Locations_Spec.js
/desktop/core/src/desktop/js/parse/sql/parserModules.ts
**/node_modules/**
2 changes: 0 additions & 2 deletions .github/workflows/commitflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ jobs:
cp -r docs /usr/share/hue
cd /usr/share/hue/tools/jison && npm install && node generateParserModuleImports.js
cd /usr/share/hue
npm install
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ junitresults*
# Generated js bundles
desktop/core/src/desktop/static/desktop/js/bundles/

# Generated ts files
desktop/core/src/desktop/js/parse/sql/parserModules.ts

# Hugo generated files
docs/docs-site/public/

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ install-env:
npm-install:
npm --version
node --version
pushd tools/jison && npm install && node generateParserModuleImports.js && popd
npm install
npm run webpack
npm run webpack-login
Expand Down
33 changes: 32 additions & 1 deletion desktop/core/src/desktop/js/parse/sql/sqlParserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,39 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable */
import { AutocompleteParser, SqlParserProvider, SyntaxParser } from 'parse/types';
import { AUTOCOMPLETE_MODULES, SYNTAX_MODULES } from './parserModules';

/**
* AUTOCOMPLETE_MODULES and SYNTAX_MODULES are generated, do not edit manually, see tools/jison/generateParsers.js
*/
const AUTOCOMPLETE_MODULES = {
calcite: () => import(/* webpackChunkName: "calcite-parser" */ './calcite/calciteAutocompleteParser'),
dasksql: () => import(/* webpackChunkName: "dasksql-parser" */ './dasksql/dasksqlAutocompleteParser'),
druid: () => import(/* webpackChunkName: "druid-parser" */ './druid/druidAutocompleteParser'),
elasticsearch: () => import(/* webpackChunkName: "elasticsearch-parser" */ './elasticsearch/elasticsearchAutocompleteParser'),
flink: () => import(/* webpackChunkName: "flink-parser" */ './flink/flinkAutocompleteParser'),
generic: () => import(/* webpackChunkName: "generic-parser" */ './generic/genericAutocompleteParser'),
hive: () => import(/* webpackChunkName: "hive-parser" */ './hive/hiveAutocompleteParser'),
impala: () => import(/* webpackChunkName: "impala-parser" */ './impala/impalaAutocompleteParser'),
ksql: () => import(/* webpackChunkName: "ksql-parser" */ './ksql/ksqlAutocompleteParser'),
phoenix: () => import(/* webpackChunkName: "phoenix-parser" */ './phoenix/phoenixAutocompleteParser'),
presto: () => import(/* webpackChunkName: "presto-parser" */ './presto/prestoAutocompleteParser')
};
const SYNTAX_MODULES = {
calcite: () => import(/* webpackChunkName: "calcite-parser" */ './calcite/calciteSyntaxParser'),
dasksql: () => import(/* webpackChunkName: "dasksql-parser" */ './dasksql/dasksqlSyntaxParser'),
druid: () => import(/* webpackChunkName: "druid-parser" */ './druid/druidSyntaxParser'),
elasticsearch: () => import(/* webpackChunkName: "elasticsearch-parser" */ './elasticsearch/elasticsearchSyntaxParser'),
flink: () => import(/* webpackChunkName: "flink-parser" */ './flink/flinkSyntaxParser'),
generic: () => import(/* webpackChunkName: "generic-parser" */ './generic/genericSyntaxParser'),
hive: () => import(/* webpackChunkName: "hive-parser" */ './hive/hiveSyntaxParser'),
impala: () => import(/* webpackChunkName: "impala-parser" */ './impala/impalaSyntaxParser'),
ksql: () => import(/* webpackChunkName: "ksql-parser" */ './ksql/ksqlSyntaxParser'),
phoenix: () => import(/* webpackChunkName: "phoenix-parser" */ './phoenix/phoenixSyntaxParser'),
presto: () => import(/* webpackChunkName: "presto-parser" */ './presto/prestoSyntaxParser')
};
/* eslint-enable */

export class SqlParserRepository implements SqlParserProvider {
modulePromises: { [dialect: string]: Promise<AutocompleteParser | SyntaxParser> } = {};
Expand Down
103 changes: 0 additions & 103 deletions tools/jison/generateParserModuleImports.js

This file was deleted.

78 changes: 53 additions & 25 deletions tools/jison/generateParsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

/* eslint-disable no-restricted-syntax */

const cli = require('jison/lib/cli');
const fs = require('fs');
const fsExtra = require('fs-extra');
const cli = require('jison/lib/cli');

const LICENSE =
'// Licensed to Cloudera, Inc. under one\n' +
Expand All @@ -44,9 +43,15 @@ const SQL_STATEMENTS_PARSER_JSDOC =
' * @return {SqlStatementsParserResult}\n' +
' */\n';

const PARSER_FOLDER = '../../desktop/core/src/desktop/js/parse/sql/';
const OUTPUT_FOLDER = '../../desktop/core/src/desktop/js/parse/';
const PARSER_FOLDER = `${OUTPUT_FOLDER}sql/`;
const JISON_FOLDER = `${OUTPUT_FOLDER}jison/`;
const JISON_FOLDER = '../../desktop/core/src/desktop/js/parse/jison/';
const SQL_PARSER_REPOSITORY_PATH =
'../../desktop/core/src/desktop/js/parse/sql/sqlParserRepository.ts';
const SYNTAX_PARSER_IMPORT_TEMPLATE =
' KEY: () => import(/* webpackChunkName: "KEY-parser" */ \'./KEY/KEYSyntaxParser\')';
const AUTOCOMPLETE_PARSER_IMPORT_TEMPLATE =
' KEY: () => import(/* webpackChunkName: "KEY-parser" */ \'./KEY/KEYAutocompleteParser\')';

const parserDefinitions = {
globalSearchParser: {
Expand Down Expand Up @@ -143,14 +148,11 @@ const readFile = path =>

const writeFile = (path, contents) =>
new Promise((resolve, reject) => {
fsExtra.ensureFile(path).then(() => {
fs.writeFile(path, contents, err => {
if (err) {
console.log(err);
reject();
}
resolve();
});
fs.writeFile(path, contents, err => {
if (err) {
reject();
}
resolve();
});
});

Expand Down Expand Up @@ -227,10 +229,7 @@ const generateParser = parserName =>
deleteFile(generatedJsFileName);
resolve();
})
.catch(error => {
console.info(error);
reject();
});
.catch(reject);
})
.catch(reject);
})
Expand Down Expand Up @@ -302,13 +301,11 @@ const addParsersFromStructure = (structure, dialect) => {
);
};

const fileIsVisible = fileName => !fileName.startsWith('.');

const identifySqlParsers = () =>
new Promise(resolve => {
listDir(JISON_FOLDER + 'sql').then(files => {
const promises = [];
files.filter(fileIsVisible).forEach(folder => {
files.forEach(folder => {
promises.push(
listDir(JISON_FOLDER + 'sql/' + folder).then(async jisonFiles => {
if (jisonFiles.find(fileName => fileName === 'structure.json')) {
Expand Down Expand Up @@ -379,10 +376,12 @@ const prepareForNewParser = () =>
listDir(JISON_FOLDER + 'sql/' + source).then(files => {
const copyPromises = [];
files.forEach(file => {
// "file" can also be a subfolder with files in it
const fromPath = JISON_FOLDER + 'sql/' + source + '/' + file;
const toPath = JISON_FOLDER + 'sql/' + target + '/' + file;
copyPromises.push(fsExtra.copy(fromPath, toPath));
copyPromises.push(
copyFile(
JISON_FOLDER + 'sql/' + source + '/' + file,
JISON_FOLDER + 'sql/' + target + '/' + file
)
);
});
Promise.all(copyPromises).then(() => {
const autocompleteSources = [
Expand Down Expand Up @@ -485,12 +484,41 @@ identifySqlParsers().then(() => {
console.log(error);
console.log('FAIL!');
});
} else {
const autocompParsers = [];
const syntaxParsers = [];
console.log('Updating sqlParserRepository.ts...');
Object.keys(parserDefinitions).forEach(key => {
if (parserDefinitions[key].sqlParser === 'AUTOCOMPLETE') {
autocompParsers.push(
AUTOCOMPLETE_PARSER_IMPORT_TEMPLATE.replace(
/KEY/g,
key.replace('AutocompleteParser', '')
)
);
} else if (parserDefinitions[key].sqlParser === 'SYNTAX') {
syntaxParsers.push(
SYNTAX_PARSER_IMPORT_TEMPLATE.replace(/KEY/g, key.replace('SyntaxParser', ''))
);
}
});
readFile(SQL_PARSER_REPOSITORY_PATH).then(contents => {
contents = contents.replace(
/const SYNTAX_MODULES = [^}]+}/,
'const SYNTAX_MODULES = {\n' + syntaxParsers.sort().join(',\n') + '\n}'
);
contents = contents.replace(
/const AUTOCOMPLETE_MODULES = [^}]+}/,
'const AUTOCOMPLETE_MODULES = {\n' + autocompParsers.sort().join(',\n') + '\n}'
);
writeFile(SQL_PARSER_REPOSITORY_PATH, contents).then(() => {
console.log('Done!\n');
});
});
}
};
generateRecursive();
});
});

/* eslint-enable no-restricted-syntax */

module.exports = { LICENSE, PARSER_FOLDER };
Loading

0 comments on commit 8f24a01

Please sign in to comment.