5656import org .apache .iotdb .db .protocol .session .IClientSession ;
5757import org .apache .iotdb .db .protocol .session .SessionManager ;
5858import org .apache .iotdb .db .protocol .thrift .OperationType ;
59- import org .apache .iotdb .db .queryengine .common .FragmentInstanceId ;
60- import org .apache .iotdb .db .queryengine .common .PlanFragmentId ;
61- import org .apache .iotdb .db .queryengine .common .QueryId ;
6259import org .apache .iotdb .db .queryengine .common .SessionInfo ;
6360import org .apache .iotdb .db .queryengine .common .header .DatasetHeader ;
6461import org .apache .iotdb .db .queryengine .common .header .DatasetHeaderFactory ;
6562import org .apache .iotdb .db .queryengine .execution .aggregation .AccumulatorFactory ;
6663import org .apache .iotdb .db .queryengine .execution .aggregation .TreeAggregator ;
6764import org .apache .iotdb .db .queryengine .execution .driver .DriverContext ;
68- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext ;
69- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceManager ;
70- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceStateMachine ;
65+ import org .apache .iotdb .db .queryengine .execution .fragment .FakedFragmentInstanceContext ;
66+ import org .apache .iotdb .db .queryengine .execution .operator .OperatorContext ;
7167import org .apache .iotdb .db .queryengine .execution .operator .process .last .LastQueryUtil ;
7268import org .apache .iotdb .db .queryengine .execution .operator .source .AbstractSeriesAggregationScanOperator ;
7369import org .apache .iotdb .db .queryengine .execution .operator .source .AlignedSeriesAggregationScanOperator ;
7470import org .apache .iotdb .db .queryengine .execution .operator .source .SeriesAggregationScanOperator ;
75- import org .apache .iotdb .db .queryengine .execution .operator .source .SeriesScanOperator ;
7671import org .apache .iotdb .db .queryengine .plan .Coordinator ;
7772import org .apache .iotdb .db .queryengine .plan .analyze .ClusterPartitionFetcher ;
7873import org .apache .iotdb .db .queryengine .plan .analyze .IPartitionFetcher ;
124119import org .apache .iotdb .db .schemaengine .template .TemplateQueryType ;
125120import org .apache .iotdb .db .storageengine .StorageEngine ;
126121import org .apache .iotdb .db .storageengine .dataregion .DataRegion ;
122+ import org .apache .iotdb .db .storageengine .dataregion .read .QueryDataSource ;
127123import org .apache .iotdb .db .storageengine .rescon .quotas .DataNodeThrottleQuotaManager ;
128124import org .apache .iotdb .db .storageengine .rescon .quotas .OperationQuota ;
129125import org .apache .iotdb .db .subscription .agent .SubscriptionAgent ;
226222
227223import static org .apache .iotdb .commons .partition .DataPartition .NOT_ASSIGNED ;
228224import static org .apache .iotdb .db .queryengine .common .DataNodeEndPoints .isSameNode ;
229- import static org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext .createFragmentInstanceContext ;
230225import static org .apache .iotdb .db .queryengine .execution .operator .AggregationUtil .initTimeRangeIterator ;
231226import static org .apache .iotdb .db .utils .CommonUtils .getContentOfRequest ;
232227import static org .apache .iotdb .db .utils .CommonUtils .getContentOfTSFastLastDataQueryForOneDeviceReq ;
@@ -270,7 +265,7 @@ public class ClientRPCServiceImpl implements IClientRPCServiceWithHandler {
270265 private final TreeDeviceSchemaCacheManager DATA_NODE_SCHEMA_CACHE =
271266 TreeDeviceSchemaCacheManager .getInstance ();
272267
273- public static Duration DEFAULT_TIME_SLICE = new Duration (60_000 , TimeUnit .MILLISECONDS );
268+ public static final Duration DEFAULT_TIME_SLICE = new Duration (60_000 , TimeUnit .MILLISECONDS );
274269
275270 private static final int DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES =
276271 TSFileDescriptor .getInstance ().getConfig ().getMaxTsBlockSizeInBytes ();
@@ -790,6 +785,9 @@ private TSExecuteStatementResp executeAggregationQueryInternal(
790785 }
791786 }
792787
788+ private final List <InputLocation []> inputLocationList =
789+ Collections .singletonList (new InputLocation [] {new InputLocation (0 , 0 )});
790+
793791 @ SuppressWarnings ("java:S2095" ) // close() do nothing
794792 private List <TsBlock > executeGroupByQueryInternal (
795793 SessionInfo sessionInfo ,
@@ -812,21 +810,14 @@ private List<TsBlock> executeGroupByQueryInternal(
812810
813811 Filter timeFilter = TimeFilterApi .between (startTime , endTime - 1 );
814812
815- QueryId queryId = new QueryId ("stub_query" );
816- FragmentInstanceId instanceId =
817- new FragmentInstanceId (new PlanFragmentId (queryId , 0 ), "stub-instance" );
818- FragmentInstanceStateMachine stateMachine =
819- new FragmentInstanceStateMachine (
820- instanceId , FragmentInstanceManager .getInstance ().instanceNotificationExecutor );
821- FragmentInstanceContext fragmentInstanceContext =
822- createFragmentInstanceContext (
823- instanceId , stateMachine , sessionInfo , dataRegionList .get (0 ), timeFilter );
813+ FakedFragmentInstanceContext fragmentInstanceContext =
814+ new FakedFragmentInstanceContext (timeFilter , dataRegionList .get (0 ));
815+
824816 DriverContext driverContext = new DriverContext (fragmentInstanceContext , 0 );
825817 PlanNodeId planNodeId = new PlanNodeId ("1" );
826- driverContext .addOperatorContext (1 , planNodeId , SeriesScanOperator .class .getSimpleName ());
827- driverContext
828- .getOperatorContexts ()
829- .forEach (operatorContext -> operatorContext .setMaxRunTime (DEFAULT_TIME_SLICE ));
818+ OperatorContext operatorContext =
819+ new OperatorContext (1 , planNodeId , "SeriesAggregationScanOperator" , driverContext );
820+ operatorContext .setMaxRunTime (DEFAULT_TIME_SLICE );
830821
831822 SeriesScanOptions .Builder scanOptionsBuilder = new SeriesScanOptions .Builder ();
832823 scanOptionsBuilder .withAllSensors (Collections .singleton (measurement ));
@@ -844,14 +835,18 @@ private List<TsBlock> executeGroupByQueryInternal(
844835 true ,
845836 true ),
846837 AggregationStep .SINGLE ,
847- Collections . singletonList ( new InputLocation [] { new InputLocation ( 0 , 0 )}) );
838+ inputLocationList );
848839
849840 GroupByTimeParameter groupByTimeParameter =
850841 new GroupByTimeParameter (
851842 startTime , endTime , new TimeDuration (0 , interval ), new TimeDuration (0 , interval ), true );
852843
853844 IMeasurementSchema measurementSchema = new MeasurementSchema (measurement , dataType );
854845 AbstractSeriesAggregationScanOperator operator ;
846+ boolean canUseStatistics =
847+ !TSDataType .BLOB .equals (dataType )
848+ || (!TAggregationType .LAST_VALUE .equals (aggregationType )
849+ && !TAggregationType .FIRST_VALUE .equals (aggregationType ));
855850 IFullPath path ;
856851 if (isAligned ) {
857852 path =
@@ -865,36 +860,37 @@ private List<TsBlock> executeGroupByQueryInternal(
865860 (AlignedFullPath ) path ,
866861 Ordering .ASC ,
867862 scanOptionsBuilder .build (),
868- driverContext . getOperatorContexts (). get ( 0 ) ,
863+ operatorContext ,
869864 Collections .singletonList (aggregator ),
870865 initTimeRangeIterator (groupByTimeParameter , true , true , sessionInfo .getZoneId ()),
871866 groupByTimeParameter ,
872867 DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES ,
873- !TSDataType .BLOB .equals (dataType )
874- || (!TAggregationType .LAST_VALUE .equals (aggregationType )
875- && !TAggregationType .FIRST_VALUE .equals (aggregationType )));
868+ canUseStatistics );
876869 } else {
877870 path = new NonAlignedFullPath (deviceID , measurementSchema );
871+ // String[] splits = device.split("\\.");
872+ // String[] fullPaths = new String[splits.length + 1];
873+ // System.arraycopy(splits, 0, fullPaths, 0, splits.length);
874+ // fullPaths[splits.length] = measurement;
875+ // path = new MeasurementPath(fullPaths, measurementSchema);
878876 operator =
879877 new SeriesAggregationScanOperator (
880878 planNodeId ,
881879 path ,
882880 Ordering .ASC ,
883881 scanOptionsBuilder .build (),
884- driverContext . getOperatorContexts (). get ( 0 ) ,
882+ operatorContext ,
885883 Collections .singletonList (aggregator ),
886884 initTimeRangeIterator (groupByTimeParameter , true , true , sessionInfo .getZoneId ()),
887885 groupByTimeParameter ,
888886 DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES ,
889- !TSDataType .BLOB .equals (dataType )
890- || (!TAggregationType .LAST_VALUE .equals (aggregationType )
891- && !TAggregationType .FIRST_VALUE .equals (aggregationType )));
887+ canUseStatistics );
892888 }
893889
894890 try {
895891 List <TsBlock > result = new ArrayList <>();
896- fragmentInstanceContext .setSourcePaths ( Collections . singletonList ( path ) );
897- operator .initQueryDataSource (fragmentInstanceContext . getSharedQueryDataSource () );
892+ QueryDataSource dataSource = fragmentInstanceContext .getSharedQueryDataSource ( path );
893+ operator .initQueryDataSource (dataSource );
898894
899895 while (operator .hasNext ()) {
900896 result .add (operator .next ());
@@ -904,7 +900,7 @@ private List<TsBlock> executeGroupByQueryInternal(
904900 } catch (Exception e ) {
905901 throw new RuntimeException (e );
906902 } finally {
907- fragmentInstanceContext .releaseResource ();
903+ fragmentInstanceContext .releaseSharedQueryDataSource ();
908904 }
909905 }
910906
@@ -1307,7 +1303,7 @@ public TSExecuteStatementResp executeGroupByQueryIntervalQuery(TSGroupByQueryInt
13071303 deviceId ,
13081304 measurementId ,
13091305 dataType ,
1310- true ,
1306+ req . isAligned ,
13111307 req .getStartTime (),
13121308 req .getEndTime (),
13131309 req .getInterval (),
0 commit comments