Skip to content

Commit db89602

Browse files
committed
Simple format and fix UT bugs.
1 parent fa450f1 commit db89602

23 files changed

+630
-212
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/GroupedTopNBuilder.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
import org.apache.tsfile.read.common.block.TsBlock;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/GroupedTopNRowNumberAccumulator.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
@@ -47,15 +66,15 @@ public long sizeOf() {
4766
}
4867

4968
public int findFirstPositionToAdd(
50-
TsBlock newPage,
69+
TsBlock newTsBlock,
5170
int groupCount,
5271
int[] groupIds,
5372
TsBlockWithPositionComparator comparator,
54-
RowReferencePageManager pageManager) {
73+
RowReferenceTsBlockManager tsBlockManager) {
5574
int currentTotalGroups = groupIdToHeapBuffer.getTotalGroups();
5675
groupIdToHeapBuffer.allocateGroupIfNeeded(groupCount);
5776

58-
for (int position = 0; position < newPage.getPositionCount(); position++) {
77+
for (int position = 0; position < newTsBlock.getPositionCount(); position++) {
5978
int groupId = groupIds[position];
6079
if (groupId >= currentTotalGroups || calculateRootRowNumber(groupId) < topN) {
6180
return position;
@@ -65,9 +84,9 @@ public int findFirstPositionToAdd(
6584
return position;
6685
}
6786
long rowId = heapNodeBuffer.getRowId(heapRootNodeIndex);
68-
TsBlock rightPage = pageManager.getPage(rowId);
69-
int rightPosition = pageManager.getPosition(rowId);
70-
if (comparator.compareTo(newPage, position, rightPage, rightPosition) < 0) {
87+
TsBlock rightTsBlock = tsBlockManager.getTsBlock(rowId);
88+
int rightPosition = tsBlockManager.getPosition(rowId);
89+
if (comparator.compareTo(newTsBlock, position, rightTsBlock, rightPosition) < 0) {
7190
return position;
7291
}
7392
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/GroupedTopNRowNumberBuilder.java

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.LongBigArray;
@@ -26,7 +45,7 @@ public class GroupedTopNRowNumberBuilder implements GroupedTopNBuilder {
2645
private final boolean produceRowNumber;
2746
private final int[] groupByChannels;
2847
private final GroupByHash groupByHash;
29-
private final RowReferencePageManager pageManager = new RowReferencePageManager();
48+
private final RowReferenceTsBlockManager tsBlockManager = new RowReferenceTsBlockManager();
3049
private final GroupedTopNRowNumberAccumulator groupedTopNRowNumberAccumulator;
3150
private final TsBlockWithPositionComparator comparator;
3251

@@ -46,14 +65,14 @@ public GroupedTopNRowNumberBuilder(
4665
this.groupedTopNRowNumberAccumulator =
4766
new GroupedTopNRowNumberAccumulator(
4867
(leftRowId, rightRowId) -> {
49-
TsBlock leftTsBlock = pageManager.getPage(leftRowId);
50-
int leftPosition = pageManager.getPosition(leftRowId);
51-
TsBlock rightTsBlock = pageManager.getPage(rightRowId);
52-
int rightPosition = pageManager.getPosition(rightRowId);
68+
TsBlock leftTsBlock = tsBlockManager.getTsBlock(leftRowId);
69+
int leftPosition = tsBlockManager.getPosition(leftRowId);
70+
TsBlock rightTsBlock = tsBlockManager.getTsBlock(rightRowId);
71+
int rightPosition = tsBlockManager.getPosition(rightRowId);
5372
return comparator.compareTo(leftTsBlock, leftPosition, rightTsBlock, rightPosition);
5473
},
5574
topN,
56-
pageManager::dereference);
75+
tsBlockManager::dereference);
5776
}
5877

5978
@Override
@@ -73,20 +92,20 @@ public Iterator<TsBlock> getResult() {
7392
public long getEstimatedSizeInBytes() {
7493
return INSTANCE_SIZE
7594
+ groupByHash.getEstimatedSize()
76-
+ pageManager.sizeOf()
95+
+ tsBlockManager.sizeOf()
7796
+ groupedTopNRowNumberAccumulator.sizeOf();
7897
}
7998

8099
private void processTsBlock(TsBlock newTsBlock, int groupCount, int[] groupIds) {
81100
int firstPositionToAdd =
82101
groupedTopNRowNumberAccumulator.findFirstPositionToAdd(
83-
newTsBlock, groupCount, groupIds, comparator, pageManager);
102+
newTsBlock, groupCount, groupIds, comparator, tsBlockManager);
84103
if (firstPositionToAdd < 0) {
85104
return;
86105
}
87106

88-
try (RowReferencePageManager.LoadCursor loadCursor =
89-
pageManager.add(newTsBlock, firstPositionToAdd)) {
107+
try (RowReferenceTsBlockManager.LoadCursor loadCursor =
108+
tsBlockManager.add(newTsBlock, firstPositionToAdd)) {
90109
for (int position = firstPositionToAdd;
91110
position < newTsBlock.getPositionCount();
92111
position++) {
@@ -96,11 +115,11 @@ private void processTsBlock(TsBlock newTsBlock, int groupCount, int[] groupIds)
96115
}
97116
}
98117

99-
pageManager.compactIfNeeded();
118+
tsBlockManager.compactIfNeeded();
100119
}
101120

102121
private class ResultIterator extends AbstractIterator<TsBlock> {
103-
private final TsBlockBuilder pageBuilder;
122+
private final TsBlockBuilder tsBlockBuilder;
104123
private final int groupIdCount = groupByHash.getGroupCount();
105124
private int currentGroupId = -1;
106125
private final LongBigArray rowIdOutput = new LongBigArray();
@@ -113,50 +132,50 @@ private class ResultIterator extends AbstractIterator<TsBlock> {
113132
if (produceRowNumber) {
114133
sourceTypesBuilders.add(TSDataType.INT64);
115134
}
116-
pageBuilder = new TsBlockBuilder(sourceTypesBuilders.build());
135+
tsBlockBuilder = new TsBlockBuilder(sourceTypesBuilders.build());
117136
}
118137

119138
@Override
120139
protected TsBlock computeNext() {
121-
pageBuilder.reset();
122-
while (!pageBuilder.isFull()) {
140+
tsBlockBuilder.reset();
141+
while (!tsBlockBuilder.isFull()) {
123142
while (currentIndexInGroup >= currentGroupSize) {
124143
if (currentGroupId + 1 >= groupIdCount) {
125-
if (pageBuilder.isEmpty()) {
144+
if (tsBlockBuilder.isEmpty()) {
126145
return endOfData();
127146
}
128-
return pageBuilder.build(
129-
new RunLengthEncodedColumn(TIME_COLUMN_TEMPLATE, pageBuilder.getPositionCount()));
147+
return tsBlockBuilder.build(
148+
new RunLengthEncodedColumn(TIME_COLUMN_TEMPLATE, tsBlockBuilder.getPositionCount()));
130149
}
131150
currentGroupId++;
132151
currentGroupSize = groupedTopNRowNumberAccumulator.drainTo(currentGroupId, rowIdOutput);
133152
currentIndexInGroup = 0;
134153
}
135154

136155
long rowId = rowIdOutput.get(currentIndexInGroup);
137-
TsBlock page = pageManager.getPage(rowId);
138-
int position = pageManager.getPosition(rowId);
156+
TsBlock tsBlock = tsBlockManager.getTsBlock(rowId);
157+
int position = tsBlockManager.getPosition(rowId);
139158
for (int i = 0; i < sourceTypes.size(); i++) {
140-
ColumnBuilder builder = pageBuilder.getColumnBuilder(i);
141-
Column column = page.getColumn(i);
159+
ColumnBuilder builder = tsBlockBuilder.getColumnBuilder(i);
160+
Column column = tsBlock.getColumn(i);
142161
builder.write(column, position);
143162
}
144163
if (produceRowNumber) {
145-
ColumnBuilder builder = pageBuilder.getColumnBuilder(sourceTypes.size());
164+
ColumnBuilder builder = tsBlockBuilder.getColumnBuilder(sourceTypes.size());
146165
builder.writeLong(currentGroupId + 1);
147166
}
148-
pageBuilder.declarePosition();
167+
tsBlockBuilder.declarePosition();
149168
currentIndexInGroup++;
150169

151170
// Deference the row for hygiene, but no need to compact them at this point
152-
pageManager.dereference(rowId);
171+
tsBlockManager.dereference(rowId);
153172
}
154173

155-
if (pageBuilder.isEmpty()) {
174+
if (tsBlockBuilder.isEmpty()) {
156175
return endOfData();
157176
}
158-
return pageBuilder.build(
159-
new RunLengthEncodedColumn(TIME_COLUMN_TEMPLATE, pageBuilder.getPositionCount()));
177+
return tsBlockBuilder.build(
178+
new RunLengthEncodedColumn(TIME_COLUMN_TEMPLATE, tsBlockBuilder.getPositionCount()));
160179
}
161180
}
162181
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/IdRegistry.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
import org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation.grouped.array.IntArrayFIFOQueue;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/RowIdComparisonStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
public interface RowIdComparisonStrategy {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/RowIdHashStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
/** Hash strategy that evaluates over row IDs */

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/RowReference.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.iotdb.db.queryengine.execution.operator;
221

322
/**

0 commit comments

Comments
 (0)