morningman commented on code in PR #27967: URL: https://github.com/apache/doris/pull/27967#discussion_r1413907702
########## fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinTableValuedFunctions.java: ########## @@ -51,6 +54,9 @@ public class BuiltinTableValuedFunctions implements FunctionHelper { tableValued(Numbers.class, "numbers"), tableValued(Queries.class, "queries"), tableValued(S3.class, "s3"), + tableValued(Mtmvs.class, "mtmvs"), Review Comment: mv_infos ########## fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/InsertTask.java: ########## @@ -188,4 +217,45 @@ public List<String> getShowInfo() { return jobInfo; } + @Override + public TRow getTvfInfo() { + TRow trow = new TRow(); + if (loadJob == null) { + return null; Review Comment: return trow? ########## fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVJob.java: ########## @@ -139,6 +164,19 @@ public List<String> getShowInfo() { return data; } + @Override + public TRow getTvfInfo() { + TRow trow = new TRow(); + trow.addToColumnValue(new TCell().setLongVal(super.getJobId())); Review Comment: For other tvf, the id is string type. Why use long for this tvf? ########## fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java: ########## @@ -50,6 +57,27 @@ public class MTMVTask extends AbstractTask { private static final Logger LOG = LogManager.getLogger(MTMVTask.class); public static final Long MAX_HISTORY_TASKS_NUM = 100L; + public static final ImmutableList<Column> SCHEMA = ImmutableList.of( + new Column("TaskId", ScalarType.createType(PrimitiveType.BIGINT)), Review Comment: ditto ########## fe/fe-core/src/main/java/org/apache/doris/tablefunction/JobsTableValuedFunction.java: ########## @@ -0,0 +1,121 @@ +// 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.doris.tablefunction; + +import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.catalog.Column; +import org.apache.doris.job.common.JobType; +import org.apache.doris.job.extensions.insert.InsertJob; +import org.apache.doris.job.extensions.mtmv.MTMVJob; +import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.thrift.TJobsMetadataParams; +import org.apache.doris.thrift.TMetaScanRange; +import org.apache.doris.thrift.TMetadataTableRequestParams; +import org.apache.doris.thrift.TMetadataType; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; + +import java.util.List; +import java.util.Map; + +/** + * The Implement of table valued function + * jobs("type" = "mtmv"). + */ +public class JobsTableValuedFunction extends MetadataTableValuedFunction { + public static final String NAME = "jobs"; + private static final String TYPE = "type"; + + private static final ImmutableSet<String> PROPERTIES_SET = ImmutableSet.of(TYPE); + + private final JobType jobType; + + public JobsTableValuedFunction(Map<String, String> params) throws AnalysisException { + Map<String, String> validParams = Maps.newHashMap(); + for (String key : params.keySet()) { + if (!PROPERTIES_SET.contains(key.toLowerCase())) { + throw new AnalysisException("'" + key + "' is invalid property"); + } + validParams.put(key.toLowerCase(), params.get(key)); + } + String type = validParams.get(TYPE); + if (type == null) { + throw new AnalysisException("Invalid job metadata query"); + } + JobType jobType = JobType.valueOf(type.toUpperCase()); + if (jobType == null) { + throw new AnalysisException("Invalid job metadata query"); + } + this.jobType = jobType; + UserIdentity userIdentity = ConnectContext.get().getCurrentUserIdentity(); + if (!userIdentity.isRootUser()) { + throw new AnalysisException("only root user can operate"); + } + } + + public static Integer getColumnIndexFromColumnName(String columnName, TMetadataTableRequestParams params) + throws org.apache.doris.common.AnalysisException { + if (!params.isSetJobsMetadataParams()) { + throw new org.apache.doris.common.AnalysisException("Jobs metadata params is not set."); + } + TJobsMetadataParams jobMetadataParams = params.getJobsMetadataParams(); + String type = jobMetadataParams.getType(); + JobType jobType = JobType.valueOf(type.toUpperCase()); + if (jobType == null) { + throw new AnalysisException("Invalid job metadata query"); + } + if (JobType.MTMV == jobType) { + return MTMVJob.COLUMN_TO_INDEX.get(columnName.toLowerCase()); + } else { Review Comment: else if. and the last else, throw exception -- 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