Skip to content

[HUDI-6804] Fix hive read schema evolution MOR table - #9573

Merged
danny0405 merged 2 commits into
apache:masterfrom
Zouxxyy:dev/6804
Sep 5, 2023
Merged

[HUDI-6804] Fix hive read schema evolution MOR table#9573
danny0405 merged 2 commits into
apache:masterfrom
Zouxxyy:dev/6804

Conversation

@Zouxxyy

@ZouxxyyZouxxyy commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

Change Logs

Current hive read schema evolution MOR table will error, e.g. :

-- spark-sqlsethoodie.schema.on.read.enable=true;
createtableif not exists hudi_mor_test_tbl (
id bigint,
name string,
num int,
ts bigint,
ds string
) using hudi tblproperties (
type ='mor',
primaryKey ='id',
preCombineField ='ts'
)
partitioned by (ds);
insert into hudi_mor_test_tbl partition(ds ='20211211') select1, 'a1', 1000,100;
update hudi_mor_test_tbl set name ='a2'where id =1;
altertable hudi_mor_test_tbl rename column name to name_new; -- hiveselect id,name_new from hudi_mor_test_tbl_rt;
Failed with exception java.io.IOException:java.lang.ArrayIndexOutOfBoundsException: 25

Impact

Fix above

Risk level (write none, low medium or high below)

low

Documentation Update

None

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

@danny0405danny0405 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@xiarixiaoyao

Copy link
Copy Markdown
Contributor

@Zouxxyy
thanks for your fix.
could you pls point out the specific reason for the error? Thank you
i cannot reproduce this problem on hive 3.1.1 (hudi 0.11) with my cluster

@Zouxxyy

Zouxxyy commented Aug 30, 2023

Copy link
Copy Markdown
ContributorAuthor

thanks for your fix. could you pls point out the specific reason for the error? Thank you i cannot reproduce this problem on hive 3.1.1 (hudi 0.11) with my cluster

The core change is internalSchemaOption = Option.of(prunedInternalSchema); You can remove it and then run the ut add in this patch

hudi 0.11 may not have this patch #6989 and #6358

/** * Get final Read Schema for support evolution. * step1: find the fileSchema for current dataBlock. * step2: determine whether fileSchema is compatible with the final read internalSchema. * step3: merge fileSchema and read internalSchema to produce final read schema. * * @param dataBlock current processed block * @return final read schema. */privateOption<Pair<Function<HoodieRecord, HoodieRecord>, Schema>> composeEvolvedSchemaTransformer(
HoodieDataBlockdataBlock) {
if (internalSchema.isEmptySchema()) {
returnOption.empty();
}
longcurrentInstantTime = Long.parseLong(dataBlock.getLogBlockHeader().get(INSTANT_TIME));
InternalSchemafileSchema = InternalSchemaCache.searchSchemaAndCache(currentInstantTime,
hoodieTableMetaClient, false);
InternalSchemamergedInternalSchema = newInternalSchemaMerger(fileSchema, internalSchema,
true, false).mergeSchema();
SchemamergedAvroSchema = AvroInternalSchemaConverter.convert(mergedInternalSchema, readerSchema.getFullName());
returnOption.of(Pair.of((record) -> {
returnrecord.rewriteRecordWithNewSchema(
dataBlock.getSchema(),
this.hoodieTableMetaClient.getTableConfig().getProps(),
mergedAvroSchema,
Collections.emptyMap());
}, mergedAvroSchema));
}

@hudi-bot

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands@hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@danny0405danny0405 added engine:hive Hive integration schema-evolution area:schema Schema evolution and data types labels Aug 31, 2023
@ZouxxyyZouxxyy closed this Sep 1, 2023
@ZouxxyyZouxxyy reopened this Sep 1, 2023
@danny0405
danny0405 merged commit 31bc565 into apache:masterSep 5, 2023
@danny0405danny0405 added release-0.14.0 priority:blocker Production down; release blocker labels Sep 5, 2023
leosanqing pushed a commit to leosanqing/hudi that referenced this pull request Sep 13, 2023
TheR1sing3un pushed a commit to TheR1sing3un/hudi that referenced this pull request Feb 12, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:schemaSchema evolution and data typesengine:hiveHive integrationpriority:blockerProduction down; release blockerrelease-0.14.0

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants

@Zouxxyy@xiarixiaoyao@hudi-bot@danny0405