Skip to content

Commit

Permalink
[hotfix][core] Add Configuration.fromMap
Browse files Browse the repository at this point in the history
  • Loading branch information
twalthr authored and wuchong committed Nov 3, 2020
1 parent e90f2b1 commit 4fa58f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public Configuration(Configuration other) {

// --------------------------------------------------------------------------------------------

/**
* Creates a new configuration that is initialized with the options of the given map.
*/
public static Configuration fromMap(Map<String, String> map) {
final Configuration configuration = new Configuration();
map.forEach(configuration::setString);
return configuration;
}

// --------------------------------------------------------------------------------------------

/**
* Returns the class associated with the given key as a string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Map;
Expand All @@ -36,14 +35,15 @@
public class DelegatingConfigurationTest {

@Test
public void testIfDelegatesImplementAllMethods() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
public void testIfDelegatesImplementAllMethods() throws IllegalArgumentException {

// For each method in the Configuration class...
Method[] confMethods = Configuration.class.getDeclaredMethods();
Method[] delegateMethods = DelegatingConfiguration.class.getDeclaredMethods();

for (Method configurationMethod : confMethods) {
if (!Modifier.isPublic(configurationMethod.getModifiers())) {
final int mod = configurationMethod.getModifiers();
if (!Modifier.isPublic(mod) || Modifier.isStatic(mod)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -404,12 +403,6 @@ private static String stringifyOption(String key, String value) {
EncodingUtils.escapeSingleQuotes(value));
}

private static Configuration asConfiguration(Map<String, String> options) {
final Configuration configuration = new Configuration();
options.forEach(configuration::setString);
return configuration;
}

private static <T> T readOption(ReadableConfig options, ConfigOption<T> option) {
try {
return options.get(option);
Expand Down Expand Up @@ -440,7 +433,7 @@ public static class TableFactoryHelper {
private TableFactoryHelper(DynamicTableFactory tableFactory, DynamicTableFactory.Context context) {
this.tableFactory = tableFactory;
this.context = context;
this.allOptions = asConfiguration(context.getCatalogTable().getOptions());
this.allOptions = Configuration.fromMap(context.getCatalogTable().getOptions());
this.consumedOptionKeys = new HashSet<>();
this.consumedOptionKeys.add(PROPERTY_VERSION.key());
this.consumedOptionKeys.add(CONNECTOR.key());
Expand Down

0 comments on commit 4fa58f3

Please sign in to comment.