20240220更新

master
RENCHAO 9 months ago
parent 34300f8cde
commit 9b2733c0e9

@ -158,7 +158,6 @@ public class Test01 {
/**
* csv
* StringJoiner
*
*/
@Test
public void test08() throws IOException {
@ -207,7 +206,6 @@ public class Test01 {
}
/**
* liststream
*/
@ -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<File> fileList) {
if (!dir.exists()) {
@ -336,235 +331,113 @@ public class Test01 {
@Test
public void test16() {
List<Integer> 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<Integer> 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;
}

@ -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+" *(,|$))" +
"|((?<!\\.)('\\d+'|\\d+) (AS| +) " + codeRuleStr2 + " *(,|$))", "ig"));
if(fields && fields.length>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<ln;i++){
var t=alltablecodes[i].tableName;
var t2=t;
var tmp=t.split(".");
for(var alli=0,allln=alltablecodes.length;alli<allln;alli++){
var key=alltablecodes[alli].tableName;
var tmp=key.split(".");
var regxstr1="";
if (tmp.length > 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] + "|(?<!.)" + currSelectTables[i].split(".")[1];
}else{
regxstr1 = regxstr1 +"(?<!.)"+ currSelectTables[i];
}
}
regxstr1=regxstr1.replace(/\./g,"\\.");
var tableWithAliasRegs =new RegExp("(" + regxstr1 + ") +" + alisaRuleStr + "\\b|(" + regxstr1 + ")\\b", "ig");
regxstr1=regxstr1.replace(/\./g,"\\.");
var tableWithAliasRegs = new RegExp("\\b(" + regxstr1 + ")\\b +" + alisaRuleStr + "|\\b(" + regxstr1 + ")\\b", "ig");
var tableWithAlias = currSelectQueryStr.match(tableWithAliasRegs);
var handlerTableAlias = function(tableAliasMap,keywords,str){
var t = str.split(" ");//table t1
if(new RegExp(bracketRuleStr).test(t[0])){
t[0]=t[0].substring(1, t[0].length - 1);
}
var factkey = getArrayValue(currSelectTables,t[0]);
if(factkey){
if(!tableAliasMap.hasOwnProperty(factkey)){

@ -84,7 +84,7 @@
:close-on-press-escape="false">
<el-form ref="form" :disabled="disabled" :model="form" :rules="rules" label-width="120px">
<el-form-item label="数据源/模式名称" prop="sourceName">
<el-input v-model="form.sourceName" placeholder="请输入数据源/模式名称" maxlength="25"/>
<el-input v-model="form.sourceName" placeholder="请输入数据源/模式名称" maxlength="50"/>
</el-form-item>
<el-form-item label="状态">
<el-radio-group v-model="form.status">
@ -120,7 +120,7 @@
:close-on-press-escape="false">
<el-form ref="syncTableForm" :model="syncTableForm" :rules="syncTableRule" label-width="50px">
<el-form-item label="表名" prop="tableName">
<el-input v-model="syncTableForm.tableName" placeholder="请输入表名" maxlength="20"/>
<el-input v-model="syncTableForm.tableName" placeholder="请输入表名" maxlength="50"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">

Loading…
Cancel
Save