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 @@ -36,4 +36,10 @@ public StatementAnalyzeException(String filterOperator, FilterConstant.FilterTyp
filterOperator, filterType, FilterConstant.filterNames.get(filterType)),
TSStatusCode.LOGICAL_OPTIMIZE_ERROR.getStatusCode());
}

public StatementAnalyzeException(String type, String message) {
super(
String.format("Unsupported type: [%s]. %s", type, message),
TSStatusCode.LOGICAL_OPTIMIZE_ERROR.getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.iotdb.db.mpp.common.filter;

import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.sql.SQLParserException;
import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant.FilterType;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void reverseFunc() {
@Override
protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws LogicalOperatorException, MetadataException {
throws StatementAnalyzeException, MetadataException {
TSDataType type = pathTSDataTypeHashMap.get(singlePath);
if (type == null) {
throw new MetadataException(
Expand Down Expand Up @@ -109,12 +109,12 @@ protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
? new Binary(value.substring(1, value.length() - 1))
: new Binary(value));
} else {
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
"For Basic operator,TEXT type only support EQUAL or NOTEQUAL operator");
}
break;
default:
throw new LogicalOperatorException(type.toString(), "");
throw new StatementAnalyzeException(type.toString(), "");
}

return new Pair<>(ret, singlePath.getFullPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.iotdb.db.mpp.common.filter;

import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant.FilterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void reverseFunc() {
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws LogicalOperatorException, MetadataException {
throws StatementAnalyzeException, MetadataException {
TSDataType type = pathTSDataTypeHashMap.get(singlePath);
if (type == null) {
throw new MetadataException(
Expand Down Expand Up @@ -131,7 +131,7 @@ protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
ret = In.getUnaryExpression(singlePath, binaryValues, not);
break;
default:
throw new LogicalOperatorException(type.toString(), "");
throw new StatementAnalyzeException(type.toString(), "");
}

return new Pair<>(ret, singlePath.getFullPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.iotdb.db.mpp.common.filter;

import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant.FilterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
Expand Down Expand Up @@ -51,17 +51,17 @@ public LikeFilter(FilterType filterType, PartialPath path, String value) {
@Override
protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws LogicalOperatorException, MetadataException {
throws StatementAnalyzeException, MetadataException {
TSDataType type = pathTSDataTypeHashMap.get(singlePath);
if (type == null) {
throw new MetadataException(
"given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
}
IUnaryExpression ret;
if (type != TEXT) {
throw new LogicalOperatorException(type.toString(), "Only TEXT is supported in 'Like'");
throw new StatementAnalyzeException(type.toString(), "Only TEXT is supported in 'Like'");
} else if (value.startsWith("\"") && value.endsWith("\"")) {
throw new LogicalOperatorException(value, "Please use single quotation marks");
throw new StatementAnalyzeException(value, "Please use single quotation marks");
} else {
ret =
Like.getUnaryExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
package org.apache.iotdb.db.mpp.common.filter;

import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant.FilterType;
Expand Down Expand Up @@ -124,18 +123,18 @@ public Set<PartialPath> getPathSet() {
* @param pathTSDataTypeHashMap
*/
public IExpression transformToExpression(Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws QueryProcessException {
throws StatementAnalyzeException {
if (isSingle) {
Pair<IUnaryExpression, String> ret;
try {
ret = transformToSingleQueryFilter(pathTSDataTypeHashMap);
} catch (MetadataException e) {
throw new QueryProcessException(e);
throw new StatementAnalyzeException("Meet error when transformToSingleQueryFilter");
}
return ret.left;
} else {
if (childOperators.isEmpty()) {
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
String.valueOf(filterType), "this filter is not leaf, but it's empty");
}
IExpression retFilter = childOperators.get(0).transformToExpression(pathTSDataTypeHashMap);
Expand All @@ -150,7 +149,7 @@ public IExpression transformToExpression(Map<PartialPath, TSDataType> pathTSData
retFilter = BinaryExpression.or(retFilter, currentFilter);
break;
default:
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
String.valueOf(filterType), "Maybe it means " + getFilterName());
}
}
Expand All @@ -168,9 +167,9 @@ public IExpression transformToExpression(Map<PartialPath, TSDataType> pathTSData
*/
protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws LogicalOperatorException, MetadataException {
throws StatementAnalyzeException, MetadataException {
if (childOperators.isEmpty()) {
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
String.valueOf(filterType),
"TransformToSingleFilter: this filter is not a leaf, but it's empty.");
}
Expand All @@ -183,7 +182,7 @@ protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
for (int i = 1; i < childOperators.size(); i++) {
currentPair = childOperators.get(i).transformToSingleQueryFilter(pathTSDataTypeHashMap);
if (!path.equals(currentPair.right)) {
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
"TransformToSingleFilter: paths among children are not inconsistent: one is: "
+ path
+ ", another is: "
Expand All @@ -199,7 +198,7 @@ protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
FilterFactory.or(retFilter.getFilter(), currentPair.left.getFilter()));
break;
default:
throw new LogicalOperatorException(
throw new StatementAnalyzeException(
String.valueOf(filterType), "Maybe it means " + getFilterName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.iotdb.db.mpp.common.filter;

import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.sql.constant.FilterConstant.FilterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
Expand Down Expand Up @@ -51,17 +51,17 @@ public RegexpFilter(FilterType filterType, PartialPath path, String value) {
@Override
protected Pair<IUnaryExpression, String> transformToSingleQueryFilter(
Map<PartialPath, TSDataType> pathTSDataTypeHashMap)
throws LogicalOperatorException, MetadataException {
throws StatementAnalyzeException, MetadataException {
TSDataType type = pathTSDataTypeHashMap.get(singlePath);
if (type == null) {
throw new MetadataException(
"given seriesPath:{" + singlePath.getFullPath() + "} don't exist in metadata");
}
IUnaryExpression ret;
if (type != TEXT) {
throw new LogicalOperatorException(type.toString(), "Only TEXT is supported in 'Regexp'");
throw new StatementAnalyzeException(type.toString(), "Only TEXT is supported in 'Regexp'");
} else if (value.startsWith("\"") && value.endsWith("\"")) {
throw new LogicalOperatorException(value, "Please use single quotation marks");
throw new StatementAnalyzeException(value, "Please use single quotation marks");
} else {
ret =
Regexp.getUnaryExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

public class SchemaTree {

private SchemaNode root;
private final SchemaNode root;

public SchemaTree(SchemaNode root) {
this.root = root;
}

/**
* Return all measurement paths for given path pattern and filter the result by slimit and offset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.common.schematree.SchemaTree;
import org.apache.iotdb.db.mpp.sql.statement.Statement;
import org.apache.iotdb.tsfile.read.expression.IExpression;
import org.apache.iotdb.tsfile.read.filter.basic.Filter;

import java.util.List;
import java.util.Map;
import java.util.Set;

/** Analysis used for planning a query. TODO: This class may need to store more info for a query. */
public class Analysis {
Expand All @@ -51,7 +50,7 @@ public class Analysis {

private SchemaTree schemaTree;

private Map<String, Set<PartialPath>> deviceIdToPathsMap;
private IExpression queryFilter;

public List<RegionReplicaSet> getPartitionInfo(PartialPath seriesPath, Filter timefilter) {
// TODO: (xingtanzjr) implement the calculation of timePartitionIdList
Expand Down Expand Up @@ -82,19 +81,19 @@ public void setSchemaPartitionInfo(SchemaPartition schemaPartition) {
this.schemaPartition = schemaPartition;
}

public Map<String, Set<PartialPath>> getDeviceIdToPathsMap() {
return deviceIdToPathsMap;
}

public void setDeviceIdToPathsMap(Map<String, Set<PartialPath>> deviceIdToPathsMap) {
this.deviceIdToPathsMap = deviceIdToPathsMap;
}

public SchemaTree getSchemaTree() {
return schemaTree;
}

public void setSchemaTree(SchemaTree schemaTree) {
this.schemaTree = schemaTree;
}

public IExpression getQueryFilter() {
return queryFilter;
}

public void setQueryFilter(IExpression expression) {
this.queryFilter = expression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@
import org.apache.iotdb.db.mpp.sql.rewriter.WildcardsRemover;
import org.apache.iotdb.db.mpp.sql.statement.Statement;
import org.apache.iotdb.db.mpp.sql.statement.StatementVisitor;
import org.apache.iotdb.db.mpp.sql.statement.component.ResultColumn;
import org.apache.iotdb.db.mpp.sql.statement.component.WhereCondition;
import org.apache.iotdb.db.mpp.sql.statement.crud.*;
import org.apache.iotdb.db.mpp.sql.statement.metadata.AlterTimeSeriesStatement;
import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateAlignedTimeSeriesStatement;
import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateTimeSeriesStatement;
import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;

import java.util.*;
import org.apache.iotdb.db.qp.constant.SQLConstant;
import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.expression.IExpression;
import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/** Analyze the statement and generate Analysis. */
public class Analyzer {
Expand Down Expand Up @@ -93,16 +105,27 @@ public Analysis visitQuery(QueryStatement queryStatement, MPPQueryContext contex
SchemaTree schemaTree = schemaFetcher.fetchSchema(patternTree);

// bind metadata, remove wildcards, and apply SLIMIT & SOFFSET
Map<String, Set<PartialPath>> deviceIdToPathsMap = new HashMap<>();
rewrittenStatement =
(QueryStatement)
new WildcardsRemover().rewrite(rewrittenStatement, schemaTree, deviceIdToPathsMap);
(QueryStatement) new WildcardsRemover().rewrite(rewrittenStatement, schemaTree);

// fetch partition information
Set<String> devicePathSet = new HashSet<>();
for (ResultColumn resultColumn : queryStatement.getSelectComponent().getResultColumns()) {
devicePathSet.addAll(
resultColumn.collectPaths().stream()
.map(PartialPath::getDevice)
.collect(Collectors.toList()));
}
if (queryStatement.getWhereCondition() != null) {
devicePathSet.addAll(
queryStatement.getWhereCondition().getQueryFilter().getPathSet().stream()
.map(PartialPath::getDevice)
.collect(Collectors.toList()));
}
List<DataPartitionQueryParam> dataPartitionQueryParams = new ArrayList<>();
for (String deviceId : deviceIdToPathsMap.keySet()) {
for (String devicePath : devicePathSet) {
DataPartitionQueryParam dataPartitionQueryParam = new DataPartitionQueryParam();
dataPartitionQueryParam.setDevicePath(deviceId);
dataPartitionQueryParam.setDevicePath(devicePath);
dataPartitionQueryParams.add(dataPartitionQueryParam);
}
DataPartition dataPartition =
Expand All @@ -115,13 +138,29 @@ public Analysis visitQuery(QueryStatement queryStatement, MPPQueryContext contex
filter = new RemoveNotOptimizer().optimize(filter);
filter = new DnfFilterOptimizer().optimize(filter);
filter = new MergeSingleFilterOptimizer().optimize(filter);
whereCondition.setQueryFilter(filter);

// transform QueryFilter to expression
List<PartialPath> filterPaths = new ArrayList<>(filter.getPathSet());
HashMap<PartialPath, TSDataType> pathTSDataTypeHashMap = new HashMap<>();
for (PartialPath filterPath : filterPaths) {
pathTSDataTypeHashMap.put(
filterPath,
SQLConstant.isReservedPath(filterPath)
? TSDataType.INT64
: filterPath.getSeriesType());
}
IExpression expression = filter.transformToExpression(pathTSDataTypeHashMap);
expression =
ExpressionOptimizer.getInstance()
.optimize(expression, queryStatement.getSelectComponent().getDeduplicatedPaths());
analysis.setQueryFilter(expression);
}
analysis.setStatement(rewrittenStatement);
analysis.setSchemaTree(schemaTree);
analysis.setDeviceIdToPathsMap(deviceIdToPathsMap);
analysis.setDataPartitionInfo(dataPartition);
} catch (StatementAnalyzeException | PathNumOverLimitException e) {
} catch (StatementAnalyzeException
| PathNumOverLimitException
| QueryFilterOptimizationException e) {
e.printStackTrace();
}
return analysis;
Expand Down
Loading