Skip to content

Commit 59eb9bb

Browse files
authored
Fix explicit time query process in TreeModel
1 parent b2cdbe0 commit 59eb9bb

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/maxby/IoTDBMaxByAlignedSeriesIT.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import org.apache.iotdb.it.env.EnvFactory;
2323

2424
import org.junit.BeforeClass;
25+
import org.junit.Test;
2526

2627
import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
28+
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
2729

2830
public class IoTDBMaxByAlignedSeriesIT extends IoTDBMaxByIT {
2931
protected static final String[] ALIGNED_DATASET =
@@ -60,6 +62,7 @@ public class IoTDBMaxByAlignedSeriesIT extends IoTDBMaxByIT {
6062
"INSERT INTO root.db.d2(timestamp,y1,y2,y3,y4,y5,y6) values(12, 8, 8, 8, 8, false, \"4\")",
6163
"INSERT INTO root.db.d2(timestamp,x1,x2,x3,x4,x5,x6) values(13, 4, 4, 4, 4, false, \"4\")",
6264
"INSERT INTO root.db.d2(timestamp,y1,y2,y3,y4,y5,y6) values(13, 8, 8, 8, 8, false, \"4\")",
65+
"insert into root.sg.d1(time,s1,s2) values(1,1,1);",
6366
};
6467

6568
@BeforeClass
@@ -68,4 +71,21 @@ public static void setUp() throws Exception {
6871
EnvFactory.getEnv().initClusterEnvironment();
6972
prepareData(ALIGNED_DATASET);
7073
}
74+
75+
@Test
76+
public void maxMinByTimeTest() {
77+
String[] expectedHeader =
78+
new String[] {"Device", "max_by(Time, s1 + 1)", "min_by(Time, s1 + 1)"};
79+
String[] retArray = new String[] {"root.sg.d1,1,1,"};
80+
resultSetEqualTest(
81+
"select max_by(time, s1+1), min_by(time, s1+1) from root.sg.* align by device",
82+
expectedHeader,
83+
retArray);
84+
85+
expectedHeader = new String[] {"Device", "max_by(Time, s1)", "min_by(Time, s1)"};
86+
resultSetEqualTest(
87+
"select max_by(time, s1), min_by(time, s1) from root.sg.* where s1>0 align by device",
88+
expectedHeader,
89+
retArray);
90+
}
7191
}

integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/maxby/IoTDBMaxByIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class IoTDBMaxByIT {
111111
"INSERT INTO root.db.d2(timestamp,y1,y2,y3,y4,y5,y6) values(12, 9, 9, 9, 9, false, \"1\")",
112112
"INSERT INTO root.db.d2(timestamp,x1,x2,x3,x4,x5,x6) values(13, 4, 4, 4, 4, false, \"4\")",
113113
"INSERT INTO root.db.d2(timestamp,y1,y2,y3,y4,y5,y6) values(13, 9, 9, 9, 9, false, \"1\")",
114+
"insert into root.sg.d1(time,s1,s2) values(1,1,1);",
114115
"flush"
115116
};
116117

@@ -487,6 +488,21 @@ public void testMaxByWithGroupByLevel() {
487488
}
488489
}
489490

491+
@Test
492+
public void maxMinByTimeTest() {
493+
String[] expectedHeader =
494+
new String[] {"max_by(Time, root.sg.d1.s1 + 1)", "min_by(Time, root.sg.d1.s1 + 1)"};
495+
String[] retArray = new String[] {"1,1,"};
496+
resultSetEqualTest(
497+
"select max_by(time, s1+1), min_by(time, s1+1) from root.sg.*", expectedHeader, retArray);
498+
499+
expectedHeader = new String[] {"max_by(Time, root.sg.d1.s1)", "min_by(Time, root.sg.d1.s1)"};
500+
resultSetEqualTest(
501+
"select max_by(time, s1), min_by(time, s1) from root.sg.* where s1>0",
502+
expectedHeader,
503+
retArray);
504+
}
505+
490506
/**
491507
* @return yInput -> expectedHeader
492508
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public TsBlock next() throws Exception {
6868
}
6969
Column[] valueColumns = new Column[remainingColumnIndexList.size()];
7070
for (int i = 0; i < remainingColumnIndexList.size(); i++) {
71-
valueColumns[i] = input.getColumn(remainingColumnIndexList.get(i));
71+
int index = remainingColumnIndexList.get(i);
72+
valueColumns[i] = index == -1 ? input.getTimeColumn() : input.getColumn(index);
7273
}
7374
return new TsBlock(input.getPositionCount(), input.getTimeColumn(), valueColumns);
7475
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ public Operator visitProject(ProjectNode node, LocalExecutionPlanContext context
606606
List<Integer> remainingColumnIndexList = new ArrayList<>();
607607
for (String outputColumnName : outputColumnNames) {
608608
int index = inputColumnNames.indexOf(outputColumnName);
609-
if (index < 0) {
609+
if (index < 0 && !outputColumnName.equals(TIMESTAMP_EXPRESSION_STRING)) {
610610
throw new IllegalStateException(
611611
String.format("Cannot find column [%s] in child's output", outputColumnName));
612612
}
@@ -3219,6 +3219,10 @@ private Map<String, List<InputLocation>> makeLayout(List<PlanNode> children) {
32193219
.add(new InputLocation(tsBlockIndex, -1));
32203220
int valueColumnIndex = 0;
32213221
for (String columnName : childNode.getOutputColumnNames()) {
3222+
if (columnName.equals(TIMESTAMP_EXPRESSION_STRING)) {
3223+
valueColumnIndex++;
3224+
continue;
3225+
}
32223226
outputMappings
32233227
.computeIfAbsent(columnName, key -> new ArrayList<>())
32243228
.add(new InputLocation(tsBlockIndex, valueColumnIndex));

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/input/QueryDataSetInputLayer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public Column[] current() {
129129

130130
@Override
131131
public TSDataType[] getDataTypes() {
132+
if (columnIndex == dataTypes.length) {
133+
return new TSDataType[] {TSDataType.INT64};
134+
}
132135
return new TSDataType[] {dataTypes[columnIndex]};
133136
}
134137

0 commit comments

Comments
 (0)