未验证 提交 7b1f5c4e 编写于 作者: X Xiangwei Wei 提交者: GitHub

[IOTDB-2415] Slimit wrong result data in align by device

上级 30e5aa29
......@@ -304,6 +304,52 @@ public class IoTDBAlignByDeviceIT {
}
}
@Test
public void selectSlimitTest2() {
String[] retArray =
new String[] {
"1,root.vehicle.d0,null,101,1101,",
};
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
boolean hasResultSet =
statement.execute(
"select * from root.vehicle.d0 limit 1 slimit 3 soffset 1 align by device");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
List<Integer> actualIndexToExpectedIndexList =
checkHeader(
resultSetMetaData,
"Time,Device,s4,s0,s1",
new int[] {
Types.TIMESTAMP, Types.VARCHAR, Types.BOOLEAN, Types.INTEGER, Types.BIGINT,
});
int cnt = 0;
while (resultSet.next()) {
String[] expectedStrings = retArray[cnt].split(",");
StringBuilder expectedBuilder = new StringBuilder();
StringBuilder actualBuilder = new StringBuilder();
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
actualBuilder.append(resultSet.getString(i)).append(",");
expectedBuilder
.append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)])
.append(",");
}
Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString());
cnt++;
}
Assert.assertEquals(1, cnt);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
@Test
public void selectSlimitTest() {
String[] retArray =
......
......@@ -243,8 +243,7 @@ public class QueryOperator extends Operator {
// remove stars in fromPaths and get deviceId with deduplication
List<PartialPath> devices = removeStarsInDeviceWithUnique(fromComponent.getPrefixPaths());
List<ResultColumn> resultColumns =
convertSpecialClauseValues(alignByDevicePlan, selectComponent.getResultColumns());
List<ResultColumn> resultColumns = selectComponent.getResultColumns();
List<String> aggregationFuncs = selectComponent.getAggregationFunctions();
// to record result measurement columns
List<String> measurements = new ArrayList<>();
......@@ -305,10 +304,17 @@ public class QueryOperator extends Operator {
// therefore the final measurements is [s1,s2,s3,s1].
measurements.addAll(measurementSetOfGivenSuffix);
}
if (specialClauseComponent.hasSlimit()
&& measurements.size()
>= specialClauseComponent.getSeriesLimit()
+ specialClauseComponent.getSeriesOffset()) {
break;
}
}
// assigns to alignByDevicePlan
alignByDevicePlan.setMeasurements(measurements);
alignByDevicePlan.setMeasurements(convertSpecialClauseValues(alignByDevicePlan, measurements));
alignByDevicePlan.setPaths(paths);
alignByDevicePlan.setAggregations(aggregations);
alignByDevicePlan.setMeasurementInfoMap(measurementInfoMap);
......@@ -345,16 +351,16 @@ public class QueryOperator extends Operator {
}
}
private List<ResultColumn> convertSpecialClauseValues(
QueryPlan queryPlan, List<ResultColumn> resultColumns) throws QueryProcessException {
private List<String> convertSpecialClauseValues(QueryPlan queryPlan, List<String> measurements)
throws QueryProcessException {
convertSpecialClauseValues(queryPlan);
// sLimit trim on the measurementColumnList
if (specialClauseComponent.hasSlimit()) {
int seriesSLimit = specialClauseComponent.getSeriesLimit();
int seriesOffset = specialClauseComponent.getSeriesOffset();
return slimitTrimColumn(resultColumns, seriesSLimit, seriesOffset);
return slimitTrimColumn(measurements, seriesSLimit, seriesOffset);
}
return resultColumns;
return measurements;
}
private List<PartialPath> removeStarsInDeviceWithUnique(List<PartialPath> paths)
......@@ -391,10 +397,9 @@ public class QueryOperator extends Operator {
return initialMeasurement;
}
private List<ResultColumn> slimitTrimColumn(
List<ResultColumn> resultColumns, int seriesLimit, int seriesOffset)
throws QueryProcessException {
int size = resultColumns.size();
private List<String> slimitTrimColumn(
List<String> measurements, int seriesLimit, int seriesOffset) throws QueryProcessException {
int size = measurements.size();
// check parameter range
if (seriesOffset >= size) {
......@@ -408,7 +413,7 @@ public class QueryOperator extends Operator {
}
// trim seriesPath list
return new ArrayList<>(resultColumns.subList(seriesOffset, endPosition));
return new ArrayList<>(measurements.subList(seriesOffset, endPosition));
}
// e.g. translate "select * from root.ln.d1, root.ln.d2 where s1 < 20 AND s2 > 10" to
......
......@@ -30,6 +30,7 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.expression.IExpression;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
......@@ -68,9 +69,14 @@ public class AlignByDevicePlan extends QueryPlan {
public void deduplicate(PhysicalGenerator physicalGenerator) {
Set<String> pathWithAggregationSet = new LinkedHashSet<>();
List<String> deduplicatedAggregations = new ArrayList<>();
HashSet<String> measurements = new HashSet<>(getMeasurements());
for (int i = 0; i < paths.size(); i++) {
PartialPath path = paths.get(i);
String aggregation = aggregations != null ? aggregations.get(i) : null;
String measurementWithAggregation = getMeasurementStrWithAggregation(path, aggregation);
if (!measurements.contains(measurementWithAggregation)) {
continue;
}
String pathStrWithAggregation = getPathStrWithAggregation(path, aggregation);
if (!pathWithAggregationSet.contains(pathStrWithAggregation)) {
pathWithAggregationSet.add(pathStrWithAggregation);
......@@ -209,6 +215,14 @@ public class AlignByDevicePlan extends QueryPlan {
this.setOperatorType(Operator.OperatorType.AGGREGATION);
}
private String getMeasurementStrWithAggregation(PartialPath path, String aggregation) {
String measurement = path.getMeasurement();
if (aggregation != null) {
measurement = aggregation + "(" + measurement + ")";
}
return measurement;
}
private String getPathStrWithAggregation(PartialPath path, String aggregation) {
String initialPath = path.getFullPath();
if (aggregation != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册