Merge pull request #13854 from dataease/pr@dev-v2@revert_code

revert: 恢复代码
This commit is contained in:
Junjun 2024-12-05 12:47:46 +08:00 committed by GitHub
commit a31be1b7d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,10 +1,12 @@
package io.dataease.extensions.datasource.dto;
import lombok.Data;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Data
@ -29,10 +31,36 @@ public class DatasourceRequest implements Serializable {
}
public String getQuery() {
return this.query;
return this.rebuildSqlWithFragment(this.query);
}
public void setQuery(String query) {
this.query = query;
}
private String rebuildSqlWithFragment(String sql) {
if (!sql.toLowerCase().startsWith("with")) {
Matcher matcher = this.WITH_SQL_FRAGMENT.matcher(sql);
if (matcher.find()) {
String withFragment = matcher.group();
if (!StringUtils.isEmpty(withFragment)) {
if (withFragment.length() > 6) {
int lastSelectIndex = withFragment.length() - 6;
sql = sql.replace(withFragment, withFragment.substring(lastSelectIndex));
withFragment = withFragment.substring(0, lastSelectIndex);
}
sql = withFragment + " " + sql;
sql = sql.replaceAll(" {2,}", " ");
}
}
}
return sql;
}
public String getREG_WITH_SQL_FRAGMENT() {
this.getClass();
return "((?i)WITH[\\s\\S]+(?i)AS?\\s*\\([\\s\\S]+\\))\\s*(?i)SELECT";
}
}