Skip to content

Commit

Permalink
Support alter index sql bind and add test case (#34160)
Browse files Browse the repository at this point in the history
* Support GroupConcat sql for aggregating multiple shards(#33797)

* Check Style fix(#33797)

* Check Style fix(#33797)

* spotless fix (#33797)

* unit test fix  (#33797)

* spotless fix (#33797)

* group_concat distinct compatible  (#33797)

* group_concat distinct compatible  (#33797)

* unit test fix for distinct group_concat  (#33797)

* e2e test for group_concat  (#33797)

* e2e test for group_concat  (#33797)

* code format  (#33797)

* e2e test  (#33797)

* e2e test  (#33797)

* e2e test  (#33797)

* remove useless code(#33797)

* code optimization (#33797)

* sql parse unit test (#33797)

* RELEASE-NOTES.md updated(#33797)

* Code Optimization (#33797)

* Support GroupConcat sql for aggregating multiple shards in opengauss and doris database(#33797)

* doris parse unit test fix (#33797)

* spotless fix (#33797)

* Update RELEASE-NOTES.md

* Add DBCOMPATIBILITY 'B' parameter to opengauss database (#33992)

* Add DBCOMPATIBILITY 'B' parameter to opengauss database for dbtbl_with_readwrite_splitting and  readwrite_splitting scenarios(#33992)

* add openGauss test case for group_concat. (#33992)

* Support alter index sql bind and add test case. (#34029)

* code fix

* spotless

* code fix

---------

Co-authored-by: yaofly <[email protected]>
Co-authored-by: Zhengqiang Duan <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2024
1 parent 5be4af4 commit ad02d16
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.ddl;

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.ddl.AlterIndexStatement;

/**
* Alter index statement binder.
*/
public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> {

@Override
public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) {
if (!sqlStatement.getSimpleTable().isPresent()) {
return sqlStatement;
}
AlterIndexStatement result = copy(sqlStatement);
Multimap<CaseInsensitiveMap.CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create();
result.setSimpleTable(SimpleTableSegmentBinder.bind(sqlStatement.getSimpleTable().get(), binderContext, tableBinderContexts));
return result;
}

@SneakyThrows(ReflectiveOperationException.class)
private static AlterIndexStatement copy(final AlterIndexStatement sqlStatement) {
AlterIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
sqlStatement.getIndex().ifPresent(result::setIndex);
sqlStatement.getSimpleTable().ifPresent(result::setSimpleTable);
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 @@ -19,6 +19,7 @@

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.AlterIndexStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.AlterTableStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateIndexStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateTableStatementBinder;
Expand All @@ -28,6 +29,7 @@
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.TruncateStatementBinder;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement;
Expand Down Expand Up @@ -75,6 +77,9 @@ public DDLStatement bind(final DDLStatement statement) {
if (statement instanceof CreateIndexStatement) {
return new CreateIndexStatementBinder().bind((CreateIndexStatement) statement, binderContext);
}
if (statement instanceof AlterIndexStatement) {
return new AlterIndexStatementBinder().bind((AlterIndexStatement) statement, binderContext);
}
if (statement instanceof TruncateStatement) {
return new TruncateStatementBinder().bind((TruncateStatement) statement, binderContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public Optional<SimpleTableSegment> getSimpleTable() {
return Optional.empty();
}

/**
* Set simple table segment.
*
* @param simpleTableSegment simple table segment
*/
public void setSimpleTable(final SimpleTableSegment simpleTableSegment) {
}

/**
* Get rename index segment.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/

package org.apache.shardingsphere.test.it.sql.binder.dialect.sqlserver;

import org.apache.shardingsphere.test.it.sql.binder.SQLBinderIT;
import org.apache.shardingsphere.test.it.sql.binder.SQLBinderITSettings;

@SQLBinderITSettings("SQLServer")
class SQLServerBinderIT extends SQLBinderIT {
}
30 changes: 30 additions & 0 deletions test/it/binder/src/test/resources/cases/ddl/alter-index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>
<alter-index sql-case-id="alter_index_with_schema">
<index name="idx_user_id" start-index="12" stop-index="22"/>
<table name="t_order" start-index="27" stop-index="37">
<owner name="dbo" start-index="27" stop-index="29"/>
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="dbo"/>
</table-bound>
</table>
</alter-index>
</sql-parser-test-cases>
21 changes: 21 additions & 0 deletions test/it/binder/src/test/resources/sqls/ddl/alter-index.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="alter_index_with_schema" value="ALTER INDEX idx_user_id ON dbo.t_order REBUILD" db-types="SQLServer" />
</sql-cases>

0 comments on commit ad02d16

Please sign in to comment.