iotdb
iotdb copied to clipboard
Update语句语法更新
由于当前update语句在表达和支持广度上有一定局限性,因此将update语句更改为以下规则:
UPDATE语句语法设计
EQUAL := '=' | '==';
NOTEQUAL := '<>' | '!=';
LESSTHANOREQUALTO := '<=';
LESSTHAN := '<';
GREATERTHANOREQUALTO := '>=';
GREATERTHAN := '>';
DOT := '.';
COMMA := ',' ;
MINUS := '-';
Letter := 'a'..'z' | 'A'..'Z';
Digit := '0'..'9';
PrecedenceEqualOperator : EQUAL | NOTEQUAL | LESSTHANOREQUALTO | LESSTHAN | GREATERTHANOREQUALTO | GREATERTHAN
StringLiteral := ( '\'' ( ~('\'') )* '\'' | '\"' ( ~('\"') )* '\"');
Integer := ('-' | '+')? Digit+;
Float := ('-' | '+')? Digit+ DOT Digit+ (('e' | 'E') ('-' | '+')? Digit+)?;
Boolean := TRUE(大小写不敏感) | FALSE(大小写不敏感) | 0 | 1
PointValue : Integer | Float | StringLiteral | Boolean
Identifier := (Letter | '_') (Letter | Digit | '_' | MINUS)*;
eg. a123
eg. _abc123
PrefixPath : ROOT (DOT <LayerName>)*
LayerName : Identifier
eg. root.laptop
eg. root
Timeseries : ROOT [DOT <LayerName>]* DOT <SensorName>
LayerName : Identifier
SensorName : Identifier
eg. root.s1
eg. root.laptop.d1.s1
eg. root.beijing.laptop.d1.s1
StarPath : (ROOT (DOT <LayerName>)* DOT <StarSymbol> (DOT <LayerName>)*) | STAR
LayerName : Identifier | <StarSymbol>
StarSymbol: STAR [LBRACKET Digit+ RBRACKET]?
eg. root.laptop.*.s1
eg. root.*[1].s1
eg. *
SuffixPath : <LayerName> (DOT <LayerName>)*
LayerName : Identifier | <StarSymbol>
StarSymbol: STAR [LBRACKET Digit+ RBRACKET]?
eg. d0.s1
eg. *.s2
UPDATE <UpdateClause> SET <SetClause> WHERE <WhereClause>
UpdateClause: <PrefixPath> | <StarPath>
SetClause: <SetExpression> [COMMA <SetExpression>]*
SetExpression: <SuffixPath> EQUAL <PointValue>
WhereClause : <WhereExpression> [(AND | OR) <WhereExpression>]*
WhereExpression : [NOT | !]? <TimeExpression> | [NOT | !]? <SensorExpression>
TimeExpression : TIME PrecedenceEqualOperator <TimeValue>
SensorExpression : (<Timeseries> | <SuffixPath>) PrecedenceEqualOperator <PointValue>
eg1.
UPDATE root.laptop SET d1.s1 = 1, mac.d1.s2 = "string" WHERE root.laptop.d1.s2 = TRUE
-- 本句话针对满足root.laptop.d1.s2 = TRUE条件的所有行,更新改行对应的root.laptop.d1.s1列的值为1, 该行对应的root.laptop.mac.d1.s2列的值为"string"
eg2.
UPDATE root.laptop.* SET d1.s1 = 1, mac.d1.s2 = "string" WHERE root.laptop.d1.s2 = TRUE
-- 本句话针对满足root.laptop.d1.s2 = TRUE条件的所有行,更新改行对应的root.laptop.*.d1.s1列的值为1, 该行对应的root.laptop.mac.d1.s2列的值为"string"
eg3.
UPDATE root.laptop SET d1.s1 = 1, mac.d1.s2 = "string" WHERE d1.s2 = TRUE
-- 本句话针对满足root.laptop.d1.s2 = TRUE条件的所有行,更新改行对应的root.laptop.d1.s1列的值为1, 该行对应的root.laptop.mac.d1.s2列的值为"string" 。即在WHERE语句中不写全路径时,所写的SuffixPath需要与UpdateClause中的PreffixPath拼接,若写全路径时,则不需要与UpdateClause中的PreffixPath拼接。
特别说明
- 注1:WhereExpression中的SensorExpression当前Update语句不支持。
- 注2:UpdateClause中的PrefixPath和SetClause中的SuffixPath需要满足PrefixPath+SuffixPath = Timeseries约束,当PrefixPath+SuffixPath不存在或为一个非Timeseries的路径时,报Timeseries不存在错误。
- 注3:SensorExpression如果是SuffixPath,需要和UpdateClause中的PrefixPath满足PrefixPath+SuffixPath=Timeseries约束,当PrefixPath+SuffixPath不存在或为一个非Timeseries的路径时,报Timeseries不存在错误。
- 注4:当多个PrefixPath+SuffixPath=Timeseries中有部分Timeseires不存在时,报第一个不存在的Timeseries不存在错误,所有Timeseries的更新均不执行。
- 注5:SetExpression中PointValue需要与该PointValue对应的PrefixPath+SuffixPath=Timeseries的数据类型一致,否则报该列数据类型错误。
- 注6:当多个PointValue中有部分PointValue与PrefixPath+SuffixPath=Timeseries数据类型不一致时,报第一个不符合PointValue的列的数据类型错误,且所有Timeseries的更新均不执行。
目前在0.3.0版本中只支持更新单个序列,过滤条件为时间