完善对 Presto, Trino 的支持:正则忽略大小写;支持预编译模式等
This commit is contained in:
parent
c445c71d5b
commit
f23204edd7
@ -3561,12 +3561,13 @@ public abstract class AbstractSQLConfig implements SQLConfig {
|
|||||||
if (isPostgreSQL() || isInfluxDB()) {
|
if (isPostgreSQL() || isInfluxDB()) {
|
||||||
return getKey(column) + " ~" + (ignoreCase ? "* " : " ") + getValue(key, column, value);
|
return getKey(column) + " ~" + (ignoreCase ? "* " : " ") + getValue(key, column, value);
|
||||||
}
|
}
|
||||||
if (isPresto() || isTrino()) {
|
|
||||||
return "regexp_like(" + getKey(column) + ", " + getValue(key, column, value) + ")";
|
|
||||||
}
|
|
||||||
if (isOracle() || isDameng() || isKingBase() || (isMySQL() && getDBVersionNums()[0] >= 8)) {
|
if (isOracle() || isDameng() || isKingBase() || (isMySQL() && getDBVersionNums()[0] >= 8)) {
|
||||||
return "regexp_like(" + getKey(column) + ", " + getValue(key, column, value) + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
|
return "regexp_like(" + getKey(column) + ", " + getValue(key, column, value) + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
|
||||||
}
|
}
|
||||||
|
if (isPresto() || isTrino()) {
|
||||||
|
return "regexp_like(" + (ignoreCase ? "lower(" : "") + getKey(column) + (ignoreCase ? ")" : "")
|
||||||
|
+ ", " + (ignoreCase ? "lower(" : "") + getValue(key, column, value) + (ignoreCase ? ")" : "") + ")";
|
||||||
|
}
|
||||||
if (isClickHouse()) {
|
if (isClickHouse()) {
|
||||||
return "match(" + (ignoreCase ? "lower(" : "") + getKey(column) + (ignoreCase ? ")" : "")
|
return "match(" + (ignoreCase ? "lower(" : "") + getKey(column) + (ignoreCase ? ")" : "")
|
||||||
+ ", " + (ignoreCase ? "lower(" : "") + getValue(key, column, value) + (ignoreCase ? ")" : "") + ")";
|
+ ", " + (ignoreCase ? "lower(" : "") + getValue(key, column, value) + (ignoreCase ? ")" : "") + ")";
|
||||||
@ -4436,14 +4437,14 @@ public abstract class AbstractSQLConfig implements SQLConfig {
|
|||||||
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? NOT : "")
|
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? NOT : "")
|
||||||
+ " ~" + (ignoreCase ? "* " : " ") + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
|
+ " ~" + (ignoreCase ? "* " : " ") + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;
|
||||||
}
|
}
|
||||||
else if (isPresto() || isTrino()) {
|
|
||||||
sql += (first ? ON : AND) + "regexp_like(" + quote + jt + quote + "." + quote + on.getKey() + quote
|
|
||||||
+ ", " + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + ")";
|
|
||||||
}
|
|
||||||
else if (isOracle() || isDameng() || isKingBase()) {
|
else if (isOracle() || isDameng() || isKingBase()) {
|
||||||
sql += (first ? ON : AND) + "regexp_like(" + quote + jt + quote + "." + quote + on.getKey() + quote
|
sql += (first ? ON : AND) + "regexp_like(" + quote + jt + quote + "." + quote + on.getKey() + quote
|
||||||
+ ", " + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
|
+ ", " + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + (ignoreCase ? ", 'i'" : ", 'c'") + ")";
|
||||||
}
|
}
|
||||||
|
else if (isPresto() || isTrino()) {
|
||||||
|
sql += (first ? ON : AND) + "regexp_like(" + (ignoreCase ? "lower(" : "") + quote + jt + quote + "." + quote + on.getKey() + quote + (ignoreCase ? ")" : "")
|
||||||
|
+ ", " + (ignoreCase ? "lower(" : "") + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + (ignoreCase ? ")" : "") + ")";
|
||||||
|
}
|
||||||
else if (isClickHouse()) {
|
else if (isClickHouse()) {
|
||||||
sql += (first ? ON : AND) + "match(" + (ignoreCase ? "lower(" : "") + quote + jt + quote + "." + quote + on.getKey() + quote + (ignoreCase ? ")" : "")
|
sql += (first ? ON : AND) + "match(" + (ignoreCase ? "lower(" : "") + quote + jt + quote + "." + quote + on.getKey() + quote + (ignoreCase ? ")" : "")
|
||||||
+ ", " + (ignoreCase ? "lower(" : "") + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + (ignoreCase ? ")" : "") + ")";
|
+ ", " + (ignoreCase ? "lower(" : "") + quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote + (ignoreCase ? ")" : "") + ")";
|
||||||
|
@ -752,7 +752,7 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
|
|||||||
//
|
//
|
||||||
// if (noAggrFun) { // 加 row_number 字段会导致 count 等聚合函数统计出错,结果偏大?
|
// if (noAggrFun) { // 加 row_number 字段会导致 count 等聚合函数统计出错,结果偏大?
|
||||||
String q = jc.getQuote();
|
String q = jc.getQuote();
|
||||||
sql2 = prepared ? jc.getSQL(true) : sql;
|
sql2 = prepared && jc.isTDengine() == false ? jc.getSQL(true) : sql;
|
||||||
|
|
||||||
String prefix = "SELECT * FROM(";
|
String prefix = "SELECT * FROM(";
|
||||||
String rnStr = ", row_number() OVER (PARTITION BY " + q + key + q + ((AbstractSQLConfig) jc).getOrderString(true) + ") _row_num_ FROM ";
|
String rnStr = ", row_number() OVER (PARTITION BY " + q + key + q + ((AbstractSQLConfig) jc).getOrderString(true) + ") _row_num_ FROM ";
|
||||||
@ -1085,7 +1085,16 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (RequestMethod.isGetMethod(config.getMethod(), true)) {
|
else if (RequestMethod.isGetMethod(config.getMethod(), true)) {
|
||||||
|
//if (config.isPresto() || config.isTrino()) {
|
||||||
|
// statement = getConnection(config).prepareStatement(sql); // , ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||||
|
//} else {
|
||||||
|
// statement = getConnection(config).prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||||
|
//}
|
||||||
|
if (config.isMySQL() || config.isPostgreSQL() || config.isOracle() || config.isSQLServer() || config.isDb2()) {
|
||||||
statement = getConnection(config).prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
statement = getConnection(config).prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||||
|
} else {
|
||||||
|
statement = getConnection(config).prepareStatement(sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
statement = getConnection(config).prepareStatement(sql);
|
statement = getConnection(config).prepareStatement(sql);
|
||||||
@ -1227,15 +1236,19 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet executeQuery(@NotNull SQLConfig config, String sql) throws Exception {
|
public ResultSet executeQuery(@NotNull SQLConfig config, String sql) throws Exception {
|
||||||
if (config.isPresto() || config.isTrino() || config.isTDengine()) {
|
if (config.isPrepared() == false || config.isTDengine() // TDengine JDBC 不支持 PreparedStatement
|
||||||
|
|| (config.isExplain() && (config.isPresto() || config.isTrino()))) { // Presto JDBC 0.277 在 EXPLAIN 模式下预编译值不会替代 ? 占位导致报错
|
||||||
|
|
||||||
Connection conn = getConnection(config);
|
Connection conn = getConnection(config);
|
||||||
Statement stt = config.isTDengine()
|
Statement stt = conn.createStatement();
|
||||||
? conn.createStatement() // fix Presto: ResultSet: Exception: set type is TYPE_FORWARD_ONLY, Result set concurrency must be CONCUR_READ_ONLY
|
//Statement stt = config.isTDengine()
|
||||||
: conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
// ? conn.createStatement() // fix Presto: ResultSet: Exception: set type is TYPE_FORWARD_ONLY, Result set concurrency must be CONCUR_READ_ONLY
|
||||||
|
// : conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||||
|
|
||||||
return executeQuery(stt, StringUtil.isEmpty(sql) ? config.getSQL(false) : sql);
|
return executeQuery(stt, StringUtil.isEmpty(sql) ? config.getSQL(false) : sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Presto JDBC 0.277 在 EXPLAIN 模式下预编译值不会替代 ? 占位导致报错
|
||||||
PreparedStatement stt = getStatement(config, sql);
|
PreparedStatement stt = getStatement(config, sql);
|
||||||
ResultSet rs = stt.executeQuery(); //PreparedStatement 不用传 SQL
|
ResultSet rs = stt.executeQuery(); //PreparedStatement 不用传 SQL
|
||||||
// if (config.isExplain() && (config.isSQLServer() || config.isOracle())) {
|
// if (config.isExplain() && (config.isSQLServer() || config.isOracle())) {
|
||||||
@ -1253,6 +1266,10 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
|
|||||||
if (config.isTDengine()) {
|
if (config.isTDengine()) {
|
||||||
Connection conn = getConnection(config);
|
Connection conn = getConnection(config);
|
||||||
stt = conn.createStatement();
|
stt = conn.createStatement();
|
||||||
|
//stt = config.isTDengine()
|
||||||
|
// ? conn.createStatement() // fix Presto: ResultSet: Exception: set type is TYPE_FORWARD_ONLY, Result set concurrency must be CONCUR_READ_ONLY
|
||||||
|
// : conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||||
|
|
||||||
count = stt.executeUpdate(StringUtil.isEmpty(sql) ? config.getSQL(false) : sql);
|
count = stt.executeUpdate(StringUtil.isEmpty(sql) ? config.getSQL(false) : sql);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user