-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[refactor](fe) Extract toThrift from descriptor classes into DescriptorToThriftConverter #62312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnAccessPath.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // 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.analysis; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Java equivalent of the Thrift {@code TColumnAccessPath} struct. | ||
| * Merges {@code TDataAccessPath} and {@code TMetaAccessPath} into a single class | ||
| * since both are structurally identical ({@code List<String> path}). | ||
| * The {@link ColumnAccessPathType} discriminates between data and metadata access. | ||
| * | ||
| * <p>This class is immutable and implements {@link Comparable} so it can be used | ||
| * in sorted collections such as {@code TreeSet}. | ||
| */ | ||
| public final class ColumnAccessPath implements Comparable<ColumnAccessPath> { | ||
| private final ColumnAccessPathType type; | ||
| private final List<String> path; | ||
|
|
||
| public ColumnAccessPath(ColumnAccessPathType type, List<String> path) { | ||
| this.type = Objects.requireNonNull(type, "type must not be null"); | ||
| this.path = Collections.unmodifiableList(new ArrayList<>( | ||
| Objects.requireNonNull(path, "path must not be null"))); | ||
| } | ||
|
|
||
| /** Creates a DATA access path. */ | ||
| public static ColumnAccessPath data(List<String> path) { | ||
| return new ColumnAccessPath(ColumnAccessPathType.DATA, path); | ||
| } | ||
|
|
||
| /** Creates a META access path. */ | ||
| public static ColumnAccessPath meta(List<String> path) { | ||
| return new ColumnAccessPath(ColumnAccessPathType.META, path); | ||
| } | ||
|
|
||
| public ColumnAccessPathType getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public List<String> getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof ColumnAccessPath)) { | ||
| return false; | ||
| } | ||
| ColumnAccessPath that = (ColumnAccessPath) o; | ||
| return type == that.type && Objects.equals(path, that.path); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(type, path); | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(ColumnAccessPath other) { | ||
| int cmp = type.compareTo(other.type); | ||
| if (cmp != 0) { | ||
| return cmp; | ||
| } | ||
| int minLen = Math.min(path.size(), other.path.size()); | ||
| for (int i = 0; i < minLen; i++) { | ||
| cmp = path.get(i).compareTo(other.path.get(i)); | ||
| if (cmp != 0) { | ||
| return cmp; | ||
| } | ||
| } | ||
| return Integer.compare(path.size(), other.path.size()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return type + ":" + String.join(".", path); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnAccessPathType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // 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.analysis; | ||
|
|
||
| /** | ||
| * Java equivalent of the Thrift {@code TAccessPathType} enum. | ||
| * Represents whether a column access path reads data or metadata. | ||
| */ | ||
| public enum ColumnAccessPathType { | ||
| DATA, | ||
| META | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
fe/fe-core/src/main/java/org/apache/doris/analysis/DescriptorToThriftConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // 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.analysis; | ||
|
|
||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.TableIf; | ||
| import org.apache.doris.thrift.TAccessPathType; | ||
| import org.apache.doris.thrift.TColumnAccessPath; | ||
| import org.apache.doris.thrift.TDataAccessPath; | ||
| import org.apache.doris.thrift.TDescriptorTable; | ||
| import org.apache.doris.thrift.TMetaAccessPath; | ||
| import org.apache.doris.thrift.TSlotDescriptor; | ||
| import org.apache.doris.thrift.TTupleDescriptor; | ||
|
|
||
| import com.google.common.collect.Maps; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Converts {@link SlotDescriptor}, {@link TupleDescriptor}, and {@link DescriptorTable} | ||
| * to their Thrift representations. | ||
| */ | ||
| public final class DescriptorToThriftConverter { | ||
| private static final Logger LOG = LogManager.getLogger(DescriptorToThriftConverter.class); | ||
|
|
||
| private DescriptorToThriftConverter() { | ||
| } | ||
|
|
||
| /** | ||
| * Converts a {@link SlotDescriptor} to its Thrift representation. | ||
| */ | ||
| public static TSlotDescriptor toThrift(SlotDescriptor slotDesc) { | ||
| String materializedColumnName = slotDesc.getMaterializedColumnName(); | ||
| Column column = slotDesc.getColumn(); | ||
| String colName = materializedColumnName != null ? materializedColumnName : | ||
| ((column != null) ? column.getNonShadowName() : ""); | ||
| TSlotDescriptor tSlotDescriptor = new TSlotDescriptor(slotDesc.getId().asInt(), | ||
| slotDesc.getParentId().asInt(), slotDesc.getType().toThrift(), -1, | ||
| 0, 0, slotDesc.getIsNullable() ? 0 : -1, colName, -1, | ||
| true); | ||
| tSlotDescriptor.setIsAutoIncrement(slotDesc.isAutoInc()); | ||
| if (column != null) { | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("column name:{}, column unique id:{}", column.getNonShadowName(), column.getUniqueId()); | ||
| } | ||
| tSlotDescriptor.setColUniqueId(column.getUniqueId()); | ||
| tSlotDescriptor.setPrimitiveType(column.getDataType().toThrift()); | ||
| tSlotDescriptor.setIsKey(column.isKey()); | ||
| tSlotDescriptor.setColDefaultValue(column.getDefaultValue()); | ||
| } | ||
| if (slotDesc.getSubColLables() != null) { | ||
| tSlotDescriptor.setColumnPaths(slotDesc.getSubColLables()); | ||
| } | ||
| if (slotDesc.getVirtualColumn() != null) { | ||
| tSlotDescriptor.setVirtualColumnExpr(ExprToThriftVisitor.treeToThrift(slotDesc.getVirtualColumn())); | ||
| } | ||
| if (slotDesc.getAllAccessPaths() != null) { | ||
| tSlotDescriptor.setAllAccessPaths(toThrift(slotDesc.getAllAccessPaths())); | ||
| } | ||
| if (slotDesc.getPredicateAccessPaths() != null) { | ||
| tSlotDescriptor.setPredicateAccessPaths(toThrift(slotDesc.getPredicateAccessPaths())); | ||
| } | ||
| return tSlotDescriptor; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a {@link ColumnAccessPath} to its Thrift representation. | ||
| */ | ||
| public static TColumnAccessPath toThrift(ColumnAccessPath accessPath) { | ||
| TColumnAccessPath result = new TColumnAccessPath( | ||
| accessPath.getType() == ColumnAccessPathType.DATA ? TAccessPathType.DATA : TAccessPathType.META); | ||
| if (accessPath.getType() == ColumnAccessPathType.DATA) { | ||
| result.setDataAccessPath(new TDataAccessPath(accessPath.getPath())); | ||
| } else { | ||
| result.setMetaAccessPath(new TMetaAccessPath(accessPath.getPath())); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a list of {@link ColumnAccessPath} to Thrift representations. | ||
| */ | ||
| public static List<TColumnAccessPath> toThrift(List<ColumnAccessPath> accessPaths) { | ||
| List<TColumnAccessPath> result = new ArrayList<>(accessPaths.size()); | ||
| for (ColumnAccessPath accessPath : accessPaths) { | ||
| result.add(toThrift(accessPath)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a {@link TupleDescriptor} to its Thrift representation. | ||
| */ | ||
| public static TTupleDescriptor toThrift(TupleDescriptor tupleDesc) { | ||
| TTupleDescriptor tTupleDesc = new TTupleDescriptor(tupleDesc.getId().asInt(), 0, 0); | ||
| if (tupleDesc.getTable() != null && tupleDesc.getTable().getId() >= 0) { | ||
| tTupleDesc.setTableId((int) tupleDesc.getTable().getId()); | ||
| } | ||
| return tTupleDesc; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a {@link DescriptorTable} to its Thrift representation. | ||
| */ | ||
| public static TDescriptorTable toThrift(DescriptorTable descTable) { | ||
| TDescriptorTable result = new TDescriptorTable(); | ||
| Map<Long, TableIf> referencedTbls = Maps.newHashMap(); | ||
| for (TupleDescriptor tupleD : descTable.getTupleDescs()) { | ||
| result.addToTupleDescriptors(toThrift(tupleD)); | ||
| if (tupleD.getTable() != null && tupleD.getTable().getId() >= 0) { | ||
| referencedTbls.put(tupleD.getTable().getId(), tupleD.getTable()); | ||
| } | ||
| for (SlotDescriptor slotD : tupleD.getSlots()) { | ||
| result.addToSlotDescriptors(toThrift(slotD)); | ||
| } | ||
| } | ||
|
|
||
| for (TableIf tbl : referencedTbls.values()) { | ||
| result.addToTableDescriptors(tbl.toThrift()); | ||
| } | ||
| return result; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getTupleDescs()exposes a livetupleDescs.values()view as public API. That collection supportsremove()/clear(), so external callers can now mutateDescriptorTablewithout updatingslotDescsor the ID generators, leaving the object internally inconsistent. SinceDescriptorToThriftConverteris in the same package, this helper can stay package-private, or it should at least return an unmodifiable view.