@@ -328,8 +328,6 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
328328 SeriesScanOptions .Builder scanOptionsBuilder = getSeriesScanOptionsBuilder (node , context );
329329 scanOptionsBuilder .withAllSensors (
330330 context .getAllSensors (seriesPath .getDevice (), seriesPath .getMeasurement ()));
331- scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
332- scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
333331
334332 Expression pushDownPredicate = node .getPushDownPredicate ();
335333 boolean predicateCanPushIntoScan = canPushIntoScan (pushDownPredicate );
@@ -341,6 +339,10 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
341339 context .getTypeProvider ().getTemplatedInfo () != null ,
342340 context .getTypeProvider ()));
343341 }
342+ if (pushDownPredicate == null || predicateCanPushIntoScan ) {
343+ scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
344+ scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
345+ }
344346
345347 OperatorContext operatorContext =
346348 context
@@ -364,17 +366,43 @@ public Operator visitSeriesScan(SeriesScanNode node, LocalExecutionPlanContext c
364366
365367 if (!predicateCanPushIntoScan ) {
366368 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 ;
378406 }
379407 return seriesScanOperator ;
380408 }
@@ -385,8 +413,6 @@ public Operator visitAlignedSeriesScan(
385413 AlignedPath seriesPath = node .getAlignedPath ();
386414
387415 SeriesScanOptions .Builder scanOptionsBuilder = getSeriesScanOptionsBuilder (node , context );
388- scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
389- scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
390416 scanOptionsBuilder .withAllSensors (
391417 new HashSet <>(
392418 context .isBuildPlanUseTemplate ()
@@ -403,6 +429,10 @@ public Operator visitAlignedSeriesScan(
403429 context .getTypeProvider ().getTemplatedInfo () != null ,
404430 context .getTypeProvider ()));
405431 }
432+ if (pushDownPredicate == null || predicateCanPushIntoScan ) {
433+ scanOptionsBuilder .withPushDownLimit (node .getPushDownLimit ());
434+ scanOptionsBuilder .withPushDownOffset (node .getPushDownOffset ());
435+ }
406436
407437 OperatorContext operatorContext =
408438 context
@@ -460,16 +490,43 @@ public Operator visitAlignedSeriesScan(
460490 dataTypes .add (alignedPath .getSubMeasurementDataType (i ));
461491 }
462492
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 ;
473530 }
474531 return seriesScanOperator ;
475532 }
0 commit comments