forked from alibaba/fluss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce version merge engine for primary key table alibaba#213
- Loading branch information
Xiaojian Sun
committed
Dec 27, 2024
1 parent
1879ddb
commit 9a0aac4
Showing
18 changed files
with
700 additions
and
80 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
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
86 changes: 86 additions & 0 deletions
86
fluss-common/src/main/java/com/alibaba/fluss/config/MergeEngine.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,86 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.fluss.config; | ||
|
||
import java.util.Map; | ||
|
||
/** The merge engine for primary key table. */ | ||
public class MergeEngine { | ||
|
||
private final Type type; | ||
private final String column; | ||
|
||
private MergeEngine(Type type) { | ||
this(type, null); | ||
} | ||
|
||
private MergeEngine(Type type, String column) { | ||
this.type = type; | ||
this.column = column; | ||
} | ||
|
||
public static MergeEngine create(Map<String, String> properties) { | ||
return create(Configuration.fromMap(properties)); | ||
} | ||
|
||
public static MergeEngine create(Configuration options) { | ||
if (options == null) { | ||
return null; | ||
} | ||
MergeEngine.Type type = options.get(ConfigOptions.TABLE_MERGE_ENGINE); | ||
if (type == null) { | ||
return null; | ||
} | ||
|
||
switch (type) { | ||
case FIRST_ROW: | ||
return new MergeEngine(Type.FIRST_ROW); | ||
case VERSION: | ||
String column = options.get(ConfigOptions.TABLE_MERGE_ENGINE_VERSION_COLUMN); | ||
if (column == null) { | ||
throw new IllegalArgumentException( | ||
"When the merge engine is set to version, the 'table.merge-engine.version.column' cannot be empty."); | ||
} | ||
return new MergeEngine(Type.VERSION, column); | ||
default: | ||
throw new UnsupportedOperationException("Unsupported merge engine: " + type); | ||
} | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public String getColumn() { | ||
return column; | ||
} | ||
|
||
public enum Type { | ||
FIRST_ROW("first_row"), | ||
VERSION("version"); | ||
private final String value; | ||
|
||
Type(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.