Skip to content

Commit ce60cf3

Browse files
the-other-tim-brownrahil-c
authored andcommitted
[MINOR] NullPointerException when reading action state of old archived timelines (apache#13579)
1 parent 6784266 commit ce60cf3

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

hudi-common/src/main/java/org/apache/hudi/common/table/timeline/versioning/v1/ArchivedTimelineV1.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ private Option<HoodieInstant> readCommit(String instantTime, GenericRecord recor
271271
TimeRangeFilter timeRangeFilter) {
272272
final String action = record.get(ACTION_TYPE_KEY).toString();
273273
final String stateTransitionTime = (String) record.get(STATE_TRANSITION_TIME);
274-
final HoodieInstant hoodieInstant = new HoodieInstant(HoodieInstant.State.valueOf(record.get(ACTION_STATE).toString()), action,
274+
final HoodieInstant.State actionState = Option.ofNullable(record.get(ACTION_STATE)).map(state -> HoodieInstant.State.valueOf(state.toString())).orElse(HoodieInstant.State.COMPLETED);
275+
final HoodieInstant hoodieInstant = new HoodieInstant(actionState, action,
275276
instantTime, stateTransitionTime, InstantComparatorV1.REQUESTED_TIME_BASED_COMPARATOR);
276277
if (timeRangeFilter != null && !timeRangeFilter.isInRange(hoodieInstant.requestedTime())) {
277278
return Option.empty();

hudi-hadoop-common/src/test/java/org/apache/hudi/common/table/timeline/TestArchivedTimelineV1.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.hudi.common.model.HoodieRecord;
3636
import org.apache.hudi.common.model.HoodieRollingStatMetadata;
3737
import org.apache.hudi.common.model.WriteOperationType;
38+
import org.apache.hudi.common.table.HoodieTableMetaClient;
3839
import org.apache.hudi.common.table.log.HoodieLogFormat;
3940
import org.apache.hudi.common.table.log.HoodieLogFormat.Writer;
4041
import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
@@ -71,6 +72,7 @@
7172
import static org.apache.hudi.common.table.timeline.HoodieInstant.State.COMPLETED;
7273
import static org.apache.hudi.common.table.timeline.HoodieInstant.State.INFLIGHT;
7374
import static org.apache.hudi.common.table.timeline.HoodieInstant.State.REQUESTED;
75+
import static org.apache.hudi.common.testutils.HoodieTestUtils.getDefaultStorageConf;
7476
import static org.junit.jupiter.api.Assertions.assertEquals;
7577
import static org.junit.jupiter.api.Assertions.assertFalse;
7678
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -419,6 +421,19 @@ public void testLoadArchivedInstantsForAdditionalActions() throws Exception {
419421
assertEquals(instants, timeline.getInstants());
420422
}
421423

424+
@Test
425+
void readLegacyArchivedTimelineWithNullFields() {
426+
String samplePath = this.getClass().getClassLoader().getResource("archived_timeline").getPath();
427+
metaClient = HoodieTableMetaClient.builder()
428+
.setBasePath(samplePath)
429+
.setConf(getDefaultStorageConf())
430+
.setLoadActiveTimelineOnLoad(false)
431+
.build();
432+
HoodieArchivedTimeline timeline = new ArchivedTimelineV1(metaClient);
433+
timeline.loadCompletedInstantDetailsInMemory();
434+
assertEquals(3, timeline.getInstants().size());
435+
}
436+
422437
/**
423438
* Validate whether the instants of given timestamps of the hudi archived timeline are loaded to memory or not.
424439
* @param hoodieArchivedTimeline archived timeline to test against
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
hoodie.table.name=raw_trips
18+
hoodie.archivelog.folder=archived
19+
hoodie.table.type=COPY_ON_WRITE
20+
hoodie.table.version=6
21+
hoodie.table.partition.fields=some_nonexistent_field
22+
hoodie.timeline.layout.version=1
23+
hoodie.datasource.write.drop.partition.columns=false
24+
hoodie.table.checksum=3360473891

0 commit comments

Comments
 (0)