-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix](iceberg)Use the correct schema for query #50376
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
37 changes: 37 additions & 0 deletions
37
...thirdparties/docker-compose/iceberg/scripts/create_preinstalled_scripts/iceberg/run09.sql
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,37 @@ | ||
| use demo.test_db; | ||
|
|
||
| create table schema_change_with_time_travel (c1 int); | ||
| insert into schema_change_with_time_travel values (1); | ||
|
|
||
| alter table schema_change_with_time_travel add column c2 int; | ||
| insert into schema_change_with_time_travel values (2,3); | ||
|
|
||
| alter table schema_change_with_time_travel add column c3 int; | ||
| insert into schema_change_with_time_travel values (4,5,6); | ||
|
|
||
| alter table schema_change_with_time_travel drop column c2; | ||
| insert into schema_change_with_time_travel values (7,8); | ||
|
|
||
| alter table schema_change_with_time_travel add column c2 int; | ||
| insert into schema_change_with_time_travel values (9,10,11); | ||
|
|
||
| alter table schema_change_with_time_travel add column c4 int; | ||
|
|
||
|
|
||
| create table schema_change_with_time_travel_orc (c1 int) tblproperties ("write.format.default"="orc"); | ||
| insert into schema_change_with_time_travel_orc values (1); | ||
|
|
||
| alter table schema_change_with_time_travel_orc add column c2 int; | ||
| insert into schema_change_with_time_travel_orc values (2,3); | ||
|
|
||
| alter table schema_change_with_time_travel_orc add column c3 int; | ||
| insert into schema_change_with_time_travel_orc values (4,5,6); | ||
|
|
||
| alter table schema_change_with_time_travel_orc drop column c2; | ||
| insert into schema_change_with_time_travel_orc values (7,8); | ||
|
|
||
| alter table schema_change_with_time_travel_orc add column c2 int; | ||
| insert into schema_change_with_time_travel_orc values (9,10,11); | ||
|
|
||
| alter table schema_change_with_time_travel_orc add column c4 int; | ||
|
|
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
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
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
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
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
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
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
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
147 changes: 147 additions & 0 deletions
147
fe/fe-core/src/main/java/org/apache/doris/datasource/hive/IcebergDlaTable.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,147 @@ | ||
| // 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.datasource.hive; | ||
|
|
||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.PartitionItem; | ||
| import org.apache.doris.catalog.PartitionType; | ||
| import org.apache.doris.common.AnalysisException; | ||
| import org.apache.doris.datasource.iceberg.IcebergSchemaCacheValue; | ||
| import org.apache.doris.datasource.iceberg.IcebergSnapshotCacheValue; | ||
| import org.apache.doris.datasource.iceberg.IcebergUtils; | ||
| import org.apache.doris.datasource.mvcc.MvccSnapshot; | ||
| import org.apache.doris.mtmv.MTMVRefreshContext; | ||
| import org.apache.doris.mtmv.MTMVSnapshotIdSnapshot; | ||
| import org.apache.doris.mtmv.MTMVSnapshotIf; | ||
|
|
||
| import com.google.common.collect.Maps; | ||
| import com.google.common.collect.Sets; | ||
| import org.apache.iceberg.PartitionField; | ||
| import org.apache.iceberg.PartitionSpec; | ||
| import org.apache.iceberg.Table; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class IcebergDlaTable extends HMSDlaTable { | ||
|
|
||
| private boolean isValidRelatedTableCached = false; | ||
| private boolean isValidRelatedTable = false; | ||
|
|
||
| public IcebergDlaTable(HMSExternalTable table) { | ||
| super(table); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, PartitionItem> getAndCopyPartitionItems(Optional<MvccSnapshot> snapshot) { | ||
| return Maps.newHashMap( | ||
| IcebergUtils.getOrFetchSnapshotCacheValue( | ||
| snapshot, hmsTable.getCatalog(), hmsTable.getDbName(), hmsTable.getName()) | ||
| .getPartitionInfo().getNameToPartitionItem()); | ||
| } | ||
|
|
||
| @Override | ||
| public PartitionType getPartitionType(Optional<MvccSnapshot> snapshot) { | ||
| return isValidRelatedTable() ? PartitionType.RANGE : PartitionType.UNPARTITIONED; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getPartitionColumnNames(Optional<MvccSnapshot> snapshot) { | ||
| return getPartitionColumns(snapshot).stream().map(Column::getName).collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Column> getPartitionColumns(Optional<MvccSnapshot> snapshot) { | ||
| IcebergSnapshotCacheValue snapshotValue = | ||
| IcebergUtils.getOrFetchSnapshotCacheValue( | ||
| snapshot, hmsTable.getCatalog(), hmsTable.getDbName(), hmsTable.getName()); | ||
| IcebergSchemaCacheValue schemaValue = IcebergUtils.getSchemaCacheValue( | ||
| hmsTable.getCatalog(), hmsTable.getDbName(), hmsTable.getName(), | ||
| snapshotValue.getSnapshot().getSchemaId()); | ||
| return schemaValue.getPartitionColumns(); | ||
| } | ||
|
|
||
| @Override | ||
| public MTMVSnapshotIf getPartitionSnapshot(String partitionName, MTMVRefreshContext context, | ||
| Optional<MvccSnapshot> snapshot) throws AnalysisException { | ||
| IcebergSnapshotCacheValue snapshotValue = | ||
| IcebergUtils.getOrFetchSnapshotCacheValue( | ||
| snapshot, hmsTable.getCatalog(), hmsTable.getDbName(), hmsTable.getName()); | ||
| long latestSnapshotId = snapshotValue.getPartitionInfo().getLatestSnapshotId(partitionName); | ||
| if (latestSnapshotId <= 0) { | ||
| throw new AnalysisException("can not find partition: " + partitionName); | ||
| } | ||
| return new MTMVSnapshotIdSnapshot(latestSnapshotId); | ||
| } | ||
|
|
||
| @Override | ||
| public MTMVSnapshotIf getTableSnapshot(MTMVRefreshContext context, Optional<MvccSnapshot> snapshot) | ||
| throws AnalysisException { | ||
| hmsTable.makeSureInitialized(); | ||
| IcebergSnapshotCacheValue snapshotValue = | ||
| IcebergUtils.getOrFetchSnapshotCacheValue( | ||
| snapshot, hmsTable.getCatalog(), hmsTable.getDbName(), hmsTable.getName()); | ||
| return new MTMVSnapshotIdSnapshot(snapshotValue.getSnapshot().getSnapshotId()); | ||
| } | ||
|
|
||
| @Override | ||
| boolean isPartitionColumnAllowNull() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isValidRelatedTable() { | ||
| if (isValidRelatedTableCached) { | ||
| return isValidRelatedTable; | ||
| } | ||
| isValidRelatedTable = false; | ||
| Set<String> allFields = Sets.newHashSet(); | ||
| Table table = IcebergUtils.getIcebergTable( | ||
| hmsTable.getCatalog(), | ||
| hmsTable.getDbName(), | ||
| hmsTable.getName() | ||
| ); | ||
| for (PartitionSpec spec : table.specs().values()) { | ||
| if (spec == null) { | ||
| isValidRelatedTableCached = true; | ||
| return false; | ||
| } | ||
| List<PartitionField> fields = spec.fields(); | ||
| if (fields.size() != 1) { | ||
| isValidRelatedTableCached = true; | ||
| return false; | ||
| } | ||
| PartitionField partitionField = spec.fields().get(0); | ||
| String transformName = partitionField.transform().toString(); | ||
| if (!IcebergUtils.YEAR.equals(transformName) | ||
| && !IcebergUtils.MONTH.equals(transformName) | ||
| && !IcebergUtils.DAY.equals(transformName) | ||
| && !IcebergUtils.HOUR.equals(transformName)) { | ||
| isValidRelatedTableCached = true; | ||
| return false; | ||
| } | ||
| allFields.add(table.schema().findColumnName(partitionField.sourceId())); | ||
| } | ||
| isValidRelatedTableCached = true; | ||
| isValidRelatedTable = allFields.size() == 1; | ||
| return isValidRelatedTable; | ||
| } | ||
| } |
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
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.
Isn't it a bit of a luxury for each catalog to hold as many threads as the number of CPU cores?
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.
Yes, it will be optimized later. This PR does not change the origin logic, just remove the code to a new place