5353import org .apache .iotdb .db .protocol .session .IClientSession ;
5454import org .apache .iotdb .db .protocol .session .SessionManager ;
5555import org .apache .iotdb .db .protocol .thrift .OperationType ;
56- import org .apache .iotdb .db .queryengine .common .FragmentInstanceId ;
57- import org .apache .iotdb .db .queryengine .common .PlanFragmentId ;
58- import org .apache .iotdb .db .queryengine .common .QueryId ;
5956import org .apache .iotdb .db .queryengine .common .SessionInfo ;
6057import org .apache .iotdb .db .queryengine .common .header .ColumnHeader ;
6158import org .apache .iotdb .db .queryengine .common .header .DatasetHeader ;
6259import org .apache .iotdb .db .queryengine .common .header .DatasetHeaderFactory ;
6360import org .apache .iotdb .db .queryengine .execution .aggregation .AccumulatorFactory ;
6461import org .apache .iotdb .db .queryengine .execution .aggregation .Aggregator ;
6562import org .apache .iotdb .db .queryengine .execution .driver .DriverContext ;
66- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext ;
67- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceManager ;
68- import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceStateMachine ;
63+ import org .apache .iotdb .db .queryengine .execution .fragment .FakedFragmentInstanceContext ;
64+ import org .apache .iotdb .db .queryengine .execution .operator .OperatorContext ;
6965import org .apache .iotdb .db .queryengine .execution .operator .process .last .LastQueryUtil ;
7066import org .apache .iotdb .db .queryengine .execution .operator .source .AbstractSeriesAggregationScanOperator ;
7167import org .apache .iotdb .db .queryengine .execution .operator .source .AlignedSeriesAggregationScanOperator ;
7268import org .apache .iotdb .db .queryengine .execution .operator .source .SeriesAggregationScanOperator ;
73- import org .apache .iotdb .db .queryengine .execution .operator .source .SeriesScanOperator ;
7469import org .apache .iotdb .db .queryengine .plan .Coordinator ;
7570import org .apache .iotdb .db .queryengine .plan .analyze .ClusterPartitionFetcher ;
7671import org .apache .iotdb .db .queryengine .plan .analyze .IPartitionFetcher ;
109104import org .apache .iotdb .db .schemaengine .template .TemplateQueryType ;
110105import org .apache .iotdb .db .storageengine .StorageEngine ;
111106import org .apache .iotdb .db .storageengine .dataregion .DataRegion ;
107+ import org .apache .iotdb .db .storageengine .dataregion .read .QueryDataSource ;
112108import org .apache .iotdb .db .storageengine .rescon .quotas .DataNodeThrottleQuotaManager ;
113109import org .apache .iotdb .db .storageengine .rescon .quotas .OperationQuota ;
114110import org .apache .iotdb .db .subscription .agent .SubscriptionAgent ;
205201
206202import static org .apache .iotdb .commons .partition .DataPartition .NOT_ASSIGNED ;
207203import static org .apache .iotdb .db .queryengine .common .DataNodeEndPoints .isSameNode ;
208- import static org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext .createFragmentInstanceContext ;
209204import static org .apache .iotdb .db .queryengine .execution .operator .AggregationUtil .initTimeRangeIterator ;
210205import static org .apache .iotdb .db .utils .CommonUtils .getContentOfRequest ;
211206import static org .apache .iotdb .db .utils .CommonUtils .getContentOfTSFastLastDataQueryForOneDeviceReq ;
@@ -244,7 +239,7 @@ public class ClientRPCServiceImpl implements IClientRPCServiceWithHandler {
244239
245240 private final DataNodeSchemaCache DATA_NODE_SCHEMA_CACHE = DataNodeSchemaCache .getInstance ();
246241
247- public static Duration DEFAULT_TIME_SLICE = new Duration (60_000 , TimeUnit .MILLISECONDS );
242+ public static final Duration DEFAULT_TIME_SLICE = new Duration (60_000 , TimeUnit .MILLISECONDS );
248243
249244 private static final int DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES =
250245 TSFileDescriptor .getInstance ().getConfig ().getMaxTsBlockSizeInBytes ();
@@ -655,6 +650,9 @@ private TSExecuteStatementResp executeAggregationQueryInternal(
655650 }
656651 }
657652
653+ private final List <InputLocation []> inputLocationList =
654+ Collections .singletonList (new InputLocation [] {new InputLocation (0 , 0 )});
655+
658656 @ SuppressWarnings ("java:S2095" ) // close() do nothing
659657 private List <TsBlock > executeGroupByQueryInternal (
660658 SessionInfo sessionInfo ,
@@ -677,21 +675,14 @@ private List<TsBlock> executeGroupByQueryInternal(
677675
678676 Filter timeFilter = TimeFilterApi .between (startTime , endTime - 1 );
679677
680- QueryId queryId = new QueryId ("stub_query" );
681- FragmentInstanceId instanceId =
682- new FragmentInstanceId (new PlanFragmentId (queryId , 0 ), "stub-instance" );
683- FragmentInstanceStateMachine stateMachine =
684- new FragmentInstanceStateMachine (
685- instanceId , FragmentInstanceManager .getInstance ().instanceNotificationExecutor );
686- FragmentInstanceContext fragmentInstanceContext =
687- createFragmentInstanceContext (
688- instanceId , stateMachine , sessionInfo , dataRegionList .get (0 ), timeFilter );
678+ FakedFragmentInstanceContext fragmentInstanceContext =
679+ new FakedFragmentInstanceContext (timeFilter , dataRegionList .get (0 ));
680+
689681 DriverContext driverContext = new DriverContext (fragmentInstanceContext , 0 );
690682 PlanNodeId planNodeId = new PlanNodeId ("1" );
691- driverContext .addOperatorContext (1 , planNodeId , SeriesScanOperator .class .getSimpleName ());
692- driverContext
693- .getOperatorContexts ()
694- .forEach (operatorContext -> operatorContext .setMaxRunTime (DEFAULT_TIME_SLICE ));
683+ OperatorContext operatorContext =
684+ new OperatorContext (1 , planNodeId , "SeriesAggregationScanOperator" , driverContext );
685+ operatorContext .setMaxRunTime (DEFAULT_TIME_SLICE );
695686
696687 SeriesScanOptions .Builder scanOptionsBuilder = new SeriesScanOptions .Builder ();
697688 scanOptionsBuilder .withAllSensors (Collections .singleton (measurement ));
@@ -709,19 +700,23 @@ private List<TsBlock> executeGroupByQueryInternal(
709700 true ,
710701 true ),
711702 AggregationStep .SINGLE ,
712- Collections . singletonList ( new InputLocation [] { new InputLocation ( 0 , 0 )}) );
703+ inputLocationList );
713704
714705 GroupByTimeParameter groupByTimeParameter =
715706 new GroupByTimeParameter (
716707 startTime , endTime , new TimeDuration (0 , interval ), new TimeDuration (0 , interval ), true );
717708
718709 IMeasurementSchema measurementSchema = new MeasurementSchema (measurement , dataType );
719710 AbstractSeriesAggregationScanOperator operator ;
711+ boolean canUseStatistics =
712+ !TSDataType .BLOB .equals (dataType )
713+ || (!TAggregationType .LAST_VALUE .equals (aggregationType )
714+ && !TAggregationType .FIRST_VALUE .equals (aggregationType ));
720715 PartialPath path ;
721716 if (isAligned ) {
722717 path =
723718 new AlignedPath (
724- device ,
719+ device . split ( " \\ ." ) ,
725720 Collections .singletonList (measurement ),
726721 Collections .singletonList (measurementSchema ));
727722 operator =
@@ -730,36 +725,36 @@ private List<TsBlock> executeGroupByQueryInternal(
730725 (AlignedPath ) path ,
731726 Ordering .ASC ,
732727 scanOptionsBuilder .build (),
733- driverContext . getOperatorContexts (). get ( 0 ) ,
728+ operatorContext ,
734729 Collections .singletonList (aggregator ),
735730 initTimeRangeIterator (groupByTimeParameter , true , true , sessionInfo .getZoneId ()),
736731 groupByTimeParameter ,
737732 DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES ,
738- !TSDataType .BLOB .equals (dataType )
739- || (!TAggregationType .LAST_VALUE .equals (aggregationType )
740- && !TAggregationType .FIRST_VALUE .equals (aggregationType )));
733+ canUseStatistics );
741734 } else {
742- path = new MeasurementPath (device , measurement , measurementSchema );
735+ String [] splits = device .split ("\\ ." );
736+ String [] fullPaths = new String [splits .length + 1 ];
737+ System .arraycopy (splits , 0 , fullPaths , 0 , splits .length );
738+ fullPaths [splits .length ] = measurement ;
739+ path = new MeasurementPath (fullPaths , measurementSchema );
743740 operator =
744741 new SeriesAggregationScanOperator (
745742 planNodeId ,
746743 path ,
747744 Ordering .ASC ,
748745 scanOptionsBuilder .build (),
749- driverContext . getOperatorContexts (). get ( 0 ) ,
746+ operatorContext ,
750747 Collections .singletonList (aggregator ),
751748 initTimeRangeIterator (groupByTimeParameter , true , true , sessionInfo .getZoneId ()),
752749 groupByTimeParameter ,
753750 DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES ,
754- !TSDataType .BLOB .equals (dataType )
755- || (!TAggregationType .LAST_VALUE .equals (aggregationType )
756- && !TAggregationType .FIRST_VALUE .equals (aggregationType )));
751+ canUseStatistics );
757752 }
758753
759754 try {
760755 List <TsBlock > result = new ArrayList <>();
761- fragmentInstanceContext .setSourcePaths ( Collections . singletonList ( path ) );
762- operator .initQueryDataSource (fragmentInstanceContext . getSharedQueryDataSource () );
756+ QueryDataSource dataSource = fragmentInstanceContext .getSharedQueryDataSource ( path );
757+ operator .initQueryDataSource (dataSource );
763758
764759 while (operator .hasNext ()) {
765760 result .add (operator .next ());
@@ -769,7 +764,7 @@ private List<TsBlock> executeGroupByQueryInternal(
769764 } catch (Exception e ) {
770765 throw new RuntimeException (e );
771766 } finally {
772- fragmentInstanceContext .releaseResource ();
767+ fragmentInstanceContext .releaseSharedQueryDataSource ();
773768 }
774769 }
775770
@@ -1075,7 +1070,7 @@ public TSExecuteStatementResp executeGroupByQueryIntervalQuery(TSGroupByQueryInt
10751070 deviceId ,
10761071 measurementId ,
10771072 dataType ,
1078- true ,
1073+ req . isAligned ,
10791074 req .getStartTime (),
10801075 req .getEndTime (),
10811076 req .getInterval (),
0 commit comments