@@ -328,8 +328,6 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
328
328
SeriesScanOptions .Builder scanOptionsBuilder = getSeriesScanOptionsBuilder (node , context );
329
329
scanOptionsBuilder .withAllSensors (
330
330
context .getAllSensors (seriesPath .getDevice (), seriesPath .getMeasurement ()));
331
- scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
332
- scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
333
331
334
332
Expression pushDownPredicate = node .getPushDownPredicate ();
335
333
boolean predicateCanPushIntoScan = canPushIntoScan (pushDownPredicate );
@@ -341,6 +339,10 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
341
339
context .getTypeProvider ().getTemplatedInfo () != null ,
342
340
context .getTypeProvider ()));
343
341
}
342
+ if (pushDownPredicate == null || predicateCanPushIntoScan ) {
343
+ scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
344
+ scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
345
+ }
344
346
345
347
OperatorContext operatorContext =
346
348
context
@@ -364,17 +366,43 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
364
366
365
367
if (!predicateCanPushIntoScan ) {
366
368
checkState (!context .isBuildPlanUseTemplate (), "Push down predicate is not supported yet" );
367
- return constructFilterOperator (
368
- pushDownPredicate ,
369
- seriesScanOperator ,
370
- Collections .singletonList (ExpressionFactory .timeSeries (node .getSeriesPath ()))
371
- .toArray (new Expression [0 ]),
372
- Collections .singletonList (node .getSeriesPath ().getSeriesType ()),
373
- makeLayout (Collections .singletonList (node )),
374
- false ,
375
- node .getPlanNodeId (),
376
- node .getScanOrder (),
377
- context );
369
+ Operator rootOperator =
370
+ constructFilterOperator (
371
+ pushDownPredicate ,
372
+ seriesScanOperator ,
373
+ Collections .singletonList (ExpressionFactory .timeSeries (node .getSeriesPath ()))
374
+ .toArray (new Expression [0 ]),
375
+ Collections .singletonList (node .getSeriesPath ().getSeriesType ()),
376
+ makeLayout (Collections .singletonList (node )),
377
+ false ,
378
+ node .getPlanNodeId (),
379
+ node .getScanOrder (),
380
+ context );
381
+ if (node .getPushDownOffset () > 0 ) {
382
+ rootOperator =
383
+ new OffsetOperator (
384
+ context
385
+ .getDriverContext ()
386
+ .addOperatorContext (
387
+ context .getNextOperatorId (),
388
+ node .getPlanNodeId (),
389
+ OffsetOperator .class .getSimpleName ()),
390
+ node .getPushDownOffset (),
391
+ rootOperator );
392
+ }
393
+ if (node .getPushDownLimit () > 0 ) {
394
+ rootOperator =
395
+ new LimitOperator (
396
+ context
397
+ .getDriverContext ()
398
+ .addOperatorContext (
399
+ context .getNextOperatorId (),
400
+ node .getPlanNodeId (),
401
+ LimitOperator .class .getSimpleName ()),
402
+ node .getPushDownLimit (),
403
+ rootOperator );
404
+ }
405
+ return rootOperator ;
378
406
}
379
407
return seriesScanOperator ;
380
408
}
@@ -385,8 +413,6 @@ public Operator visitAlignedSeriesScan(
385
413
AlignedPath seriesPath = node .getAlignedPath ();
386
414
387
415
SeriesScanOptions .Builder scanOptionsBuilder = getSeriesScanOptionsBuilder (node , context );
388
- scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
389
- scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
390
416
scanOptionsBuilder .withAllSensors (
391
417
new HashSet <>(
392
418
context .isBuildPlanUseTemplate ()
@@ -403,6 +429,10 @@ public Operator visitAlignedSeriesScan(
403
429
context .getTypeProvider ().getTemplatedInfo () != null ,
404
430
context .getTypeProvider ()));
405
431
}
432
+ if (pushDownPredicate == null || predicateCanPushIntoScan ) {
433
+ scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
434
+ scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
435
+ }
406
436
407
437
OperatorContext operatorContext =
408
438
context
@@ -460,16 +490,43 @@ public Operator visitAlignedSeriesScan(
460
490
dataTypes .add (alignedPath .getSubMeasurementDataType (i ));
461
491
}
462
492
463
- return constructFilterOperator (
464
- pushDownPredicate ,
465
- seriesScanOperator ,
466
- expressions .toArray (new Expression [0 ]),
467
- dataTypes ,
468
- makeLayout (Collections .singletonList (node )),
469
- false ,
470
- node .getPlanNodeId (),
471
- node .getScanOrder (),
472
- context );
493
+ Operator rootOperator =
494
+ constructFilterOperator (
495
+ pushDownPredicate ,
496
+ seriesScanOperator ,
497
+ expressions .toArray (new Expression [0 ]),
498
+ dataTypes ,
499
+ makeLayout (Collections .singletonList (node )),
500
+ false ,
501
+ node .getPlanNodeId (),
502
+ node .getScanOrder (),
503
+ context );
504
+
505
+ if (node .getPushDownOffset () > 0 ) {
506
+ rootOperator =
507
+ new OffsetOperator (
508
+ context
509
+ .getDriverContext ()
510
+ .addOperatorContext (
511
+ context .getNextOperatorId (),
512
+ node .getPlanNodeId (),
513
+ OffsetOperator .class .getSimpleName ()),
514
+ node .getPushDownOffset (),
515
+ rootOperator );
516
+ }
517
+ if (node .getPushDownLimit () > 0 ) {
518
+ rootOperator =
519
+ new LimitOperator (
520
+ context
521
+ .getDriverContext ()
522
+ .addOperatorContext (
523
+ context .getNextOperatorId (),
524
+ node .getPlanNodeId (),
525
+ LimitOperator .class .getSimpleName ()),
526
+ node .getPushDownLimit (),
527
+ rootOperator );
528
+ }
529
+ return rootOperator ;
473
530
}
474
531
return seriesScanOperator ;
475
532
}
0 commit comments