ignite系列之20-数据源扩展GaussDB

其它内容参见

ignite系列之19-数据源扩展Postgresql

 

public String loadCacheSelectRangeQuery(String fullTblName, Collection<String> keyCols) {
String cols = mkString(keyCols, ",");
String condition = DataSourceUtils.getCondition(fullTblName);
return StringUtils.isBlank(condition) ? String.format("SELECT %s FROM (SELECT %s, row_number() over(order by %s) AS rn FROM %s ) as temp WHERE mod(rn, ?) = 0", cols, cols, cols, fullTblName) : String.format("SELECT %s FROM (SELECT %s, row_number() over(order by %s) AS rn FROM %s where %s) as temp WHERE mod(rn, ?) = 0", cols, cols, cols, fullTblName, condition);
}

public boolean hasMerge() {
return true;
}

public String mergeQuery(String fullTblName, Collection<String> keyCols, Collection<String> uniqCols) {
Collection<String> cols = F.concat(false, keyCols, uniqCols);
String onPart = mkString(keyCols, new C1<String, String>() {
public String apply(String col) {
return String.format("T.%s = S.%s", col, col);
}
}, "", " AND ", "");
String updatePart = mkString(uniqCols, new C1<String, String>() {
public String apply(String col) {
return String.format("T.%s = S.%s", col, col);
}
}, "", ", ", "");
String insertPart = mkString(cols, new C1<String, String>() {
public String apply(String col) {
return String.format("S.%s", col);
}
}, "", ", ", "");
return String.format("MERGE INTO %s AS T USING (SELECT * FROM (VALUES (%s)) AS V (%s)) AS S ON %s WHEN MATCHED THEN UPDATE SET %s WHEN NOT MATCHED THEN INSERT (%s) VALUES (%s)", fullTblName, repeat("?", cols.size(), "", ",", ""), mkString(cols, ", "), onPart, updatePart, mkString(cols, ", "), insertPart);
}
posted @ 2024-08-08 15:06  life_start  阅读(7)  评论(0编辑  收藏  举报