This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 29166be19c0 sql parser support clickHouse (#31226)
29166be19c0 is described below
commit 29166be19c046c06745ee3f2575963c1696f39c1
Author: GG Bond <[email protected]>
AuthorDate: Thu May 16 18:14:47 2024 +0800
sql parser support clickHouse (#31226)
* feature support clickHouse
* add license
* checkstyle
* add 'final' to visitors;
update g4 file to keep format consistent;
---
.../statement/CommonSQLStatementContext.java | 4 +
parser/sql/dialect/clickhouse/pom.xml | 40 ++
.../src/main/antlr4/imports/clickhouse/BaseRule.g4 | 320 ++++++++++++
.../main/antlr4/imports/clickhouse/DMLStatement.g4 | 166 +++++++
.../antlr4/imports/clickhouse/LexerAlphabet.g4 | 51 ++
.../imports/clickhouse/LexerClickHouseKeyword.g4 | 243 +++++++++
.../antlr4/imports/clickhouse/LexerComments.g4 | 25 +
.../main/antlr4/imports/clickhouse/LexerKeyword.g4 | 547 +++++++++++++++++++++
.../antlr4/imports/clickhouse/LexerLiterals.g4 | 50 ++
.../main/antlr4/imports/clickhouse/LexerNumber.g4 | 29 ++
.../main/antlr4/imports/clickhouse/LexerSymbol.g4 | 59 +++
.../sql/parser/autogen/ClickHouseStatement.g4 | 41 ++
.../parser/clickhouse/parser/ClickHouseLexer.java | 33 ++
.../parser/clickhouse/parser/ClickHouseParser.java | 40 ++
.../clickhouse/parser/ClickHouseParserFacade.java | 43 ++
.../visitor/format/ClickHouseFormatVisitor.java | 33 ++
.../statement/ClickHouseStatementVisitor.java | 546 ++++++++++++++++++++
.../ClickHouseStatementVisitorFacade.java | 73 +++
.../type/ClickHouseDALStatementVisitor.java | 27 +
.../type/ClickHouseDCLStatementVisitor.java | 27 +
.../type/ClickHouseDDLStatementVisitor.java | 28 ++
.../type/ClickHouseDMLStatementVisitor.java | 457 +++++++++++++++++
.../type/ClickHouseRLStatementVisitor.java | 27 +
.../type/ClickHouseTCLStatementVisitor.java | 28 ++
....sql.parser.api.visitor.format.SQLFormatVisitor | 18 +
...ingsphere.sql.parser.spi.DialectSQLParserFacade | 18 +
...sphere.sql.parser.spi.SQLStatementVisitorFacade | 18 +
parser/sql/dialect/pom.xml | 1 +
.../statement/clickhouse/ClickHouseStatement.java | 33 ++
.../ddl/ClickHouseAlterTableStatement.java | 27 +
.../ddl/ClickHouseCreateTableStatement.java | 41 ++
.../ddl/ClickHouseDropTableStatement.java | 27 +
.../clickhouse/dml/ClickHouseDeleteStatement.java | 28 ++
.../clickhouse/dml/ClickHouseInsertStatement.java | 27 +
.../clickhouse/dml/ClickHouseSelectStatement.java | 27 +
.../clickhouse/dml/ClickHouseUpdateStatement.java | 27 +
36 files changed, 3229 insertions(+)
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
index 8e9fa75726b..1dccea69ec7 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;
@@ -69,6 +70,9 @@ public abstract class CommonSQLStatementContext implements
SQLStatementContext {
if (sqlStatement instanceof SQL92Statement) {
return TypedSPILoader.getService(DatabaseType.class, "SQL92");
}
+ if (sqlStatement instanceof ClickHouseStatement) {
+ return TypedSPILoader.getService(DatabaseType.class, "ClickHouse");
+ }
throw new
UnsupportedSQLOperationException(sqlStatement.getClass().getName());
}
}
diff --git a/parser/sql/dialect/clickhouse/pom.xml
b/parser/sql/dialect/clickhouse/pom.xml
new file mode 100644
index 00000000000..ea8b09334a7
--- /dev/null
+++ b/parser/sql/dialect/clickhouse/pom.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-sql-dialect</artifactId>
+ <version>5.5.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-parser-sql-clickhouse</artifactId>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <dialect.parser>clickhouse</dialect.parser>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-database-clickhouse</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/BaseRule.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/BaseRule.g4
new file mode 100644
index 00000000000..2438a896e44
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/BaseRule.g4
@@ -0,0 +1,320 @@
+/*
+ * 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.
+ */
+
+grammar BaseRule;
+
+import LexerSymbol, LexerKeyword, LexerClickHouseKeyword, LexerLiterals;
+
+cluster: ON CLUSTER identifier;
+
+parameterMarker
+ : QUESTION_
+ ;
+
+literals
+ : stringLiterals
+ | numberLiterals
+ | dateTimeLiterals
+ | hexadecimalLiterals
+ | bitValueLiterals
+ | booleanLiterals
+ | nullValueLiterals
+ ;
+
+stringLiterals
+ : characterSetName? STRING_ collateClause?
+ ;
+
+numberLiterals
+ : (PLUS_ | MINUS_)? NUMBER_
+ ;
+
+dateTimeLiterals
+ : (DATE | TIME | TIMESTAMP) STRING_
+ | LBE_ identifier STRING_ RBE_
+ ;
+
+hexadecimalLiterals
+ : characterSetName? HEX_DIGIT_ collateClause?
+ ;
+
+bitValueLiterals
+ : characterSetName? BIT_NUM_ collateClause?
+ ;
+
+booleanLiterals
+ : TRUE | FALSE
+ ;
+
+nullValueLiterals
+ : NULL
+ ;
+
+identifier
+ : IDENTIFIER_
+ | unreservedWord
+ | interval
+ ;
+
+unreservedWord
+ : AFTER | ALIAS | ALL | ALTER | AND | ANTI | ANY | ARRAY | AS |
ASCENDING | ASOF | AST | ASYNC | ATTACH | BETWEEN | BOTH | BY | CASE
+ | CAST | CHECK | CLEAR | CLUSTER | CODEC | COLLATE | COLUMN | COMMENT
| CONSTRAINT | CREATE | CROSS | CUBE | CURRENT | DATABASE
+ | DATABASES | DATE | DEDUPLICATE | DEFAULT | DELAY | DELETE | DESCRIBE
| DESC | DESCENDING | DETACH | DICTIONARIES | DICTIONARY | DISK
+ | DISTINCT | DISTRIBUTED | DROP | ELSE | END | ENGINE | EVENTS |
EXISTS | EXPLAIN | EXPRESSION | EXTRACT | FETCHES | FINAL | FIRST
+ | FLUSH | FOR | FOLLOWING | FOR | FORMAT | FREEZE | FROM | FULL |
FUNCTION | GLOBAL | GRANULARITY | GROUP | HAVING | HIERARCHICAL | ID
+ | IF | ILIKE | IN | INDEX | INJECTIVE | INNER | INSERT | INTERVAL |
INTO | IS | IS_OBJECT_ID | JOIN | JSON_FALSE | JSON_TRUE | KEY
+ | KILL | LAST | LAYOUT | LEADING | LEFT | LIFETIME | LIKE | LIMIT |
LIVE | LOCAL | LOGS | MATERIALIZE | MATERIALIZED | MAX | MERGES
+ | MIN | MODIFY | MOVE | MUTATION | NO | NOT | NULLS | OFFSET | ON |
OPTIMIZE | OR | ORDER | OUTER | OUTFILE | OVER | PARTITION
+ | POPULATE | PRECEDING | PREWHERE | PRIMARY | RANGE | RELOAD | REMOVE
| RENAME | REPLACE | REPLICA | REPLICATED | RIGHT | ROLLUP | ROW
+ | ROWS | SAMPLE | SELECT | SEMI | SENDS | SET | SETTINGS | SHOW |
SOURCE | START | STOP | SUBSTRING | SYNC | SYNTAX | SYSTEM | TABLE
+ | TABLES | TEMPORARY | TEST | THEN | TIES | TIMEOUT | TIMESTAMP |
TOTALS | TRAILING | TRIM | TRUNCATE | TO | TOP | TTL | TYPE
+ | UNBOUNDED | UNION | UPDATE | USE | USING | UUID | VALUES | VIEW |
VOLUME | WATCH | WHEN | WHERE | WINDOW | WITH
+ ;
+
+interval: SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER | YEAR;
+
+variable
+ : (AT_? AT_)? (GLOBAL | LOCAL)? DOT_? identifier
+ ;
+
+schemaName
+ : identifier
+ ;
+
+tableName
+ : (owner DOT_)? name
+ ;
+
+columnName
+ : (owner DOT_)? name
+ ;
+
+viewName
+ : identifier
+ | (owner DOT_)? identifier
+ ;
+
+owner
+ : identifier
+ ;
+
+name
+ : identifier
+ ;
+
+constraintName
+ : identifier
+ ;
+
+columnNames
+ : LP_? columnName (COMMA_ columnName)* RP_?
+ ;
+
+tableNames
+ : LP_? tableName (COMMA_ tableName)* RP_?
+ ;
+
+characterSetName
+ : IDENTIFIER_
+ ;
+
+expr
+ : expr andOperator expr
+ | expr orOperator expr
+ | notOperator expr
+ | LP_ expr RP_
+ | booleanPrimary
+ ;
+
+andOperator
+ : AND | AND_
+ ;
+
+orOperator
+ : OR
+ ;
+
+notOperator
+ : NOT | NOT_
+ ;
+
+booleanPrimary
+ : booleanPrimary IS NOT? (TRUE | FALSE | NULL)
+ | booleanPrimary SAFE_EQ_ predicate
+ | booleanPrimary comparisonOperator predicate
+ | booleanPrimary comparisonOperator (ALL | ANY) subquery
+ | predicate
+ ;
+
+comparisonOperator
+ : EQ_ | GTE_ | GT_ | LTE_ | LT_ | NEQ_
+ ;
+
+predicate
+ : bitExpr NOT? IN subquery
+ | bitExpr NOT? IN LP_ expr (COMMA_ expr)* RP_
+ | bitExpr NOT? BETWEEN bitExpr AND predicate
+ | bitExpr NOT? LIKE simpleExpr (ESCAPE simpleExpr)?
+ | bitExpr
+ ;
+
+bitExpr
+ : bitExpr VERTICAL_BAR_ bitExpr
+ | bitExpr AMPERSAND_ bitExpr
+ | bitExpr SIGNED_LEFT_SHIFT_ bitExpr
+ | bitExpr SIGNED_RIGHT_SHIFT_ bitExpr
+ | bitExpr PLUS_ bitExpr
+ | bitExpr MINUS_ bitExpr
+ | bitExpr ASTERISK_ bitExpr
+ | bitExpr SLASH_ bitExpr
+ | bitExpr MOD_ bitExpr
+ | bitExpr CARET_ bitExpr
+ | bitExpr PLUS_ intervalExpression
+ | bitExpr MINUS_ intervalExpression
+ | simpleExpr
+ ;
+
+simpleExpr
+ : functionCall
+ | parameterMarker
+ | literals
+ | columnName
+ | simpleExpr COLLATE (STRING_ | identifier)
+ | variable
+ | (PLUS_ | MINUS_ | TILDE_ | NOT_) simpleExpr
+ | LP_ expr (COMMA_ expr)* RP_
+ | EXISTS? subquery
+ | LBE_ identifier expr RBE_
+ | caseExpression
+ | intervalExpression
+ ;
+
+functionCall
+ : aggregationFunction | specialFunction | regularFunction
+ ;
+
+aggregationFunction
+ : aggregationFunctionName LP_ distinct? (expr (COMMA_ expr)* | ASTERISK_)?
RP_
+ ;
+
+aggregationFunctionName
+ : MAX | MIN | SUM | COUNT | AVG
+ ;
+
+distinct
+ : DISTINCT
+ ;
+
+specialFunction
+ : castFunction | positionFunction | substringFunction | extractFunction |
trimFunction
+ ;
+
+castFunction
+ : CAST LP_ (expr | NULL) AS dataType RP_
+ ;
+
+positionFunction
+ : POSITION LP_ expr IN expr RP_
+ ;
+
+substringFunction
+ : SUBSTRING LP_ expr FROM NUMBER_ (FOR NUMBER_)? RP_
+ ;
+
+extractFunction
+ : EXTRACT LP_ identifier FROM expr RP_
+ ;
+
+trimFunction
+ : TRIM LP_ (LEADING | BOTH | TRAILING) STRING_ FROM STRING_ RP_
+ ;
+
+regularFunction
+ : regularFunctionName LP_ (expr (COMMA_ expr)* | ASTERISK_)? RP_
+ ;
+
+regularFunctionName
+ : identifier | IF | LOCALTIME | LOCALTIMESTAMP | INTERVAL
+ ;
+
+
+caseExpression
+ : CASE simpleExpr? caseWhen+ caseElse? END
+ ;
+
+caseWhen
+ : WHEN expr THEN expr
+ ;
+
+caseElse
+ : ELSE expr
+ ;
+
+intervalExpression
+ : INTERVAL expr intervalUnit
+ ;
+
+intervalUnit
+ : MICROSECOND | SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER |
YEAR
+ ;
+
+subquery
+ : 'Default does not match anything'
+ ;
+
+orderByClause
+ : ORDER BY orderByItem (COMMA_ orderByItem)*
+ ;
+
+orderByItem
+ : (columnName | numberLiterals) (ASC | DESC)?
+ ;
+
+dataType
+ : dataTypeName dataTypeLength? characterSet? collateClause?
+ | dataTypeName LP_ STRING_ (COMMA_ STRING_)* RP_ characterSet?
collateClause?
+ ;
+
+dataTypeName
+ :UINT8 | UINT16 | UINT32 | UINT64 | INT8 | INT16 | INT32 | INT64 | FLOAT32
| FLOAT64
+ |STRING | FIXED_STRING
+ | DATE | DATETIME | DATETIME64
+ | ENUM8 | ENUM16
+ | UUID
+ | ARRAY | TUPLE
+ | IPV4 | IPV6 | NESTED
+ | NULLABLE
+ | identifier
+ ;
+
+dataTypeLength
+ : LP_ NUMBER_ (COMMA_ NUMBER_)? RP_
+ ;
+
+characterSet
+ : (CHARACTER | CHAR) SET EQ_? ignoredIdentifier
+ ;
+
+collateClause
+ : COLLATE EQ_? (STRING_ | ignoredIdentifier)
+ ;
+
+ignoredIdentifier
+ : identifier (DOT_ identifier)?
+ ;
+
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/DMLStatement.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/DMLStatement.g4
new file mode 100644
index 00000000000..292b8cfac40
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/DMLStatement.g4
@@ -0,0 +1,166 @@
+/*
+ * 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.
+ */
+
+grammar DMLStatement;
+
+import BaseRule;
+
+insert
+ : INSERT INTO? tableName (insertValuesClause | insertSelectClause)
+ ;
+
+insertValuesClause
+ : columnNames? (VALUES ) assignmentValues (COMMA_ assignmentValues)*
+ ;
+
+insertSelectClause
+ : columnNames? select
+ ;
+
+assignmentValues
+ : LP_ assignmentValue (COMMA_ assignmentValue)* RP_
+ | LP_ RP_
+ ;
+
+update
+ : UPDATE tableReferences setAssignmentsClause whereClause?
+ ;
+
+setAssignmentsClause
+ : SET assignment (COMMA_ assignment)*
+ ;
+
+assignment
+ : columnName EQ_ VALUES? LP_? assignmentValue RP_?
+ ;
+
+assignmentValue
+ : expr | DEFAULT | blobValue
+ ;
+
+blobValue
+ : STRING_
+ ;
+
+delete
+ :
+ | ALTER TABLE tableName cluster? DELETE whereClause?
+ ;
+
+
+
+singleTableClause
+ : FROM tableName (AS? alias)?
+ ;
+
+select
+ : combineClause
+ ;
+
+combineClause
+ : selectClause (UNION (ALL)? selectClause)*
+ ;
+
+selectClause
+ : SELECT selectSpecification* projections fromClause? whereClause?
groupByClause? havingClause? orderByClause? limitClause?
+ ;
+
+selectSpecification
+ : duplicateSpecification
+ ;
+
+duplicateSpecification
+ : ALL | DISTINCT
+ ;
+
+projections
+ : (unqualifiedShorthand | projection) (COMMA_ projection)*
+ ;
+
+projection
+ : (columnName | expr) (AS? alias)? | qualifiedShorthand
+ ;
+
+alias
+ : identifier | STRING_
+ ;
+
+unqualifiedShorthand
+ : ASTERISK_
+ ;
+
+qualifiedShorthand
+ : identifier DOT_ASTERISK_
+ ;
+
+fromClause
+ : FROM tableReferences
+ ;
+
+tableReferences
+ : escapedTableReference (COMMA_ escapedTableReference)*
+ ;
+
+escapedTableReference
+ : tableReference | LBE_ tableReference RBE_
+ ;
+
+tableReference
+ : tableFactor joinedTable*
+ ;
+
+tableFactor
+ : tableName (AS? alias)? | subquery AS? alias columnNames? | LP_
tableReferences RP_
+ ;
+
+joinedTable
+ : ((INNER | CROSS)? JOIN) tableFactor joinSpecification?
+ | (LEFT | RIGHT) OUTER? JOIN tableFactor joinSpecification
+ | NATURAL (INNER | (LEFT | RIGHT) (OUTER))? JOIN tableFactor
+ ;
+
+joinSpecification
+ : ON expr | USING columnNames
+ ;
+
+whereClause
+ : WHERE expr
+ ;
+
+groupByClause
+ : GROUP BY orderByItem (COMMA_ orderByItem)*
+ ;
+
+havingClause
+ : HAVING expr
+ ;
+
+limitClause
+ : LIMIT ((limitOffset COMMA_)? limitRowCount | limitRowCount OFFSET
limitOffset)
+ ;
+
+limitRowCount
+ : numberLiterals | parameterMarker
+ ;
+
+limitOffset
+ : numberLiterals | parameterMarker
+ ;
+
+subquery
+ : LP_ combineClause RP_
+ ;
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerAlphabet.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerAlphabet.g4
new file mode 100644
index 00000000000..87096bcc58a
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerAlphabet.g4
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerAlphabet;
+
+FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
+
+fragment A: [Aa];
+fragment B: [Bb];
+fragment C: [Cc];
+fragment D: [Dd];
+fragment E: [Ee];
+fragment F: [Ff];
+fragment G: [Gg];
+fragment H: [Hh];
+fragment I: [Ii];
+fragment J: [Jj];
+fragment K: [Kk];
+fragment L: [Ll];
+fragment M: [Mm];
+fragment N: [Nn];
+fragment O: [Oo];
+fragment P: [Pp];
+fragment Q: [Qq];
+fragment R: [Rr];
+fragment S: [Ss];
+fragment T: [Tt];
+fragment U: [Uu];
+fragment V: [Vv];
+fragment W: [Ww];
+fragment X: [Xx];
+fragment Y: [Yy];
+fragment Z: [Zz];
+fragment UL_: '_';
+
+
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerClickHouseKeyword.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerClickHouseKeyword.g4
new file mode 100644
index 00000000000..14db53d93c6
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerClickHouseKeyword.g4
@@ -0,0 +1,243 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerClickHouseKeyword;
+
+import LexerAlphabet, LexerKeyword,LexerNumber;
+
+
+ADD: A D D;
+AFTER: A F T E R;
+ALIAS: A L I A S;
+ALL: A L L;
+ALTER: A L T E R;
+AND: A N D;
+ANTI: A N T I;
+ANY: A N Y;
+ARRAY: A R R A Y;
+AS: A S;
+ASCENDING: A S C | A S C E N D I N G;
+ASOF: A S O F;
+AST: A S T;
+ASYNC: A S Y N C;
+ATTACH: A T T A C H;
+BETWEEN: B E T W E E N;
+BOTH: B O T H;
+BY: B Y;
+CASE: C A S E;
+CAST: C A S T;
+CHECK: C H E C K;
+CLEAR: C L E A R;
+CLUSTER: C L U S T E R;
+CODEC: C O D E C;
+COLLATE: C O L L A T E;
+COLUMN: C O L U M N;
+COMMENT: C O M M E N T;
+CONSTRAINT: C O N S T R A I N T;
+CREATE: C R E A T E;
+CROSS: C R O S S;
+CUBE: C U B E;
+CURRENT: C U R R E N T;
+DATABASE: D A T A B A S E;
+DATABASES: D A T A B A S E S;
+DATE: D A T E;
+DAY: D A Y;
+DEDUPLICATE: D E D U P L I C A T E;
+DEFAULT: D E F A U L T;
+DELAY: D E L A Y;
+DELETE: D E L E T E;
+DESC: D E S C;
+DESCENDING: D E S C E N D I N G;
+DESCRIBE: D E S C R I B E;
+DETACH: D E T A C H;
+DICTIONARIES: D I C T I O N A R I E S;
+DICTIONARY: D I C T I O N A R Y;
+DISK: D I S K;
+DISTINCT: D I S T I N C T;
+DISTRIBUTED: D I S T R I B U T E D;
+DROP: D R O P;
+ELSE: E L S E;
+END: E N D;
+ENGINE: E N G I N E;
+EVENTS: E V E N T S;
+EXISTS: E X I S T S;
+EXPLAIN: E X P L A I N;
+EXPRESSION: E X P R E S S I O N;
+EXTRACT: E X T R A C T;
+FETCHES: F E T C H E S;
+FINAL: F I N A L;
+FIRST: F I R S T;
+FLUSH: F L U S H;
+FOLLOWING: F O L L O W I N G;
+FOR: F O R;
+FORMAT: F O R M A T;
+FREEZE: F R E E Z E;
+FROM: F R O M;
+FULL: F U L L;
+FUNCTION: F U N C T I O N;
+GLOBAL: G L O B A L;
+GRANULARITY: G R A N U L A R I T Y;
+GROUP: G R O U P;
+HAVING: H A V I N G;
+HIERARCHICAL: H I E R A R C H I C A L;
+HOUR: H O U R;
+ID: I D;
+IF: I F;
+ILIKE: I L I K E;
+IN: I N;
+INDEX: I N D E X;
+INF: I N F | I N F I N I T Y;
+INJECTIVE: I N J E C T I V E;
+INNER: I N N E R;
+INSERT: I N S E R T;
+INTERVAL: I N T E R V A L;
+INTO: I N T O;
+IS: I S;
+IS_OBJECT_ID: I S UL_ O B J E C T UL_ I D;
+JOIN: J O I N;
+KEY: K E Y;
+KILL: K I L L;
+LAST: L A S T;
+LAYOUT: L A Y O U T;
+LEADING: L E A D I N G;
+LEFT: L E F T;
+LIFETIME: L I F E T I M E;
+LIKE: L I K E;
+LIMIT: L I M I T;
+LIVE: L I V E;
+LOCAL: L O C A L;
+LOGS: L O G S;
+MATERIALIZE: M A T E R I A L I Z E;
+MATERIALIZED: M A T E R I A L I Z E D;
+MAX: M A X;
+MERGES: M E R G E S;
+MIN: M I N;
+MINUTE: M I N U T E;
+MODIFY: M O D I F Y;
+MONTH: M O N T H;
+MOVE: M O V E;
+MUTATION: M U T A T I O N;
+NAN_SQL: N A N; // conflicts with macro NAN
+NO: N O;
+NOT: N O T;
+NULL_SQL: N U L L; // conflicts with macro NULL
+NULLS: N U L L S;
+OFFSET: O F F S E T;
+ON: O N;
+OPTIMIZE: O P T I M I Z E;
+OR: O R;
+ORDER: O R D E R;
+OUTER: O U T E R;
+OUTFILE: O U T F I L E;
+OVER: O V E R;
+PARTITION: P A R T I T I O N;
+POPULATE: P O P U L A T E;
+PRECEDING: P R E C E D I N G;
+PREWHERE: P R E W H E R E;
+PRIMARY: P R I M A R Y;
+PROJECTION: P R O J E C T I O N;
+QUARTER: Q U A R T E R;
+RANGE: R A N G E;
+RELOAD: R E L O A D;
+REMOVE: R E M O V E;
+RENAME: R E N A M E;
+REPLACE: R E P L A C E;
+REPLICA: R E P L I C A;
+REPLICATED: R E P L I C A T E D;
+RIGHT: R I G H T;
+ROLLUP: R O L L U P;
+ROW: R O W;
+ROWS: R O W S;
+SAMPLE: S A M P L E;
+SECOND: S E C O N D;
+SELECT: S E L E C T;
+SEMI: S E M I;
+SENDS: S E N D S;
+SET: S E T;
+SETTINGS: S E T T I N G S;
+SHOW: S H O W;
+SOURCE: S O U R C E;
+START: S T A R T;
+STOP: S T O P;
+SUBSTRING: S U B S T R I N G;
+SYNC: S Y N C;
+SYNTAX: S Y N T A X;
+SYSTEM: S Y S T E M;
+TABLE: T A B L E;
+TABLES: T A B L E S;
+TEMPORARY: T E M P O R A R Y;
+TEST: T E S T;
+THEN: T H E N;
+TIES: T I E S;
+TIMEOUT: T I M E O U T;
+TIMESTAMP: T I M E S T A M P;
+TO: T O;
+TOP: T O P;
+TOTALS: T O T A L S;
+TRAILING: T R A I L I N G;
+TRIM: T R I M;
+TRUNCATE: T R U N C A T E;
+TTL: T T L;
+TYPE: T Y P E;
+UNBOUNDED: U N B O U N D E D;
+UNION: U N I O N;
+UPDATE: U P D A T E;
+USE: U S E;
+USING: U S I N G;
+UUID: U U I D;
+VALUES: V A L U E S;
+VIEW: V I E W;
+VOLUME: V O L U M E;
+WATCH: W A T C H;
+WEEK: W E E K;
+WHEN: W H E N;
+WHERE: W H E R E;
+WINDOW: W I N D O W;
+WITH: W I T H;
+YEAR: Y E A R | Y Y Y Y;
+ESCAPE: E S C A P E;
+JSON_FALSE: 'false';
+JSON_TRUE: 'true';
+
+//dataType
+UINT8: U I N T EIGHT_;
+UINT16: U I N T ONE_ SIX_;
+UINT32: U I N T THREE_ TWO_;
+UINT64: U I N T SIX_ FOUR_;
+INT8: I N T EIGHT_;
+INT16: I N T ONE_ SIX_;
+INT32: I N T THREE_ TWO_;
+INT64: I N T SIX_ FOUR_;
+FLOAT32: F L O A T THREE_ TWO_;
+FLOAT64: F L O A T SIX_ FOUR_;
+DECIMAL: D E C I M A L;
+STRING: S T R I N G;
+FIXED_STRING: F I X E D S T R I N G;
+DATETIME: D A T E T I M E;
+DATETIME64: D A T E T I M E SIX_ FOUR_;
+ENUM8: E N U M EIGHT_;
+ENUM16: E N U M ONE_ SIX_;
+TUPLE: T U P L E;
+IPV4: I P V FOUR_;
+IPV6: I P V SIX_;
+NESTED: N E S T E D;
+NULLABLE: N U L L A B L E;
+
+
+
+
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerComments.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerComments.g4
new file mode 100644
index 00000000000..cb3e4182fe8
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerComments.g4
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerComments;
+
+import LexerSymbol;
+
+MULTI_LINE_COMMENT: '/*' .*? '*/' -> skip;
+SINGLE_LINE_COMMENT: '--' ~('\n'|'\r')* ('\n' | '\r' | EOF) -> skip;
+WHITESPACE: [ \u000B\u000C\t\r\n] -> skip; // '\n' can be part of multiline
single query
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerKeyword.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerKeyword.g4
new file mode 100644
index 00000000000..a685c39406c
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerKeyword.g4
@@ -0,0 +1,547 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerKeyword;
+
+import LexerAlphabet;
+
+WS
+ : [ \t\r\n] + ->skip
+ ;
+
+SELECT
+ : S E L E C T
+ ;
+
+INSERT
+ : I N S E R T
+ ;
+
+UPDATE
+ : U P D A T E
+ ;
+
+DELETE
+ : D E L E T E
+ ;
+
+CREATE
+ : C R E A T E
+ ;
+
+ALTER
+ : A L T E R
+ ;
+
+DROP
+ : D R O P
+ ;
+
+TRUNCATE
+ : T R U N C A T E
+ ;
+
+SCHEMA
+ : S C H E M A
+ ;
+
+GRANT
+ : G R A N T
+ ;
+
+REVOKE
+ : R E V O K E
+ ;
+
+ADD
+ : A D D
+ ;
+
+SET
+ : S E T
+ ;
+
+TABLE
+ : T A B L E
+ ;
+
+COLUMN
+ : C O L U M N
+ ;
+
+INDEX
+ : I N D E X
+ ;
+
+CONSTRAINT
+ : C O N S T R A I N T
+ ;
+
+PRIMARY
+ : P R I M A R Y
+ ;
+
+UNIQUE
+ : U N I Q U E
+ ;
+
+FOREIGN
+ : F O R E I G N
+ ;
+
+KEY
+ : K E Y
+ ;
+
+POSITION
+ : P O S I T I O N
+ ;
+
+PRECISION
+ : P R E C I S I O N
+ ;
+
+FUNCTION
+ : F U N C T I O N
+ ;
+
+TRIGGER
+ : T R I G G E R
+ ;
+
+PROCEDURE
+ : P R O C E D U R E
+ ;
+
+VIEW
+ : V I E W
+ ;
+
+INTO
+ : I N T O
+ ;
+
+VALUES
+ : V A L U E S
+ ;
+
+WITH
+ : W I T H
+ ;
+
+UNION
+ : U N I O N
+ ;
+
+DISTINCT
+ : D I S T I N C T
+ ;
+
+CASE
+ : C A S E
+ ;
+
+WHEN
+ : W H E N
+ ;
+
+CAST
+ : C A S T
+ ;
+
+TRIM
+ : T R I M
+ ;
+
+SUBSTRING
+ : S U B S T R I N G
+ ;
+
+FROM
+ : F R O M
+ ;
+
+NATURAL
+ : N A T U R A L
+ ;
+
+JOIN
+ : J O I N
+ ;
+
+FULL
+ : F U L L
+ ;
+
+INNER
+ : I N N E R
+ ;
+
+OUTER
+ : O U T E R
+ ;
+
+LEFT
+ : L E F T
+ ;
+
+RIGHT
+ : R I G H T
+ ;
+
+CROSS
+ : C R O S S
+ ;
+
+USING
+ : U S I N G
+ ;
+
+WHERE
+ : W H E R E
+ ;
+
+AS
+ : A S
+ ;
+
+ON
+ : O N
+ ;
+
+IF
+ : I F
+ ;
+
+ELSE
+ : E L S E
+ ;
+
+THEN
+ : T H E N
+ ;
+
+FOR
+ : F O R
+ ;
+
+TO
+ : T O
+ ;
+
+AND
+ : A N D
+ ;
+
+OR
+ : O R
+ ;
+
+IS
+ : I S
+ ;
+
+NOT
+ : N O T
+ ;
+
+NULL
+ : N U L L
+ ;
+
+TRUE
+ : T R U E
+ ;
+
+FALSE
+ : F A L S E
+ ;
+
+EXISTS
+ : E X I S T S
+ ;
+
+BETWEEN
+ : B E T W E E N
+ ;
+
+IN
+ : I N
+ ;
+
+ALL
+ : A L L
+ ;
+
+ANY
+ : A N Y
+ ;
+
+LIKE
+ : L I K E
+ ;
+
+ORDER
+ : O R D E R
+ ;
+
+GROUP
+ : G R O U P
+ ;
+
+BY
+ : B Y
+ ;
+
+ASC
+ : A S C
+ ;
+
+DESC
+ : D E S C
+ ;
+
+HAVING
+ : H A V I N G
+ ;
+
+LIMIT
+ : L I M I T
+ ;
+
+OFFSET
+ : O F F S E T
+ ;
+
+BEGIN
+ : B E G I N
+ ;
+
+COMMIT
+ : C O M M I T
+ ;
+
+ROLLBACK
+ : R O L L B A C K
+ ;
+
+SAVEPOINT
+ : S A V E P O I N T
+ ;
+
+BOOLEAN
+ : B O O L E A N
+ ;
+
+DOUBLE
+ : D O U B L E
+ ;
+
+CHAR
+ : C H A R
+ ;
+
+CHARACTER
+ : C H A R A C T E R
+ ;
+
+ARRAY
+ : A R R A Y
+ ;
+
+INTERVAL
+ : I N T E R V A L
+ ;
+
+DATE
+ : D A T E
+ ;
+
+TIME
+ : T I M E
+ ;
+
+TIMESTAMP
+ : T I M E S T A M P
+ ;
+
+LOCALTIME
+ : L O C A L T I M E
+ ;
+
+LOCALTIMESTAMP
+ : L O C A L T I M E S T A M P
+ ;
+
+YEAR
+ : Y E A R
+ ;
+
+QUARTER
+ : Q U A R T E R
+ ;
+
+MONTH
+ : M O N T H
+ ;
+
+WEEK
+ : W E E K
+ ;
+
+DAY
+ : D A Y
+ ;
+
+HOUR
+ : H O U R
+ ;
+
+MINUTE
+ : M I N U T E
+ ;
+
+SECOND
+ : S E C O N D
+ ;
+
+MICROSECOND
+ : M I C R O S E C O N D
+ ;
+
+MAX
+ : M A X
+ ;
+
+MIN
+ : M I N
+ ;
+
+SUM
+ : S U M
+ ;
+
+COUNT
+ : C O U N T
+ ;
+
+AVG
+ : A V G
+ ;
+
+DEFAULT
+ : D E F A U L T
+ ;
+
+CURRENT
+ : C U R R E N T
+ ;
+
+ENABLE
+ : E N A B L E
+ ;
+
+DISABLE
+ : D I S A B L E
+ ;
+
+CALL
+ : C A L L
+ ;
+
+INSTANCE
+ : I N S T A N C E
+ ;
+
+PRESERVE
+ : P R E S E R V E
+ ;
+
+DO
+ : D O
+ ;
+
+DEFINER
+ : D E F I N E R
+ ;
+
+CURRENT_USER
+ : C U R R E N T UL_ U S E R
+ ;
+
+SQL
+ : S Q L
+ ;
+
+
+CASCADED
+ : C A S C A D E D
+ ;
+
+LOCAL
+ : L O C A L
+ ;
+
+CLOSE
+ : C L O S E
+ ;
+
+OPEN
+ : O P E N
+ ;
+
+NEXT
+ : N E X T
+ ;
+
+NAME
+ : N A M E
+ ;
+
+COLLATION
+ : C O L L A T I O N
+ ;
+
+NAMES
+ : N A M E S
+ ;
+
+INTEGER
+ : I N T E G E R
+ ;
+
+REAL
+ : R E A L
+ ;
+
+DECIMAL
+ : D E C I M A L
+ ;
+
+TYPE
+ : T Y P E
+ ;
+
+VARCHAR
+ : V A R C H A R
+ ;
+
+FLOAT
+ : F L O A T
+ ;
+
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerLiterals.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerLiterals.g4
new file mode 100644
index 00000000000..d3f2d5bb2db
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerLiterals.g4
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerLiterals;
+
+import LexerAlphabet, LexerSymbol;
+
+IDENTIFIER_
+ :
[A-Za-z_$0-9\u0080-\uFFFF]*?[A-Za-z_$\u0080-\uFFFF]+?[A-Za-z_$0-9\u0080-\uFFFF]*
+ | DQ_ ~'"'+ DQ_
+ ;
+
+STRING_
+ : (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_)
+ ;
+
+NUMBER_
+ : INT_? DOT_? INT_ (E (PLUS_ | MINUS_)? INT_)?
+ ;
+
+HEX_DIGIT_
+ : '0x' HEX_+
+ | 'X' SQ_ HEX_+ SQ_
+ ;
+
+BIT_NUM_
+ : '0b' ('0' | '1')+ | B SQ_ ('0' | '1')+ SQ_
+ ;
+
+fragment INT_
+ : [0-9]+
+ ;
+
+fragment HEX_
+ : [0-9a-fA-F]
+ ;
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerNumber.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerNumber.g4
new file mode 100644
index 00000000000..90a25e259bb
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerNumber.g4
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerNumber;
+
+fragment ZERO_: [0];
+fragment ONE_: [1];
+fragment TWO_: [2];
+fragment THREE_: [3];
+fragment FOUR_: [4];
+fragment FIVE_: [5];
+fragment SIX_: [6];
+fragment SEVEN_: [7];
+fragment EIGHT_: [8];
+fragment NINE_: [9];
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerSymbol.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerSymbol.g4
new file mode 100644
index 00000000000..cbbc8b8f3cd
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/imports/clickhouse/LexerSymbol.g4
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+lexer grammar LexerSymbol;
+
+AND_: '&&';
+CONCAT_: '||';
+NOT_: '!';
+TILDE_: '~';
+VERTICAL_BAR_: '|';
+AMPERSAND_: '&';
+SIGNED_LEFT_SHIFT_: '<<';
+SIGNED_RIGHT_SHIFT_: '>>';
+CARET_: '^';
+MOD_: '%';
+COLON_: ':';
+PLUS_: '+';
+MINUS_: '-';
+ASTERISK_: '*';
+SLASH_: '/';
+BACKSLASH_: '\\';
+DOT_: '.';
+DOT_ASTERISK_: '.*';
+SAFE_EQ_: '<=>';
+DEQ_: '==';
+EQ_: '=';
+NEQ_: '<>' | '!=';
+GT_: '>';
+GTE_: '>=';
+LT_: '<';
+LTE_: '<=';
+POUND_: '#';
+LP_: '(';
+RP_: ')';
+LBE_: '{';
+RBE_: '}';
+LBT_: '[';
+RBT_: ']';
+COMMA_: ',';
+DQ_: '"';
+SQ_ : '\'';
+QUESTION_: '?';
+AT_: '@';
+SEMI_: ';';
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/ClickHouseStatement.g4
b/parser/sql/dialect/clickhouse/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/ClickHouseStatement.g4
new file mode 100644
index 00000000000..c4f298a100c
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/ClickHouseStatement.g4
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+grammar ClickHouseStatement;
+
+import DMLStatement;
+
+execute
+ : (select
+ | insert
+ | update
+ | delete
+// | createDatabase
+// | dropDatabase
+// | createTable
+// | alterTable
+// | dropTable
+// | createView
+// | dropView
+// | setTransaction
+// | commit
+// | rollback
+// | grant
+// | revoke
+ ) SEMI_? EOF
+ ;
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseLexer.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseLexer.java
new file mode 100644
index 00000000000..6083060ce38
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseLexer.java
@@ -0,0 +1,33 @@
+/*
+ * 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.clickhouse.parser;
+
+import org.antlr.v4.runtime.CharStream;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
+import org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementLexer;
+
+/**
+ * ClickHouse lexer.
+ */
+public final class ClickHouseLexer extends ClickHouseStatementLexer implements
SQLLexer {
+
+ public ClickHouseLexer(final CharStream input) {
+ super(input);
+ }
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParser.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParser.java
new file mode 100644
index 00000000000..665e1ba1cd3
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParser.java
@@ -0,0 +1,40 @@
+/*
+ * 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.clickhouse.parser;
+
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.TokenStream;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
+import org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
+
+/**
+ * ClickHouse parser.
+ */
+public final class ClickHouseParser extends ClickHouseStatementParser
implements SQLParser {
+
+ public ClickHouseParser(final TokenStream input) {
+ super(input);
+ }
+
+ @Override
+ public ASTNode parse() {
+ return new ParseASTNode(execute(), (CommonTokenStream)
getTokenStream());
+ }
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParserFacade.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParserFacade.java
new file mode 100644
index 00000000000..bc5522a9efb
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/parser/ClickHouseParserFacade.java
@@ -0,0 +1,43 @@
+/*
+ * 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.clickhouse.parser;
+
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
+import org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade;
+
+/**
+ * SQL parser facade for ClickHouse.
+ */
+public final class ClickHouseParserFacade implements DialectSQLParserFacade {
+
+ @Override
+ public Class<? extends SQLLexer> getLexerClass() {
+ return ClickHouseLexer.class;
+ }
+
+ @Override
+ public Class<? extends SQLParser> getParserClass() {
+ return ClickHouseParser.class;
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "ClickHouse";
+ }
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/format/ClickHouseFormatVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/format/ClickHouseFormatVisitor.java
new file mode 100644
index 00000000000..341d1022e1c
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/format/ClickHouseFormatVisitor.java
@@ -0,0 +1,33 @@
+/*
+ * 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.clickhouse.visitor.format;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.format.SQLFormatVisitor;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementBaseVisitor;
+
+/**
+ * ClickHouse Format SQL Visitor.
+ */
+public final class ClickHouseFormatVisitor extends
ClickHouseStatementBaseVisitor<String> implements SQLFormatVisitor {
+
+ @Override
+ public String getDatabaseType() {
+ return "ClickHouse";
+ }
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitor.java
new file mode 100644
index 00000000000..c2ee6c1a7e4
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitor.java
@@ -0,0 +1,546 @@
+/*
+ * 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.clickhouse.visitor.statement;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.misc.Interval;
+import org.antlr.v4.runtime.tree.TerminalNode;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementBaseVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser;
+import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType;
+import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection;
+import
org.apache.shardingsphere.sql.parser.sql.common.enums.ParameterMarkerType;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.NotExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.OrderBySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.OrderByItemSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeLengthSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.ParameterMarkerSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.keyword.KeywordValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.BooleanLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NullLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.OtherLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.parametermarker.ParameterMarkerValue;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.dml.SQL92SelectStatement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * ClickHouse Statement visitor.
+ */
+@Getter(AccessLevel.PROTECTED)
+public abstract class ClickHouseStatementVisitor extends
ClickHouseStatementBaseVisitor<ASTNode> {
+
+ private final Collection<ParameterMarkerSegment> parameterMarkerSegments =
new LinkedList<>();
+
+ @Override
+ public final ASTNode visitParameterMarker(final
ClickHouseStatementParser.ParameterMarkerContext ctx) {
+ return new ParameterMarkerValue(parameterMarkerSegments.size(),
ParameterMarkerType.QUESTION);
+ }
+
+ @Override
+ public final ASTNode visitLiterals(final
ClickHouseStatementParser.LiteralsContext ctx) {
+ if (null != ctx.stringLiterals()) {
+ return visit(ctx.stringLiterals());
+ }
+ if (null != ctx.numberLiterals()) {
+ return visit(ctx.numberLiterals());
+ }
+ if (null != ctx.hexadecimalLiterals()) {
+ return visit(ctx.hexadecimalLiterals());
+ }
+ if (null != ctx.bitValueLiterals()) {
+ return visit(ctx.bitValueLiterals());
+ }
+ if (null != ctx.booleanLiterals()) {
+ return visit(ctx.booleanLiterals());
+ }
+ if (null != ctx.nullValueLiterals()) {
+ return visit(ctx.nullValueLiterals());
+ }
+ throw new IllegalStateException("Literals must have string, number,
dateTime, hex, bit, boolean or null.");
+ }
+
+ @Override
+ public final ASTNode visitStringLiterals(final
ClickHouseStatementParser.StringLiteralsContext ctx) {
+ return new StringLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitNumberLiterals(final
ClickHouseStatementParser.NumberLiteralsContext ctx) {
+ return new NumberLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitHexadecimalLiterals(final
ClickHouseStatementParser.HexadecimalLiteralsContext ctx) {
+ // TODO deal with hexadecimalLiterals
+ return new OtherLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitBitValueLiterals(final
ClickHouseStatementParser.BitValueLiteralsContext ctx) {
+ // TODO deal with bitValueLiterals
+ return new OtherLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitBooleanLiterals(final
ClickHouseStatementParser.BooleanLiteralsContext ctx) {
+
+ return new BooleanLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitNullValueLiterals(final
ClickHouseStatementParser.NullValueLiteralsContext ctx) {
+ return new NullLiteralValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitIdentifier(final
ClickHouseStatementParser.IdentifierContext ctx) {
+ ClickHouseStatementParser.UnreservedWordContext unreservedWord =
ctx.unreservedWord();
+ return null == unreservedWord ? new IdentifierValue(ctx.getText()) :
visit(unreservedWord);
+ }
+
+ @Override
+ public final ASTNode visitUnreservedWord(final
ClickHouseStatementParser.UnreservedWordContext ctx) {
+ return new IdentifierValue(ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitSchemaName(final
ClickHouseStatementParser.SchemaNameContext ctx) {
+ return visit(ctx.identifier());
+ }
+
+ @Override
+ public final ASTNode visitTableName(final
ClickHouseStatementParser.TableNameContext ctx) {
+ SimpleTableSegment result = new SimpleTableSegment(new
TableNameSegment(ctx.name().getStart().getStartIndex(),
ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())));
+ ClickHouseStatementParser.OwnerContext owner = ctx.owner();
+ if (null != owner) {
+ result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(),
owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier())));
+ }
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitColumnName(final
ClickHouseStatementParser.ColumnNameContext ctx) {
+ ColumnSegment result = new
ColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
(IdentifierValue) visit(ctx.name()));
+ ClickHouseStatementParser.OwnerContext owner = ctx.owner();
+ if (null != owner) {
+ result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(),
owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier())));
+ }
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitTableNames(final
ClickHouseStatementParser.TableNamesContext ctx) {
+ CollectionValue<SimpleTableSegment> result = new CollectionValue<>();
+ for (ClickHouseStatementParser.TableNameContext each :
ctx.tableName()) {
+ result.getValue().add((SimpleTableSegment) visit(each));
+ }
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitColumnNames(final
ClickHouseStatementParser.ColumnNamesContext ctx) {
+ CollectionValue<ColumnSegment> result = new CollectionValue<>();
+ for (ClickHouseStatementParser.ColumnNameContext each :
ctx.columnName()) {
+ result.getValue().add((ColumnSegment) visit(each));
+ }
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitExpr(final ClickHouseStatementParser.ExprContext
ctx) {
+ if (null != ctx.booleanPrimary()) {
+ return visit(ctx.booleanPrimary());
+ }
+ if (null != ctx.LP_()) {
+ return visit(ctx.expr(0));
+ }
+ if (null != ctx.andOperator()) {
+ return createBinaryOperationExpression(ctx,
ctx.andOperator().getText());
+ }
+ if (null != ctx.orOperator()) {
+ return createBinaryOperationExpression(ctx,
ctx.orOperator().getText());
+ }
+ return new NotExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), (ExpressionSegment) visit(ctx.expr(0)), false);
+ }
+
+ private ASTNode createBinaryOperationExpression(final
ClickHouseStatementParser.ExprContext ctx, final String operator) {
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.expr(0));
+ ExpressionSegment right = (ExpressionSegment) visit(ctx.expr(1));
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, operator, text);
+ }
+
+ @Override
+ public final ASTNode visitBooleanPrimary(final
ClickHouseStatementParser.BooleanPrimaryContext ctx) {
+ if (null != ctx.IS()) {
+ String rightText = "";
+ if (null != ctx.NOT()) {
+ rightText =
rightText.concat(ctx.start.getInputStream().getText(new
Interval(ctx.NOT().getSymbol().getStartIndex(),
+ ctx.NOT().getSymbol().getStopIndex()))).concat(" ");
+ }
+ Token operatorToken = null;
+ if (null != ctx.NULL()) {
+ operatorToken = ctx.NULL().getSymbol();
+ }
+ if (null != ctx.TRUE()) {
+ operatorToken = ctx.TRUE().getSymbol();
+ }
+ if (null != ctx.FALSE()) {
+ operatorToken = ctx.FALSE().getSymbol();
+ }
+ int startIndex = null == operatorToken ?
ctx.IS().getSymbol().getStopIndex() + 2 : operatorToken.getStartIndex();
+ rightText =
rightText.concat(ctx.start.getInputStream().getText(new Interval(startIndex,
ctx.stop.getStopIndex())));
+ ExpressionSegment right = new
LiteralExpressionSegment(ctx.IS().getSymbol().getStopIndex() + 2,
ctx.stop.getStopIndex(), rightText);
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ ExpressionSegment left = (ExpressionSegment)
visit(ctx.booleanPrimary());
+ String operator = "IS";
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, operator, text);
+ }
+ if (null != ctx.comparisonOperator() || null != ctx.SAFE_EQ_()) {
+ return createCompareSegment(ctx);
+ }
+ return visit(ctx.predicate());
+ }
+
+ private ASTNode createCompareSegment(final
ClickHouseStatementParser.BooleanPrimaryContext ctx) {
+ ExpressionSegment left = (ExpressionSegment)
visit(ctx.booleanPrimary());
+ ExpressionSegment right;
+ if (null != ctx.predicate()) {
+ right = (ExpressionSegment) visit(ctx.predicate());
+ } else {
+ right = (ExpressionSegment) visit(ctx.subquery());
+ }
+ String operator = null == ctx.SAFE_EQ_() ?
ctx.comparisonOperator().getText() : ctx.SAFE_EQ_().getText();
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, operator, text);
+ }
+
+ @Override
+ public final ASTNode visitPredicate(final
ClickHouseStatementParser.PredicateContext ctx) {
+ if (null != ctx.IN()) {
+ return createInSegment(ctx);
+ }
+ if (null != ctx.BETWEEN()) {
+ return createBetweenSegment(ctx);
+ }
+ if (null != ctx.LIKE()) {
+ return createBinaryOperationExpressionFromLike(ctx);
+ }
+ return visit(ctx.bitExpr(0));
+ }
+
+ private BinaryOperationExpression
createBinaryOperationExpressionFromLike(final
ClickHouseStatementParser.PredicateContext ctx) {
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0));
+ ListExpression right = new
ListExpression(ctx.simpleExpr(0).start.getStartIndex(),
ctx.simpleExpr().get(ctx.simpleExpr().size() - 1).stop.getStopIndex());
+ for (ClickHouseStatementParser.SimpleExprContext each :
ctx.simpleExpr()) {
+ right.getItems().add((ExpressionSegment) visit(each));
+ }
+ String operator = null == ctx.NOT() ? "LIKE" : "NOT LIKE";
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, operator, text);
+ }
+
+ private InExpression createInSegment(final
ClickHouseStatementParser.PredicateContext ctx) {
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0));
+ ExpressionSegment right;
+ if (null != ctx.subquery()) {
+ right = new SubqueryExpressionSegment(new
SubquerySegment(ctx.subquery().start.getStartIndex(),
ctx.subquery().stop.getStopIndex(), (SQL92SelectStatement)
visit(ctx.subquery()),
+ getOriginalText(ctx.subquery())));
+ } else {
+ ListExpression listExpression = new
ListExpression(ctx.LP_().getSymbol().getStartIndex(),
ctx.RP_().getSymbol().getStopIndex());
+ for (ClickHouseStatementParser.ExprContext each : ctx.expr()) {
+ listExpression.getItems().add((ExpressionSegment) visit(each));
+ }
+ right = listExpression;
+ }
+ boolean not = null != ctx.NOT();
+ return new InExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, not);
+ }
+
+ private BetweenExpression createBetweenSegment(final
ClickHouseStatementParser.PredicateContext ctx) {
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0));
+ ExpressionSegment between = (ExpressionSegment) visit(ctx.bitExpr(1));
+ ExpressionSegment and = (ExpressionSegment) visit(ctx.predicate());
+ boolean not = null != ctx.NOT();
+ return new BetweenExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, between, and, not);
+ }
+
+ @Override
+ public final ASTNode visitBitExpr(final
ClickHouseStatementParser.BitExprContext ctx) {
+ if (null != ctx.simpleExpr()) {
+ return createExpressionSegment(visit(ctx.simpleExpr()), ctx);
+ }
+ ExpressionSegment left = (ExpressionSegment) visit(ctx.getChild(0));
+ ExpressionSegment right = (ExpressionSegment) visit(ctx.getChild(2));
+ String operator = ctx.getChild(1).getText();
+ String text = ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ return new BinaryOperationExpression(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), left, right, operator, text);
+ }
+
+ private ASTNode createExpressionSegment(final ASTNode astNode, final
ParserRuleContext context) {
+ if (astNode instanceof StringLiteralValue) {
+ return new LiteralExpressionSegment(context.start.getStartIndex(),
context.stop.getStopIndex(), ((StringLiteralValue) astNode).getValue());
+ }
+ if (astNode instanceof NumberLiteralValue) {
+ return new LiteralExpressionSegment(context.start.getStartIndex(),
context.stop.getStopIndex(), ((NumberLiteralValue) astNode).getValue());
+ }
+ if (astNode instanceof BooleanLiteralValue) {
+ return new LiteralExpressionSegment(context.start.getStartIndex(),
context.stop.getStopIndex(), ((BooleanLiteralValue) astNode).getValue());
+ }
+ if (astNode instanceof ParameterMarkerValue) {
+ ParameterMarkerValue parameterMarker = (ParameterMarkerValue)
astNode;
+ ParameterMarkerExpressionSegment segment = new
ParameterMarkerExpressionSegment(context.start.getStartIndex(),
context.stop.getStopIndex(),
+ parameterMarker.getValue(), parameterMarker.getType());
+ parameterMarkerSegments.add(segment);
+ return segment;
+ }
+ if (astNode instanceof SubquerySegment) {
+ return new SubqueryExpressionSegment((SubquerySegment) astNode);
+ }
+ if (astNode instanceof OtherLiteralValue) {
+ return new
CommonExpressionSegment(context.getStart().getStartIndex(),
context.getStop().getStopIndex(), ((OtherLiteralValue) astNode).getValue());
+ }
+ return astNode;
+ }
+
+ @Override
+ public final ASTNode visitSimpleExpr(final
ClickHouseStatementParser.SimpleExprContext ctx) {
+ int startIndex = ctx.getStart().getStartIndex();
+ int stopIndex = ctx.getStop().getStopIndex();
+ if (null != ctx.subquery()) {
+ return new SubquerySegment(startIndex, stopIndex,
(SQL92SelectStatement) visit(ctx.subquery()), getOriginalText(ctx.subquery()));
+ }
+ if (null != ctx.parameterMarker()) {
+ ParameterMarkerValue parameterMarker = (ParameterMarkerValue)
visit(ctx.parameterMarker());
+ ParameterMarkerExpressionSegment segment = new
ParameterMarkerExpressionSegment(startIndex, stopIndex,
parameterMarker.getValue(), parameterMarker.getType());
+ parameterMarkerSegments.add(segment);
+ return segment;
+ }
+ if (null != ctx.literals()) {
+ return SQLUtils.createLiteralExpression(visit(ctx.literals()),
startIndex, stopIndex, ctx.literals().start.getInputStream().getText(new
Interval(startIndex, stopIndex)));
+ }
+ if (null != ctx.functionCall()) {
+ return visit(ctx.functionCall());
+ }
+ if (null != ctx.columnName()) {
+ return visit(ctx.columnName());
+ }
+ return new CommonExpressionSegment(startIndex, stopIndex,
ctx.getText());
+ }
+
+ @Override
+ public final ASTNode visitIntervalExpression(final
ClickHouseStatementParser.IntervalExpressionContext ctx) {
+ calculateParameterCount(Collections.singleton(ctx.expr()));
+ return new ExpressionProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), getOriginalText(ctx));
+ }
+
+ @Override
+ public final ASTNode visitFunctionCall(final
ClickHouseStatementParser.FunctionCallContext ctx) {
+ if (null != ctx.aggregationFunction()) {
+ return visit(ctx.aggregationFunction());
+ }
+ if (null != ctx.specialFunction()) {
+ return visit(ctx.specialFunction());
+ }
+ if (null != ctx.regularFunction()) {
+ return visit(ctx.regularFunction());
+ }
+ throw new IllegalStateException("FunctionCallContext must have
aggregationFunction, regularFunction or specialFunction.");
+ }
+
+ @Override
+ public final ASTNode visitAggregationFunction(final
ClickHouseStatementParser.AggregationFunctionContext ctx) {
+ String aggregationType = ctx.aggregationFunctionName().getText();
+ return AggregationType.isAggregationType(aggregationType)
+ ? createAggregationSegment(ctx, aggregationType)
+ : new
ExpressionProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), getOriginalText(ctx));
+ }
+
+ private ASTNode createAggregationSegment(final
ClickHouseStatementParser.AggregationFunctionContext ctx, final String
aggregationType) {
+ AggregationType type =
AggregationType.valueOf(aggregationType.toUpperCase());
+ if (null != ctx.distinct()) {
+ AggregationDistinctProjectionSegment result =
+ new
AggregationDistinctProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), type, getOriginalText(ctx),
getDistinctExpression(ctx));
+ result.getParameters().addAll(getExpressions(ctx));
+ return result;
+ }
+ AggregationProjectionSegment result = new
AggregationProjectionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), type, getOriginalText(ctx));
+ result.getParameters().addAll(getExpressions(ctx));
+ return result;
+ }
+
+ private Collection<ExpressionSegment> getExpressions(final
ClickHouseStatementParser.AggregationFunctionContext ctx) {
+ if (null == ctx.expr()) {
+ return Collections.emptyList();
+ }
+ Collection<ExpressionSegment> result = new LinkedList<>();
+ for (ClickHouseStatementParser.ExprContext each : ctx.expr()) {
+ result.add((ExpressionSegment) visit(each));
+ }
+ return result;
+ }
+
+ private String getDistinctExpression(final
ClickHouseStatementParser.AggregationFunctionContext ctx) {
+ StringBuilder result = new StringBuilder();
+ for (int i = 3; i < ctx.getChildCount() - 1; i++) {
+ result.append(ctx.getChild(i).getText());
+ }
+ return result.toString();
+ }
+
+ @Override
+ public final ASTNode visitSpecialFunction(final
ClickHouseStatementParser.SpecialFunctionContext ctx) {
+ if (null != ctx.castFunction()) {
+ return visit(ctx.castFunction());
+ }
+ return new FunctionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), ctx.getChild(0).getChild(0).getText(),
getOriginalText(ctx));
+ }
+
+ @Override
+ public final ASTNode visitCastFunction(final
ClickHouseStatementParser.CastFunctionContext ctx) {
+ calculateParameterCount(Collections.singleton(ctx.expr()));
+ FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.CAST().getText(), getOriginalText(ctx));
+ ASTNode exprSegment = visit(ctx.expr());
+ if (exprSegment instanceof ColumnSegment) {
+ result.getParameters().add((ColumnSegment) exprSegment);
+ } else if (exprSegment instanceof LiteralExpressionSegment) {
+ result.getParameters().add((LiteralExpressionSegment) exprSegment);
+ }
+ result.getParameters().add((DataTypeSegment) visit(ctx.dataType()));
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitRegularFunction(final
ClickHouseStatementParser.RegularFunctionContext ctx) {
+ FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.regularFunctionName().getText(), getOriginalText(ctx));
+ Collection<ExpressionSegment> expressionSegments =
ctx.expr().stream().map(each -> (ExpressionSegment)
visit(each)).collect(Collectors.toList());
+ result.getParameters().addAll(expressionSegments);
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitDataTypeName(final
ClickHouseStatementParser.DataTypeNameContext ctx) {
+ Collection<String> dataTypeNames = new LinkedList<>();
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ dataTypeNames.add(ctx.getChild(i).getText());
+ }
+ return new KeywordValue(String.join(" ", dataTypeNames));
+ }
+
+ // TODO :FIXME, sql case id: insert_with_str_to_date
+ private void calculateParameterCount(final
Collection<ClickHouseStatementParser.ExprContext> exprContexts) {
+ for (ClickHouseStatementParser.ExprContext each : exprContexts) {
+ visit(each);
+ }
+ }
+
+ @Override
+ public final ASTNode visitOrderByClause(final
ClickHouseStatementParser.OrderByClauseContext ctx) {
+ Collection<OrderByItemSegment> items = new LinkedList<>();
+ for (ClickHouseStatementParser.OrderByItemContext each :
ctx.orderByItem()) {
+ items.add((OrderByItemSegment) visit(each));
+ }
+ return new OrderBySegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), items);
+ }
+
+ @Override
+ public final ASTNode visitOrderByItem(final
ClickHouseStatementParser.OrderByItemContext ctx) {
+ OrderDirection orderDirection = null == ctx.DESC() ?
OrderDirection.ASC : OrderDirection.DESC;
+ if (null != ctx.columnName()) {
+ ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
+ return new ColumnOrderByItemSegment(column, orderDirection, null);
+ }
+ return new
IndexOrderByItemSegment(ctx.numberLiterals().getStart().getStartIndex(),
ctx.numberLiterals().getStop().getStopIndex(),
+ SQLUtils.getExactlyNumber(ctx.numberLiterals().getText(),
10).intValue(), orderDirection, null);
+ }
+
+ @Override
+ public final ASTNode visitDataType(final
ClickHouseStatementParser.DataTypeContext ctx) {
+ DataTypeSegment result = new DataTypeSegment();
+ result.setDataTypeName(((KeywordValue)
visit(ctx.dataTypeName())).getValue());
+ result.setStartIndex(ctx.start.getStartIndex());
+ result.setStopIndex(ctx.stop.getStopIndex());
+ if (null != ctx.dataTypeLength()) {
+ DataTypeLengthSegment dataTypeLengthSegment =
(DataTypeLengthSegment) visit(ctx.dataTypeLength());
+ result.setDataLength(dataTypeLengthSegment);
+ }
+ return result;
+ }
+
+ @Override
+ public final ASTNode visitDataTypeLength(final
ClickHouseStatementParser.DataTypeLengthContext ctx) {
+ DataTypeLengthSegment result = new DataTypeLengthSegment();
+ result.setStartIndex(ctx.start.getStartIndex());
+ result.setStopIndex(ctx.stop.getStartIndex());
+ List<TerminalNode> numbers = ctx.NUMBER_();
+ if (numbers.size() == 1) {
+ result.setPrecision(Integer.parseInt(numbers.get(0).getText()));
+ }
+ if (numbers.size() == 2) {
+ result.setPrecision(Integer.parseInt(numbers.get(0).getText()));
+ result.setScale(Integer.parseInt(numbers.get(1).getText()));
+ }
+ return result;
+ }
+
+ /**
+ * Get original text.
+ *
+ * @param ctx context
+ * @return original text
+ */
+ protected String getOriginalText(final ParserRuleContext ctx) {
+ return ctx.start.getInputStream().getText(new
Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+ }
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitorFacade.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitorFacade.java
new file mode 100644
index 00000000000..4017b95226d
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/ClickHouseStatementVisitorFacade.java
@@ -0,0 +1,73 @@
+/*
+ * 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.clickhouse.visitor.statement;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.RLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDALStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDDLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseRLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseTCLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade;
+
+/**
+ * Statement visitor facade for ClickHouse.
+ */
+public final class ClickHouseStatementVisitorFacade implements
SQLStatementVisitorFacade {
+
+ @Override
+ public Class<? extends DMLStatementVisitor> getDMLVisitorClass() {
+ return ClickHouseDMLStatementVisitor.class;
+ }
+
+ @Override
+ public Class<? extends DDLStatementVisitor> getDDLVisitorClass() {
+ return ClickHouseDDLStatementVisitor.class;
+ }
+
+ @Override
+ public Class<? extends TCLStatementVisitor> getTCLVisitorClass() {
+ return ClickHouseTCLStatementVisitor.class;
+ }
+
+ @Override
+ public Class<? extends DCLStatementVisitor> getDCLVisitorClass() {
+ return ClickHouseDCLStatementVisitor.class;
+ }
+
+ @Override
+ public Class<? extends DALStatementVisitor> getDALVisitorClass() {
+ return ClickHouseDALStatementVisitor.class;
+ }
+
+ @Override
+ public Class<? extends RLStatementVisitor> getRLVisitorClass() {
+ return ClickHouseRLStatementVisitor.class;
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "ClickHouse";
+ }
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDALStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDALStatementVisitor.java
new file mode 100644
index 00000000000..5e21100b885
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDALStatementVisitor.java
@@ -0,0 +1,27 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+
+/**
+ * ClickHouse DAL statement visitor.
+ */
+public final class ClickHouseDALStatementVisitor extends
ClickHouseStatementVisitor implements DALStatementVisitor {
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDCLStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDCLStatementVisitor.java
new file mode 100644
index 00000000000..a8bc2384a37
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDCLStatementVisitor.java
@@ -0,0 +1,27 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+
+/**
+ * ClickHouse DCL statement visitor.
+ */
+public final class ClickHouseDCLStatementVisitor extends
ClickHouseStatementVisitor implements DCLStatementVisitor {
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDDLStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDDLStatementVisitor.java
new file mode 100644
index 00000000000..913c02120aa
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDDLStatementVisitor.java
@@ -0,0 +1,28 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+
+/**
+ * ClickHouse DDL statement visitor.
+ */
+public final class ClickHouseDDLStatementVisitor extends
ClickHouseStatementVisitor implements DDLStatementVisitor {
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDMLStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDMLStatementVisitor.java
new file mode 100644
index 00000000000..6252301137d
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseDMLStatementVisitor.java
@@ -0,0 +1,457 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import org.antlr.v4.runtime.misc.Interval;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DMLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.AssignmentValuesContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.ColumnNamesContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.DeleteContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.InsertContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.InsertValuesClauseContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.SelectClauseContext;
+import
org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser.SubqueryContext;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.OrderBySegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.OrderByItemSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.HavingSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.BooleanLiteralValue;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.dml.ClickHouseDeleteStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.dml.ClickHouseInsertStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.dml.ClickHouseSelectStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.dml.ClickHouseUpdateStatement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * DML Statement visitor for ClickHouse.
+ */
+public final class ClickHouseDMLStatementVisitor extends
ClickHouseStatementVisitor implements DMLStatementVisitor {
+
+ @Override
+ public ASTNode visitInsert(final InsertContext ctx) {
+ ClickHouseInsertStatement result = (ClickHouseInsertStatement)
visit(ctx.insertValuesClause());
+ result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+ result.addParameterMarkerSegments(getParameterMarkerSegments());
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ASTNode visitInsertValuesClause(final InsertValuesClauseContext
ctx) {
+ ClickHouseInsertStatement result = new ClickHouseInsertStatement();
+ if (null != ctx.columnNames()) {
+ ColumnNamesContext columnNames = ctx.columnNames();
+ CollectionValue<ColumnSegment> columnSegments =
(CollectionValue<ColumnSegment>) visit(columnNames);
+ result.setInsertColumns(new
InsertColumnsSegment(columnNames.start.getStartIndex(),
columnNames.stop.getStopIndex(), columnSegments.getValue()));
+ } else {
+ result.setInsertColumns(new
InsertColumnsSegment(ctx.start.getStartIndex() - 1, ctx.start.getStartIndex() -
1, Collections.emptyList()));
+ }
+
result.getValues().addAll(createInsertValuesSegments(ctx.assignmentValues()));
+ return result;
+ }
+
+ private Collection<InsertValuesSegment> createInsertValuesSegments(final
Collection<AssignmentValuesContext> assignmentValuesContexts) {
+ Collection<InsertValuesSegment> result = new LinkedList<>();
+ for (ClickHouseStatementParser.AssignmentValuesContext each :
assignmentValuesContexts) {
+ result.add((InsertValuesSegment) visit(each));
+ }
+ return result;
+ }
+
+ @Override
+ public ASTNode visitUpdate(final ClickHouseStatementParser.UpdateContext
ctx) {
+ ClickHouseUpdateStatement result = new ClickHouseUpdateStatement();
+ result.setTable((TableSegment) visit(ctx.tableReferences()));
+ result.setSetAssignment((SetAssignmentSegment)
visit(ctx.setAssignmentsClause()));
+ if (null != ctx.whereClause()) {
+ result.setWhere((WhereSegment) visit(ctx.whereClause()));
+ }
+ result.addParameterMarkerSegments(getParameterMarkerSegments());
+ return result;
+ }
+
+ @Override
+ public ASTNode visitSetAssignmentsClause(final
ClickHouseStatementParser.SetAssignmentsClauseContext ctx) {
+ Collection<ColumnAssignmentSegment> assignments = new LinkedList<>();
+ for (ClickHouseStatementParser.AssignmentContext each :
ctx.assignment()) {
+ assignments.add((ColumnAssignmentSegment) visit(each));
+ }
+ return new SetAssignmentSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), assignments);
+ }
+
+ @Override
+ public ASTNode visitAssignmentValues(final AssignmentValuesContext ctx) {
+ List<ExpressionSegment> segments = new LinkedList<>();
+ for (ClickHouseStatementParser.AssignmentValueContext each :
ctx.assignmentValue()) {
+ segments.add((ExpressionSegment) visit(each));
+ }
+ return new InsertValuesSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), segments);
+ }
+
+ @Override
+ public ASTNode visitAssignment(final
ClickHouseStatementParser.AssignmentContext ctx) {
+ ColumnSegment column = (ColumnSegment)
visitColumnName(ctx.columnName());
+ List<ColumnSegment> columnSegments = new LinkedList<>();
+ columnSegments.add(column);
+ ExpressionSegment value = (ExpressionSegment)
visit(ctx.assignmentValue());
+ ColumnAssignmentSegment result = new
ColumnAssignmentSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), columnSegments, value);
+ result.getColumns().add(column);
+ return result;
+ }
+
+ @Override
+ public ASTNode visitAssignmentValue(final
ClickHouseStatementParser.AssignmentValueContext ctx) {
+ ClickHouseStatementParser.ExprContext expr = ctx.expr();
+ if (null != expr) {
+ return visit(expr);
+ }
+ return new CommonExpressionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), ctx.getText());
+ }
+
+ @Override
+ public ASTNode visitDelete(final DeleteContext ctx) {
+ ClickHouseDeleteStatement result = new ClickHouseDeleteStatement();
+ result.setTable((SimpleTableSegment) visit(ctx.tableName()));
+ if (null != ctx.whereClause()) {
+ result.setWhere((WhereSegment) visit(ctx.whereClause()));
+ }
+ result.addParameterMarkerSegments(getParameterMarkerSegments());
+ return result;
+ }
+
+ @Override
+ public ASTNode visitSingleTableClause(final
ClickHouseStatementParser.SingleTableClauseContext ctx) {
+ SimpleTableSegment result = (SimpleTableSegment)
visit(ctx.tableName());
+ if (null != ctx.alias()) {
+ result.setAlias((AliasSegment) visit(ctx.alias()));
+ }
+ return result;
+ }
+
+ @Override
+ public ASTNode visitSelect(final ClickHouseStatementParser.SelectContext
ctx) {
+ // TODO :Unsupported for withClause.
+ ClickHouseSelectStatement result = (ClickHouseSelectStatement)
visit(ctx.combineClause());
+ result.addParameterMarkerSegments(getParameterMarkerSegments());
+ return result;
+ }
+
+ @Override
+ public ASTNode visitCombineClause(final
ClickHouseStatementParser.CombineClauseContext ctx) {
+ // TODO :Unsupported for union SQL.
+ return visit(ctx.selectClause(0));
+ }
+
+ @Override
+ public ASTNode visitSelectClause(final SelectClauseContext ctx) {
+ ClickHouseSelectStatement result = new ClickHouseSelectStatement();
+ result.setProjections((ProjectionsSegment) visit(ctx.projections()));
+ if (!ctx.selectSpecification().isEmpty()) {
+
result.getProjections().setDistinctRow(isDistinct(ctx.selectSpecification().get(0)));
+ }
+ if (null != ctx.fromClause()) {
+ TableSegment tableSegment = (TableSegment) visit(ctx.fromClause());
+ result.setFrom(tableSegment);
+ }
+ if (null != ctx.whereClause()) {
+ result.setWhere((WhereSegment) visit(ctx.whereClause()));
+ }
+ if (null != ctx.groupByClause()) {
+ result.setGroupBy((GroupBySegment) visit(ctx.groupByClause()));
+ }
+ if (null != ctx.orderByClause()) {
+ result.setOrderBy((OrderBySegment) visit(ctx.orderByClause()));
+ }
+ if (null != ctx.havingClause()) {
+ result.setHaving((HavingSegment) visit(ctx.havingClause()));
+ }
+ return result;
+ }
+
+ @Override
+ public ASTNode visitHavingClause(final
ClickHouseStatementParser.HavingClauseContext ctx) {
+ ExpressionSegment expr = (ExpressionSegment) visit(ctx.expr());
+ return new HavingSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), expr);
+ }
+
+ private boolean isDistinct(final
ClickHouseStatementParser.SelectSpecificationContext ctx) {
+ return ((BooleanLiteralValue)
visit(ctx.duplicateSpecification())).getValue();
+ }
+
+ @Override
+ public ASTNode visitDuplicateSpecification(final
ClickHouseStatementParser.DuplicateSpecificationContext ctx) {
+ return new BooleanLiteralValue(null != ctx.DISTINCT());
+ }
+
+ @Override
+ public ASTNode visitProjections(final
ClickHouseStatementParser.ProjectionsContext ctx) {
+ Collection<ProjectionSegment> projections = new LinkedList<>();
+ if (null != ctx.unqualifiedShorthand()) {
+ projections.add(new
ShorthandProjectionSegment(ctx.unqualifiedShorthand().getStart().getStartIndex(),
ctx.unqualifiedShorthand().getStop().getStopIndex()));
+ }
+ for (ClickHouseStatementParser.ProjectionContext each :
ctx.projection()) {
+ projections.add((ProjectionSegment) visit(each));
+ }
+ ProjectionsSegment result = new
ProjectionsSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex());
+ result.getProjections().addAll(projections);
+ return result;
+ }
+
+ @Override
+ public ASTNode visitProjection(final
ClickHouseStatementParser.ProjectionContext ctx) {
+ // FIXME :The stop index of project is the stop index of projection,
instead of alias.
+ if (null != ctx.qualifiedShorthand()) {
+ ClickHouseStatementParser.QualifiedShorthandContext shorthand =
ctx.qualifiedShorthand();
+ ShorthandProjectionSegment result = new
ShorthandProjectionSegment(shorthand.getStart().getStartIndex(),
shorthand.getStop().getStopIndex());
+ IdentifierValue identifier = new
IdentifierValue(shorthand.identifier().getText());
+ result.setOwner(new
OwnerSegment(shorthand.identifier().getStart().getStartIndex(),
shorthand.identifier().getStop().getStopIndex(), identifier));
+ return result;
+ }
+ AliasSegment alias = null == ctx.alias() ? null : (AliasSegment)
visit(ctx.alias());
+ if (null != ctx.columnName()) {
+ ColumnSegment column = (ColumnSegment) visit(ctx.columnName());
+ ColumnProjectionSegment result = new
ColumnProjectionSegment(column);
+ result.setAlias(alias);
+ return result;
+ }
+ return createProjection(ctx, alias);
+ }
+
+ @Override
+ public ASTNode visitAlias(final ClickHouseStatementParser.AliasContext
ctx) {
+ return null == ctx.identifier() ? new
AliasSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), new
IdentifierValue(ctx.STRING_().getText()))
+ : new AliasSegment(ctx.start.getStartIndex(),
ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier()));
+ }
+
+ private ASTNode createProjection(final
ClickHouseStatementParser.ProjectionContext ctx, final AliasSegment alias) {
+ ASTNode projection = visit(ctx.expr());
+ if (projection instanceof AggregationProjectionSegment) {
+ ((AggregationProjectionSegment) projection).setAlias(alias);
+ return projection;
+ }
+ if (projection instanceof ExpressionProjectionSegment) {
+ ((ExpressionProjectionSegment) projection).setAlias(alias);
+ return projection;
+ }
+ if (projection instanceof FunctionSegment) {
+ FunctionSegment segment = (FunctionSegment) projection;
+ ExpressionProjectionSegment result = new
ExpressionProjectionSegment(segment.getStartIndex(), segment.getStopIndex(),
segment.getText(), segment);
+ result.setAlias(alias);
+ return result;
+ }
+ if (projection instanceof CommonExpressionSegment) {
+ CommonExpressionSegment segment = (CommonExpressionSegment)
projection;
+ ExpressionProjectionSegment result = new
ExpressionProjectionSegment(segment.getStartIndex(), segment.getStopIndex(),
segment.getText(), segment);
+ result.setAlias(alias);
+ return result;
+ }
+ // FIXME :For DISTINCT()
+ if (projection instanceof ColumnSegment) {
+ ExpressionProjectionSegment result = new
ExpressionProjectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(),
getOriginalText(ctx), (ColumnSegment) projection);
+ result.setAlias(alias);
+ return result;
+ }
+ if (projection instanceof SubqueryExpressionSegment) {
+ SubqueryExpressionSegment subqueryExpressionSegment =
(SubqueryExpressionSegment) projection;
+ String text = ctx.start.getInputStream().getText(new
Interval(subqueryExpressionSegment.getStartIndex(),
subqueryExpressionSegment.getStopIndex()));
+ SubqueryProjectionSegment result = new
SubqueryProjectionSegment(((SubqueryExpressionSegment)
projection).getSubquery(), text);
+ result.setAlias(alias);
+ return result;
+ }
+ if (projection instanceof BinaryOperationExpression) {
+ BinaryOperationExpression binaryExpression =
(BinaryOperationExpression) projection;
+ int startIndex = binaryExpression.getStartIndex();
+ int stopIndex = null == alias ? binaryExpression.getStopIndex() :
alias.getStopIndex();
+ ExpressionProjectionSegment result = new
ExpressionProjectionSegment(startIndex, stopIndex, binaryExpression.getText(),
binaryExpression);
+ result.setAlias(alias);
+ return result;
+ }
+ if (projection instanceof ParameterMarkerExpressionSegment) {
+ ParameterMarkerExpressionSegment result =
(ParameterMarkerExpressionSegment) projection;
+ result.setAlias(alias);
+ return projection;
+ }
+ LiteralExpressionSegment column = (LiteralExpressionSegment)
projection;
+ ExpressionProjectionSegment result = null == alias ? new
ExpressionProjectionSegment(column.getStartIndex(), column.getStopIndex(),
String.valueOf(column.getLiterals()), column)
+ : new ExpressionProjectionSegment(column.getStartIndex(),
ctx.alias().stop.getStopIndex(), String.valueOf(column.getLiterals()), column);
+ result.setAlias(alias);
+ return result;
+ }
+
+ @Override
+ public ASTNode visitFromClause(final
ClickHouseStatementParser.FromClauseContext ctx) {
+ return visit(ctx.tableReferences());
+ }
+
+ @Override
+ public ASTNode visitTableReferences(final
ClickHouseStatementParser.TableReferencesContext ctx) {
+ TableSegment result = (TableSegment)
visit(ctx.escapedTableReference(0));
+ if (ctx.escapedTableReference().size() > 1) {
+ for (int i = 1; i < ctx.escapedTableReference().size(); i++) {
+ result =
generateJoinTableSourceFromEscapedTableReference(ctx.escapedTableReference(i),
result);
+ }
+ }
+ return result;
+ }
+
+ private JoinTableSegment
generateJoinTableSourceFromEscapedTableReference(final
ClickHouseStatementParser.EscapedTableReferenceContext ctx, final TableSegment
tableSegment) {
+ JoinTableSegment result = new JoinTableSegment();
+ result.setStartIndex(tableSegment.getStartIndex());
+ result.setStopIndex(ctx.stop.getStopIndex());
+ result.setLeft(tableSegment);
+ result.setRight((TableSegment) visit(ctx));
+ result.setJoinType(JoinType.COMMA.name());
+ return result;
+ }
+
+ @Override
+ public ASTNode visitEscapedTableReference(final
ClickHouseStatementParser.EscapedTableReferenceContext ctx) {
+ return visit(ctx.tableReference());
+ }
+
+ @Override
+ public ASTNode visitTableReference(final
ClickHouseStatementParser.TableReferenceContext ctx) {
+ TableSegment result;
+ TableSegment left;
+ left = (TableSegment) visit(ctx.tableFactor());
+ if (!ctx.joinedTable().isEmpty()) {
+ for (ClickHouseStatementParser.JoinedTableContext each :
ctx.joinedTable()) {
+ left = visitJoinedTable(each, left);
+ }
+ }
+ result = left;
+ return result;
+ }
+
+ @Override
+ public ASTNode visitTableFactor(final
ClickHouseStatementParser.TableFactorContext ctx) {
+ if (null != ctx.subquery()) {
+ ClickHouseSelectStatement subquery = (ClickHouseSelectStatement)
visit(ctx.subquery());
+ SubquerySegment subquerySegment = new
SubquerySegment(ctx.subquery().start.getStartIndex(),
ctx.subquery().stop.getStopIndex(), subquery, getOriginalText(ctx.subquery()));
+ SubqueryTableSegment result = new
SubqueryTableSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(),
subquerySegment);
+ if (null != ctx.alias()) {
+ result.setAlias((AliasSegment) visit(ctx.alias()));
+ }
+ return result;
+ }
+ if (null != ctx.tableName()) {
+ SimpleTableSegment result = (SimpleTableSegment)
visit(ctx.tableName());
+ if (null != ctx.alias()) {
+ result.setAlias((AliasSegment) visit(ctx.alias()));
+ }
+ return result;
+ }
+ return visit(ctx.tableReferences());
+ }
+
+ private JoinTableSegment visitJoinedTable(final
ClickHouseStatementParser.JoinedTableContext ctx, final TableSegment
tableSegment) {
+ JoinTableSegment result = new JoinTableSegment();
+ result.setLeft(tableSegment);
+ result.setStartIndex(tableSegment.getStartIndex());
+ result.setStopIndex(ctx.stop.getStopIndex());
+ TableSegment right = (TableSegment) visit(ctx.tableFactor());
+ result.setRight(right);
+ result.setJoinType(getJoinType(ctx));
+ if (null != ctx.joinSpecification()) {
+ visitJoinSpecification(ctx.joinSpecification(), result);
+ }
+ return result;
+ }
+
+ private String getJoinType(final
ClickHouseStatementParser.JoinedTableContext ctx) {
+ if (null != ctx.LEFT()) {
+ return JoinType.LEFT.name();
+ } else if (null != ctx.RIGHT()) {
+ return JoinType.RIGHT.name();
+ } else if (null != ctx.INNER()) {
+ return JoinType.INNER.name();
+ } else if (null != ctx.CROSS()) {
+ return JoinType.CROSS.name();
+ }
+ return JoinType.INNER.name();
+ }
+
+ private void visitJoinSpecification(final
ClickHouseStatementParser.JoinSpecificationContext ctx, final JoinTableSegment
joinTableSource) {
+ if (null != ctx.expr()) {
+ ExpressionSegment condition = (ExpressionSegment)
visit(ctx.expr());
+ joinTableSource.setCondition(condition);
+ }
+ if (null != ctx.USING()) {
+
joinTableSource.setUsing(ctx.columnNames().columnName().stream().map(each ->
(ColumnSegment) visit(each)).collect(Collectors.toList()));
+ }
+ }
+
+ @Override
+ public ASTNode visitWhereClause(final
ClickHouseStatementParser.WhereClauseContext ctx) {
+ ExpressionSegment segment = (ExpressionSegment) visit(ctx.expr());
+ return new WhereSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), segment);
+ }
+
+ @Override
+ public ASTNode visitGroupByClause(final
ClickHouseStatementParser.GroupByClauseContext ctx) {
+ Collection<OrderByItemSegment> items = new LinkedList<>();
+ for (ClickHouseStatementParser.OrderByItemContext each :
ctx.orderByItem()) {
+ items.add((OrderByItemSegment) visit(each));
+ }
+ return new GroupBySegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), items);
+ }
+
+ @Override
+ public ASTNode visitSubquery(final SubqueryContext ctx) {
+ return visit(ctx.combineClause());
+ }
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseRLStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseRLStatementVisitor.java
new file mode 100644
index 00000000000..e23bf9ff358
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseRLStatementVisitor.java
@@ -0,0 +1,27 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.RLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+
+/**
+ * ClickHouse RL statement visitor.
+ */
+public final class ClickHouseRLStatementVisitor extends
ClickHouseStatementVisitor implements RLStatementVisitor {
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseTCLStatementVisitor.java
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseTCLStatementVisitor.java
new file mode 100644
index 00000000000..34b0cfb7b16
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/java/org/apache/shardingsphere/sql/parser/clickhouse/visitor/statement/type/ClickHouseTCLStatementVisitor.java
@@ -0,0 +1,28 @@
+/*
+ * 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.clickhouse.visitor.statement.type;
+
+import
org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor;
+import
org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor;
+
+/**
+ * ClickHouse TCL statement visitor.
+ */
+public final class ClickHouseTCLStatementVisitor extends
ClickHouseStatementVisitor implements TCLStatementVisitor {
+
+}
diff --git
a/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.api.visitor.format.SQLFormatVisitor
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.api.visitor.format.SQLFormatVisitor
new file mode 100644
index 00000000000..03a8ee23f9a
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.api.visitor.format.SQLFormatVisitor
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+
diff --git
a/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade
new file mode 100644
index 00000000000..a43f0f9fc23
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.DialectSQLParserFacade
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseParserFacade
diff --git
a/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade
new file mode 100644
index 00000000000..911e46d5f73
--- /dev/null
+++
b/parser/sql/dialect/clickhouse/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLStatementVisitorFacade
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitorFacade
diff --git a/parser/sql/dialect/pom.xml b/parser/sql/dialect/pom.xml
index 5b357da4d73..77750eb81ab 100644
--- a/parser/sql/dialect/pom.xml
+++ b/parser/sql/dialect/pom.xml
@@ -33,6 +33,7 @@
<module>oracle</module>
<module>sqlserver</module>
<module>opengauss</module>
+ <module>clickhouse</module>
</modules>
<dependencies>
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ClickHouseStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ClickHouseStatement.java
new file mode 100644
index 00000000000..3fa9bd454b8
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ClickHouseStatement.java
@@ -0,0 +1,33 @@
+/*
+ * 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.sql.dialect.statement.clickhouse;
+
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+/**
+ * ClickHouse statement.
+ */
+public interface ClickHouseStatement extends SQLStatement {
+
+ @Override
+ default DatabaseType getDatabaseType() {
+ return TypedSPILoader.getService(DatabaseType.class, "ClickHouse");
+ }
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseAlterTableStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseAlterTableStatement.java
new file mode 100644
index 00000000000..312b85dddf3
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseAlterTableStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.ddl;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse AlterTable Statement.
+ */
+public final class ClickHouseAlterTableStatement extends AlterTableStatement
implements ClickHouseStatement {
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseCreateTableStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseCreateTableStatement.java
new file mode 100644
index 00000000000..04b737026f4
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseCreateTableStatement.java
@@ -0,0 +1,41 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.ddl;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse Create Table Statement.
+ */
+@RequiredArgsConstructor
+@Getter
+@Setter
+public final class ClickHouseCreateTableStatement extends CreateTableStatement
implements ClickHouseStatement {
+
+ private SimpleTableSegment uuidClause;
+
+ private SimpleTableSegment clusterClause;
+
+ private SimpleTableSegment tableSchemaClause;
+
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseDropTableStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseDropTableStatement.java
new file mode 100644
index 00000000000..fab789ed66c
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/ddl/ClickHouseDropTableStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.ddl;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse Drop Table Statement.
+ */
+public final class ClickHouseDropTableStatement extends DropTableStatement
implements ClickHouseStatement {
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseDeleteStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseDeleteStatement.java
new file mode 100644
index 00000000000..8bb4e6a3408
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseDeleteStatement.java
@@ -0,0 +1,28 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.dml;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse delete statement.
+ */
+public class ClickHouseDeleteStatement extends DeleteStatement implements
ClickHouseStatement {
+
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseInsertStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseInsertStatement.java
new file mode 100644
index 00000000000..a9f62d66f1b
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseInsertStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.dml;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse insert statement.
+ */
+public class ClickHouseInsertStatement extends InsertStatement implements
ClickHouseStatement {
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseSelectStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseSelectStatement.java
new file mode 100644
index 00000000000..924b9d7469d
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseSelectStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.dml;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse select statement.
+ */
+public class ClickHouseSelectStatement extends SelectStatement implements
ClickHouseStatement {
+}
diff --git
a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseUpdateStatement.java
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseUpdateStatement.java
new file mode 100644
index 00000000000..5281b2b9717
--- /dev/null
+++
b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/clickhouse/dml/ClickHouseUpdateStatement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.sql.dialect.statement.clickhouse.dml;
+
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.clickhouse.ClickHouseStatement;
+
+/**
+ * ClickHouse update statement.
+ */
+public class ClickHouseUpdateStatement extends UpdateStatement implements
ClickHouseStatement {
+}