Эх сурвалжийг харах

HUE-8888 [editor] Adding autocompleter npm plugin example

Romain 5 жил өмнө
parent
commit
f38acada6e

+ 3 - 0
tools/parser/hue_dep/.babelrc

@@ -0,0 +1,3 @@
+{
+  "presets": ["@babel/preset-env"]
+}

+ 18 - 0
tools/parser/hue_dep/.eslintignore

@@ -0,0 +1,18 @@
+/desktop/core/src/desktop/js/ext/**
+/desktop/core/src/desktop/js/ko/bindings/charts/mapchart/topo/**
+/desktop/core/src/desktop/js/parse/globalSearchParser.js
+/desktop/core/src/desktop/js/parse/solrFormulaParser.js
+/desktop/core/src/desktop/js/parse/solrQueryParser.js
+/desktop/core/src/desktop/js/parse/sqlAutocompleteParser.js
+/desktop/core/src/desktop/js/parse/sqlStatementsParser.js
+/desktop/core/src/desktop/js/parse/sqlSyntaxParser.js
+/desktop/core/src/desktop/js/utils/json.bigDataParse.js
+/desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.js
+/desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.js
+/desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js
+/desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js
+/desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js
+/desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js
+/desktop/core/src/desktop/js/parse/sql/generic/spec/genericAutocompleteParser_Locations_Spec.js
+/desktop/core/src/desktop/js/parse/sql/hive/spec/hiveAutocompleteParser_Locations_Spec.js
+/desktop/core/src/desktop/js/parse/sql/impala/spec/impalaAutocompleteParser_Locations_Spec.js

+ 3 - 0
tools/parser/hue_dep/.gitignore

@@ -0,0 +1,3 @@
+node_modules
+dist
+.idea

+ 72 - 0
tools/parser/hue_dep/README.md

@@ -0,0 +1,72 @@
+ 
+ Using Parser in node.js app
+ 
+        cd hue_dep
+        npm install
+        npm run webpack
+        npm run app
+
+In package.json there’s a dependency on Hue:
+
+        "dependencies": {
+          "hue": "file:../hue"
+        },
+
+Note that it can also be a GitHub link: “hue”: "git://github.com/cloudera/hue.git” but takes a bit longer to do “npm install"
+
+
+{ locations:
+   [ { type: 'statement', location: [Object] },
+     { type: 'statementType',
+       location: [Object],
+       identifier: 'SELECT' },
+     { type: 'selectList', missing: false, location: [Object] },
+     { type: 'column',
+       location: [Object],
+       identifierChain: [Array],
+       qualified: false,
+       tables: [Array] },
+     { type: 'column',
+       location: [Object],
+       identifierChain: [Array],
+       qualified: false,
+       tables: [Array] },
+     { type: 'column',
+       location: [Object],
+       identifierChain: [Array],
+       qualified: false,
+       tables: [Array] },
+     { type: 'table', location: [Object], identifierChain: [Array] },
+     { type: 'whereClause', missing: true, location: [Object] },
+     { type: 'limitClause', missing: true, location: [Object] } ],
+  lowerCase: false,
+  suggestKeywords:
+   [ { value: 'ABORT', weight: -1 },
+     { value: 'ALTER', weight: -1 },
+     { value: 'ANALYZE TABLE', weight: -1 },
+     { value: 'CREATE', weight: -1 },
+     { value: 'DELETE', weight: -1 },
+     { value: 'DESCRIBE', weight: -1 },
+     { value: 'DROP', weight: -1 },
+     { value: 'EXPLAIN', weight: -1 },
+     { value: 'EXPORT', weight: -1 },
+     { value: 'FROM', weight: -1 },
+     { value: 'GRANT', weight: -1 },
+     { value: 'IMPORT', weight: -1 },
+     { value: 'INSERT', weight: -1 },
+     { value: 'LOAD', weight: -1 },
+     { value: 'MERGE', weight: -1 },
+     { value: 'MSCK', weight: -1 },
+     { value: 'RELOAD FUNCTION', weight: -1 },
+     { value: 'RESET', weight: -1 },
+     { value: 'REVOKE', weight: -1 },
+     { value: 'SELECT', weight: -1 },
+     { value: 'SET', weight: -1 },
+     { value: 'SHOW', weight: -1 },
+     { value: 'TRUNCATE', weight: -1 },
+     { value: 'UPDATE', weight: -1 },
+     { value: 'USE', weight: -1 },
+     { value: 'WITH', weight: -1 } ],
+  definitions: [] }
+
+

+ 30 - 0
tools/parser/hue_dep/package.json

@@ -0,0 +1,30 @@
+{
+  "name": "hue_dep",
+  "version": "1.0.0",
+  "private": true,
+  "description": "",
+  "main": "app.js",
+  "scripts": {
+    "webpack": "webpack --config webpack.config.js",
+    "app": "node dist/app.js"
+  },
+  "author": "Queso",
+  "license": "ISC",
+  "dependencies": {
+    "hue": "file:../../../hue"
+  },
+  "devDependencies": {
+    "@babel/cli": "^7.2.3",
+    "@babel/core": "^7.4.0",
+    "@babel/node": "^7.2.2",
+    "@babel/preset-env": "^7.4.1",
+    "babel-jscs": "3.0.0-beta1",
+    "babel-loader": "8.0.5",
+    "babel-plugin-module-resolver": "^3.2.0",
+    "webpack": "4.29.0",
+    "webpack-bundle-analyzer": "^3.0.4",
+    "webpack-bundle-tracker": "0.4.2-beta",
+    "webpack-clean-obsolete-chunks": "^0.4.0",
+    "webpack-cli": "^3.2.1"
+  }
+}

+ 15 - 0
tools/parser/hue_dep/src/app.js

@@ -0,0 +1,15 @@
+
+import sqlAutocompleteParser from 'hue/desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser';
+
+const beforeCursor = 'SELECT col1, col2, tbl2.col3 FROM tbl; '; // Note extra space at end
+const afterCursor = '';
+const dialect = 'impala';
+const debug = false;
+
+console.log(
+  JSON.stringify(
+    sqlAutocompleteParser.parseSql(beforeCursor, afterCursor, dialect, debug),
+    null,
+    2
+  )
+);

+ 32 - 0
tools/parser/hue_dep/webpack.config.js

@@ -0,0 +1,32 @@
+
+module.exports = {
+  devtool: 'source-map',
+  mode: 'development',
+  resolve: {
+    extensions: ['.json', '.jsx', '.js'],
+    modules: [
+      'node_modules',
+      'js'
+    ]
+  },
+  entry: {
+    app: ['./src/app.js']
+  },
+  optimization: {
+    minimize: false,
+  },
+  output: {
+    path:  __dirname + '/dist/',
+    filename: '[name].js'
+  },
+  module: {
+    rules: [
+      {
+        test: /\.jsx?$/,
+        exclude: /node_modules/,
+        loader: 'babel-loader'
+      }
+    ]
+  },
+  plugins: []
+};