Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support load data and load xml sql bind and add test case. #34177

Merged
merged 46 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
03ae5ed
Support GroupConcat sql for aggregating multiple shards(#33797)
Nov 26, 2024
c0552d1
Check Style fix(#33797)
Nov 26, 2024
c256c10
Check Style fix(#33797)
Nov 26, 2024
812f813
spotless fix (#33797)
Nov 26, 2024
05ccc96
unit test fix (#33797)
Nov 26, 2024
05eaecb
spotless fix (#33797)
YaoFly Nov 26, 2024
07209e2
group_concat distinct compatible (#33797)
Nov 27, 2024
879b107
group_concat distinct compatible (#33797)
Nov 27, 2024
8feb644
unit test fix for distinct group_concat (#33797)
Nov 27, 2024
2201278
Merge branch 'apache:master' into master
YaoFly Nov 27, 2024
96d9bef
Merge branch 'apache:master' into master
YaoFly Nov 27, 2024
3efdfb6
Merge branch 'apache:master' into master
YaoFly Nov 28, 2024
f0b2f9c
e2e test for group_concat (#33797)
Dec 2, 2024
4b028ec
e2e test for group_concat (#33797)
Dec 2, 2024
9fb37fa
Merge remote-tracking branch 'origin/master'
Dec 2, 2024
91278c4
code format (#33797)
Dec 2, 2024
1f9a97f
e2e test (#33797)
Dec 2, 2024
c2411b8
e2e test (#33797)
Dec 2, 2024
ded3745
e2e test (#33797)
Dec 2, 2024
c080d71
remove useless code(#33797)
Dec 2, 2024
c96dd07
code optimization (#33797)
Dec 4, 2024
576cc33
sql parse unit test (#33797)
Dec 4, 2024
bd11a26
RELEASE-NOTES.md updated(#33797)
Dec 4, 2024
a6fe2b2
Merge branch 'master' into master
YaoFly Dec 4, 2024
370e53d
Merge branch 'apache:master' into master
YaoFly Dec 5, 2024
e9ee8e4
Code Optimization (#33797)
Dec 5, 2024
f01105d
Merge branch 'apache:master' into master
YaoFly Dec 10, 2024
fdcdf04
Support GroupConcat sql for aggregating multiple shards in opengauss …
Dec 10, 2024
cf7acbe
doris parse unit test fix (#33797)
Dec 10, 2024
022e56e
spotless fix (#33797)
Dec 10, 2024
315183a
Update RELEASE-NOTES.md
strongduanmu Dec 10, 2024
bdc9023
Merge branch 'apache:master' into master
YaoFly Dec 12, 2024
b60b453
Add DBCOMPATIBILITY 'B' parameter to opengauss database (#33992)
Dec 15, 2024
e7d0326
Merge remote-tracking branch 'origin/master'
Dec 15, 2024
702a318
Merge branch 'apache:master' into master
YaoFly Dec 15, 2024
ec7ea74
Add DBCOMPATIBILITY 'B' parameter to opengauss database for dbtbl_wit…
Dec 16, 2024
0a26e50
Merge remote-tracking branch 'origin/master'
Dec 16, 2024
31f9f11
add openGauss test case for group_concat. (#33992)
Dec 16, 2024
878d16b
Merge branch 'apache:master' into master
YaoFly Dec 24, 2024
b9760da
Merge branch 'apache:master' into master
YaoFly Dec 26, 2024
fea4fa2
Merge branch 'apache:master' into master
YaoFly Dec 26, 2024
abcda97
Merge branch 'apache:master' into master
YaoFly Dec 27, 2024
160682c
Support load data and load xml sql bind and add test case.
Dec 26, 2024
0ab8948
Merge remote-tracking branch 'origin/master' into load-data-load-xml
Dec 27, 2024
4bfc98c
code fix
Dec 27, 2024
9fa3141
code fix
Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class ShardingLoadDataSupportedCheckerTest {

@Test
void assertCheckWithSingleTable() {
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement)));
}

@Test
void assertCheckWithShardingTable() {
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class ShardingLoadXmlSupportedCheckerTest {

@Test
void assertCheckWithSingleTable() {
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement)));
}

@Test
void assertCheckWithShardingTable() {
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/

package org.apache.shardingsphere.infra.binder.engine.statement.dml;

import com.cedarsoftware.util.CaseInsensitiveMap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadDataStatement;

/**
* Load data statement binder.
*/
public class LoadDataStatementBinder implements SQLStatementBinder<LoadDataStatement> {
YaoFly marked this conversation as resolved.
Show resolved Hide resolved

@Override
public LoadDataStatement bind(final LoadDataStatement sqlStatement, final SQLStatementBinderContext binderContext) {
LoadDataStatement result = copy(sqlStatement);
Multimap<CaseInsensitiveMap.CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create();
result.setTableSegment(SimpleTableSegmentBinder.bind(sqlStatement.getTableSegment(), binderContext, tableBinderContexts));
return result;
}

@SneakyThrows(ReflectiveOperationException.class)
private static LoadDataStatement copy(final LoadDataStatement sqlStatement) {
LoadDataStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
result.getVariableNames().addAll(sqlStatement.getVariableNames());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -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.
*/

package org.apache.shardingsphere.infra.binder.engine.statement.dml;

import com.cedarsoftware.util.CaseInsensitiveMap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadXMLStatement;

/**
* Load XML statement binder.
*/
public class LoadXMLStatementBinder implements SQLStatementBinder<LoadXMLStatement> {
YaoFly marked this conversation as resolved.
Show resolved Hide resolved

@Override
public LoadXMLStatement bind(final LoadXMLStatement sqlStatement, final SQLStatementBinderContext binderContext) {
LoadXMLStatement result = copy(sqlStatement);
Multimap<CaseInsensitiveMap.CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create();
result.setTableSegment(SimpleTableSegmentBinder.bind(sqlStatement.getTableSegment(), binderContext, tableBinderContexts));
return result;
}

@SneakyThrows(ReflectiveOperationException.class)
private static LoadXMLStatement copy(final LoadXMLStatement sqlStatement) {
LoadXMLStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
result.getVariableNames().addAll(sqlStatement.getVariableNames());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.shardingsphere.infra.binder.engine.statement.dml.InsertStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.dml.UpdateStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.dml.LoadDataStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.dml.LoadXMLStatementBinder;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.CopyStatement;
Expand All @@ -32,6 +34,8 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadDataStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadXMLStatement;

/**
* DML statement bind engine.
Expand Down Expand Up @@ -68,6 +72,12 @@ public DMLStatement bind(final DMLStatement statement) {
if (statement instanceof CopyStatement) {
return new CopyStatementBinder().bind((CopyStatement) statement, binderContext);
}
if (statement instanceof LoadDataStatement) {
return new LoadDataStatementBinder().bind((LoadDataStatement) statement, binderContext);
}
if (statement instanceof LoadXMLStatement) {
return new LoadXMLStatementBinder().bind((LoadXMLStatement) statement, binderContext);
}
return statement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ public ASTNode visitLoadStatement(final LoadStatementContext ctx) {

@Override
public ASTNode visitLoadDataStatement(final LoadDataStatementContext ctx) {
return new DorisLoadDataStatement((SimpleTableSegment) visit(ctx.tableName()));
DorisLoadDataStatement result = new DorisLoadDataStatement();
result.setTableSegment((SimpleTableSegment) visit(ctx.tableName()));
return result;
}

@Override
public ASTNode visitLoadXmlStatement(final LoadXmlStatementContext ctx) {
return new DorisLoadXMLStatement((SimpleTableSegment) visit(ctx.tableName()));
DorisLoadXMLStatement result = new DorisLoadXMLStatement();
result.setTableSegment((SimpleTableSegment) visit(ctx.tableName()));
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ public ASTNode visitLoadStatement(final LoadStatementContext ctx) {

@Override
public ASTNode visitLoadDataStatement(final LoadDataStatementContext ctx) {
return new MySQLLoadDataStatement((SimpleTableSegment) visit(ctx.tableName()));
MySQLLoadDataStatement result = new MySQLLoadDataStatement();
result.setTableSegment((SimpleTableSegment) visit(ctx.tableName()));
return result;
}

@Override
public ASTNode visitLoadXmlStatement(final LoadXmlStatementContext ctx) {
return new MySQLLoadXMLStatement((SimpleTableSegment) visit(ctx.tableName()));
MySQLLoadXMLStatement result = new MySQLLoadXMLStatement();
result.setTableSegment((SimpleTableSegment) visit(ctx.tableName()));
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
package org.apache.shardingsphere.sql.parser.statement.core.statement.dml;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;

/**
* Load data statement.
*/
@RequiredArgsConstructor
@Getter
@Setter
public abstract class LoadDataStatement extends AbstractSQLStatement implements DMLStatement {

private final SimpleTableSegment tableSegment;
private SimpleTableSegment tableSegment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
package org.apache.shardingsphere.sql.parser.statement.core.statement.dml;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;

/**
* Load xml statement.
*/
@RequiredArgsConstructor
@Setter
@Getter
public abstract class LoadXMLStatement extends AbstractSQLStatement implements DMLStatement {

private final SimpleTableSegment tableSegment;
private SimpleTableSegment tableSegment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@

package org.apache.shardingsphere.sql.parser.statement.doris.dml;

import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadDataStatement;
import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement;

/**
* Doris load data statement.
*/
public final class DorisLoadDataStatement extends LoadDataStatement implements DorisStatement {

public DorisLoadDataStatement(final SimpleTableSegment tableSegment) {
super(tableSegment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@

package org.apache.shardingsphere.sql.parser.statement.doris.dml;

import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadXMLStatement;
import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement;

/**
* Doris load xml statement.
*/
public final class DorisLoadXMLStatement extends LoadXMLStatement implements DorisStatement {

public DorisLoadXMLStatement(final SimpleTableSegment tableSegment) {
super(tableSegment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@

package org.apache.shardingsphere.sql.parser.statement.mysql.dml;

import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadDataStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.MySQLStatement;

/**
* MySQL load data statement.
*/
public final class MySQLLoadDataStatement extends LoadDataStatement implements MySQLStatement {

public MySQLLoadDataStatement(final SimpleTableSegment tableSegment) {
super(tableSegment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@

package org.apache.shardingsphere.sql.parser.statement.mysql.dml;

import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadXMLStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.MySQLStatement;

/**
* MySQL load xml statement.
*/
public final class MySQLLoadXMLStatement extends LoadXMLStatement implements MySQLStatement {

public MySQLLoadXMLStatement(final SimpleTableSegment tableSegment) {
super(tableSegment);
}
}
29 changes: 29 additions & 0 deletions test/it/binder/src/test/resources/cases/dml/load-data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.
-->

<sql-parser-test-cases>
<load-data sql-case-id="load_data_into_table_with_schema_name">
<table name="t_order" start-index="45" stop-index="60">
<owner name="foo_db_1" start-index="45" stop-index="52"/>
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="foo_db_1"/>
</table-bound>
</table>
</load-data>
</sql-parser-test-cases>
29 changes: 29 additions & 0 deletions test/it/binder/src/test/resources/cases/dml/load-xml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.
-->

<sql-parser-test-cases>
<load-xml sql-case-id="load_xml_into_table_with_schema_name">
<table name="t_order" start-index="44" stop-index="59">
<owner name="foo_db_1" start-index="44" stop-index="51"/>
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="foo_db_1"/>
</table-bound>
</table>
</load-xml>
</sql-parser-test-cases>
21 changes: 21 additions & 0 deletions test/it/binder/src/test/resources/sqls/dml/load-data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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.
-->

<sql-cases>
<sql-case id="load_data_into_table_with_schema_name" value="LOAD DATA INFILE '/temp/test.txt' INTO TABLE foo_db_1.t_order" db-types="MySQL,Doris" />
</sql-cases>
Loading
Loading