forked from apache/hudi
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUDI-5244] Fix bugs in schema evolution client with lost operation f…
…ield and not found schema (apache#7248) * [HUDI-5244] Fix bugs in schema evolution client with lost operation field and not found schema
- Loading branch information
1 parent
63668f9
commit 321451d
Showing
3 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
96 changes: 96 additions & 0 deletions
96
...a-client/src/test/java/org/apache/hudi/table/action/commit/TestSchemaEvolutionClient.java
This file contains 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,96 @@ | ||
/* | ||
* 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.hudi.table.action.commit; | ||
|
||
import org.apache.hudi.client.HoodieJavaWriteClient; | ||
import org.apache.hudi.common.engine.EngineType; | ||
import org.apache.hudi.common.model.HoodieAvroRecord; | ||
import org.apache.hudi.common.model.HoodieKey; | ||
import org.apache.hudi.common.table.TableSchemaResolver; | ||
import org.apache.hudi.common.testutils.RawTripTestPayload; | ||
import org.apache.hudi.config.HoodieWriteConfig; | ||
import org.apache.hudi.internal.schema.Types; | ||
import org.apache.hudi.testutils.HoodieJavaClientTestBase; | ||
|
||
import org.apache.avro.Schema; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import static org.apache.hudi.common.testutils.SchemaTestUtil.getSchemaFromResource; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Tests for schema evolution client api. | ||
*/ | ||
public class TestSchemaEvolutionClient extends HoodieJavaClientTestBase { | ||
|
||
private static final Schema SCHEMA = getSchemaFromResource(TestSchemaEvolutionClient.class, "/exampleSchema.avsc"); | ||
|
||
@BeforeEach | ||
public void setUpClient() throws IOException { | ||
HoodieJavaWriteClient<RawTripTestPayload> writeClient = getWriteClient(); | ||
this.writeClient = writeClient; | ||
prepareTable(writeClient); | ||
} | ||
|
||
@AfterEach | ||
public void closeClient() { | ||
if (writeClient != null) { | ||
writeClient.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testUpdateColumnType() { | ||
writeClient.updateColumnType("number", Types.LongType.get()); | ||
assertEquals(Types.LongType.get(), getFieldByName("number").type()); | ||
} | ||
|
||
private HoodieJavaWriteClient<RawTripTestPayload> getWriteClient() { | ||
HoodieWriteConfig config = HoodieWriteConfig.newBuilder() | ||
.withEngineType(EngineType.JAVA) | ||
.withPath(basePath) | ||
.withSchema(SCHEMA.toString()) | ||
.build(); | ||
return new HoodieJavaWriteClient<>(context, config); | ||
} | ||
|
||
private void prepareTable(HoodieJavaWriteClient<RawTripTestPayload> writeClient) throws IOException { | ||
String commitTime = "1"; | ||
writeClient.startCommitWithTime(commitTime); | ||
//language=JSON | ||
String jsonRow = "{\"_row_key\": \"1\", \"time\": \"2000-01-01T00:00:00.000Z\", \"number\": 1}"; | ||
RawTripTestPayload payload = new RawTripTestPayload(jsonRow); | ||
HoodieAvroRecord<RawTripTestPayload> record = new HoodieAvroRecord<>( | ||
new HoodieKey(payload.getRowKey(), payload.getPartitionPath()), payload); | ||
writeClient.insert(Collections.singletonList(record), commitTime); | ||
} | ||
|
||
private Types.Field getFieldByName(String fieldName) { | ||
return new TableSchemaResolver(metaClient) | ||
.getTableInternalSchemaFromCommitMetadata() | ||
.get() | ||
.findField(fieldName); | ||
} | ||
} |
This file contains 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