From 9b2733c0e95f3dfbdd6996cb0173784c21a59b88 Mon Sep 17 00:00:00 2001 From: RENCHAO <542607047@qq.com> Date: Tue, 20 Feb 2024 09:58:22 +0800 Subject: [PATCH] =?UTF-8?q?20240220=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/src/com/renchao/Test01.java | 285 +++++------------- .../src/components/SqlEditor/sqlquery-hint.js | 90 +++--- .../metadata/datasource/DataSourceList.vue | 4 +- 3 files changed, 135 insertions(+), 244 deletions(-) diff --git a/Test/src/com/renchao/Test01.java b/Test/src/com/renchao/Test01.java index ca066489..f5f3534b 100644 --- a/Test/src/com/renchao/Test01.java +++ b/Test/src/com/renchao/Test01.java @@ -158,7 +158,6 @@ public class Test01 { /** * 按照csv格式保存为文件, * StringJoiner按照指定分隔符拼串 - * */ @Test public void test08() throws IOException { @@ -207,7 +206,6 @@ public class Test01 { } - /** * 对比list直接迭代与stream的效率 */ @@ -243,7 +241,6 @@ public class Test01 { /** * 读取大文件最后一行 - * */ @Test public void test15() throws IOException { @@ -293,7 +290,6 @@ public class Test01 { /** * 文件压缩 - * */ private void compression(File file) throws IOException { FileOutputStream outputStream = new FileOutputStream(file.toString().replace("csv", "zip")); @@ -314,7 +310,6 @@ public class Test01 { /** * 遍历目录,获取所有文件列表 - * */ private void getFileList(File dir, List fileList) { if (!dir.exists()) { @@ -336,235 +331,113 @@ public class Test01 { @Test public void test16() { - List intList = new ArrayList<>(); - int n = 100000000; - for (int i = 0; i < n; i++) { - intList.add((int) (Math.random() * 10)); - } - - int aa = 0; - long l1 = System.currentTimeMillis(); - for (Integer integer : intList) { - aa += (integer * 10); - } - System.out.println(aa + "::耗时1:" + (System.currentTimeMillis() - l1)); - - - aa = 0; - long l2 = System.currentTimeMillis(); - for (Integer integer : intList) { - aa += x10(integer); - } - System.out.println(aa + "::耗时2:" + (System.currentTimeMillis() - l2)); + // System.out.println(isMatch("abcdef", "a*ef")); + // System.out.println(isMatch("abcdefghi", "a*ef*i")); + // System.out.println(isMatch("abcdefghi", ".*")); + System.out.println(isMatch("aa", "a")); + System.out.println(isMatch("aa", "a*b*")); + System.out.println(isMatch("aab", "c*a*b")); + System.out.println(isMatch("aab", ".*")); + System.out.println(isMatch("abcde", ".*de")); - aa = 0; - long l3 = System.currentTimeMillis(); - for (Integer integer : intList) { - aa += x102(integer); - } - System.out.println(aa + "::耗时3:" + (System.currentTimeMillis() - l3)); + // System.out.println("abcd".substring(1)); } - private int x10(int a) { - int c = a; - for (int i = 0; i < 9; i++) { - c += a; - } - return c; - } - private int x102(int a) { - int c = a; - for (int i = 0; i < 3; i++) { - c = c << 1; + public boolean isMatch(String s, String p) { + if (p.length() == 0 && s.length() != 0) { + return false; } - c = (a << 1) + c; - return c; - } - - - @Test - public void test17() { - // List intList = new ArrayList<>(); - // int n = 10000000; - // for (int i = 0; i < n; i++) { - // intList.add((int) (Math.random() * 10)); - // } - // long l1 = System.currentTimeMillis(); - // for (Integer integer : intList) { - // reverse(integer); - // } - // System.out.println("::耗时1:" + (System.currentTimeMillis() - l1)); - // - // long l2 = System.currentTimeMillis(); - // for (Integer integer : intList) { - // reverse2(integer); - // } - // System.out.println("::耗时2:" + (System.currentTimeMillis() - l2)); - // - // long l3 = System.currentTimeMillis(); - // for (Integer integer : intList) { - // reverse3(integer); - // } - // System.out.println("::耗时3:" + (System.currentTimeMillis() - l3)); - // - // long l4 = System.currentTimeMillis(); - // for (Integer integer : intList) { - // reverse4(integer); - // } - // System.out.println("::耗时4:" + (System.currentTimeMillis() - l4)); - // - // long l5 = System.currentTimeMillis(); - // for (Integer integer : intList) { - // reverse5(integer); - // } - // System.out.println("::耗时5:" + (System.currentTimeMillis() - l5)); - - - int i = -2147483648; - System.out.println(reverse2(i)); - System.out.println(reverse3(i)); - System.out.println(reverse4(i)); - System.out.println(Integer.MAX_VALUE); - } - public int reverse(int x) { - int b = x >>> 31; - int bit = 0; - int k = 0; - while (x != 0) { - if (bit == 9 && k / 100000000 > 2) { - return 0; + if (s.length() == 0) { + if (p.length() == 0) { + return true; } - bit++; - k = k * 10 + x % 10; - x = x / 10; - } - if (b != k >>> 31) { - k = 0; + if (p.length() == 1) { + return false; + } + if (p.charAt(1) == '*') { + return isMatch(s, p.substring(2)); + } + return false; } - return k; - } - public int reverse2(int x) { - int b = x >>> 31; - int k = 0; - while (x != 0) { - int a = k; - for (int i = 0; i < 3; i++) { - a = a << 1; - if (b != a >>> 31) { - return 0; - } + if (p.charAt(0) == '.') { + if (p.length() == 1 || ) { + return isMatch(s.substring(1), p.substring(1)); } - a = (k << 1) + a; - if (b != a >>> 31) { - return 0; - } - k = a + x % 10; - x = x / 10; + if () } - return k; - } - public int reverse3(int x) { - int b = x >>> 31; - int k = x % 10; - x = x / 10; - while (x != 0) { - int a = k; - for (int i = 0; i < 4; i++) { - if (i < 3) { - a = a << 1; - } else { - a = (k << 1) + a; - } - if (b != a >>> 31) { - return 0; - } + + if (s.charAt(0) != p.charAt(0)) { + if (p.length() < 2 || p.charAt(1) != '*') { + return false; } - k = a + x % 10; - if (b != k >>> 31) { - return 0; + if (p.charAt(1) == '*') { + return isMatch(s, p.substring(2)); } - x = x / 10; } - return k; - } - public int reverse4(int x) { - int b = x >>> 31; - int k = x % 10; - x = x / 10; - while (x != 0) { - if (k > -1000000000 && k < 1000000000) { - k = k * 10 + x % 10; - } else { - int a = k; - for (int i = 0; i < 4; i++) { - if (i < 3) { - a = a << 1; - } else { - a = (k << 1) + a; - } - if (b != a >>> 31) { - return 0; - } - } - k = a + x % 10; - if (b != k >>> 31) { - return 0; - } + if (s.charAt(0) == p.charAt(0)) { + if (p.length() == 1 || p.charAt(1) != '*') { + return isMatch(s.substring(1), p.substring(1)); } - x = x / 10; + return isMatch(s.substring(1), p); } - return k; + return false; } - public int reverse41(int x) { - int sign = x >>> 31; - int result = x % 10; - x = x / 10; - while (x != 0) { - if (result > -100000000 && result < 100000000) { - result = result * 10 + x % 10; - } else { - int tem = result; - for (int i = 0; i < 4; i++) { - if (i < 3) { - tem = tem << 1; - } else { - tem = (result << 1) + tem; - } - if (sign != tem >>> 31) { - return 0; - } - } - result = tem + x % 10; - if (sign != result >>> 31) { - return 0; - } + public boolean isMatch3(String s, String p) { + int sIndex = 0; + int pIndex = 0; + int tem = -1; + while (sIndex < s.length() && pIndex < p.length()) { + char c1 = s.charAt(sIndex++); + char c2 = p.charAt(pIndex); + if (c1 == c2 || c2 == '.') { + pIndex++; + continue; + } + if (c2 == '*') { + tem = pIndex++; + } + if (tem == p.length() - 1) { + sIndex = s.length(); + break; + } + if (pIndex < p.length() && (c1 == p.charAt(pIndex) || '.' == p.charAt(pIndex))) { + pIndex++; + } else if (tem != -1) { + pIndex = tem; + } + + if (tem != -1 && pIndex == p.length() && sIndex < s.length()) { + pIndex = tem; } - x = x / 10; } - return result; + return pIndex == p.length() && sIndex == s.length(); } - public int reverse5(int x) { - int result = 0; - while (x != 0) { - int m = x % 10; - x = x / 10; - int n = result * 10; - if (n / 10 != result) { - return 0; + + public boolean isMatch2(String s, String p) { + int pIndex = 0; + for (int i = 0; i < s.length(); i++) { + if (pIndex >= p.length()) { + return false; + } + char c1 = s.charAt(i); + char c2 = p.charAt(pIndex); + if (c1 == c2 || c2 == '.') { + pIndex++; + } else if (c2 == '*') { + } else { + return false; } - int var = n + m; - result = var; } - return result; + return true; } diff --git a/sptcc_agile_etl/src/system/src/trunk/agile-system/agile-system-console-ui/src/components/SqlEditor/sqlquery-hint.js b/sptcc_agile_etl/src/system/src/trunk/agile-system/agile-system-console-ui/src/components/SqlEditor/sqlquery-hint.js index 1ebee73b..38343f03 100644 --- a/sptcc_agile_etl/src/system/src/trunk/agile-system/agile-system-console-ui/src/components/SqlEditor/sqlquery-hint.js +++ b/sptcc_agile_etl/src/system/src/trunk/agile-system/agile-system-console-ui/src/components/SqlEditor/sqlquery-hint.js @@ -9,8 +9,9 @@ var codeRuleStr="((\"[\u4E00-\u9FA50-9a-z _]+\")|(\\[[\u4E00-\u9FA50-9a-z _]+\\])|(`[\u4E00-\u9FA50-9a-z _]+`)|([a-z]+[0-9]*(_[a-z]+[0-9]*)*))"; var codeRuleStr2="((\"[\u4E00-\u9FA50-9a-z _]+\")|(\\[[\u4E00-\u9FA50-9a-z _]+\\])|(`[\u4E00-\u9FA50-9a-z _]+`)|([a-z]+[0-9]*(_[a-z]+[0-9]*)*))"; var bracketRuleStr="^(\"|`|\\[)"; - var tableRuleStr="\"%s\"|\\[%s\\]|`%s`|\\b%s"; - var schemaTableRuleStr="\"%x\".\"%s\"|\\[%x\\].\\[%s\\]|`%x`.`%s`|%x.%s"; + var bracketRuleClear= new RegExp("[\"`\\[\\]]+","g"); + var tableRuleStr="\"%s\"|\\[%s\\]|`%s`|\\b%s\\b"; + var schemaTableRuleStr= "\"\\w+\".\"%s\"|\\[\\w+\\].\\[%s\\]|`\\w+`.`%s`|\\b\\w+.%s\\b"; var alisaTempKey="ALISAALISAALISA"; var showPath=true; var likeMatch=true; @@ -265,6 +266,7 @@ function markCharOrder(search, word) { if(!text){ return; } + text=text.replace(new RegExp("\\b(INSERT INTO|CREATE TABLE)\\b.*?\\)( |AS)*(?=\\bSELECT\\b)", "i")," "); inputAlias = inputAlias.toLowerCase(); var groupdata = getNestingDepth(currTableCodes,text, currKey); if(!groupdata){ @@ -337,7 +339,8 @@ function markCharOrder(search, word) { var fields = c.fields.match(new RegExp("(("+alisalist.join("|")+")\\."+codeRuleStr+" (AS| +) "+codeRuleStr2+" *(,|$))"+ "|(("+alisalist.join("|")+")\\."+codeRuleStr+"[^,]+ (AS| ) "+codeRuleStr2+" *(,|$))"+ "|([^,]*\\(.*?\\).*?(AS| +) "+codeRuleStr2+" *(,|$))"+ - "|(("+alisalist.join("|")+")\\.\\* *(,|$))|(("+alisalist.join("|")+")\\."+codeRuleStr+" *(,|$))","ig")); + "|(("+alisalist.join("|")+")\\.\\* *(,|$))|(("+alisalist.join("|")+")\\."+codeRuleStr+" *(,|$))" + + "|((?0){ for (var j = 0; j < fields.length; j++) { var fstr = fields[j]; @@ -457,7 +460,7 @@ function markCharOrder(search, word) { if(keys.length>0){ tables[inputAlias].push(displayHandler(fm[fm.length-1],descs.join("+"),keys.join("+"))); }else{ - tables[inputAlias].push(displayHandler(fm[fm.length-1],null,factcode)); + tables[inputAlias].push(displayHandler(fm[fm.length-1],null,null)); } } } @@ -615,7 +618,7 @@ function markCharOrder(search, word) { if(!text1){ return ""; } - text1 = text1.replace(/'.*?'/ig,"' '").replace(/(\\n|\n|\\t|\t)/g," ") + text1 = clearContextValue(text1).replace(/(\\n|\n|\\t|\t)/g," ") .replace(/ +/g," ").replace(regxSemicolon,""); text1 = clearContentComment(text1,true); return text1; @@ -624,7 +627,7 @@ function markCharOrder(search, word) { if(!text){ return ""; } - text=text.replace(/'.*?'/ig,"' '").replace(/''/ig," "); + text= clearContextValue(text).replace(/''/ig," "); var lines = text.split('\n'); var text2=""; for (var i = 0; i < lines.length; i++) { @@ -656,7 +659,7 @@ function markCharOrder(search, word) { text2=text2+"\n"+linex; } } - text2 = text2.replace(/'.*?'/ig,"' '").replace(/(\\n|\n|\\t|\t)/g," ") + text2 = text2.replace(/(\\n|\n|\\t|\t)/g," ") .replace(/ +/g," "); return text2; } @@ -685,7 +688,19 @@ function markCharOrder(search, word) { } return text2; } - + function clearContextValue(text1) { + if (!text1) { + return ""; + } + text1 = text1.replace(/ +/g, " ").replace(new RegExp("'.*?'( AS\\b)*","ig"), (match) => { + if (/\bAS\b/i.test(match)) { + return match; + } else { + return "' '"; + } + }); + return text1; + } function addTableList(tables,tablesList){ if(!tablesList){ return; @@ -1201,38 +1216,46 @@ export const sqlqueryUtils = { tempSqlTables={}; if(startLineStr && startLineStr.length > 10){ - currSelectQueryStr=startLineStr; - currInputAlias=inputAlias; - //console.log("currSelectQueryStr",currSelectQueryStr); - for(var i=0,ln=alltablecodes.length;i 1) { - t2 = t.replace(".", "\\.") + "|" + "\\w+\\."+tmp[1] +"|"+tmp[1]; + regxstr1 = regxstr1 + schemaTableRuleStr.replace(/%s/g, tmp[1]) + +"|"+tableRuleStr.replace(/%s/g, tmp[1]) + }else{ + regxstr1 = regxstr1 + tableRuleStr.replace(/%s/g, key); } - var mresult=startLineStr.match(new RegExp("\\b(" + t2 + ")\\b", "ig")); + regxstr1 = regxstr1.replace(/\./g, "\\."); + var mresult = startLineStr.match(new RegExp(regxstr1, "ig")); if(!mresult){ continue; } var result=false; - for (var mi = 0, mln = mresult.length; mi < mln; mi++) { - if(t.toLowerCase()===mresult[mi].toLowerCase() || tmp[1].toLowerCase()===mresult[mi].toLowerCase()){ + for (var i = 0, ln = mresult.length; i < ln; i++) { + var newcode = mresult[i].replace(bracketRuleClear,""); + startLineStr = startLineStr.replace(new RegExp(mresult[i],"g"), newcode); + if(key.toLowerCase()===newcode.toLowerCase() || (tmp.length > 1 && newcode.indexOf(".")===-1 + && tmp[1].toLowerCase()===newcode.toLowerCase())){ result=true; - break; - } + } } + if(result){ - tempSqlTables[t] = []; - currSelectTables.push(t); + tempSqlTables[key] = []; + currSelectTables.push(key); } if(currSelectTables.length>50){ //正常不应该有这么多表。也不建议所有sql放一起 break; } } + currSelectQueryStr=startLineStr; + currInputAlias=inputAlias; } + //console.log("currSelectQueryStr>>",currSelectQueryStr,currSelectTables); }catch(e){ console.log(e); } @@ -1266,25 +1289,20 @@ export const sqlqueryUtils = { var regxstr1; for (var i = 0, ln = currSelectTables.length; i < ln; i++) { - regxstr1=(i==0?"":regxstr1+"|"); - if (currSelectTables[i].indexOf(".") > -1) { - var ct=currSelectTables[i].split("."); - regxstr1 = regxstr1 + schemaTableRuleStr.replace(/%x/g, ct[0]).replace(/%s/g, ct[1]) - +"|"+tableRuleStr.replace(/%s/g, ct[1]) - }else{ - regxstr1 = regxstr1 + tableRuleStr.replace(/%s/g, currSelectTables[i]); - } + regxstr1=(i==0?"":regxstr1+"|"); + if (currSelectTables[i].indexOf(".") > -1) { + regxstr1 = regxstr1 + currSelectTables[i] + "|(? - + @@ -120,7 +120,7 @@ :close-on-press-escape="false"> - +