Skip to content

Commit

Permalink
[IOTDB-4319] move transform above the DevieView and fix the case sens…
Browse files Browse the repository at this point in the history
…itive issue (apache#7308)
  • Loading branch information
Wei-hao-Li authored Sep 18, 2022
1 parent a28329e commit f140313
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void selectDifferentSeriesWithValueFilterWithoutCacheTest() {
"103,root.vehicle.d0,99,",
"104,root.vehicle.d0,90,",
"105,root.vehicle.d0,99,",
"946684800000,root.vehicle.d0,null",
"946684800000,root.vehicle.d0,null"
};

try (Connection connection = EnvFactory.getEnv().getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
import static org.apache.iotdb.itbase.constant.TestConstant.avg;
import static org.apache.iotdb.itbase.constant.TestConstant.count;
import static org.apache.iotdb.itbase.constant.TestConstant.lastValue;
import static org.apache.iotdb.itbase.constant.TestConstant.sum;

@RunWith(IoTDBTestRunner.class)
Expand Down Expand Up @@ -260,4 +261,54 @@ public void sameConstantTest() {
expectedHeader,
retArray);
}

@Test
public void caseSensitiveHavingTest() {
String[] expectedHeader =
new String[] {
TIMESTAMP_STR,
lastValue("root.test.sg5.s1"),
lastValue("root.test.sg1.s1"),
lastValue("root.test.sg2.s1"),
};
String[] retArray =
new String[] {
"1,true,true,true,", "5,null,true,true,", "7,null,true,true,", "9,null,true,true,"
};
resultSetEqualTest(
"select last_value(s1) from root.** "
+ "GROUP BY ([1,11),2ms) "
+ "Having LAST_VALUE(s2) > 0 ",
expectedHeader,
retArray);

expectedHeader = new String[] {TIMESTAMP_STR, lastValue("root.test.*.s1")};
retArray = new String[] {"1,true,", "5,true,", "7,true,", "9,true,"};
resultSetEqualTest(
"select last_value(s1) from root.** "
+ "GROUP BY ([1,11),2ms), level=1 "
+ "Having LAST_VALUE(s2) > 0 ",
expectedHeader,
retArray);

expectedHeader = new String[] {TIMESTAMP_STR, "Device", lastValue("s1")};
retArray =
new String[] {
"1,root.test.sg1,true,",
"5,root.test.sg1,true,",
"7,root.test.sg1,true,",
"9,root.test.sg1,true,",
"1,root.test.sg2,true,",
"5,root.test.sg2,true,",
"7,root.test.sg2,true,",
"9,root.test.sg2,true,"
};
resultSetEqualTest(
"select last_value(s1) from root.** "
+ "GROUP BY ([1,11),2ms) "
+ "Having LAST_VALUE(s2) > 0 "
+ "align by device",
expectedHeader,
retArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public class Analysis {

private Expression queryFilter;

private Expression havingExpression;

// map from grouped path name to list of input aggregation in `GROUP BY LEVEL` clause
private Map<Expression, Set<Expression>> groupByLevelExpressions;

Expand All @@ -100,6 +98,10 @@ public class Analysis {
// Query Analysis (used in ALIGN BY DEVICE)
/////////////////////////////////////////////////////////////////////////////////////////////////

// used to planTransform after planDeviceView
Set<Expression> transformInput;
Set<Expression> transformOutput;

// map from device name to series/aggregation under this device
private Map<String, Set<Expression>> deviceToSourceExpressions;

Expand All @@ -115,9 +117,6 @@ public class Analysis {
// map from device name to query filter under this device
private Map<String, Expression> deviceToQueryFilter;

// map from device name to havingExpression under this device
private Map<String, Expression> deviceToHavingExpression;

// e.g. [s1,s2,s3] is query, but [s1, s3] exists in device1, then device1 -> [1, 3], s1 is 1 but
// not 0 because device is the first column
private Map<String, List<Integer>> deviceToMeasurementIndexesMap;
Expand All @@ -133,6 +132,8 @@ public class Analysis {
// indicate is there a value filter
private boolean hasValueFilter = false;

private Expression havingExpression;

// true if nested expressions and UDFs exist in aggregation function
private boolean isHasRawDataInputAggregation;

Expand Down Expand Up @@ -310,14 +311,6 @@ public void setHavingExpression(Expression havingExpression) {
this.havingExpression = havingExpression;
}

public Map<String, Expression> getDeviceToHavingExpression() {
return deviceToHavingExpression;
}

public void setDeviceToHavingExpression(Map<String, Expression> deviceTohavingExpression) {
this.deviceToHavingExpression = deviceTohavingExpression;
}

public void setGroupByTimeParameter(GroupByTimeParameter groupByTimeParameter) {
this.groupByTimeParameter = groupByTimeParameter;
}
Expand Down Expand Up @@ -371,6 +364,22 @@ public void setTransformExpressions(Set<Expression> transformExpressions) {
this.transformExpressions = transformExpressions;
}

public Set<Expression> getTransformInput() {
return transformInput;
}

public void setTransformInput(Set<Expression> transformInput) {
this.transformInput = transformInput;
}

public Set<Expression> getTransformOutput() {
return transformOutput;
}

public void setTransformOutput(Set<Expression> transformOutput) {
this.transformOutput = transformOutput;
}

public Map<String, Set<Expression>> getDeviceToSourceExpressions() {
return deviceToSourceExpressions;
}
Expand Down
Loading

0 comments on commit f140313

Please sign in to comment.