-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2560] introduce id_based schema to support full schema evolution. #3808
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
Changes from all commits
a48664d
ac61a6e
bb45b4d
77d54d7
0f24af2
06246f3
5a5ccf4
8f3cb81
f2ed0cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ public enum WriteOperationType { | |
| INSERT_OVERWRITE_TABLE("insert_overwrite_table"), | ||
| // compact | ||
| COMPACT("compact"), | ||
| // alter schema | ||
| ALTER_SCHEMA("alter_schema"), | ||
| // used for old version | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We store Alter Schema commands as a separate commits like other write operations. Hence, the need for a separate WriteOperation enum
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense |
||
| UNKNOWN("unknown"); | ||
|
|
||
|
|
@@ -86,6 +88,8 @@ public static WriteOperationType fromValue(String value) { | |
| return CLUSTER; | ||
| case "compact": | ||
| return COMPACT; | ||
| case "alter_schema": | ||
| return ALTER_SCHEMA; | ||
| case "unknown": | ||
| return UNKNOWN; | ||
| default: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,13 +18,6 @@ | |
|
|
||
| package org.apache.hudi.common.table; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.Schema.Field; | ||
| import org.apache.avro.SchemaCompatibility; | ||
| import org.apache.avro.generic.IndexedRecord; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.io.hfile.CacheConfig; | ||
| import org.apache.hudi.avro.HoodieAvroUtils; | ||
| import org.apache.hudi.common.model.HoodieCommitMetadata; | ||
| import org.apache.hudi.common.model.HoodieFileFormat; | ||
|
|
@@ -44,8 +37,18 @@ | |
| import org.apache.hudi.exception.HoodieException; | ||
| import org.apache.hudi.exception.InvalidTableException; | ||
| import org.apache.hudi.io.storage.HoodieHFileReader; | ||
|
|
||
| import org.apache.hudi.io.storage.HoodieOrcReader; | ||
| import org.apache.hudi.internal.schema.InternalSchema; | ||
| import org.apache.hudi.internal.schema.io.FileBasedInternalSchemaStorageManager; | ||
| import org.apache.hudi.internal.schema.utils.SerDeHelper; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.Schema.Field; | ||
| import org.apache.avro.SchemaCompatibility; | ||
| import org.apache.avro.generic.IndexedRecord; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.io.hfile.CacheConfig; | ||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
| import org.apache.parquet.avro.AvroSchemaConverter; | ||
|
|
@@ -537,4 +540,51 @@ private boolean hasOperationField() { | |
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the InternalSchema for a hoodie table from the HoodieCommitMetadata of the instant. | ||
| * | ||
| * @return InternalSchema for this table | ||
| */ | ||
| public Option<InternalSchema> getTableInternalSchemaFromCommitMetadata() { | ||
| HoodieTimeline timeline = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants(); | ||
|
||
| if (timeline.lastInstant().isPresent()) { | ||
| return getTableInternalSchemaFromCommitMetadata(timeline.lastInstant().get()); | ||
| } else { | ||
| return Option.empty(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the InternalSchema for a hoodie table from the HoodieCommitMetadata of the instant. | ||
| * | ||
| * @return InternalSchema for this table | ||
| */ | ||
| private Option<InternalSchema> getTableInternalSchemaFromCommitMetadata(HoodieInstant instant) { | ||
| try { | ||
| HoodieTimeline timeline = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants(); | ||
| byte[] data = timeline.getInstantDetails(instant).get(); | ||
| HoodieCommitMetadata metadata = HoodieCommitMetadata.fromBytes(data, HoodieCommitMetadata.class); | ||
| String latestInternalSchemaStr = metadata.getMetadata(SerDeHelper.LATESTSCHEMA); | ||
| if (latestInternalSchemaStr != null) { | ||
| return SerDeHelper.fromJson(latestInternalSchemaStr); | ||
| } else { | ||
| return Option.empty(); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new HoodieException("Failed to read schema from commit metadata", e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the history schemas as String for a hoodie table from the HoodieCommitMetadata of the instant. | ||
| * | ||
| * @return history schemas string for this table | ||
| */ | ||
| public Option<String> getTableHistorySchemaStrFromCommitMetadata() { | ||
| // now we only support FileBaseInternalSchemaManager | ||
| FileBasedInternalSchemaStorageManager manager = new FileBasedInternalSchemaStorageManager(metaClient); | ||
| String result = manager.getHistorySchemaStr(); | ||
| return result.isEmpty() ? Option.empty() : Option.of(result); | ||
| } | ||
| } | ||
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.
should this be in cleaner?
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.
i am ok to move this to cleaner.