Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
3adbafc4
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,发现更多精彩内容 >>
未验证
提交
3adbafc4
编写于
2月 12, 2020
作者:
L
Liang Zhang
提交者:
GitHub
2月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PostgreSQL visitor init version (#4272)
上级
9d9c0673
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
1370 addition
and
12 deletion
+1370
-12
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/PostgreSQLParserEntry.java
...ache/shardingsphere/sql/parser/PostgreSQLParserEntry.java
+18
-2
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/PostgreSQLVisitor.java
...g/apache/shardingsphere/sql/parser/PostgreSQLVisitor.java
+432
-10
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDALVisitor.java
...ardingsphere/sql/parser/visitor/PostgreSQLDALVisitor.java
+28
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDCLVisitor.java
...ardingsphere/sql/parser/visitor/PostgreSQLDCLVisitor.java
+103
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDDLVisitor.java
...ardingsphere/sql/parser/visitor/PostgreSQLDDLVisitor.java
+287
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDMLVisitor.java
...ardingsphere/sql/parser/visitor/PostgreSQLDMLVisitor.java
+437
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLTCLVisitor.java
...ardingsphere/sql/parser/visitor/PostgreSQLTCLVisitor.java
+64
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/VisitorParameterizedParsingTest.java
...ser/integrate/engine/VisitorParameterizedParsingTest.java
+1
-0
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/PostgreSQLParserEntry.java
浏览文件 @
3adbafc4
...
...
@@ -22,12 +22,16 @@ import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import
org.apache.shardingsphere.sql.parser.api.SQLParser
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementLexer
;
import
org.apache.shardingsphere.sql.parser.spi.SQLParserEntry
;
import
org.apache.shardingsphere.sql.parser.visitor.PostgreSQLDALVisitor
;
import
org.apache.shardingsphere.sql.parser.visitor.PostgreSQLDCLVisitor
;
import
org.apache.shardingsphere.sql.parser.visitor.PostgreSQLDDLVisitor
;
import
org.apache.shardingsphere.sql.parser.visitor.PostgreSQLDMLVisitor
;
import
org.apache.shardingsphere.sql.parser.visitor.PostgreSQLTCLVisitor
;
/**
* SQL parser entry for PostgreSQL.
*
* @author zhangliang
* @author panjuan
*/
public
final
class
PostgreSQLParserEntry
implements
SQLParserEntry
{
...
...
@@ -48,6 +52,18 @@ public final class PostgreSQLParserEntry implements SQLParserEntry {
@Override
public
Class
<?
extends
ParseTreeVisitor
>
getVisitorClass
(
final
String
visitorName
)
{
return
PostgreSQLVisitor
.
class
;
if
(
PostgreSQLDMLVisitor
.
class
.
getSimpleName
().
contains
(
visitorName
))
{
return
PostgreSQLDMLVisitor
.
class
;
}
if
(
PostgreSQLDDLVisitor
.
class
.
getSimpleName
().
contains
(
visitorName
))
{
return
PostgreSQLDDLVisitor
.
class
;
}
if
(
PostgreSQLTCLVisitor
.
class
.
getSimpleName
().
contains
(
visitorName
))
{
return
PostgreSQLTCLVisitor
.
class
;
}
if
(
PostgreSQLDCLVisitor
.
class
.
getSimpleName
().
contains
(
visitorName
))
{
return
PostgreSQLDCLVisitor
.
class
;
}
return
PostgreSQLDALVisitor
.
class
;
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/PostgreSQLVisitor.java
浏览文件 @
3adbafc4
此差异已折叠。
点击以展开。
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDALVisitor.java
0 → 100644
浏览文件 @
3adbafc4
/*
* 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.sql.parser.visitor
;
import
org.apache.shardingsphere.sql.parser.PostgreSQLVisitor
;
/**
* PostgreSQL DAL visitor.
*
* @author zhangliang
*/
public
final
class
PostgreSQLDALVisitor
extends
PostgreSQLVisitor
{
}
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDCLVisitor.java
0 → 100644
浏览文件 @
3adbafc4
/*
* 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.sql.parser.visitor
;
import
org.apache.shardingsphere.sql.parser.PostgreSQLVisitor
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterUserContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateRoleContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateUserContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropRoleContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropUserContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.GrantContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.PrivilegeClause_Context
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RevokeContext
;
import
org.apache.shardingsphere.sql.parser.sql.ASTNode
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.AlterUserStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.CreateRoleStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.CreateUserStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.DropRoleStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.DropUserStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.GrantStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dcl.RevokeStatement
;
import
org.apache.shardingsphere.sql.parser.sql.value.collection.CollectionValue
;
import
java.util.Collection
;
import
java.util.Collections
;
/**
* PostgreSQL DCL visitor.
*
* @author zhangliang
*/
public
final
class
PostgreSQLDCLVisitor
extends
PostgreSQLVisitor
{
@Override
public
ASTNode
visitGrant
(
final
GrantContext
ctx
)
{
GrantStatement
result
=
new
GrantStatement
();
if
(
null
!=
ctx
.
privilegeClause_
())
{
for
(
TableSegment
each
:
getTableFromPrivilegeClause
(
ctx
.
privilegeClause_
()))
{
result
.
getAllSQLSegments
().
add
(
each
);
result
.
getTables
().
add
(
each
);
}
}
return
result
;
}
@Override
public
ASTNode
visitRevoke
(
final
RevokeContext
ctx
)
{
RevokeStatement
result
=
new
RevokeStatement
();
if
(
null
!=
ctx
.
privilegeClause_
())
{
for
(
TableSegment
each
:
getTableFromPrivilegeClause
(
ctx
.
privilegeClause_
()))
{
result
.
getAllSQLSegments
().
add
(
each
);
result
.
getTables
().
add
(
each
);
}
}
return
result
;
}
@SuppressWarnings
(
"unchecked"
)
private
Collection
<
TableSegment
>
getTableFromPrivilegeClause
(
final
PrivilegeClause_Context
ctx
)
{
return
null
==
ctx
.
onObjectClause_
().
tableNames
()
?
Collections
.<
TableSegment
>
emptyList
()
:
((
CollectionValue
<
TableSegment
>)
visit
(
ctx
.
onObjectClause_
().
tableNames
())).
getValue
();
}
@Override
public
ASTNode
visitCreateUser
(
final
CreateUserContext
ctx
)
{
return
new
CreateUserStatement
();
}
@Override
public
ASTNode
visitDropUser
(
final
DropUserContext
ctx
)
{
return
new
DropUserStatement
();
}
@Override
public
ASTNode
visitAlterUser
(
final
AlterUserContext
ctx
)
{
return
new
AlterUserStatement
();
}
@Override
public
ASTNode
visitCreateRole
(
final
CreateRoleContext
ctx
)
{
return
new
CreateRoleStatement
();
}
@Override
public
ASTNode
visitDropRole
(
final
DropRoleContext
ctx
)
{
return
new
DropRoleStatement
();
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDDLVisitor.java
0 → 100644
浏览文件 @
3adbafc4
/*
* 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.sql.parser.visitor
;
import
org.apache.shardingsphere.sql.parser.PostgreSQLVisitor
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.AlterTableContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateIndexContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CreateTableContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropColumnSpecificationContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropIndexContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.DropTableContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RenameColumnSpecificationContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNameClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TableNamesClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.TruncateTableContext
;
import
org.apache.shardingsphere.sql.parser.sql.ASTNode
;
import
org.apache.shardingsphere.sql.parser.sql.segment.SQLSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.ddl.column.alter.DropColumnDefinitionSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.ddl.column.alter.RenameColumnSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateIndexStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropIndexStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropTableStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.ddl.TruncateStatement
;
import
org.apache.shardingsphere.sql.parser.sql.value.collection.CollectionValue
;
import
java.util.Collection
;
import
java.util.LinkedList
;
/**
* PostgreSQL DDL visitor.
*
* @author zhangliang
*/
public
final
class
PostgreSQLDDLVisitor
extends
PostgreSQLVisitor
{
@Override
public
ASTNode
visitCreateTable
(
final
CreateTableContext
ctx
)
{
CreateTableStatement
result
=
new
CreateTableStatement
();
TableSegment
table
=
(
TableSegment
)
visit
(
ctx
.
tableName
());
result
.
getTables
().
add
(
table
);
result
.
getAllSQLSegments
().
add
(
table
);
if
(
null
!=
ctx
.
createDefinitionClause_
())
{
CreateTableStatement
createDefinition
=
(
CreateTableStatement
)
visit
(
ctx
.
createDefinitionClause_
());
result
.
getColumnDefinitions
().
addAll
(
createDefinition
.
getColumnDefinitions
());
for
(
SQLSegment
each
:
createDefinition
.
getAllSQLSegments
())
{
result
.
getAllSQLSegments
().
add
(
each
);
if
(
each
instanceof
TableSegment
)
{
result
.
getTables
().
add
((
TableSegment
)
each
);
}
}
}
return
result
;
}
@Override
public
ASTNode
visitAlterTable
(
final
AlterTableContext
ctx
)
{
AlterTableStatement
result
=
new
AlterTableStatement
();
TableSegment
table
=
(
TableSegment
)
visit
(
ctx
.
tableNameClause
());
result
.
getTables
().
add
(
table
);
result
.
getAllSQLSegments
().
add
(
table
);
if
(
null
!=
ctx
.
alterDefinitionClause_
())
{
AlterTableStatement
alterDefinition
=
(
AlterTableStatement
)
visit
(
ctx
.
alterDefinitionClause_
());
result
.
getAddedColumnDefinitions
().
addAll
(
alterDefinition
.
getAddedColumnDefinitions
());
result
.
getChangedPositionColumns
().
addAll
(
alterDefinition
.
getChangedPositionColumns
());
result
.
getDroppedColumnNames
().
addAll
(
alterDefinition
.
getDroppedColumnNames
());
for
(
SQLSegment
each
:
alterDefinition
.
getAllSQLSegments
())
{
result
.
getAllSQLSegments
().
add
(
each
);
if
(
each
instanceof
TableSegment
)
{
result
.
getTables
().
add
((
TableSegment
)
each
);
}
}
}
return
result
;
}
// @Override
// public ASTNode visitAlterDefinitionClause_(final AlterDefinitionClause_Context ctx) {
// final AlterTableStatement result = new AlterTableStatement();
// for (AlterTableActionContext each : ctx.alterTableActions().alterTableAction()) {
// AddColumnSpecificationContext addColumnSpecification = each.addColumnSpecification();
// if (null != addColumnSpecification) {
// CollectionValue<AddColumnDefinitionSegment> addColumnDefinitions = (CollectionValue<AddColumnDefinitionSegment>) visit(addColumnSpecification);
// for (AddColumnDefinitionSegment addColumnDefinition : addColumnDefinitions.getValue()) {
// result.getAddedColumnDefinitions().add(addColumnDefinition.getColumnDefinition());
// Optional<ColumnPositionSegment> columnPositionSegment = addColumnDefinition.getColumnPosition();
// if (columnPositionSegment.isPresent()) {
// result.getChangedPositionColumns().add(columnPositionSegment.get());
// }
// }
// result.getAllSQLSegments().addAll(extractColumnDefinitions(addColumnSpecification.columnDefinition()));
// }
// AddConstraintSpecificationContext addConstraintSpecification = each.addConstraintSpecification();
// ForeignKeyOptionContext foreignKeyOption = null == addConstraintSpecification
// ? null : addConstraintSpecification.constraintDefinition().foreignKeyOption();
// if (null != foreignKeyOption) {
// result.getAllSQLSegments().add((TableSegment) visit(foreignKeyOption));
// }
// ChangeColumnSpecificationContext changeColumnSpecification = each.changeColumnSpecification();
// if (null != changeColumnSpecification) {
// Optional<ColumnPositionSegment> columnPositionSegment = ((ModifyColumnDefinitionSegment) visit(changeColumnSpecification)).getColumnPosition();
// if (columnPositionSegment.isPresent()) {
// result.getChangedPositionColumns().add(columnPositionSegment.get());
// }
// result.getAllSQLSegments().addAll(extractColumnDefinition(changeColumnSpecification.columnDefinition()));
// }
// DropColumnSpecificationContext dropColumnSpecification = each.dropColumnSpecification();
// if (null != dropColumnSpecification) {
// result.getDroppedColumnNames().add(((DropColumnDefinitionSegment) visit(dropColumnSpecification)).getColumnName());
// }
// ModifyColumnSpecificationContext modifyColumnSpecification = each.modifyColumnSpecification();
// if (null != modifyColumnSpecification) {
// Optional<ColumnPositionSegment> columnPositionSegment = ((ModifyColumnDefinitionSegment) visit(modifyColumnSpecification)).getColumnPosition();
// if (columnPositionSegment.isPresent()) {
// result.getChangedPositionColumns().add(columnPositionSegment.get());
// }
// result.getAllSQLSegments().addAll(extractColumnDefinition(modifyColumnSpecification.columnDefinition()));
// }
// }
// if (result.getAddedColumnDefinitions().isEmpty()) {
// result.getAllSQLSegments().addAll(result.getAddedColumnDefinitions());
// }
// if (result.getChangedPositionColumns().isEmpty()) {
// result.getAllSQLSegments().addAll(result.getChangedPositionColumns());
// }
// return result;
// }
@SuppressWarnings
(
"unchecked"
)
@Override
public
ASTNode
visitDropTable
(
final
DropTableContext
ctx
)
{
DropTableStatement
result
=
new
DropTableStatement
();
CollectionValue
<
TableSegment
>
tables
=
(
CollectionValue
<
TableSegment
>)
visit
(
ctx
.
tableNames
());
result
.
getTables
().
addAll
(
tables
.
getValue
());
result
.
getAllSQLSegments
().
addAll
(
tables
.
getValue
());
return
result
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
ASTNode
visitTruncateTable
(
final
TruncateTableContext
ctx
)
{
TruncateStatement
result
=
new
TruncateStatement
();
CollectionValue
<
TableSegment
>
tables
=
(
CollectionValue
<
TableSegment
>)
visit
(
ctx
.
tableNamesClause
());
result
.
getTables
().
addAll
(
tables
.
getValue
());
result
.
getAllSQLSegments
().
addAll
(
tables
.
getValue
());
return
result
;
}
@Override
public
ASTNode
visitTableNameClause
(
final
TableNameClauseContext
ctx
)
{
return
visit
(
ctx
.
tableName
());
}
@Override
public
ASTNode
visitTableNamesClause
(
final
TableNamesClauseContext
ctx
)
{
Collection
<
TableSegment
>
tableSegments
=
new
LinkedList
<>();
for
(
int
i
=
0
;
i
<
ctx
.
tableNameClause
().
size
();
i
++)
{
tableSegments
.
add
((
TableSegment
)
visit
(
ctx
.
tableNameClause
(
i
)));
}
CollectionValue
<
TableSegment
>
result
=
new
CollectionValue
<>();
result
.
getValue
().
addAll
(
tableSegments
);
return
result
;
}
@Override
public
ASTNode
visitCreateIndex
(
final
CreateIndexContext
ctx
)
{
CreateIndexStatement
result
=
new
CreateIndexStatement
();
TableSegment
table
=
(
TableSegment
)
visit
(
ctx
.
tableName
());
result
.
setTable
(
table
);
result
.
getAllSQLSegments
().
add
(
table
);
return
result
;
}
@Override
public
ASTNode
visitDropIndex
(
final
DropIndexContext
ctx
)
{
return
new
DropIndexStatement
();
}
// @Override
// public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
// Collection<InlineDataTypeContext> inlineDataTypes = Collections2.filter(ctx.inlineDataType(), new Predicate<InlineDataTypeContext>() {
//
// @Override
// public boolean apply(final InlineDataTypeContext inlineDataType) {
// return null != inlineDataType.commonDataTypeOption() && null != inlineDataType.commonDataTypeOption().primaryKey();
// }
// });
// Collection<GeneratedDataTypeContext> generatedDataTypes = Collections2.filter(ctx.generatedDataType(), new Predicate<GeneratedDataTypeContext>() {
// @Override
// public boolean apply(final GeneratedDataTypeContext generatedDataType) {
// return null != generatedDataType.commonDataTypeOption() && null != generatedDataType.commonDataTypeOption().primaryKey();
// }
// });
// ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
// boolean isPrimaryKey = inlineDataTypes.size() > 0 || generatedDataTypes.size() > 0;
// IdentifierValue dataType = (IdentifierValue) visit(ctx.dataType().dataTypeName());
// return new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column.getIdentifier().getValue(), dataType.getValue(), isPrimaryKey);
// }
// @Override
// public ASTNode visitAddColumnSpecification(final AddColumnSpecificationContext ctx) {
// CollectionValue<AddColumnDefinitionSegment> result = new CollectionValue<>();
// List<AddColumnDefinitionSegment> addColumnDefinitions = Lists.transform(ctx.columnDefinition(), new Function<ColumnDefinitionContext, AddColumnDefinitionSegment>() {
// @Override
// public AddColumnDefinitionSegment apply(final ColumnDefinitionContext columnDefinition) {
// return new AddColumnDefinitionSegment(columnDefinition.getStart().getStartIndex(),
// columnDefinition.getStop().getStopIndex(), (ColumnDefinitionSegment) visit(columnDefinition));
// }
// });
// if (null == ctx.firstOrAfterColumn()) {
// result.getValue().addAll(addColumnDefinitions);
// } else {
// AddColumnDefinitionSegment addColumnDefinition = addColumnDefinitions.get(0);
// addColumnDefinition.setColumnPosition(extractColumnDefinition(addColumnDefinition.getColumnDefinition(),
// (ColumnPositionSegment) visit(ctx.firstOrAfterColumn())));
// result.getValue().add(addColumnDefinition);
// }
// return result;
// }
@Override
public
ASTNode
visitDropColumnSpecification
(
final
DropColumnSpecificationContext
ctx
)
{
return
new
DropColumnDefinitionSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
(),
((
ColumnSegment
)
visit
(
ctx
.
columnName
())).
getIdentifier
().
getValue
());
}
// @Override
// public ASTNode visitModifyColumnSpecification(final ModifyColumnSpecificationContext ctx) {
// return extractModifyColumnDefinition(ctx.getStart(), ctx.getStop(), ctx.columnDefinition(), ctx.firstOrAfterColumn());
// }
@Override
public
ASTNode
visitRenameColumnSpecification
(
final
RenameColumnSpecificationContext
ctx
)
{
return
new
RenameColumnSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
(),
((
ColumnSegment
)
visit
(
ctx
.
columnName
(
0
))).
getIdentifier
().
getValue
(),
((
ColumnSegment
)
visit
(
ctx
.
columnName
(
1
))).
getIdentifier
().
getValue
());
}
// private ModifyColumnDefinitionSegment extractModifyColumnDefinition(final Token start, final Token stop, final ColumnDefinitionContext columnDefinition,
// final FirstOrAfterColumnContext firstOrAfterColumn) {
// ModifyColumnDefinitionSegment result = new ModifyColumnDefinitionSegment(start.getStartIndex(), stop.getStopIndex(),
// (ColumnDefinitionSegment) visit(columnDefinition));
// if (null != firstOrAfterColumn) {
// result.setColumnPosition(extractColumnDefinition(result.getColumnDefinition(), (ColumnPositionSegment) visit(firstOrAfterColumn)));
// }
// return result;
// }
// private ColumnPositionSegment extractColumnDefinition(final ColumnDefinitionSegment columnDefinition, final ColumnPositionSegment columnPosition) {
// return columnPosition instanceof ColumnFirstPositionSegment
// ? new ColumnFirstPositionSegment(columnPosition.getStartIndex(), columnPosition.getStopIndex(), columnDefinition.getColumnName())
// : new ColumnAfterPositionSegment(columnPosition.getStartIndex(), columnPosition.getStopIndex(), columnDefinition.getColumnName(),
// ((ColumnAfterPositionSegment) columnPosition).getAfterColumnName());
// }
//
// private Collection<TableSegment> extractColumnDefinition(final ColumnDefinitionContext columnDefinition) {
// Collection<TableSegment> result = new LinkedList<>();
// for (InlineDataTypeContext inlineDataType : columnDefinition.inlineDataType()) {
// if (null != inlineDataType.commonDataTypeOption() && null != inlineDataType.commonDataTypeOption().referenceDefinition()) {
// result.add((TableSegment) visit(inlineDataType.commonDataTypeOption().referenceDefinition()));
// }
// }
// for (GeneratedDataTypeContext generatedDataType : columnDefinition.generatedDataType()) {
// if (null != generatedDataType.commonDataTypeOption() && null != generatedDataType.commonDataTypeOption().referenceDefinition()) {
// result.add((TableSegment) visit(generatedDataType.commonDataTypeOption().referenceDefinition()));
// }
// }
// return result;
// }
}
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLDMLVisitor.java
0 → 100644
浏览文件 @
3adbafc4
此差异已折叠。
点击以展开。
shardingsphere-sql-parser/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/PostgreSQLTCLVisitor.java
0 → 100644
浏览文件 @
3adbafc4
/*
* 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.sql.parser.visitor
;
import
org.apache.shardingsphere.sql.parser.PostgreSQLVisitor
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.BeginTransactionContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.CommitContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.RollbackContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.SavepointContext
;
import
org.apache.shardingsphere.sql.parser.autogen.PostgreSQLStatementParser.SetTransactionContext
;
import
org.apache.shardingsphere.sql.parser.sql.ASTNode
;
import
org.apache.shardingsphere.sql.parser.sql.statement.tcl.BeginTransactionStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.tcl.CommitStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.tcl.RollbackStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.tcl.SavepointStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.tcl.SetTransactionStatement
;
/**
* PostgreSQL TCL visitor.
*
* @author zhangliang
*/
public
final
class
PostgreSQLTCLVisitor
extends
PostgreSQLVisitor
{
@Override
public
ASTNode
visitSetTransaction
(
final
SetTransactionContext
ctx
)
{
return
new
SetTransactionStatement
();
}
@Override
public
ASTNode
visitBeginTransaction
(
final
BeginTransactionContext
ctx
)
{
return
new
BeginTransactionStatement
();
}
@Override
public
ASTNode
visitCommit
(
final
CommitContext
ctx
)
{
return
new
CommitStatement
();
}
@Override
public
ASTNode
visitRollback
(
final
RollbackContext
ctx
)
{
return
new
RollbackStatement
();
}
@Override
public
ASTNode
visitSavepoint
(
final
SavepointContext
ctx
)
{
return
new
SavepointStatement
();
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/VisitorParameterizedParsingTest.java
浏览文件 @
3adbafc4
...
...
@@ -95,6 +95,7 @@ public final class VisitorParameterizedParsingTest {
String
sqlCaseId
=
each
[
0
].
toString
();
String
databaseType
=
each
[
1
].
toString
();
SQLCaseType
sqlCaseType
=
(
SQLCaseType
)
each
[
2
];
// if (!"MySQL".contains(databaseType) && !"PostgreSQL".contains(databaseType)) {
if
(!
"MySQL"
.
contains
(
databaseType
))
{
continue
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录