-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(schema): Migrate hudi-flink to use HoodieSchema instead of avro Schema #14355
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
2e872e4
bccc169
cf94d6c
96b5fcf
96b1c26
83ca6a7
6ddca22
5395b5a
12b3889
76ae7a7
20b6c46
2f4dbea
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * 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.common.schema; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
| import com.github.benmanes.caffeine.cache.LoadingCache; | ||
|
|
||
| /** | ||
| * A global cache for HoodieSchema instances to ensure that there is only one | ||
| * variable instance of the same schema within an entire JVM lifetime. | ||
| * | ||
| * <p>This is a global cache which works for a JVM lifecycle. | ||
| * A collection of schema instances are maintained. | ||
| * | ||
| * <p>NOTE: The schema which is used frequently should be cached through this cache. | ||
| */ | ||
| public class HoodieSchemaCache { | ||
|
|
||
| // Ensure that there is only one variable instance of the same schema within an entire JVM lifetime | ||
| private static final LoadingCache<HoodieSchema, HoodieSchema> SCHEMA_CACHE = | ||
| Caffeine.newBuilder().weakValues().maximumSize(1024).build(k -> k); | ||
|
|
||
| /** | ||
| * Get schema variable from global cache. If not found, put it into the cache and then return it. | ||
| * @param schema schema to get | ||
| * @return if found, return the exist schema variable, otherwise return the param itself. | ||
| */ | ||
| public static HoodieSchema intern(HoodieSchema schema) { | ||
| return SCHEMA_CACHE.get(schema); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| package org.apache.hudi.schema; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.hudi.common.schema.HoodieSchema; | ||
|
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. Based on discussion for the Hudi-Utilities SchemaProviders, we should preserve the existing APIs for now to ensure user's have an easy upgrade path. See my suggestions on how to proceed on this other PR: #14382 (comment)
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. I've made changes based on the comments. Can reference that (if it's correct) |
||
|
|
||
| import java.io.Serializable; | ||
|
|
||
|
|
@@ -29,9 +29,9 @@ public abstract class SchemaProvider implements Serializable { | |
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public abstract Schema getSourceSchema(); | ||
| public abstract HoodieSchema getSourceSchema(); | ||
|
|
||
| public Schema getTargetSchema() { | ||
| public HoodieSchema getTargetSchema() { | ||
| // by default, use source schema as target for hoodie table as well | ||
| return getSourceSchema(); | ||
| } | ||
|
|
||
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 know you did not set this up this way but currently this code is failing to close the input stream provided to the parsers. Let's make sure we close these while we're updating this code.