-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][mysql-service] Add autoincrement id to mysql protocol OkPacket
- Loading branch information
Showing
10 changed files
with
316 additions
and
25 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
dingo-calcite/src/main/java/io/dingodb/calcite/operation/ShowLastInsertIdOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class ShowLastInsertIdOperation implements QueryOperation { | ||
Connection connection; | ||
|
||
public ShowLastInsertIdOperation(Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
@Override | ||
public Iterator getIterator() { | ||
try { | ||
List<Object[]> variableValList = new ArrayList<>(); | ||
String value = connection.getClientInfo().getProperty("last_insert_id", "0"); | ||
variableValList.add(new Object[]{value}); | ||
return variableValList.iterator(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> columns() { | ||
List<String> columns = new ArrayList<>(); | ||
columns.add("last_insert_id()"); | ||
return columns; | ||
} | ||
} |
182 changes: 182 additions & 0 deletions
182
dingo-calcite/src/main/java/io/dingodb/calcite/rel/AutoIncrementShuttle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
* 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.rel; | ||
|
||
import io.dingodb.calcite.DingoTable; | ||
import io.dingodb.common.table.ColumnDefinition; | ||
import org.apache.calcite.linq4j.Ord; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.RelShuttle; | ||
import org.apache.calcite.rel.core.TableFunctionScan; | ||
import org.apache.calcite.rel.core.TableScan; | ||
import org.apache.calcite.rel.logical.LogicalAggregate; | ||
import org.apache.calcite.rel.logical.LogicalCalc; | ||
import org.apache.calcite.rel.logical.LogicalCorrelate; | ||
import org.apache.calcite.rel.logical.LogicalExchange; | ||
import org.apache.calcite.rel.logical.LogicalFilter; | ||
import org.apache.calcite.rel.logical.LogicalIntersect; | ||
import org.apache.calcite.rel.logical.LogicalJoin; | ||
import org.apache.calcite.rel.logical.LogicalMatch; | ||
import org.apache.calcite.rel.logical.LogicalMinus; | ||
import org.apache.calcite.rel.logical.LogicalProject; | ||
import org.apache.calcite.rel.logical.LogicalSort; | ||
import org.apache.calcite.rel.logical.LogicalTableModify; | ||
import org.apache.calcite.rel.logical.LogicalUnion; | ||
import org.apache.calcite.rel.logical.LogicalValues; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
public class AutoIncrementShuttle implements RelShuttle { | ||
|
||
public static AutoIncrementShuttle INSTANCE = new AutoIncrementShuttle(); | ||
|
||
protected final Deque<RelNode> stack = new ArrayDeque<>(); | ||
|
||
@Override | ||
public RelNode visit(TableScan scan) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(TableFunctionScan scan) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalValues values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalFilter filter) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalCalc calc) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalProject project) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalJoin join) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalCorrelate correlate) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalUnion union) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalIntersect intersect) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalMinus minus) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalAggregate aggregate) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalMatch match) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalSort sort) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalExchange exchange) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(LogicalTableModify modify) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RelNode visit(RelNode other) { | ||
if (other instanceof DingoTableModify) { | ||
DingoTableModify modify = (DingoTableModify) other; | ||
if (modify.isInsert()) { | ||
DingoTable table = modify.getTable().unwrap(DingoTable.class); | ||
boolean hasAutoIncrement = false; | ||
for (ColumnDefinition columnDefinition : table.getTableDefinition().getColumns()) { | ||
if (columnDefinition.isAutoIncrement()) { | ||
hasAutoIncrement = true; | ||
} | ||
} | ||
if (hasAutoIncrement && other.getInputs().size() > 0) { | ||
RelNode values = visitChildren(other); | ||
if (values instanceof DingoValues) { | ||
DingoValues dingoValues = (DingoValues) values; | ||
dingoValues.setHasAutoIncrement(true); | ||
return dingoValues; | ||
} | ||
} | ||
} | ||
return null; | ||
} else if (other instanceof DingoValues) { | ||
return other; | ||
} else { | ||
if (other.getInputs().size() > 0) { | ||
return visitChildren(other); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
protected RelNode visitChildren(RelNode rel) { | ||
for (Ord<RelNode> input : Ord.zip(rel.getInputs())) { | ||
rel = visitChild(rel, input.e); | ||
} | ||
return rel; | ||
} | ||
|
||
protected RelNode visitChild(RelNode parent, RelNode child) { | ||
stack.push(parent); | ||
try { | ||
RelNode child2 = child.accept(this); | ||
if (child2 instanceof DingoValues) { | ||
return child2; | ||
} | ||
return null; | ||
} finally { | ||
stack.pop(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.