Skip to content

Commit d4ff30c

Browse files
dongweibhnieqiurong
authored andcommittedMar 5, 2025·
增加支持hive2分页查询功能
1 parent 53650e3 commit d4ff30c

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
 

‎mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/DbType.java

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ public enum DbType {
226226
* yasdb
227227
*/
228228
YASDB("yasdb", "崖山数据库"),
229+
/**
230+
* Hadoop的数据仓库
231+
*/
232+
HIVE2("hive2", "Hadoop数据仓库"),
229233
/**
230234
* UNKNOWN DB
231235
*/

‎mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectFactory.java

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ else if (dbType == DbType.ORACLE_12C
7373
} else if (dbType == DbType.TRINO
7474
|| dbType == DbType.PRESTO) {
7575
dialect = new TrinoDialect();
76+
} else if (dbType == DbType.HIVE2) {
77+
dialect = new Hive2Dialect();
7678
}
7779
DIALECT_ENUM_MAP.put(dbType, dialect);
7880
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2011-2025, baomidou (jobob@qq.com).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
17+
18+
import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
19+
20+
/**
21+
* DB2 数据库分页方言
22+
*
23+
* @author hubin
24+
* @since 2016-11-10
25+
*/
26+
public class Hive2Dialect implements IDialect {
27+
28+
@Override
29+
public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
30+
long firstParam = offset + 1;
31+
long secondParam = limit;
32+
/**
33+
* select * from ( select t.*,ROW_NUMBER() OVER(ORDER BY INNER_NO) AS row_num FROM ("
34+
* +sqlcmd+") t ) a offset "+startNo+" rows fetch next "+fetchCount+" rows only
35+
*/
36+
String sql = "SELECT a.* FROM (SELECT TMP_PAGE.*,ROW_NUMBER() OVER() AS ROW_ID FROM ( "
37+
+ originalSql +
38+
" ) TMP_PAGE) a OFFSET "
39+
+ firstParam
40+
+ " ROWS FETCH NEXT "
41+
+ secondParam + " ROWS ONLY";
42+
return new DialectModel(sql);
43+
}
44+
}

‎mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/JdbcUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public static DbType getDbType(String jdbcUrl) {
153153
return DbType.DUCKDB;
154154
} else if (url.contains(":yasdb:")) {
155155
return DbType.YASDB;
156+
} else if (url.contains(":hive2:") || url.contains(":inceptor2:")) {
157+
return DbType.HIVE2;
156158
} else {
157159
logger.warn("The jdbcUrl is " + jdbcUrl + ", Mybatis Plus Cannot Read Database type or The Database's Not Supported!");
158160
return DbType.OTHER;

0 commit comments

Comments
 (0)
Please sign in to comment.