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
4 changes: 2 additions & 2 deletions cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private static void executeQuery(IoTDBConnection connection, String cmd) {
private static List<List<String>> cacheResult(ResultSet resultSet, List<Integer> maxSizeList,
int columnCount, ResultSetMetaData resultSetMetaData, ZoneId zoneId) throws SQLException {
List<List<String>> lists = new ArrayList<>(columnCount);
if( resultSet instanceof IoTDBQueryResultSet) {
if (resultSet instanceof IoTDBQueryResultSet) {
for (int i = 1; i <= columnCount; i++) {
List<String> list = new ArrayList<>(maxPrintRowCount + 1);
list.add(resultSetMetaData.getColumnLabel(i));
Expand All @@ -607,7 +607,7 @@ private static List<List<String>> cacheResult(ResultSet resultSet, List<Integer>
isReachEnd = !resultSet.next();
cursorBeforeFirst = false;
}
if(resultSet instanceof IoTDBQueryResultSet) {
if (resultSet instanceof IoTDBQueryResultSet) {
boolean printTimestamp = !((IoTDBQueryResultSet) resultSet).isIgnoreTimeStamp();
while (j < maxPrintRowCount && !isReachEnd) {
for (int i = 1; i <= columnCount; i++) {
Expand Down
14 changes: 14 additions & 0 deletions server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ public List<String> getAllTimeseriesName(String prefixPath) throws MetadataExcep
}
}

/**
* Similar to method getAllTimeseriesName(), but return Path instead of String in order to include alias.
*/
public List<Path> getAllTimeseriesPath(String prefixPath) throws MetadataException {
lock.readLock().lock();
try {
return mtree.getAllTimeseriesPath(prefixPath);
} catch (MetadataException e) {
throw new MetadataException(e);
} finally {
lock.readLock().unlock();
}
}

public List<ShowTimeSeriesResult> getAllTimeseriesSchema(ShowTimeSeriesPlan plan)
throws MetadataException {
lock.readLock().lock();
Expand Down
20 changes: 20 additions & 0 deletions server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,26 @@ List<String> getAllTimeseriesName(String prefixPath) throws MetadataException {
return paths;
}

/**
* Get all timeseries paths under the given path
*
* @param prefixPath a prefix path or a full path, may contain '*'.
*/
List<Path> getAllTimeseriesPath(String prefixPath) throws MetadataException {
Path prePath = new Path(prefixPath);
ShowTimeSeriesPlan plan = new ShowTimeSeriesPlan(prePath);
List<String[]> res = getAllMeasurementSchema(plan);
List<Path> paths = new ArrayList<>();
for (String[] p : res) {
Path path = new Path(p[0]);
if (prePath.getMeasurement().equals(p[1])){
path.setAlias(p[1]);
}
paths.add(path);
}
return paths;
}

/**
* Get all time series schema under the given path
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public PhysicalPlan transformToPhysicalPlan(Operator operator) throws QueryProce
insert.getMeasurementList(),
insert.getValueList());
case MERGE:
if(operator.getTokenIntType() == SQLConstant.TOK_FULL_MERGE) {
if (operator.getTokenIntType() == SQLConstant.TOK_FULL_MERGE) {
return new MergePlan(OperatorType.FULL_MERGE);
} else {
return new MergePlan();
Expand Down Expand Up @@ -398,16 +398,14 @@ private PhysicalPlan transformQuery(QueryOperator queryOperator) throws QueryPro

String aggregation =
originAggregations != null && !originAggregations.isEmpty()
? originAggregations.get(i)
: null;
? originAggregations.get(i) : null;
List<TSDataType> dataTypes = getSeriesTypes(actualPaths, aggregation);
for (int pathIdx = 0; pathIdx < actualPaths.size(); pathIdx++) {
Path path = new Path(actualPaths.get(pathIdx));

// check datatype consistency
// a example of inconsistency: select s0 from root.sg1.d1, root.sg2.d3 align by
// device,
// while root.sg1.d1.s0 is INT32 and root.sg2.d3.s0 is FLOAT.
// a example of inconsistency: select s0 from root.sg1.d1, root.sg1.d2 align by device,
// while root.sg1.d1.s0 is INT32 and root.sg1.d2.s0 is FLOAT.
String measurementChecked;
if (originAggregations != null && !originAggregations.isEmpty()) {
measurementChecked = originAggregations.get(i) + "(" + path.getMeasurement() + ")";
Expand Down Expand Up @@ -592,7 +590,12 @@ private void deduplicate(QueryPlan queryPlan) throws MetadataException {
if (queryPlan instanceof LastQueryPlan) {
for (int i = 0; i < paths.size(); i++) {
Path path = paths.get(i);
String column = path.toString();
String column;
if (path.getAlias() != null) {
column = path.getFullPathWithAlias();
} else {
column = path.toString();
}
if (!columnSet.contains(column)) {
TSDataType seriesType = dataTypes.get(i);
rawDataQueryPlan.addDeduplicatedPaths(path);
Expand All @@ -613,18 +616,21 @@ private void deduplicate(QueryPlan queryPlan) throws MetadataException {
int index = 0;
for (Pair<Path, Integer> indexedPath : indexedPaths) {
String column;
if (queryPlan instanceof AggregationPlan) {
column = queryPlan.getAggregations().get(indexedPath.right) + "(" + indexedPath.left.toString() + ")";
if (indexedPath.left.getAlias() != null) {
column = indexedPath.left.getFullPathWithAlias();
} else {
column = indexedPath.left.toString();
}
if (queryPlan instanceof AggregationPlan) {
column = queryPlan.getAggregations().get(indexedPath.right) + "(" + column + ")";
}
if (!columnSet.contains(column)) {
TSDataType seriesType = dataTypes.get(indexedPath.right);
rawDataQueryPlan.addDeduplicatedPaths(indexedPath.left);
rawDataQueryPlan.addDeduplicatedDataTypes(seriesType);
columnSet.add(column);
rawDataQueryPlan.addPathToIndex(column, index++);
if (queryPlan instanceof AggregationPlan){
if (queryPlan instanceof AggregationPlan) {
((AggregationPlan) queryPlan)
.addDeduplicatedAggregations(queryPlan.getAggregations().get(indexedPath.right));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import org.apache.iotdb.db.exception.metadata.MetadataException;
Expand Down Expand Up @@ -279,19 +278,17 @@ private FilterOperator constructBinaryFilterTreeWithAnd(List<Path> noStarPaths,
*/
private List<Path> removeStarsInPathWithUnique(List<Path> paths) throws LogicalOptimizeException {
List<Path> retPaths = new ArrayList<>();
LinkedHashMap<String, Integer> pathMap = new LinkedHashMap<>();
HashSet<String> pathSet = new HashSet<>();
try {
for (Path path : paths) {
List<String> all = removeWildcard(path.getFullPath());
for (String subPath : all) {
if (!pathMap.containsKey(subPath)) {
pathMap.put(subPath, 1);
List<Path> all = removeWildcard(path.getFullPath());
for (Path subPath : all) {
if (!pathSet.contains(subPath.getFullPath())) {
pathSet.add(subPath.getFullPath());
retPaths.add(subPath);
}
}
}
for (String pathStr : pathMap.keySet()) {
retPaths.add(new Path(pathStr));
}
} catch (MetadataException e) {
throw new LogicalOptimizeException("error when remove star: " + e.getMessage());
}
Expand All @@ -304,9 +301,9 @@ private void removeStarsInPath(List<Path> paths, List<String> afterConcatAggrega
List<String> newAggregations = new ArrayList<>();
for (int i = 0; i < paths.size(); i++) {
try {
List<String> actualPaths = removeWildcard(paths.get(i).getFullPath());
for (String actualPath : actualPaths) {
retPaths.add(new Path(actualPath));
List<Path> actualPaths = removeWildcard(paths.get(i).getFullPath());
for (Path actualPath : actualPaths) {
retPaths.add(actualPath);
if (afterConcatAggregations != null && !afterConcatAggregations.isEmpty()) {
newAggregations.add(afterConcatAggregations.get(i));
}
Expand All @@ -319,7 +316,7 @@ private void removeStarsInPath(List<Path> paths, List<String> afterConcatAggrega
selectOperator.setAggregations(newAggregations);
}

protected List<String> removeWildcard(String path) throws MetadataException {
return MManager.getInstance().getAllTimeseriesName(path);
protected List<Path> removeWildcard(String path) throws MetadataException {
return MManager.getInstance().getAllTimeseriesPath(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
import java.util.Arrays;
import java.util.List;

import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;

public class LastQueryExecutor {
private List<Path> selectedSeries;
private List<TSDataType> dataTypes;
Expand Down Expand Up @@ -86,7 +83,11 @@ public QueryDataSet execute(QueryContext context, LastQueryPlan lastQueryPlan)
if (lastTimeValuePair.getValue() != null) {
RowRecord resultRecord = new RowRecord(lastTimeValuePair.getTimestamp());
Field pathField = new Field(TSDataType.TEXT);
pathField.setBinaryV(new Binary(selectedSeries.get(i).getFullPath()));
if (selectedSeries.get(i).getAlias() != null) {
pathField.setBinaryV(new Binary(selectedSeries.get(i).getFullPathWithAlias()));
} else {
pathField.setBinaryV(new Binary(selectedSeries.get(i).getFullPath()));
}
resultRecord.addField(pathField);

Field valueField = new Field(TSDataType.TEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,11 @@ private void getWideQueryHeaders(
case QUERY:
case FILL:
for (Path p : paths) {
respColumns.add(p.getFullPath());
if (p.getAlias() != null) {
respColumns.add(p.getFullPathWithAlias());
} else {
respColumns.add(p.getFullPath());
}
}
seriesTypes = getSeriesTypesByString(respColumns, null);
break;
Expand All @@ -676,7 +680,11 @@ private void getWideQueryHeaders(
}
}
for (int i = 0; i < paths.size(); i++) {
respColumns.add(aggregations.get(i) + "(" + paths.get(i).getFullPath() + ")");
if (paths.get(i).getAlias() != null) {
respColumns.add(aggregations.get(i) + "(" + paths.get(i).getFullPathWithAlias() + ")");
} else {
respColumns.add(aggregations.get(i) + "(" + paths.get(i).getFullPath() + ")");
}
}
seriesTypes = getSeriesTypesByPath(paths, aggregations);
break;
Expand Down
Loading