1
0

[HUDI-1659] Basic Implement Of Spark Sql Support For Hoodie (#2645)

Main functions:
Support create table for hoodie.
Support CTAS.
Support Insert for hoodie. Including dynamic partition and static partition insert.
Support MergeInto for hoodie.
Support DELETE
Support UPDATE
Both support spark2 & spark3 based on DataSourceV1.

Main changes:
Add sql parser for spark2.
Add HoodieAnalysis for sql resolve and logical plan rewrite.
Add commands implementation for CREATE TABLE、INSERT、MERGE INTO & CTAS.
In order to push down the update&insert logical to the HoodieRecordPayload for MergeInto, I make same change to the
HoodieWriteHandler and other related classes.
1、Add the inputSchema for parser the incoming record. This is because the inputSchema for MergeInto is different from writeSchema as there are some transforms in the update& insert expression.
2、Add WRITE_SCHEMA to HoodieWriteConfig to pass the write schema for merge into.
3、Pass properties to HoodieRecordPayload#getInsertValue to pass the insert expression and table schema.


Verify this pull request
Add TestCreateTable for test create hoodie tables and CTAS.
Add TestInsertTable for test insert hoodie tables.
Add TestMergeIntoTable for test merge hoodie tables.
Add TestUpdateTable for test update hoodie tables.
Add TestDeleteTable for test delete hoodie tables.
Add TestSqlStatement for test supported ddl/dml currently.
This commit is contained in:
pengzhiwei
2021-06-08 14:24:32 +08:00
committed by GitHub
parent cf83f10f5b
commit f760ec543e
86 changed files with 7346 additions and 255 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,107 @@
/*
* 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 HoodieSqlBase;
import SqlBase;
singleStatement
: statement EOF
;
statement
: mergeInto #mergeIntoTable
| updateTableStmt #updateTable
| deleteTableStmt #deleteTable
| .*? #passThrough
;
mergeInto
: MERGE INTO target=tableIdentifier tableAlias
USING (source=tableIdentifier | '(' subquery = query ')') tableAlias
mergeCondition
matchedClauses*
notMatchedClause*
;
mergeCondition
: ON condition=booleanExpression
;
matchedClauses
: deleteClause
| updateClause
;
notMatchedClause
: insertClause
;
deleteClause
: WHEN MATCHED (AND deleteCond=booleanExpression)? THEN deleteAction
| WHEN deleteCond=booleanExpression THEN deleteAction
;
updateClause
: WHEN MATCHED (AND updateCond=booleanExpression)? THEN updateAction
| WHEN updateCond=booleanExpression THEN updateAction
;
insertClause
: WHEN NOT MATCHED (AND insertCond=booleanExpression)? THEN insertAction
| WHEN insertCond=booleanExpression THEN insertAction
;
deleteAction
: DELETE
;
updateAction
: UPDATE SET ASTERISK
| UPDATE SET assignmentList
;
insertAction
: INSERT ASTERISK
| INSERT '(' columns=qualifiedNameList ')' VALUES '(' expression (',' expression)* ')'
;
assignmentList
: assignment (',' assignment)*
;
assignment
: key=qualifiedName EQ value=expression
;
qualifiedNameList
: qualifiedName (',' qualifiedName)*
;
updateTableStmt
: UPDATE tableIdentifier SET assignmentList (WHERE where=booleanExpression)?
;
deleteTableStmt
: DELETE FROM tableIdentifier (WHERE where=booleanExpression)?
;
PRIMARY: 'PRIMARY';
KEY: 'KEY';
MERGE: 'MERGE';
MATCHED: 'MATCHED';
UPDATE: 'UPDATE';