Github user jackylk commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2197#discussion_r183286607
--- Diff:
core/src/main/java/org/apache/carbondata/core/profiler/ExplainCollector.java ---
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.carbondata.core.profiler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.core.metadata.schema.table.DataMapSchema;
+
+/**
+ * An information collector used for EXPLAIN command, to print out
+ * SQL rewrite and pruning information
+ */
[email protected]
+public class ExplainCollector {
+
+ private static final ThreadLocal<ExplainCollector> explainProfiler = new
ThreadLocal<>();
+
+ private List<String> olapDataMapProviders = new ArrayList<>();
+ private List<String> olapDataMapNames = new ArrayList<>();
+
+ // mapping of table name to pruning info
+ private Map<String, TablePruningInfo> scans = new ConcurrentHashMap<>();
+
+ public void recordMatchedOlapDataMap(String dataMapProvider, String
dataMapName) {
+ Objects.requireNonNull(dataMapProvider);
+ Objects.requireNonNull(dataMapName);
+ olapDataMapProviders.add(dataMapProvider);
+ olapDataMapNames.add(dataMapName);
+ }
+
+ public static boolean enabled() {
+ return explainProfiler.get() != null;
+ }
+
+ public static void setup() {
+ explainProfiler.set(new ExplainCollector());
+ }
+
+ public static ExplainCollector get() {
+ return explainProfiler.get();
+ }
+
+ public static void addPruningInfo(String tableName) {
+ if (enabled()) {
+ ExplainCollector profiler = get();
+ if (!profiler.scans.containsKey(tableName)) {
+ profiler.scans.put(tableName, new TablePruningInfo());
+ }
+ }
+ }
+
+ public static void setFilterStatement(String filterStatement) {
+ if (enabled()) {
+ TablePruningInfo scan = getCurrentTablePruningInfo();
+ scan.setFilterStatement(filterStatement);
+ }
+ }
+
+ public static void recordDefaultDataMapPruning(DataMapSchema
dataMapSchema, int numBlocklets) {
+ if (enabled()) {
+ TablePruningInfo scan = getCurrentTablePruningInfo();
+ scan.setNumBlockletsAfterDefaultPruning(dataMapSchema, numBlocklets);
+ }
+ }
+
+ public static void recordCGDataMapPruning(DataMapSchema dataMapSchema,
int numBlocklets) {
+ if (enabled()) {
+ TablePruningInfo scan = getCurrentTablePruningInfo();
+ scan.setNumBlockletsAfterCGPruning(dataMapSchema, numBlocklets);
+ }
+ }
+
+ public static void recordFGDataMapPruning(DataMapSchema dataMapSchema,
int numBlocklets) {
+ if (enabled()) {
+ TablePruningInfo scan = getCurrentTablePruningInfo();
+ scan.setNumBlockletsAfterFGPruning(dataMapSchema, numBlocklets);
+ }
+ }
+
+ public static void setTotalBlocklets(int totalBlocklets) {
+ if (enabled()) {
+ TablePruningInfo scan = getCurrentTablePruningInfo();
+ scan.setTotalBlocklets(totalBlocklets);
+ }
+ }
+
+ /**
+ * Return the current TablePruningInfo (It is the last one in the map,
since it is in
+ * single thread)
+ */
+ private static TablePruningInfo getCurrentTablePruningInfo() {
--- End diff --
ok, I will add CarbonTable parameter in all functions in this class
---