Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
f3ec4141
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,发现更多精彩内容 >>
提交
f3ec4141
编写于
8月 12, 2020
作者:
T
tristaZero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add create sharding rule parsing definitions
上级
2ed28df3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
114 addition
and
25 deletion
+114
-25
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
...re-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
+18
-17
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
...gsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
+45
-8
shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/CreateShardingRuleStatement.java
...rdl/parser/statement/rdl/CreateShardingRuleStatement.java
+9
-0
shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/TableRuleSegment.java
...dingsphere/rdl/parser/statement/rdl/TableRuleSegment.java
+42
-0
未找到文件。
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
浏览文件 @
f3ec4141
...
...
@@ -24,48 +24,49 @@ createSchema
;
createDatasource
: CREATE DATASOURCE data
source (COMMA datas
ource)*
: CREATE DATASOURCE data
Source (COMMA dataS
ource)*
;
createSharding
r
ule
: CREATE SHARDINGRULE
shardingrule (COMMA shardingr
ule)*
createSharding
R
ule
: CREATE SHARDINGRULE
tableRule (COMMA tableR
ule)*
;
shardingr
ule
:
key EQ shardingruleValue
tableR
ule
:
tableName EQ tableRuleDefinition
;
data
s
ource
:
key EQ datasourceValue
data
S
ource
:
dataSourceName EQ dataSourceDefinition
;
key
: IDENTIFIER
;
datasourceValue
dataSourceDefinition
: hostName COLON port COLON dbName COLON user COLON password
;
shardingruleValue
: strategyType LP strategy
Value
RP
tableRuleDefinition
: strategyType LP strategy
Definition
RP
;
strategyType
: IDENTIFIER
;
strategy
Value
:
tableName COMMA columName COMMA strategyProps+
strategy
Definition
:
columName COMMA strategyProps
;
strategyProps
: strategyProp (COMMA strategyProp)*
;
strategyProp
: IDENTIFIER | NUMBER | INT
;
dataSourceName
: IDENTIFIER
;
schemaName
: IDENTIFIER
;
...
...
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
浏览文件 @
f3ec4141
...
...
@@ -20,14 +20,21 @@ package org.apache.shardingsphere.rdl.parser.sql.visitor;
import
lombok.AccessLevel
;
import
lombok.Getter
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementBaseVisitor
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateSchemaContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateDatasourceContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DatasourceContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DatasourceValueContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateSchemaContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateShardingRuleContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DataSourceContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DataSourceDefinitionContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.StrategyPropContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.StrategyPropsContext
;
import
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.TableRuleContext
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateDataSourcesStatement
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateSchemaStatement
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateShardingRuleStatement
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.DataSourceConnectionSegment
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.TableRuleSegment
;
import
org.apache.shardingsphere.sql.parser.api.ASTNode
;
import
org.apache.shardingsphere.sql.parser.sql.value.collection.CollectionValue
;
import
java.util.Collection
;
import
java.util.LinkedList
;
...
...
@@ -46,21 +53,21 @@ public final class ShardingSphereVisitor extends ShardingSphereStatementBaseVisi
@Override
public
ASTNode
visitCreateDatasource
(
final
CreateDatasourceContext
ctx
)
{
Collection
<
DataSourceConnectionSegment
>
connectionInfos
=
new
LinkedList
<>();
for
(
Data
sourceContext
each
:
ctx
.
datas
ource
())
{
for
(
Data
SourceContext
each
:
ctx
.
dataS
ource
())
{
connectionInfos
.
add
((
DataSourceConnectionSegment
)
visit
(
each
));
}
return
new
CreateDataSourcesStatement
(
connectionInfos
);
}
@Override
public
ASTNode
visitData
source
(
final
Datas
ourceContext
ctx
)
{
DataSourceConnectionSegment
result
=
(
DataSourceConnectionSegment
)
visit
DatasourceValue
(
ctx
.
datasourceValue
());
result
.
setName
(
ctx
.
key
().
getText
());
public
ASTNode
visitData
Source
(
final
DataS
ourceContext
ctx
)
{
DataSourceConnectionSegment
result
=
(
DataSourceConnectionSegment
)
visit
(
ctx
.
dataSourceDefinition
());
result
.
setName
(
ctx
.
dataSourceName
().
getText
());
return
result
;
}
@Override
public
ASTNode
visitData
sourceValue
(
final
DatasourceValue
Context
ctx
)
{
public
ASTNode
visitData
SourceDefinition
(
final
DataSourceDefinition
Context
ctx
)
{
DataSourceConnectionSegment
result
=
new
DataSourceConnectionSegment
();
result
.
setHostName
(
ctx
.
hostName
().
getText
());
result
.
setPort
(
ctx
.
port
().
getText
());
...
...
@@ -69,4 +76,34 @@ public final class ShardingSphereVisitor extends ShardingSphereStatementBaseVisi
result
.
setPassword
(
null
==
ctx
.
password
()
?
""
:
ctx
.
password
().
getText
());
return
result
;
}
@Override
public
ASTNode
visitCreateShardingRule
(
final
CreateShardingRuleContext
ctx
)
{
Collection
<
TableRuleSegment
>
tables
=
new
LinkedList
<>();
for
(
TableRuleContext
each
:
ctx
.
tableRule
())
{
tables
.
add
((
TableRuleSegment
)
visit
(
each
));
}
return
new
CreateShardingRuleStatement
(
tables
);
}
@Override
public
ASTNode
visitTableRule
(
final
TableRuleContext
ctx
)
{
TableRuleSegment
result
=
new
TableRuleSegment
();
result
.
setLogicTable
(
ctx
.
tableName
().
getText
());
result
.
setAlgorithmType
(
ctx
.
tableRuleDefinition
().
strategyType
().
getText
());
result
.
setShardingColumn
(
ctx
.
tableRuleDefinition
().
strategyDefinition
().
columName
().
getText
());
result
.
setDataSources
(
new
LinkedList
<>());
CollectionValue
<
String
>
props
=
(
CollectionValue
)
visit
(
ctx
.
tableRuleDefinition
().
strategyDefinition
().
strategyProps
());
result
.
setProperties
(
props
.
getValue
());
return
result
;
}
@Override
public
ASTNode
visitStrategyProps
(
final
StrategyPropsContext
ctx
)
{
CollectionValue
<
String
>
result
=
new
CollectionValue
();
for
(
StrategyPropContext
each
:
ctx
.
strategyProp
())
{
result
.
getValue
().
add
(
each
.
getText
());
}
return
result
;
}
}
shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/CreateShardingRuleStatement.java
浏览文件 @
f3ec4141
...
...
@@ -17,8 +17,17 @@
package
org.apache.shardingsphere.rdl.parser.statement.rdl
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
java.util.Collection
;
/**
* Create sharding rule statement.
*/
@RequiredArgsConstructor
@Getter
public
final
class
CreateShardingRuleStatement
extends
RDLStatement
{
private
final
Collection
<
TableRuleSegment
>
tables
;
}
shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/TableRuleSegment.java
0 → 100644
浏览文件 @
f3ec4141
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.rdl.parser.statement.rdl
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.sql.parser.api.ASTNode
;
import
java.util.Collection
;
/**
* Table rule segment.
*/
@Getter
@Setter
public
final
class
TableRuleSegment
implements
ASTNode
{
private
String
logicTable
;
private
Collection
<
String
>
dataSources
;
private
String
shardingColumn
;
private
String
algorithmType
;
private
Collection
<
String
>
properties
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录