Skip to content

Commit

Permalink
[common] Fix get immutable option keys
Browse files Browse the repository at this point in the history
  • Loading branch information
schnappi17 committed Aug 31, 2023
1 parent 8bb1852 commit 89f0587
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import org.apache.paimon.options.description.TextElement;
import org.apache.paimon.table.TableType;

import java.lang.reflect.Field;
import java.time.Duration;
import java.util.HashSet;
import java.util.Set;

import static org.apache.paimon.options.ConfigOptions.key;

Expand Down Expand Up @@ -115,4 +118,20 @@ public class CatalogOptions {
.defaultValue(false)
.withDescription(
"Whether save the data lineage information or not, by default is false.");

public static Set<String> getImmutableOptionKeys() {
final Field[] fields = CatalogOptions.class.getFields();
final Set<String> immutableKeys = new HashSet<>(fields.length);
for (Field field : fields) {
if (ConfigOption.class.isAssignableFrom(field.getType())
&& field.getAnnotation(Documentation.Immutable.class) != null) {
try {
immutableKeys.add(((ConfigOption<?>) field.get(CatalogOptions.class)).key());
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
return immutableKeys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.paimon.factories.FactoryUtil;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.options.CatalogOptions;
import org.apache.paimon.options.Options;
import org.apache.paimon.utils.Preconditions;

Expand Down Expand Up @@ -92,7 +93,7 @@ static Catalog createCatalog(CatalogContext context, ClassLoader classLoader) {
CatalogOptionsManager catalogOptionsManager =
new CatalogOptionsManager(fileIO, new Path(warehouse));
Map<String, String> immutableOptions =
immutableOptions(context, CatalogOptionsManager.IMMUTABLE_CATALOG_OPTION_KEYS);
immutableOptions(context, CatalogOptions.getImmutableOptionKeys());
if (fileIO.exists(catalogOptionsManager.getCatalogOptionPath())) {
Map<String, String> originImmutableOptions =
catalogOptionsManager.immutableOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.apache.paimon.options.CatalogOptions.DATA_LINEAGE;
import static org.apache.paimon.options.CatalogOptions.LINEAGE_META;
import static org.apache.paimon.options.CatalogOptions.TABLE_LINEAGE;

/** Manage read and write of immutable {@link org.apache.paimon.options.CatalogOptions}. */
public class CatalogOptionsManager {
private static final String OPTIONS = "options";
public static final Set<String> IMMUTABLE_CATALOG_OPTION_KEYS =
new HashSet<>(
Arrays.asList(LINEAGE_META.key(), TABLE_LINEAGE.key(), DATA_LINEAGE.key()));
private final FileIO fileIO;
private final Path warehouse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.options.CatalogOptions;
import org.apache.paimon.options.Options;

import org.junit.jupiter.api.AfterEach;
Expand All @@ -30,6 +31,7 @@
import java.io.IOException;

import static org.apache.paimon.options.CatalogOptions.DATA_LINEAGE;
import static org.apache.paimon.options.CatalogOptions.LINEAGE_META;
import static org.apache.paimon.options.CatalogOptions.TABLE_LINEAGE;
import static org.apache.paimon.options.CatalogOptions.WAREHOUSE;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -168,6 +170,13 @@ public void testCreatingCatalogWithConflictOptions() throws IOException {
cleanCatalog();
}

@Test
public void testCatalogImmutableOptionKeys() {
assertThat(CatalogOptions.getImmutableOptionKeys())
.containsExactlyInAnyOrder(
LINEAGE_META.key(), TABLE_LINEAGE.key(), DATA_LINEAGE.key());
}

private static void cleanCatalog() throws IOException {
fileIO.delete(new Path(tempDir.toString()), true);
}
Expand Down

0 comments on commit 89f0587

Please sign in to comment.