Skip to content
New issue

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

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

Already on GitHub? # to your account

Support drop index sql bind and add test case. #34165

Merged
merged 42 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
91bff1d
Support drop index sql bind and add test case.
Dec 26, 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
@@ -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.
*/

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.DropIndexStatement;

/**
* Drop index statement binder.
*/
public class DropIndexStatementBinder implements SQLStatementBinder<DropIndexStatement> {

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

@SneakyThrows(ReflectiveOperationException.class)
private static DropIndexStatement copy(final DropIndexStatement sqlStatement) {
DropIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance();
sqlStatement.getSimpleTable().ifPresent(result::setSimpleTable);
sqlStatement.getAlgorithmType().ifPresent(result::setAlgorithmType);
sqlStatement.getLockTable().ifPresent(result::setLockTable);
result.setIfExists(sqlStatement.isIfExists());
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 @@ -25,6 +25,7 @@
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateTableStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CursorStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.DropTableStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.DropIndexStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.RenameTableStatementBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.ddl.TruncateStatementBinder;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand All @@ -36,6 +37,7 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CursorStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.RenameTableStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.TruncateStatement;

Expand Down Expand Up @@ -83,6 +85,9 @@ public DDLStatement bind(final DDLStatement statement) {
if (statement instanceof TruncateStatement) {
return new TruncateStatementBinder().bind((TruncateStatement) statement, binderContext);
}
if (statement instanceof DropIndexStatement) {
return new DropIndexStatementBinder().bind((DropIndexStatement) statement, binderContext);
}
return statement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public ASTNode visitAlterIndex(final AlterIndexContext ctx) {

@Override
public ASTNode visitDropIndex(final DropIndexContext ctx) {
SQLServerDropIndexStatement result = new SQLServerDropIndexStatement(null != ctx.ifExists());
SQLServerDropIndexStatement result = new SQLServerDropIndexStatement();
result.setIfExists(null != ctx.ifExists());
result.getIndexes().add((IndexSegment) visit(ctx.indexName()));
result.setSimpleTable((SimpleTableSegment) visit(ctx.tableName()));
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public Optional<SimpleTableSegment> getSimpleTable() {
return Optional.empty();
}

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

/**
* Judge whether contains exist clause or not.
*
Expand All @@ -54,6 +62,14 @@ public boolean isIfExists() {
return false;
}

/**
* Set if exists or not.
*
* @param ifExists if exists or not
*/
public void setIfExists(final boolean ifExists) {
}

/**
* Get algorithm type.
*
Expand All @@ -63,6 +79,14 @@ public Optional<AlgorithmTypeSegment> getAlgorithmType() {
return Optional.empty();
}

/**
* Set algorithm type.
*
* @param algorithmTypeSegment algorithm type
*/
public void setAlgorithmType(final AlgorithmTypeSegment algorithmTypeSegment) {
}

/**
* Get lock table segment.
*
Expand All @@ -71,4 +95,12 @@ public Optional<AlgorithmTypeSegment> getAlgorithmType() {
public Optional<LockTableSegment> getLockTable() {
return Optional.empty();
}

/**
* Set lock table segment.
*
* @param lockTableSegment lock table segment
*/
public void setLockTable(final LockTableSegment lockTableSegment) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@Setter
public final class SQLServerDropIndexStatement extends DropIndexStatement implements SQLServerStatement {

private final boolean ifExists;
private boolean ifExists;

private SimpleTableSegment simpleTable;

Expand Down
49 changes: 49 additions & 0 deletions test/it/binder/src/test/resources/cases/ddl/drop-index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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>
<drop-index sql-case-id="drop_index">
<index name="idx_user_id" start-index="11" stop-index="21"/>
<table name="t_order" start-index="26" stop-index="32">
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="foo_db_1"/>
</table-bound>
</table>
</drop-index>
<drop-index sql-case-id="drop_index_for_sqlserver">
<index name="idx_user_id" start-index="11" stop-index="21"/>
<table name="t_order" start-index="26" stop-index="32">
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="dbo"/>
</table-bound>
</table>
</drop-index>
<drop-index sql-case-id="drop_index_with_lock_algorithm">
<index name="idx_user_id" start-index="11" stop-index="21"/>
<table name="t_order" start-index="26" stop-index="32">
<table-bound>
<original-database name="foo_db_1"/>
<original-schema name="foo_db_1"/>
</table-bound>
</table>
<lock-option type="SHARED" start-index="40" stop-index="50"/>
<algorithm-option type="COPY" start-index="52" stop-index="65"/>
</drop-index>
</sql-parser-test-cases>
23 changes: 23 additions & 0 deletions test/it/binder/src/test/resources/sqls/ddl/drop-index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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="drop_index" value="DROP INDEX idx_user_id ON t_order" db-types="MySQL,Doris" />
<sql-case id="drop_index_for_sqlserver" value="DROP INDEX idx_user_id ON t_order" db-types="SQLServer" />
<sql-case id="drop_index_with_lock_algorithm" value="DROP INDEX idx_user_id ON t_order LOCK=SHARED ALGORITHM=COPY" db-types="MySQL,Doris" />
</sql-cases>
Loading