1919 *
2020 */
2121
22- package org .apache .iotdb .db .queryengine .plan .relational .planner . ir ;
22+ package org .apache .iotdb .db .queryengine .plan .relational .planner ;
2323
2424import org .apache .iotdb .common .rpc .thrift .TEndPoint ;
2525import org .apache .iotdb .commons .client .IClientManager ;
7070public class CteMaterializer {
7171 private static final Logger LOGGER = LoggerFactory .getLogger (CteMaterializer .class );
7272 private static String CTE_MATERIALIZATION_FAILURE_WARNING =
73- "***** CTE MATERIALIZATION failed ! INLINE mode is adopted in main query *****" ;
73+ "***** Failed to materialize CTE ! INLINE mode is adopted in the main query *****" ;
7474
7575 private static final Coordinator coordinator = Coordinator .getInstance ();
7676
77- private CteMaterializer () {}
77+ public void materializeCTE (Analysis analysis , MPPQueryContext context ) {
78+ if (coordinator == null ) {
79+ return ;
80+ }
7881
79- public static void materializeCTE (Analysis analysis , MPPQueryContext context ) {
8082 analysis
8183 .getNamedQueries ()
8284 .forEach (
@@ -104,7 +106,7 @@ public static void materializeCTE(Analysis analysis, MPPQueryContext context) {
104106 });
105107 }
106108
107- public static void cleanUpCTE (MPPQueryContext context ) {
109+ public void cleanUpCTE (MPPQueryContext context ) {
108110 Map <NodeRef <Table >, CteDataStore > cteDataStores = context .getCteDataStores ();
109111 cteDataStores
110112 .values ()
@@ -116,8 +118,7 @@ public static void cleanUpCTE(MPPQueryContext context) {
116118 cteDataStores .clear ();
117119 }
118120
119- private static CteDataStore fetchCteQueryResult (
120- Table table , Query query , MPPQueryContext context ) {
121+ private CteDataStore fetchCteQueryResult (Table table , Query query , MPPQueryContext context ) {
121122 final long queryId = SessionManager .getInstance ().requestQueryId ();
122123 Throwable t = null ;
123124 try {
@@ -184,7 +185,7 @@ private static CteDataStore fetchCteQueryResult(
184185 return null ;
185186 }
186187
187- private static TableSchema getTableSchema (DatasetHeader datasetHeader , String cteName ) {
188+ private TableSchema getTableSchema (DatasetHeader datasetHeader , String cteName ) {
188189 final List <String > columnNames = datasetHeader .getRespColumns ();
189190 final List <TSDataType > columnDataTypes = datasetHeader .getRespDataTypes ();
190191 if (columnNames .size () != columnDataTypes .size ()) {
@@ -213,7 +214,7 @@ private static TableSchema getTableSchema(DatasetHeader datasetHeader, String ct
213214 return new TableSchema (cteName , columnSchemaList );
214215 }
215216
216- private static List <String > getCteExplainAnalyzeLines (
217+ private List <String > getCteExplainAnalyzeLines (
217218 FragmentInstanceStatisticsDrawer fragmentInstanceStatisticsDrawer ,
218219 List <FragmentInstance > instances ,
219220 boolean verbose )
@@ -231,7 +232,7 @@ private static List<String> getCteExplainAnalyzeLines(
231232 return statisticLines .stream ().map (StatisticLine ::getValue ).collect (Collectors .toList ());
232233 }
233234
234- private static void handleCteExplainAnalyzeResults (
235+ private void handleCteExplainAnalyzeResults (
235236 MPPQueryContext context , long queryId , Table table , String warnMessage ) {
236237 QueryExecution execution = (QueryExecution ) coordinator .getQueryExecution (queryId );
237238 DistributedQueryPlan distributedQueryPlan = execution .getDistributedPlan ();
@@ -265,7 +266,7 @@ private static void handleCteExplainAnalyzeResults(
265266 }
266267 }
267268
268- private static void handleCteExplainResults (MPPQueryContext context , long queryId , Table table ) {
269+ private void handleCteExplainResults (MPPQueryContext context , long queryId , Table table ) {
269270 QueryExecution execution = (QueryExecution ) coordinator .getQueryExecution (queryId );
270271 DistributedQueryPlan distributedQueryPlan = execution .getDistributedPlan ();
271272 if (distributedQueryPlan == null ) {
@@ -276,4 +277,16 @@ private static void handleCteExplainResults(MPPQueryContext context, long queryI
276277 List <String > lines = distributedQueryPlan .getPlanText ();
277278 context .addCteExplainResult (table , new Pair <>(-1 , lines ));
278279 }
280+
281+ private static class CteMaterializerHolder {
282+ private static final CteMaterializer INSTANCE = new CteMaterializer ();
283+
284+ private CteMaterializerHolder () {
285+ // Empty constructor
286+ }
287+ }
288+
289+ public static CteMaterializer getInstance () {
290+ return CteMaterializerHolder .INSTANCE ;
291+ }
279292}
0 commit comments