forked from IGinX-THU/IGinX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sql): auto increment sequence & alter key (IGinX-THU#458)
1. 增加生成自增列的语法 2. 增加KEY列的操作语法,包括:将特定列升级成KEY列,将KEY列降级成普通列 详见https://oxlh5mrwi0.feishu.cn/docx/Gd8pd1aMDoNMIexXBPJcaea6n0g
- Loading branch information
Showing
27 changed files
with
859 additions
and
39 deletions.
There are no files selected for viewing
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
90 changes: 90 additions & 0 deletions
90
...va/cn/edu/tsinghua/iginx/engine/physical/memory/execute/stream/AddSequenceLazyStream.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,90 @@ | ||
/* | ||
* IGinX - the polystore system with high performance | ||
* Copyright (C) Tsinghua University | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package cn.edu.tsinghua.iginx.engine.physical.memory.execute.stream; | ||
|
||
import cn.edu.tsinghua.iginx.engine.physical.exception.PhysicalException; | ||
import cn.edu.tsinghua.iginx.engine.shared.data.read.Field; | ||
import cn.edu.tsinghua.iginx.engine.shared.data.read.Header; | ||
import cn.edu.tsinghua.iginx.engine.shared.data.read.Row; | ||
import cn.edu.tsinghua.iginx.engine.shared.data.read.RowStream; | ||
import cn.edu.tsinghua.iginx.engine.shared.operator.AddSequence; | ||
import cn.edu.tsinghua.iginx.thrift.DataType; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AddSequenceLazyStream extends UnaryLazyStream { | ||
|
||
private Header header; | ||
|
||
private final AddSequence addSequence; | ||
|
||
private final List<Long> cur; | ||
|
||
private final List<Long> increments; | ||
|
||
private final int oldSize; | ||
|
||
private final int newSize; | ||
|
||
private final int sequenceSize; | ||
|
||
public AddSequenceLazyStream(AddSequence addSequence, RowStream stream) throws PhysicalException { | ||
super(stream); | ||
this.addSequence = addSequence; | ||
this.cur = new ArrayList<>(addSequence.getStartList()); | ||
this.increments = new ArrayList<>(addSequence.getIncrementList()); | ||
this.header = getHeader(); | ||
this.oldSize = stream.getHeader().getFieldSize(); | ||
this.newSize = header.getFieldSize(); | ||
this.sequenceSize = newSize - oldSize; | ||
} | ||
|
||
@Override | ||
public Header getHeader() throws PhysicalException { | ||
if (header == null) { | ||
Header header = stream.getHeader(); | ||
List<Field> targetFields = new ArrayList<>(stream.getHeader().getFields()); | ||
addSequence | ||
.getColumns() | ||
.forEach(column -> targetFields.add(new Field(column, DataType.LONG))); | ||
this.header = new Header(header.getKey(), targetFields); | ||
} | ||
return header; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() throws PhysicalException { | ||
return stream.hasNext(); | ||
} | ||
|
||
@Override | ||
public Row next() throws PhysicalException { | ||
if (!hasNext()) { | ||
throw new IllegalStateException("row stream doesn't have more data!"); | ||
} | ||
|
||
Row row = stream.next(); | ||
Object[] values = new Object[newSize]; | ||
System.arraycopy(row.getValues(), 0, values, 0, oldSize); | ||
for (int i = 0; i < sequenceSize; i++) { | ||
values[oldSize + i] = cur.get(i); | ||
cur.set(i, cur.get(i) + increments.get(i)); | ||
} | ||
return new Row(header, row.getKey(), values); | ||
} | ||
} |
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.