2727import org .apache .iotdb .db .exception .sql .SemanticException ;
2828import org .apache .iotdb .db .index .common .IndexType ;
2929import org .apache .iotdb .db .metadata .path .PartialPath ;
30- import org .apache .iotdb .db .mpp .common .filter .*;
30+ import org .apache .iotdb .db .mpp .common .filter .BasicFunctionFilter ;
31+ import org .apache .iotdb .db .mpp .common .filter .InFilter ;
32+ import org .apache .iotdb .db .mpp .common .filter .LikeFilter ;
33+ import org .apache .iotdb .db .mpp .common .filter .QueryFilter ;
34+ import org .apache .iotdb .db .mpp .common .filter .RegexpFilter ;
3135import org .apache .iotdb .db .mpp .sql .constant .FilterConstant ;
32- import org .apache .iotdb .db .mpp .sql .statement .*;
33- import org .apache .iotdb .db .mpp .sql .statement .component .*;
34- import org .apache .iotdb .db .mpp .sql .statement .crud .*;
36+ import org .apache .iotdb .db .mpp .sql .statement .Statement ;
37+ import org .apache .iotdb .db .mpp .sql .statement .component .FillComponent ;
38+ import org .apache .iotdb .db .mpp .sql .statement .component .FilterNullComponent ;
39+ import org .apache .iotdb .db .mpp .sql .statement .component .FromComponent ;
40+ import org .apache .iotdb .db .mpp .sql .statement .component .GroupByLevelComponent ;
41+ import org .apache .iotdb .db .mpp .sql .statement .component .GroupByTimeComponent ;
42+ import org .apache .iotdb .db .mpp .sql .statement .component .OrderBy ;
43+ import org .apache .iotdb .db .mpp .sql .statement .component .ResultColumn ;
44+ import org .apache .iotdb .db .mpp .sql .statement .component .ResultSetFormat ;
45+ import org .apache .iotdb .db .mpp .sql .statement .component .SelectComponent ;
46+ import org .apache .iotdb .db .mpp .sql .statement .component .WhereCondition ;
47+ import org .apache .iotdb .db .mpp .sql .statement .crud .AggregationQueryStatement ;
48+ import org .apache .iotdb .db .mpp .sql .statement .crud .FillQueryStatement ;
49+ import org .apache .iotdb .db .mpp .sql .statement .crud .GroupByFillQueryStatement ;
50+ import org .apache .iotdb .db .mpp .sql .statement .crud .GroupByQueryStatement ;
51+ import org .apache .iotdb .db .mpp .sql .statement .crud .InsertStatement ;
52+ import org .apache .iotdb .db .mpp .sql .statement .crud .LastQueryStatement ;
53+ import org .apache .iotdb .db .mpp .sql .statement .crud .QueryStatement ;
54+ import org .apache .iotdb .db .mpp .sql .statement .crud .UDAFQueryStatement ;
55+ import org .apache .iotdb .db .mpp .sql .statement .crud .UDTFQueryStatement ;
56+ import org .apache .iotdb .db .mpp .sql .statement .metadata .AlterTimeSeriesStatement ;
3557import org .apache .iotdb .db .mpp .sql .statement .metadata .CreateAlignedTimeSeriesStatement ;
3658import org .apache .iotdb .db .mpp .sql .statement .metadata .CreateTimeSeriesStatement ;
3759import org .apache .iotdb .db .mpp .sql .statement .metadata .ShowDevicesStatement ;
4567import org .apache .iotdb .db .query .executor .fill .PreviousFill ;
4668import org .apache .iotdb .db .query .executor .fill .ValueFill ;
4769import org .apache .iotdb .db .query .expression .Expression ;
48- import org .apache .iotdb .db .query .expression .binary .*;
70+ import org .apache .iotdb .db .query .expression .binary .AdditionExpression ;
71+ import org .apache .iotdb .db .query .expression .binary .DivisionExpression ;
72+ import org .apache .iotdb .db .query .expression .binary .ModuloExpression ;
73+ import org .apache .iotdb .db .query .expression .binary .MultiplicationExpression ;
74+ import org .apache .iotdb .db .query .expression .binary .SubtractionExpression ;
4975import org .apache .iotdb .db .query .expression .unary .ConstantOperand ;
5076import org .apache .iotdb .db .query .expression .unary .FunctionExpression ;
5177import org .apache .iotdb .db .query .expression .unary .NegationExpression ;
6288import java .util .*;
6389import java .util .regex .Pattern ;
6490
65- import static org .apache .iotdb .db .index .common .IndexConstant .*;
91+ import static org .apache .iotdb .db .index .common .IndexConstant .PATTERN ;
92+ import static org .apache .iotdb .db .index .common .IndexConstant .THRESHOLD ;
93+ import static org .apache .iotdb .db .index .common .IndexConstant .TOP_K ;
6694import static org .apache .iotdb .db .qp .constant .SQLConstant .TIME_PATH ;
6795
6896/** Parse AST to Statement. */
@@ -121,7 +149,7 @@ public Statement visitCreateNonAlignedTimeseries(
121149 public Statement visitCreateAlignedTimeseries (IoTDBSqlParser .CreateAlignedTimeseriesContext ctx ) {
122150 CreateAlignedTimeSeriesStatement createAlignedTimeSeriesStatement =
123151 new CreateAlignedTimeSeriesStatement ();
124- createAlignedTimeSeriesStatement .setDeviceId (parseFullPath (ctx .fullPath ()));
152+ createAlignedTimeSeriesStatement .setDevicePath (parseFullPath (ctx .fullPath ()));
125153 parseAlignedMeasurements (ctx .alignedMeasurements (), createAlignedTimeSeriesStatement );
126154 return createAlignedTimeSeriesStatement ;
127155 }
@@ -233,11 +261,9 @@ public void parseTagClause(IoTDBSqlParser.TagClauseContext ctx, Statement statem
233261 ((CreateTimeSeriesStatement ) statement ).setTags (tags );
234262 } else if (statement instanceof CreateAlignedTimeSeriesStatement ) {
235263 ((CreateAlignedTimeSeriesStatement ) statement ).addTagsList (tags );
264+ } else if (statement instanceof AlterTimeSeriesStatement ) {
265+ ((AlterTimeSeriesStatement ) statement ).setTagsMap (tags );
236266 }
237- // TODO: remove comments
238- // else if (statement instanceof AlterTimeSeriesStatement) {
239- // ((AlterTimeSeriesStatement) statement).setTagsMap(tags);
240- // }
241267 }
242268
243269 public void parseAttributeClause (IoTDBSqlParser .AttributeClauseContext ctx , Statement statement ) {
@@ -246,11 +272,66 @@ public void parseAttributeClause(IoTDBSqlParser.AttributeClauseContext ctx, Stat
246272 ((CreateTimeSeriesStatement ) statement ).setAttributes (attributes );
247273 } else if (statement instanceof CreateAlignedTimeSeriesStatement ) {
248274 ((CreateAlignedTimeSeriesStatement ) statement ).addAttributesList (attributes );
275+ } else if (statement instanceof AlterTimeSeriesStatement ) {
276+ ((AlterTimeSeriesStatement ) statement ).setAttributesMap (attributes );
277+ }
278+ }
279+
280+ @ Override
281+ public Statement visitAlterTimeseries (IoTDBSqlParser .AlterTimeseriesContext ctx ) {
282+ AlterTimeSeriesStatement alterTimeSeriesStatement = new AlterTimeSeriesStatement ();
283+ alterTimeSeriesStatement .setPath (parseFullPath (ctx .fullPath ()));
284+ parseAlterClause (ctx .alterClause (), alterTimeSeriesStatement );
285+ return alterTimeSeriesStatement ;
286+ }
287+
288+ private void parseAlterClause (
289+ IoTDBSqlParser .AlterClauseContext ctx , AlterTimeSeriesStatement alterTimeSeriesStatement ) {
290+ Map <String , String > alterMap = new HashMap <>();
291+ // rename
292+ if (ctx .RENAME () != null ) {
293+ alterTimeSeriesStatement .setAlterType (AlterTimeSeriesStatement .AlterType .RENAME );
294+ alterMap .put (
295+ parseIdentifier ((ctx .beforeName .getText ())), parseIdentifier (ctx .currentName .getText ()));
296+ } else if (ctx .SET () != null ) {
297+ // set
298+ alterTimeSeriesStatement .setAlterType (AlterTimeSeriesStatement .AlterType .SET );
299+ setMap (ctx , alterMap );
300+ } else if (ctx .DROP () != null ) {
301+ // drop
302+ alterTimeSeriesStatement .setAlterType (AlterTimeSeriesStatement .AlterType .DROP );
303+ for (IoTDBSqlParser .IdentifierContext dropId : ctx .identifier ()) {
304+ alterMap .put (parseIdentifier (dropId .getText ()), null );
305+ }
306+ } else if (ctx .TAGS () != null ) {
307+ // add tag
308+ alterTimeSeriesStatement .setAlterType ((AlterTimeSeriesStatement .AlterType .ADD_TAGS ));
309+ setMap (ctx , alterMap );
310+ } else if (ctx .ATTRIBUTES () != null ) {
311+ // add attribute
312+ alterTimeSeriesStatement .setAlterType (AlterTimeSeriesStatement .AlterType .ADD_ATTRIBUTES );
313+ setMap (ctx , alterMap );
314+ } else {
315+ // upsert
316+ alterTimeSeriesStatement .setAlterType (AlterTimeSeriesStatement .AlterType .UPSERT );
317+ if (ctx .aliasClause () != null ) {
318+ parseAliasClause (ctx .aliasClause (), alterTimeSeriesStatement );
319+ }
320+ if (ctx .tagClause () != null ) {
321+ parseTagClause (ctx .tagClause (), alterTimeSeriesStatement );
322+ }
323+ if (ctx .attributeClause () != null ) {
324+ parseAttributeClause (ctx .attributeClause (), alterTimeSeriesStatement );
325+ }
326+ }
327+ alterTimeSeriesStatement .setAlterMap (alterMap );
328+ }
329+
330+ public void parseAliasClause (
331+ IoTDBSqlParser .AliasClauseContext ctx , AlterTimeSeriesStatement alterTimeSeriesStatement ) {
332+ if (alterTimeSeriesStatement != null && ctx .identifier () != null ) {
333+ alterTimeSeriesStatement .setAlias ((parseIdentifier (ctx .identifier ().getText ())));
249334 }
250- // TODO: remove comments
251- // else if (operator instanceof AlterTimeSeriesOperator) {
252- // ((AlterTimeSeriesOperator) operator).setAttributesMap(attributes);
253- // }
254335 }
255336
256337 // Show Timeseries ========================================================================
0 commit comments