hekaifei commented on PR #1725:
URL:
https://github.com/apache/incubator-paimon/pull/1725#issuecomment-1665073147
> @hekaifei hi, can you explain why the latest fields can't be used in this
case. I thought the latest schema should be synced to HMS, and If I remember
correctly, Hive uses Table-level fields when fields is empty in `Partition`.
@YannByron The original code had two problems
1. There is no problem with table schema sync to HMS, but when adding a new
partition, the table schema is not obtained in real time, only initialized once
https://github.com/apache/incubator-paimon/blob/master/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveMetastoreClient.java
```sql
private final StorageDescriptor sd;
private HiveMetastoreClient(Identifier identifier, TableSchema schema,
IMetaStoreClient client)
throws Exception {
this.identifier = identifier;
this.partitionComputer =
new RowDataPartitionComputer(
new
CoreOptions(schema.options()).partitionDefaultName(),
schema.logicalPartitionType(),
schema.partitionKeys().toArray(new String[0]));
this.client = client;
this.sd = client.getTable(identifier.getDatabaseName(),
identifier.getObjectName()).getSd();
}
```
2. An existing partition will not resolve new fields because of the
partition metadata,We should update the partition metadata according to the
latest data。
one example :
```sql
create table test_partition(
c1 string
)partitioned by (part string);
insert into test_partition partition(part='part1') values('col1');
alter table test_partition add columns(c2 string);
insert into test_partition partition(part='part1') values('col1','col2');
-- query result
hive> select * from test_partition where part='part1';
OK
col1 NULL part1
col1 NULL part1
```
If update partition metadata , We can query the new field in existing
partitions
like doing this:
```sql
alter table test_partition partition(part='part1') add columns(c2 string);
hive> select * from test_partition where part='part1';
OK
col1 NULL part1
col1 col2 part1
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]