Skip to content

Commit

Permalink
[fix][dingo-calcite] Add lock operation for transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and JYcz committed Nov 22, 2023
1 parent 2945cab commit 44cf1f2
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 13 deletions.
28 changes: 17 additions & 11 deletions dingo-calcite/src/main/java/io/dingodb/calcite/DingoParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
import com.google.common.collect.ImmutableList;
import io.dingodb.calcite.grammar.ddl.SqlAnalyze;
import io.dingodb.calcite.grammar.ddl.SqlBeginTx;
import io.dingodb.calcite.grammar.ddl.SqlBlock;
import io.dingodb.calcite.grammar.ddl.SqlCommit;
import io.dingodb.calcite.grammar.ddl.SqlLockBlock;
import io.dingodb.calcite.grammar.ddl.SqlLockTable;
import io.dingodb.calcite.grammar.ddl.SqlRollback;
import io.dingodb.calcite.grammar.ddl.SqlSetPassword;
import io.dingodb.calcite.grammar.ddl.SqlUnLockBlock;
import io.dingodb.calcite.grammar.ddl.SqlUnLockTable;
import io.dingodb.calcite.grammar.dml.SqlExecute;
import io.dingodb.calcite.grammar.dml.SqlPrepare;
import io.dingodb.calcite.grammar.dql.SqlDesc;
Expand Down Expand Up @@ -76,6 +81,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -88,6 +94,7 @@
@Slf4j
public class DingoParser {
private static Map<String, String> sensitiveKey = new HashMap();

static {
sensitiveKey.put(".\"USER\"", ".USER");
}
Expand Down Expand Up @@ -241,17 +248,16 @@ protected static boolean compatibleMysql(SqlNode sqlNode) {
return false;
} else if (sqlNode instanceof SqlSetOption && !(sqlNode instanceof SqlSetPassword)) {
return true;
} else if (sqlNode instanceof SqlPrepare) {
return true;
} else if (sqlNode instanceof SqlExecute) {
return true;
} else if (sqlNode instanceof SqlAnalyze) {
return true;
} else if (sqlNode instanceof SqlBeginTx) {
return true;
} else if (sqlNode instanceof SqlCommit) {
return true;
} else if (sqlNode instanceof SqlRollback) {
} else if (sqlNode instanceof SqlPrepare
|| sqlNode instanceof SqlExecute
|| sqlNode instanceof SqlAnalyze
|| sqlNode instanceof SqlBeginTx
|| sqlNode instanceof SqlCommit
|| sqlNode instanceof SqlRollback
|| sqlNode instanceof SqlLockTable
|| sqlNode instanceof SqlLockBlock
|| sqlNode instanceof SqlUnLockTable
|| sqlNode instanceof SqlUnLockBlock) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.dingodb.calcite.grammar.ddl;

import org.apache.calcite.sql.SqlDdl;
import lombok.Getter;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlOperator;
Expand All @@ -28,7 +28,8 @@

public class SqlLockBlock extends SqlLock {

List<SqlBlock> sqlBlockList;
@Getter
private List<SqlBlock> sqlBlockList;

private static final SqlOperator OPERATOR =
new SqlSpecialOperator("LOCK BLOCK", SqlKind.OTHER_DDL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.dingodb.calcite.grammar.ddl;

import lombok.Getter;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlSpecialOperator;
Expand All @@ -26,6 +27,7 @@

public class SqlUnLockBlock extends SqlUnLock {

@Getter
List<SqlBlock> sqlUnBlockList;

private static final SqlOperator OPERATOR =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed 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 io.dingodb.calcite.operation;

import io.dingodb.calcite.grammar.ddl.SqlBlock;

import java.sql.Connection;
import java.util.List;

public class LockBlockOperation implements DdlOperation {
private Connection connection;
private List<SqlBlock> sqlBlockList;

public LockBlockOperation(Connection connection, List<SqlBlock> sqlBlockList) {
this.connection = connection;
this.sqlBlockList = sqlBlockList;
}

@Override
public void execute() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed 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 io.dingodb.calcite.operation;

import java.sql.Connection;
import java.util.List;

public class LockTableOperation implements DdlOperation {

private Connection connection;

private List<String> tableList;

public LockTableOperation(Connection connection, List<String> tableList) {
this.connection = connection;
this.tableList = tableList;
}

@Override
public void execute() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import io.dingodb.calcite.grammar.ddl.SqlAnalyze;
import io.dingodb.calcite.grammar.ddl.SqlBeginTx;
import io.dingodb.calcite.grammar.ddl.SqlCommit;
import io.dingodb.calcite.grammar.ddl.SqlLockBlock;
import io.dingodb.calcite.grammar.ddl.SqlLockTable;
import io.dingodb.calcite.grammar.ddl.SqlRollback;
import io.dingodb.calcite.grammar.ddl.SqlUnLockBlock;
import io.dingodb.calcite.grammar.ddl.SqlUnLockTable;
import io.dingodb.calcite.grammar.dql.SqlDesc;
import io.dingodb.calcite.grammar.dql.SqlNextAutoIncrement;
import io.dingodb.calcite.grammar.dql.SqlShowColumns;
Expand Down Expand Up @@ -132,6 +136,18 @@ public static Optional<Operation> convert(SqlNode sqlNode, Connection connection
} else if (sqlNode instanceof SqlBeginTx) {
SqlBeginTx sqlBeginTx = (SqlBeginTx) sqlNode;
return Optional.of(new StartTransactionOperation(connection, sqlBeginTx.pessimistic));
} else if (sqlNode instanceof SqlLockTable) {
SqlLockTable sqlLockTable = (SqlLockTable) sqlNode;
return Optional.of(new LockTableOperation(connection, sqlLockTable.tableList));
} else if (sqlNode instanceof SqlLockBlock) {
SqlLockBlock sqlLockBlock = (SqlLockBlock) sqlNode;
return Optional.of(new LockBlockOperation(connection, sqlLockBlock.getSqlBlockList()));
} else if (sqlNode instanceof SqlUnLockTable) {
SqlUnLockTable sqlUnLockTable = (SqlUnLockTable) sqlNode;
return Optional.of(new UnlockTableOperation(connection, sqlUnLockTable.tableList));
} else if (sqlNode instanceof SqlUnLockBlock) {
SqlUnLockBlock sqlUnLockBlock = (SqlUnLockBlock) sqlNode;
return Optional.of(new UnlockBlockOperation(connection, sqlUnLockBlock.getSqlUnBlockList()));
} else {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed 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 io.dingodb.calcite.operation;

import io.dingodb.calcite.grammar.ddl.SqlBlock;

import java.sql.Connection;
import java.util.List;

public class UnlockBlockOperation implements DdlOperation {

private Connection connection;
private List<SqlBlock> sqlBlockList;

public UnlockBlockOperation(Connection connection, List<SqlBlock> sqlBlockList) {
this.connection = connection;
this.sqlBlockList = sqlBlockList;
}

@Override
public void execute() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed 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 io.dingodb.calcite.operation;

import java.sql.Connection;
import java.util.List;

public class UnlockTableOperation implements DdlOperation {

private Connection connection;

private List<String> tableList;

public UnlockTableOperation(Connection connection, List<String> tableList) {
this.connection = connection;
this.tableList = tableList;
}

@Override
public void execute() {

}
}

0 comments on commit 44cf1f2

Please sign in to comment.