Class ExpressionAnalyzer
- java.lang.Object
-
- org.apache.iotdb.db.mpp.plan.analyze.ExpressionAnalyzer
-
public class ExpressionAnalyzer extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ExpressionAnalyzer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckIsAllMeasurement(Expression expression)Check if all suffix paths in expression are measurements or one-level wildcards, used in ALIGN BY DEVICE query or GroupByLevel query.static booleancheckIsNeedTransform(Expression expression)Check for arithmetic expression, logical expression, UDF.static java.util.List<Expression>concatDeviceAndRemoveWildcard(Expression expression, org.apache.iotdb.commons.path.PartialPath devicePath, ISchemaTree schemaTree, TypeProvider typeProvider)Concat expression with the device path in the FROM clause.And then, bind schema (PartialPath->MeasurementPath) and removes wildcards in Expression.static java.util.List<org.apache.iotdb.commons.path.PartialPath>concatExpressionWithSuffixPaths(Expression expression, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths)Concat suffix path in SELECT or WITHOUT NULL clause with the prefix path in the FROM clause.static java.util.List<Expression>concatExpressionWithSuffixPaths(Expression expression, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, PathPatternTree patternTree)Concat suffix path in SELECT or WITHOUT NULL clause with the prefix path in the FROM clause.static voidconstructPatternTreeFromExpression(Expression predicate, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, PathPatternTree patternTree)Concat suffix path in WHERE clause with the prefix path in the FROM clause and Construct aPathPatternTree.static ExpressionevaluatePredicate(Expression predicate)static java.lang.StringgetDeviceNameInSourceExpression(Expression expression)static ExpressiongetMeasurementExpression(Expression expression)static ResultColumn.ColumnTypeidentifyOutputColumnType(Expression expression, boolean isRoot)Identify the expression is a valid built-in aggregation function.static ExpressionremoveAliasFromExpression(Expression expression)Remove alias from expression.static java.util.List<Expression>removeWildcardInExpression(Expression expression, ISchemaTree schemaTree)Bind schema (PartialPath->MeasurementPath) and removes wildcards in Expression.static java.util.List<Expression>removeWildcardInFilter(Expression predicate, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, ISchemaTree schemaTree, TypeProvider typeProvider, boolean isWhere)Concat suffix path in WHERE and HAVING clause with the prefix path in the FROM clause.static java.util.List<Expression>removeWildcardInFilterByDevice(Expression predicate, org.apache.iotdb.commons.path.PartialPath devicePath, ISchemaTree schemaTree, TypeProvider typeProvider, boolean isWhere)Concat measurement in WHERE and HAVING clause with device path.static ExpressionreplaceRawPathWithGroupedPath(Expression predicate, java.util.Map<Expression,Expression> rawPathToGroupedPathMapInHaving)static java.util.List<Expression>searchAggregationExpressions(Expression expression)Search for built-in aggregate functions subexpressions.static java.util.List<Expression>searchSourceExpressions(Expression expression, boolean isRawDataSource)Search for subexpressions that can be queried natively, including time series raw data and built-in aggregate functions.static org.apache.iotdb.tsfile.utils.Pair<org.apache.iotdb.tsfile.read.filter.basic.Filter,java.lang.Boolean>transformToGlobalTimeFilter(Expression predicate, boolean canRewrite, boolean isFirstOr)Extract global time filter from query filter.static voidupdateTypeProvider(Expression expression, TypeProvider typeProvider)Update typeProvider by expression.
-
-
-
Method Detail
-
checkIsAllMeasurement
public static void checkIsAllMeasurement(Expression expression)
Check if all suffix paths in expression are measurements or one-level wildcards, used in ALIGN BY DEVICE query or GroupByLevel query. If not, throw aSemanticException.- Parameters:
expression- expression to be checked
-
identifyOutputColumnType
public static ResultColumn.ColumnType identifyOutputColumnType(Expression expression, boolean isRoot)
Identify the expression is a valid built-in aggregation function.- Parameters:
expression- expression to be checked- Returns:
- true if this expression is valid
-
concatExpressionWithSuffixPaths
public static java.util.List<Expression> concatExpressionWithSuffixPaths(Expression expression, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, PathPatternTree patternTree)
Concat suffix path in SELECT or WITHOUT NULL clause with the prefix path in the FROM clause. and Construct aPathPatternTree.- Parameters:
expression- expression in SELECT or WITHOUT NULL clause which may include suffix pathsprefixPaths- prefix paths in the FROM clausepatternTree- a PathPatternTree contains all paths to query- Returns:
- the concatenated expression list
-
concatExpressionWithSuffixPaths
public static java.util.List<org.apache.iotdb.commons.path.PartialPath> concatExpressionWithSuffixPaths(Expression expression, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths)
Concat suffix path in SELECT or WITHOUT NULL clause with the prefix path in the FROM clause.- Parameters:
expression- expression in SELECT or WITHOUT NULL clause which may include suffix pathsprefixPaths- prefix paths in the FROM clause- Returns:
- the concatenated partialPath list
-
constructPatternTreeFromExpression
public static void constructPatternTreeFromExpression(Expression predicate, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, PathPatternTree patternTree)
Concat suffix path in WHERE clause with the prefix path in the FROM clause and Construct aPathPatternTree. This method return void, i.e. will not rewrite the statement.- Parameters:
predicate- expression in WHERE clauseprefixPaths- prefix paths in the FROM clausepatternTree- a PathPatternTree contains all paths to query
-
removeWildcardInExpression
public static java.util.List<Expression> removeWildcardInExpression(Expression expression, ISchemaTree schemaTree)
Bind schema (PartialPath->MeasurementPath) and removes wildcards in Expression.- Parameters:
schemaTree- interface for querying schema information- Returns:
- the expression list after binding schema
-
removeWildcardInFilter
public static java.util.List<Expression> removeWildcardInFilter(Expression predicate, java.util.List<org.apache.iotdb.commons.path.PartialPath> prefixPaths, ISchemaTree schemaTree, TypeProvider typeProvider, boolean isWhere)
Concat suffix path in WHERE and HAVING clause with the prefix path in the FROM clause. And then, bind schema (PartialPath->MeasurementPath) and removes wildcards in Expression.- Parameters:
prefixPaths- prefix paths in the FROM clauseschemaTree- interface for querying schema informationtypeProvider- a map to record output symbols and their data types- Returns:
- the expression list with full path and after binding schema
-
replaceRawPathWithGroupedPath
public static Expression replaceRawPathWithGroupedPath(Expression predicate, java.util.Map<Expression,Expression> rawPathToGroupedPathMapInHaving)
-
concatDeviceAndRemoveWildcard
public static java.util.List<Expression> concatDeviceAndRemoveWildcard(Expression expression, org.apache.iotdb.commons.path.PartialPath devicePath, ISchemaTree schemaTree, TypeProvider typeProvider)
Concat expression with the device path in the FROM clause.And then, bind schema (PartialPath->MeasurementPath) and removes wildcards in Expression. This method used in ALIGN BY DEVICE query.- Parameters:
devicePath- device path in the FROM clause- Returns:
- expression list with full path and after binding schema
-
removeWildcardInFilterByDevice
public static java.util.List<Expression> removeWildcardInFilterByDevice(Expression predicate, org.apache.iotdb.commons.path.PartialPath devicePath, ISchemaTree schemaTree, TypeProvider typeProvider, boolean isWhere)
Concat measurement in WHERE and HAVING clause with device path. And then, bind schema (PartialPath->MeasurementPath) and removes wildcards.- Returns:
- the expression list with full path and after binding schema
-
transformToGlobalTimeFilter
public static org.apache.iotdb.tsfile.utils.Pair<org.apache.iotdb.tsfile.read.filter.basic.Filter,java.lang.Boolean> transformToGlobalTimeFilter(Expression predicate, boolean canRewrite, boolean isFirstOr)
Extract global time filter from query filter.- Parameters:
predicate- raw query filtercanRewrite- determined by the father of current expressionisFirstOr- whether it is the first LogicOrExpression encountered- Returns:
- global time filter
-
searchSourceExpressions
public static java.util.List<Expression> searchSourceExpressions(Expression expression, boolean isRawDataSource)
Search for subexpressions that can be queried natively, including time series raw data and built-in aggregate functions.- Parameters:
expression- expression to be searchedisRawDataSource- if true, built-in aggregate functions are not be returned- Returns:
- searched subexpression list
-
searchAggregationExpressions
public static java.util.List<Expression> searchAggregationExpressions(Expression expression)
Search for built-in aggregate functions subexpressions.- Parameters:
expression- expression to be searched- Returns:
- searched aggregate functions list
-
updateTypeProvider
public static void updateTypeProvider(Expression expression, TypeProvider typeProvider)
Update typeProvider by expression.
-
removeAliasFromExpression
public static Expression removeAliasFromExpression(Expression expression)
Remove alias from expression. eg: root.sg.d1.status + 1 -> root.sg.d1.s2 + 1- Returns:
- expression after removing alias
-
checkIsNeedTransform
public static boolean checkIsNeedTransform(Expression expression)
Check for arithmetic expression, logical expression, UDF. Returns true if it exists.
-
getDeviceNameInSourceExpression
public static java.lang.String getDeviceNameInSourceExpression(Expression expression)
-
getMeasurementExpression
public static Expression getMeasurementExpression(Expression expression)
-
evaluatePredicate
public static Expression evaluatePredicate(Expression predicate)
-
-