Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
78df234b
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
78df234b
编写于
5月 12, 2017
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: DerivedUtils = DerivedColumnUtils
上级
750cbf19
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
12 addition
and
12 deletion
+12
-12
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/rewrite/DerivedColumnUtils.java
...dang/ddframe/rdb/sharding/rewrite/DerivedColumnUtils.java
+10
-10
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/router/SQLRouteEngine.java
.../dangdang/ddframe/rdb/sharding/router/SQLRouteEngine.java
+2
-2
未找到文件。
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/rewrite/DerivedUtils.java
→
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/rewrite/Derived
Column
Utils.java
浏览文件 @
78df234b
...
...
@@ -31,7 +31,7 @@ import com.google.common.base.Optional;
*
* @author zhangliang
*/
public
final
class
DerivedUtils
{
public
final
class
Derived
Column
Utils
{
private
static
final
String
DERIVED_COUNT_ALIAS
=
"AVG_DERIVED_COUNT_%s"
;
...
...
@@ -62,16 +62,16 @@ public final class DerivedUtils {
if
(!(
each
instanceof
AggregationSelectItemContext
)
||
AggregationType
.
AVG
!=
((
AggregationSelectItemContext
)
each
).
getAggregationType
())
{
continue
;
}
AggregationSelectItemContext
a
ggregationSelectItem
Context
=
(
AggregationSelectItemContext
)
each
;
AggregationSelectItemContext
countSelectItemContext
=
new
AggregationSelectItemContext
(
aggregationSelectItemContext
.
getInnerExpression
(),
Optional
.
of
(
String
.
format
(
DERIVED_COUNT_ALIAS
,
derivedColumnOffset
)
),
-
1
,
AggregationType
.
COUNT
);
AggregationSelectItemContext
sumSelectItemContext
=
new
AggregationSelectItemContext
(
aggregationSelectItemContext
.
getInnerExpression
(),
Optional
.
of
(
String
.
format
(
DERIVED_SUM_ALIAS
,
derivedColumnOffset
)
),
-
1
,
AggregationType
.
SUM
);
a
ggregationSelectItemContext
.
getDerivedAggregationSelectItemContexts
().
add
(
countSelectItem
Context
);
a
ggregationSelectItemContext
.
getDerivedAggregationSelectItemContexts
().
add
(
sumSelectIte
mContext
);
AggregationSelectItemContext
a
vg
Context
=
(
AggregationSelectItemContext
)
each
;
String
countAlias
=
String
.
format
(
DERIVED_COUNT_ALIAS
,
derivedColumnOffset
);
AggregationSelectItemContext
countContext
=
new
AggregationSelectItemContext
(
avgContext
.
getInnerExpression
(),
Optional
.
of
(
countAlias
),
-
1
,
AggregationType
.
COUNT
);
String
sumAlias
=
String
.
format
(
DERIVED_SUM_ALIAS
,
derivedColumnOffset
);
AggregationSelectItemContext
sumContext
=
new
AggregationSelectItemContext
(
avgContext
.
getInnerExpression
(),
Optional
.
of
(
sumAlias
),
-
1
,
AggregationType
.
SUM
);
a
vgContext
.
getDerivedAggregationSelectItemContexts
().
add
(
count
Context
);
a
vgContext
.
getDerivedAggregationSelectItemContexts
().
add
(
su
mContext
);
// TODO 将AVG列替换成常数,避免数据库再计算无用的AVG函数
itemsToken
.
getItems
().
add
(
count
SelectItemContext
.
getExpression
()
+
" AS "
+
countSelectItemContext
.
getAlias
().
get
()
+
" "
);
itemsToken
.
getItems
().
add
(
sum
SelectItemContext
.
getExpression
()
+
" AS "
+
sumSelectItemContext
.
getAlias
().
get
()
+
" "
);
itemsToken
.
getItems
().
add
(
count
Context
.
getExpression
()
+
" AS "
+
countAlias
+
" "
);
itemsToken
.
getItems
().
add
(
sum
Context
.
getExpression
()
+
" AS "
+
sumAlias
+
" "
);
derivedColumnOffset
++;
}
}
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/router/SQLRouteEngine.java
浏览文件 @
78df234b
...
...
@@ -34,7 +34,7 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.context.UpdateSQLContext
import
com.dangdang.ddframe.rdb.sharding.parsing.parser.exception.SQLParsingException
;
import
com.dangdang.ddframe.rdb.sharding.parsing.parser.token.OffsetLimitToken
;
import
com.dangdang.ddframe.rdb.sharding.parsing.parser.token.RowCountLimitToken
;
import
com.dangdang.ddframe.rdb.sharding.rewrite.DerivedUtils
;
import
com.dangdang.ddframe.rdb.sharding.rewrite.Derived
Column
Utils
;
import
com.dangdang.ddframe.rdb.sharding.rewrite.GenerateKeysUtils
;
import
com.dangdang.ddframe.rdb.sharding.rewrite.SQLBuilder
;
import
com.dangdang.ddframe.rdb.sharding.rewrite.SQLRewriteEngine
;
...
...
@@ -100,7 +100,7 @@ public final class SQLRouteEngine {
GenerateKeysUtils
.
appendGenerateKeys
(
shardingRule
,
parameters
,
(
InsertSQLContext
)
result
);
}
if
(
result
instanceof
SelectSQLContext
)
{
DerivedUtils
.
appendDerivedColumns
((
SelectSQLContext
)
result
);
Derived
Column
Utils
.
appendDerivedColumns
((
SelectSQLContext
)
result
);
}
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录