Skip to content

Commit c6c7950

Browse files
committed
[IOTDB-17635] Fix window function identity with OVER clause
1 parent 9348cb8 commit c6c7950

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBWindowFunction3IT.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ public void testSwapWindowFunctions() {
116116
DATABASE_NAME);
117117
}
118118

119+
@Test
120+
public void testSameWindowFunctionWithDifferentOrdering() {
121+
String[] expectedHeader = new String[] {"time", "device", "value", "rank_time", "rank_value"};
122+
String[] retArray =
123+
new String[] {
124+
"2021-01-01T09:05:00.000Z,d1,3.0,1,2,",
125+
"2021-01-01T09:07:00.000Z,d1,5.0,2,4,",
126+
"2021-01-01T09:09:00.000Z,d1,3.0,3,2,",
127+
"2021-01-01T09:10:00.000Z,d1,1.0,4,1,",
128+
"2021-01-01T09:08:00.000Z,d2,2.0,1,1,",
129+
"2021-01-01T09:15:00.000Z,d2,4.0,2,2,",
130+
};
131+
tableResultSetEqualTest(
132+
"SELECT *, rank() OVER (PARTITION BY device ORDER BY \"time\") AS rank_time, rank() OVER (PARTITION BY device ORDER BY value) AS rank_value FROM demo ORDER BY device, \"time\"",
133+
expectedHeader,
134+
retArray,
135+
DATABASE_NAME);
136+
}
137+
119138
@Test
120139
public void testPushDownFilterIntoWindow() {
121140
String[] expectedHeader = new String[] {"time", "device", "value", "rn"};

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/sql/ast/FunctionCall.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public <R, C> R accept(IAstVisitor<R, C> visitor, C context) {
177177
public List<Node> getChildren() {
178178
ImmutableList.Builder<Node> nodes = ImmutableList.builder();
179179
nodes.addAll(arguments);
180+
window.ifPresent(window -> nodes.add((Node) window));
180181
return nodes.build();
181182
}
182183

@@ -190,14 +191,16 @@ public boolean equals(Object obj) {
190191
}
191192
FunctionCall o = (FunctionCall) obj;
192193
return Objects.equals(name, o.name)
194+
&& Objects.equals(window, o.window)
195+
&& Objects.equals(nullTreatment, o.nullTreatment)
193196
&& Objects.equals(distinct, o.distinct)
194197
&& Objects.equals(processingMode, o.processingMode)
195198
&& Objects.equals(arguments, o.arguments);
196199
}
197200

198201
@Override
199202
public int hashCode() {
200-
return Objects.hash(name, distinct, processingMode, arguments);
203+
return Objects.hash(name, window, nullTreatment, distinct, processingMode, arguments);
201204
}
202205

203206
public enum NullTreatment {
@@ -214,6 +217,8 @@ public boolean shallowEquals(Node other) {
214217
FunctionCall otherFunction = (FunctionCall) other;
215218

216219
return name.equals(otherFunction.name)
220+
&& window.isPresent() == otherFunction.window.isPresent()
221+
&& nullTreatment.equals(otherFunction.nullTreatment)
217222
&& distinct == otherFunction.distinct
218223
&& processingMode.equals(otherFunction.processingMode);
219224
}

0 commit comments

Comments
 (0)