JackieTien97 commented on code in PR #15735:
URL: https://github.com/apache/iotdb/pull/15735#discussion_r2176509369
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/process/last/LastQueryNode.java:
##########
@@ -46,31 +59,100 @@ public class LastQueryNode extends MultiChildProcessNode {
// if children contains LastTransformNode, this variable is only used in
distribute plan
private boolean containsLastTransformNode;
+ private Map<IMeasurementSchema, Integer> measurementSchema2IdxMap;
+ // All LastSeriesSourceNode share this structure
+ private List<IMeasurementSchema> globalMeasurementSchemaList;
+
public LastQueryNode(
PlanNodeId id, @Nullable Ordering timeseriesOrdering, boolean
containsLastTransformNode) {
super(id);
this.timeseriesOrdering = timeseriesOrdering;
this.containsLastTransformNode = containsLastTransformNode;
+ this.measurementSchema2IdxMap = new HashMap<>();
+ this.globalMeasurementSchemaList = new ArrayList<>();
}
public LastQueryNode(
PlanNodeId id,
- List<PlanNode> children,
@Nullable Ordering timeseriesOrdering,
- boolean containsLastTransformNode) {
- super(id, children);
+ boolean containsLastTransformNode,
+ List<IMeasurementSchema> globalMeasurementSchemaList) {
+ super(id);
this.timeseriesOrdering = timeseriesOrdering;
this.containsLastTransformNode = containsLastTransformNode;
+ this.globalMeasurementSchemaList = globalMeasurementSchemaList;
+ }
+
+ public long addDeviceLastQueryScanNode(
+ PlanNodeId id,
+ PartialPath devicePath,
+ boolean aligned,
+ List<IMeasurementSchema> measurementSchemas,
+ String outputViewPath) {
+ List<Integer> idxList = new ArrayList<>(measurementSchemas.size());
+ for (IMeasurementSchema measurementSchema : measurementSchemas) {
+ int idx =
+ measurementSchema2IdxMap.computeIfAbsent(
+ measurementSchema,
+ key -> {
+ this.globalMeasurementSchemaList.add(key);
+ return globalMeasurementSchemaList.size() - 1;
+ });
+ idxList.add(idx);
+ }
+ LastQueryScanNode scanNode =
+ new LastQueryScanNode(
+ id, devicePath, aligned, idxList, outputViewPath,
globalMeasurementSchemaList);
+ children.add(scanNode);
+ return scanNode.getMemorySize();
+ }
+
+ public void sort() {
+ if (timeseriesOrdering == null) {
+ return;
+ }
+ children.sort(
+ Comparator.comparing(
+ child -> {
+ String sortKey = "";
+ if (child instanceof LastQueryScanNode) {
+ sortKey = ((LastQueryScanNode) child).getOutputSymbolForSort();
+ } else if (child instanceof LastQueryTransformNode) {
+ sortKey = ((LastQueryTransformNode)
child).getOutputSymbolForSort();
+ }
+ return sortKey;
+ }));
+ if (timeseriesOrdering.equals(Ordering.DESC)) {
+ Collections.reverse(children);
+ }
+ }
+
+ public void setGlobalMeasurementSchemaList(List<IMeasurementSchema>
globalMeasurementSchemaList) {
+ this.globalMeasurementSchemaList = globalMeasurementSchemaList;
+ }
+
+ public List<IMeasurementSchema> getGlobalMeasurementSchemaList() {
+ return globalMeasurementSchemaList;
+ }
+
+ public void setMeasurementSchema2IdxMap(
+ Map<IMeasurementSchema, Integer> measurementSchema2IdxMap) {
+ this.measurementSchema2IdxMap = measurementSchema2IdxMap;
+ }
+
+ public long getMemorySizeOfSharedStructures() {
+ return RamUsageEstimator.shallowSizeOf(this.globalMeasurementSchemaList)
+ +
RamUsageEstimator.sizeOfObjectArray(globalMeasurementSchemaList.size());
Review Comment:
```suggestion
return
RamUsageEstimator.sizeOfCollection(this.globalMeasurementSchemaList, 0);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]