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
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,35 @@ public Map<String, AggregateResult> getAggPathByLevel() throws QueryProcessExcep
return levelAggPaths;
}

@Override
public void setAlignByTime(boolean align) throws QueryProcessException {
if (!align) {
throw new QueryProcessException(
getOperatorType().name() + " doesn't support disable align clause.");
}
}

@Override
public String getColumnForReaderFromPath(PartialPath path, int pathIndex) {
String columnForReader = super.getColumnForReaderFromPath(path, pathIndex);
if (!path.isTsAliasExists()) {
columnForReader = this.getAggregations().get(pathIndex) + "(" + columnForReader + ")";
}
return columnForReader;
}

@Override
public String getColumnForDisplay(String columnForReader, int pathIndex)
throws IllegalPathException {
String columnForDisplay = columnForReader;
if (level >= 0) {
PartialPath path = paths.get(pathIndex);
String aggregatePath =
path.isMeasurementAliasExists()
? FilePathUtils.generatePartialPathByLevel(path.getFullPathWithAlias(), level)
: FilePathUtils.generatePartialPathByLevel(path.toString(), level);
columnForDisplay = aggregations.get(pathIndex) + "(" + aggregatePath + ")";
}
return columnForDisplay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void setFillType(Map<TSDataType, IFill> fillType) {
this.fillType = fillType;
}

@Override
public void setAlignByTime(boolean align) throws QueryProcessException {
if (!align) {
throw new QueryProcessException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iotdb.db.qp.physical.crud;

import org.apache.iotdb.db.exception.metadata.IllegalPathException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.PartialPath;
import org.apache.iotdb.db.qp.logical.Operator;
Expand Down Expand Up @@ -111,4 +112,18 @@ public boolean isAscending() {
public void setAscending(boolean ascending) {
this.ascending = ascending;
}

public String getColumnForReaderFromPath(PartialPath path, int pathIndex) {
String columnForReader = path.isTsAliasExists() ? path.getTsAlias() : null;
if (columnForReader == null) {
columnForReader =
path.isMeasurementAliasExists() ? path.getFullPathWithAlias() : path.toString();
}
return columnForReader;
}

public String getColumnForDisplay(String columnForReader, int pathIndex)
throws IllegalPathException {
return columnForReader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ public void addRawQueryOutputColumn(String rawQueryOutputColumn) {
public void setPathNameToReaderIndex(Map<String, Integer> pathNameToReaderIndex) {
this.pathNameToReaderIndex = pathNameToReaderIndex;
}

@Override
public String getColumnForDisplay(String columnForReader, int pathIndex) {
if (paths.get(pathIndex) == null) {
return this.getExecutorByOriginalOutputColumnIndex(pathIndex).getContext().getColumnName();
}
return columnForReader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
import org.apache.iotdb.db.exception.query.PathNumOverLimitException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.exception.runtime.SQLParserException;
import org.apache.iotdb.db.metadata.PartialPath;
Expand Down Expand Up @@ -125,7 +124,6 @@
import org.apache.iotdb.db.qp.physical.sys.TracingPlan;
import org.apache.iotdb.db.query.udf.core.context.UDFContext;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.utils.FilePathUtils;
import org.apache.iotdb.db.utils.SchemaUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.expression.IExpression;
Expand Down Expand Up @@ -825,8 +823,7 @@ private void concatFilterPath(
}

@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
private void deduplicate(QueryPlan queryPlan)
throws MetadataException, PathNumOverLimitException {
private void deduplicate(QueryPlan queryPlan) throws MetadataException {
// generate dataType first
List<PartialPath> paths = queryPlan.getPaths();
List<TSDataType> dataTypes = getSeriesTypes(paths);
Expand All @@ -843,12 +840,7 @@ private void deduplicate(QueryPlan queryPlan)
if (queryPlan instanceof LastQueryPlan) {
for (int i = 0; i < paths.size(); i++) {
PartialPath path = paths.get(i);
String column;
if (path.isTsAliasExists()) {
column = path.getTsAlias();
} else {
column = path.isMeasurementAliasExists() ? path.getFullPathWithAlias() : path.toString();
}
String column = queryPlan.getColumnForReaderFromPath(path, i);
if (!columnForReaderSet.contains(column)) {
TSDataType seriesType = dataTypes.get(i);
rawDataQueryPlan.addDeduplicatedPaths(path);
Expand Down Expand Up @@ -881,18 +873,7 @@ private void deduplicate(QueryPlan queryPlan)
PartialPath originalPath = indexedPath.left;
Integer originalIndex = indexedPath.right;

String columnForReader = originalPath.isTsAliasExists() ? originalPath.getTsAlias() : null;
if (columnForReader == null) {
columnForReader =
originalPath.isMeasurementAliasExists()
? originalPath.getFullPathWithAlias()
: originalPath.toString();
if (queryPlan instanceof AggregationPlan) {
columnForReader =
queryPlan.getAggregations().get(originalIndex) + "(" + columnForReader + ")";
}
}

String columnForReader = queryPlan.getColumnForReaderFromPath(originalPath, originalIndex);
boolean isUdf = queryPlan instanceof UDTFPlan && paths.get(originalIndex) == null;

if (!columnForReaderSet.contains(columnForReader)) {
Expand All @@ -907,23 +888,8 @@ private void deduplicate(QueryPlan queryPlan)
columnForReaderSet.add(columnForReader);
}

String columnForDisplay =
isUdf
? ((UDTFPlan) queryPlan)
.getExecutorByOriginalOutputColumnIndex(originalIndex)
.getContext()
.getColumnName()
: columnForReader;
if (queryPlan instanceof AggregationPlan && ((AggregationPlan) queryPlan).getLevel() >= 0) {
String aggregatePath =
originalPath.isMeasurementAliasExists()
? FilePathUtils.generatePartialPathByLevel(
originalPath.getFullPathWithAlias(), ((AggregationPlan) queryPlan).getLevel())
: FilePathUtils.generatePartialPathByLevel(
originalPath.toString(), ((AggregationPlan) queryPlan).getLevel());
columnForDisplay =
queryPlan.getAggregations().get(originalIndex) + "(" + aggregatePath + ")";
}
String columnForDisplay = queryPlan.getColumnForDisplay(columnForReader, originalIndex);

if (!columnForDisplaySet.contains(columnForDisplay)) {
queryPlan.addPathToIndex(columnForDisplay, queryPlan.getPathToIndex().size());
if (queryPlan instanceof UDTFPlan) {
Expand All @@ -948,10 +914,9 @@ private List<String> slimitTrimColumn(List<String> columnList, int seriesLimit,

// check parameter range
if (seriesOffset >= size) {
throw new QueryProcessException(
String.format(
"The value of SOFFSET (%d) is equal to or exceeds the number of sequences (%d) that can actually be returned.",
seriesOffset, size));
String errorMessage =
"The value of SOFFSET (%d) is equal to or exceeds the number of sequences (%d) that can actually be returned.";
throw new QueryProcessException(String.format(errorMessage, seriesOffset, size));
}
int endPosition = seriesOffset + seriesLimit;
if (endPosition > size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ private TSExecuteStatementResp internalExecuteQueryStatement(
/**
* get fetchSize and deduplicatedPathNum that are used for memory estimation
*
* @return Pair<fetchSize, deduplicatedPathNum>
* @return Pair - fetchSize, deduplicatedPathNum
*/
private Pair<Integer, Integer> getMemoryParametersFromPhysicalPlan(
PhysicalPlan plan, int fetchSizeBefore) {
Expand Down