EmmyMiao87 commented on code in PR #8861: URL: https://github.com/apache/incubator-doris/pull/8861#discussion_r867311515
########## fe/fe-core/src/main/java/org/apache/doris/statistics/MetaStatisticsTask.java: ########## @@ -17,21 +17,85 @@ package org.apache.doris.statistics; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.DdlException; + +import com.google.common.collect.Maps; + import java.util.List; +import java.util.Map; -/* -A statistics task that directly collects statistics by reading FE meta. +/** + * A statistics task that directly collects statistics by reading FE meta. + * e.g. for fixed-length types such as Int type and Long type we get their size from metadata. */ public class MetaStatisticsTask extends StatisticsTask { - public MetaStatisticsTask(long jobId, StatsGranularityDesc granularityDesc, - StatsCategoryDesc categoryDesc, List<StatsType> statsTypeList) { + public MetaStatisticsTask(long jobId, + StatsGranularityDesc granularityDesc, + StatsCategoryDesc categoryDesc, + List<StatsType> statsTypeList) { super(jobId, granularityDesc, categoryDesc, statsTypeList); } @Override public StatisticsTaskResult call() throws Exception { - // TODO - return null; + Map<StatsType, String> statsTypeToValue = Maps.newHashMap(); + List<StatsType> statsTypeList = getStatsTypeList(); + + for (StatsType statsType : statsTypeList) { + switch (statsType) { + case ROW_COUNT: + getRowCount(statsType, statsTypeToValue); + break; + case DATA_SIZE: + getDataSize(statsType, statsTypeToValue); + break; + case MAX_SIZE: + case AVG_SIZE: + getColSize(statsType, statsTypeToValue); + break; + default: + throw new DdlException("Unsupported statistics type(" + statsType + ")."); + } + } + + return new StatisticsTaskResult(granularityDesc, categoryDesc, statsTypeToValue); + } + + private void getRowCount(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); Review Comment: Add Preconditions.check() before this line. Avoid situations where table id is null. ########## fe/fe-core/src/main/java/org/apache/doris/statistics/MetaStatisticsTask.java: ########## @@ -17,21 +17,85 @@ package org.apache.doris.statistics; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.DdlException; + +import com.google.common.collect.Maps; + import java.util.List; +import java.util.Map; -/* -A statistics task that directly collects statistics by reading FE meta. +/** + * A statistics task that directly collects statistics by reading FE meta. + * e.g. for fixed-length types such as Int type and Long type we get their size from metadata. */ public class MetaStatisticsTask extends StatisticsTask { - public MetaStatisticsTask(long jobId, StatsGranularityDesc granularityDesc, - StatsCategoryDesc categoryDesc, List<StatsType> statsTypeList) { + public MetaStatisticsTask(long jobId, + StatsGranularityDesc granularityDesc, + StatsCategoryDesc categoryDesc, + List<StatsType> statsTypeList) { super(jobId, granularityDesc, categoryDesc, statsTypeList); } @Override public StatisticsTaskResult call() throws Exception { - // TODO - return null; + Map<StatsType, String> statsTypeToValue = Maps.newHashMap(); + List<StatsType> statsTypeList = getStatsTypeList(); + + for (StatsType statsType : statsTypeList) { + switch (statsType) { + case ROW_COUNT: + getRowCount(statsType, statsTypeToValue); + break; + case DATA_SIZE: + getDataSize(statsType, statsTypeToValue); + break; + case MAX_SIZE: + case AVG_SIZE: + getColSize(statsType, statsTypeToValue); + break; + default: + throw new DdlException("Unsupported statistics type(" + statsType + ")."); + } + } + + return new StatisticsTaskResult(granularityDesc, categoryDesc, statsTypeToValue); + } + + private void getRowCount(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); + long rowCount = olapTable.getRowCount(); + statsTypeToValue.put(statsType, String.valueOf(rowCount)); + } + + private void getDataSize(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); Review Comment: Same as above ########## fe/fe-core/src/main/java/org/apache/doris/statistics/MetaStatisticsTask.java: ########## @@ -17,21 +17,85 @@ package org.apache.doris.statistics; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.DdlException; + +import com.google.common.collect.Maps; + import java.util.List; +import java.util.Map; -/* -A statistics task that directly collects statistics by reading FE meta. +/** + * A statistics task that directly collects statistics by reading FE meta. + * e.g. for fixed-length types such as Int type and Long type we get their size from metadata. */ public class MetaStatisticsTask extends StatisticsTask { - public MetaStatisticsTask(long jobId, StatsGranularityDesc granularityDesc, - StatsCategoryDesc categoryDesc, List<StatsType> statsTypeList) { + public MetaStatisticsTask(long jobId, + StatsGranularityDesc granularityDesc, + StatsCategoryDesc categoryDesc, + List<StatsType> statsTypeList) { super(jobId, granularityDesc, categoryDesc, statsTypeList); } @Override public StatisticsTaskResult call() throws Exception { - // TODO - return null; + Map<StatsType, String> statsTypeToValue = Maps.newHashMap(); + List<StatsType> statsTypeList = getStatsTypeList(); + + for (StatsType statsType : statsTypeList) { + switch (statsType) { + case ROW_COUNT: + getRowCount(statsType, statsTypeToValue); + break; + case DATA_SIZE: + getDataSize(statsType, statsTypeToValue); + break; + case MAX_SIZE: + case AVG_SIZE: + getColSize(statsType, statsTypeToValue); + break; + default: + throw new DdlException("Unsupported statistics type(" + statsType + ")."); + } + } + + return new StatisticsTaskResult(granularityDesc, categoryDesc, statsTypeToValue); + } + + private void getRowCount(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); + long rowCount = olapTable.getRowCount(); + statsTypeToValue.put(statsType, String.valueOf(rowCount)); + } + + private void getDataSize(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); + long dataSize = olapTable.getDataSize(); + statsTypeToValue.put(statsType, String.valueOf(dataSize)); + } + + private void getColSize(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + long tableId = categoryDesc.getTableId(); + Table table = db.getTableOrDdlException(tableId); + String columnName = categoryDesc.getColumnName(); Review Comment: same as above ########## fe/fe-core/src/main/java/org/apache/doris/statistics/MetaStatisticsTask.java: ########## @@ -17,21 +17,85 @@ package org.apache.doris.statistics; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.DdlException; + +import com.google.common.collect.Maps; + import java.util.List; +import java.util.Map; -/* -A statistics task that directly collects statistics by reading FE meta. +/** + * A statistics task that directly collects statistics by reading FE meta. + * e.g. for fixed-length types such as Int type and Long type we get their size from metadata. */ public class MetaStatisticsTask extends StatisticsTask { - public MetaStatisticsTask(long jobId, StatsGranularityDesc granularityDesc, - StatsCategoryDesc categoryDesc, List<StatsType> statsTypeList) { + public MetaStatisticsTask(long jobId, + StatsGranularityDesc granularityDesc, + StatsCategoryDesc categoryDesc, + List<StatsType> statsTypeList) { super(jobId, granularityDesc, categoryDesc, statsTypeList); } @Override public StatisticsTaskResult call() throws Exception { - // TODO - return null; + Map<StatsType, String> statsTypeToValue = Maps.newHashMap(); + List<StatsType> statsTypeList = getStatsTypeList(); + + for (StatsType statsType : statsTypeList) { + switch (statsType) { + case ROW_COUNT: + getRowCount(statsType, statsTypeToValue); + break; + case DATA_SIZE: + getDataSize(statsType, statsTypeToValue); + break; + case MAX_SIZE: + case AVG_SIZE: + getColSize(statsType, statsTypeToValue); + break; + default: + throw new DdlException("Unsupported statistics type(" + statsType + ")."); + } + } + + return new StatisticsTaskResult(granularityDesc, categoryDesc, statsTypeToValue); + } + + private void getRowCount(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); + long rowCount = olapTable.getRowCount(); + statsTypeToValue.put(statsType, String.valueOf(rowCount)); + } + + private void getDataSize(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + long tableId = categoryDesc.getTableId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + OlapTable olapTable = (OlapTable) db.getTableOrDdlException(tableId); + long dataSize = olapTable.getDataSize(); + statsTypeToValue.put(statsType, String.valueOf(dataSize)); + } + + private void getColSize(StatsType statsType, Map<StatsType, String> statsTypeToValue) throws DdlException { + StatsCategoryDesc categoryDesc = getCategoryDesc(); + long dbId = categoryDesc.getDbId(); + Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbId); + long tableId = categoryDesc.getTableId(); Review Comment: same as above -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org