Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/SystemDesign/DataQuery/AlignByDeviceQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ First explain the meaning of some important fields in AlignByDevicePlan:
Before explaining the specific implementation process, a relatively complete example is given first, and the following explanation will be used in conjunction with this example.

```sql
SELECT s1, "1", *, s2, s5 FROM root.sg.d1, root.sg.* WHERE time = 1 AND s1 < 25 ALIGN BY DEVICE
SELECT s1, '1', *, s2, s5 FROM root.sg.d1, root.sg.* WHERE time = 1 AND s1 < 25 ALIGN BY DEVICE
```

Among them, the time series in the system is:
Expand Down Expand Up @@ -87,7 +87,7 @@ It splices the suffix paths obtained in the SELECT statement with the prefix pat
// See the following for an example
Set<String> measurementSetOfGivenSuffix = new LinkedHashSet<>();
// If a constant. Recording, continue to the next suffix path
if (suffixPath.startWith("'") || suffixPath.startWith("\"")) {
if (suffixPath.startWith("'"))) {
...
continue;
}
Expand Down Expand Up @@ -174,11 +174,11 @@ In the example, the result of splicing the filter conditions of device 1 is `tim

The following example summarizes the variable information calculated through this stage:

- measurement list `measurements`:`[s1, "1", s1, s2, s2, s5]`
- measurement list `measurements`:`[s1, '1', s1, s2, s2, s5]`
- measurement type `measurementTypeMap`:
- `s1 -> Exist`
- `s2 -> Exist`
- `"1" -> Constant`
- `'1' -> Constant`
- `s5 -> NonExist`
- Filter condition `deviceToFilterMap` for each device:
- `root.sg.d1 -> time = 1 AND root.sg.d1.s1 < 25`
Expand Down Expand Up @@ -213,7 +213,7 @@ The resulting header is:
| ---- | ------ | --- | --- | --- | --- | --- | --- |
| | | | | | | | |

The deduplicated `measurements` are `[s1, "1", s2, s5]`.
The deduplicated `measurements` are `[s1, '1', s2, s5]`.

### Result set generation

Expand Down
2 changes: 1 addition & 1 deletion docs/UserGuide/Concept/Data Model and Terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Single quotes are not allowed in the path. If you want to use special characters

The timeseries path is the core concept in IoTDB. A timeseries path can be thought of as the complete path of a sensor that produces the time series data. All timeseries paths in IoTDB must start with root and end with the sensor. A timeseries path can also be called a full path.

For example, if device1 of the vehicle type has a sensor named sensor1, its timeseries path can be expressed as: `root.vehicle.device1.sensor1`.
For example, if device1 of the vehicle type has a sensor named sensor1, its timeseries path can be expressed as: `root.vehicle.device1.sensor1`. Double quotes can be nested with escape characters, e.g. `root.sg.d1."s.\"t\"1"`.

> Note: The layer of timeseries paths supported by the current IoTDB must be greater than or equal to four (it will be changed to two in the future).

Expand Down
10 changes: 5 additions & 5 deletions docs/zh/SystemDesign/DataQuery/AlignByDeviceQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AlignByDevicePlan 即按设备对齐查询对应的表结构为:
在进行具体实现过程的讲解前,先给出一个覆盖较为完整的例子,下面的解释过程中将结合该示例进行说明。

```sql
SELECT s1, "1", *, s2, s5 FROM root.sg.d1, root.sg.* WHERE time = 1 AND s1 < 25 ALIGN BY DEVICE
SELECT s1, '1', *, s2, s5 FROM root.sg.d1, root.sg.* WHERE time = 1 AND s1 < 25 ALIGN BY DEVICE
```

其中,系统中的时间序列为:
Expand Down Expand Up @@ -87,7 +87,7 @@ SELECT s1, "1", *, s2, s5 FROM root.sg.d1, root.sg.* WHERE time = 1 AND s1 < 25
// 用于记录此后缀路径对应的所有 measurement,示例见下文
Set<String> measurementSetOfGivenSuffix = new LinkedHashSet<>();
// 该后缀路径为常量,记录后继续遍历下一后缀路径
if (suffixPath.startWith("'") || suffixPath.startWith("\"")) {
if (suffixPath.startWith("'")) {
...
continue;
}
Expand Down Expand Up @@ -172,11 +172,11 @@ Map<String, IExpression> concatFilterByDevice(List<String> devices,

下面用示例总结一下通过该阶段计算得到的变量信息:

- measurement 列表 `measurements`:`[s1, "1", s1, s2, s2, s5]`
- measurement 列表 `measurements`:`[s1, '1', s1, s2, s2, s5]`
- measurement 类型 `measurementTypeMap`:
- `s1 -> Exist`
- `s2 -> Exist`
- `"1" -> Constant`
- `'1' -> Constant`
- `s5 -> NonExist`
- 每个设备的过滤条件 `deviceToFilterMap`:
- `root.sg.d1 -> time = 1 AND root.sg.d1.s1 < 25`
Expand Down Expand Up @@ -211,7 +211,7 @@ private void getAlignByDeviceQueryHeaders(
| ---- | ------ | --- | --- | --- | --- | --- | --- |
| | | | | | | | |

去重后的 `measurements` 为 `[s1, "1", s2, s5]`。
去重后的 `measurements` 为 `[s1, '1', s2, s5]`。

### 结果集生成

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/UserGuide/Concept/Data Model and Terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ LayerName: Identifier | STAR

值得说明的是,在路径中,root为一个保留字符,它只允许出现在下文提到的时间序列的开头,若其他层级出现root,则无法解析,提示报错。

在路径中,不允许使用单引号。如果你想在LayerName中使用“.”等特殊字符,请使用双引号。例如,`root.sg."d.1"."s.1"`。
在路径中,不允许使用单引号。如果你想在LayerName中使用“.”等特殊字符,请使用双引号。例如,`root.sg."d.1"."s.1"`。双引号内支持使用转义符进行双引号的嵌套,如 `root.sg.d1."s.\"t\"1"`。

> 注意: storage group中的LayerName只支持数字,字母,和下划线。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static String getNodeRegByIdx(int idx, String[] nodes) {
}

/**
* @param path the path will split. ex, root.ln. note: doesn't support escape character
* @param path the path will split. ex, root.ln.
* @return string array. ex, [root, ln]
* @throws IllegalPathException if path isn't correct, the exception will throw
*/
Expand All @@ -50,6 +50,10 @@ public static String[] splitPathToDetachedPath(String path) throws IllegalPathEx
startIndex = i + 1;
} else if (path.charAt(i) == '"') {
int endIndex = path.indexOf('"', i + 1);
// if a double quotes with escape character
while (endIndex != -1 && path.charAt(endIndex - 1) == '\\') {
endIndex = path.indexOf('"', endIndex + 1);
}
if (endIndex != -1 && (endIndex == path.length() - 1 || path.charAt(endIndex + 1) == '.')) {
nodes.add(path.substring(startIndex, endIndex + 1));
i = endIndex + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,47 +327,43 @@ protected List<TSDataType> getSeriesTypes(List<PartialPath> paths) throws Metada
private PhysicalPlan transformQuery(QueryOperator queryOperator) throws QueryProcessException {
QueryPlan queryPlan;

if (queryOperator.isGroupByTime() && queryOperator.isFill()) {
queryPlan = new GroupByTimeFillPlan();
((GroupByTimeFillPlan) queryPlan).setInterval(queryOperator.getUnit());
((GroupByTimeFillPlan) queryPlan).setSlidingStep(queryOperator.getSlidingStep());
((GroupByTimeFillPlan) queryPlan).setLeftCRightO(queryOperator.isLeftCRightO());
if (!queryOperator.isLeftCRightO()) {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime() + 1);
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime() + 1);
if (queryOperator.hasAggregation()) {
if (queryOperator.isGroupByTime() && queryOperator.isFill()) {
queryPlan = new GroupByTimeFillPlan();
} else if (queryOperator.isGroupByTime()) {
queryPlan = new GroupByTimePlan();
} else {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime());
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime());
queryPlan = new AggregationPlan();
}
((GroupByTimeFillPlan) queryPlan)
((AggregationPlan) queryPlan)
.setAggregations(queryOperator.getSelectOperator().getAggregations());
for (String aggregation : queryPlan.getAggregations()) {
if (!SQLConstant.LAST_VALUE.equals(aggregation)) {
throw new QueryProcessException("Group By Fill only support last_value function");

if (queryOperator.isGroupByTime()) {
((GroupByTimePlan) queryPlan).setInterval(queryOperator.getUnit());
((GroupByTimePlan) queryPlan).setSlidingStep(queryOperator.getSlidingStep());
((GroupByTimePlan) queryPlan).setLeftCRightO(queryOperator.isLeftCRightO());
if (!queryOperator.isLeftCRightO()) {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime() + 1);
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime() + 1);
} else {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime());
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime());
}
}
((GroupByTimeFillPlan) queryPlan).setFillType(queryOperator.getFillTypes());
} else if (queryOperator.isGroupByTime()) {
queryPlan = new GroupByTimePlan();
((GroupByTimePlan) queryPlan).setInterval(queryOperator.getUnit());
((GroupByTimePlan) queryPlan).setSlidingStep(queryOperator.getSlidingStep());
((GroupByTimePlan) queryPlan).setLeftCRightO(queryOperator.isLeftCRightO());
if (!queryOperator.isLeftCRightO()) {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime() + 1);
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime() + 1);
if (queryOperator.isFill()) {
((GroupByTimeFillPlan) queryPlan).setFillType(queryOperator.getFillTypes());
for (String aggregation : queryPlan.getAggregations()) {
if (!SQLConstant.LAST_VALUE.equals(aggregation)) {
throw new QueryProcessException("Group By Fill only support last_value function");
}
}
} else {
((GroupByTimePlan) queryPlan).setStartTime(queryOperator.getStartTime());
((GroupByTimePlan) queryPlan).setEndTime(queryOperator.getEndTime());
}
((GroupByTimePlan) queryPlan)
.setAggregations(queryOperator.getSelectOperator().getAggregations());

((GroupByTimePlan) queryPlan).setLevel(queryOperator.getLevel());
if (queryOperator.getLevel() >= 0) {
for (int i = 0; i < queryOperator.getSelectOperator().getAggregations().size(); i++) {
if (!SQLConstant.COUNT
.equals(queryOperator.getSelectOperator().getAggregations().get(i))) {
throw new QueryProcessException("group by level only support count now.");
((AggregationPlan) queryPlan).setLevel(queryOperator.getLevel());
if (queryOperator.getLevel() >= 0) {
for (String aggregation : queryPlan.getAggregations()) {
if (!SQLConstant.COUNT.equals(aggregation)) {
throw new QueryProcessException("group by level only support count now.");
}
}
}
}
Expand All @@ -380,32 +376,13 @@ private PhysicalPlan transformQuery(QueryOperator queryOperator) throws QueryPro
long time = Long.parseLong(((BasicFunctionOperator) timeFilter).getValue());
((FillQueryPlan) queryPlan).setQueryTime(time);
((FillQueryPlan) queryPlan).setFillType(queryOperator.getFillTypes());
} else if (queryOperator.hasAggregation()) {
queryPlan = new AggregationPlan();
((AggregationPlan) queryPlan).setLevel(queryOperator.getLevel());
((AggregationPlan) queryPlan)
.setAggregations(queryOperator.getSelectOperator().getAggregations());
if (queryOperator.getLevel() >= 0) {
for (int i = 0; i < queryOperator.getSelectOperator().getAggregations().size(); i++) {
if (!SQLConstant.COUNT
.equals(queryOperator.getSelectOperator().getAggregations().get(i))) {
throw new QueryProcessException("group by level only support count now.");
}
}
}
} else if (queryOperator.isLastQuery()) {
queryPlan = new LastQueryPlan();
} else {
queryPlan = new RawDataQueryPlan();
}
if (queryPlan instanceof LastQueryPlan) {
// Last query result set will not be affected by alignment
if (!queryOperator.isAlignByTime()) {
throw new QueryProcessException("Disable align cannot be applied to LAST query.");
}
List<PartialPath> paths = queryOperator.getSelectedPaths();
queryPlan.setPaths(paths);
} else if (queryOperator.isAlignByDevice()) {

if (queryOperator.isAlignByDevice()) {
// below is the core realization of ALIGN_BY_DEVICE sql logic
AlignByDevicePlan alignByDevicePlan = new AlignByDevicePlan();
if (queryPlan instanceof GroupByTimePlan) {
Expand Down Expand Up @@ -444,7 +421,7 @@ private PhysicalPlan transformQuery(QueryOperator queryOperator) throws QueryPro
Set<String> measurementSetOfGivenSuffix = new LinkedHashSet<>();

// if const measurement
if (suffixPath.getMeasurement().startsWith("'") || suffixPath.getMeasurement().startsWith("\"")) {
if (suffixPath.getMeasurement().startsWith("'")) {
measurements.add(suffixPath.getMeasurement());
measurementTypeMap.put(suffixPath.getMeasurement(), MeasurementType.Constant);
continue;
Expand Down Expand Up @@ -573,9 +550,13 @@ private PhysicalPlan transformQuery(QueryOperator queryOperator) throws QueryPro

queryPlan = alignByDevicePlan;
} else {
queryPlan.setAlignByTime(queryOperator.isAlignByTime());
List<PartialPath> paths = queryOperator.getSelectedPaths();
queryPlan.setPaths(paths);
// Last query result set will not be affected by alignment
if (queryPlan instanceof LastQueryPlan && !queryOperator.isAlignByTime()) {
throw new QueryProcessException("Disable align cannot be applied to LAST query.");
}
queryPlan.setAlignByTime(queryOperator.isAlignByTime());

// transform filter operator to expression
FilterOperator filterOperator = queryOperator.getFilterOperator();
Expand Down
Loading