You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/07/15 02:15:23 UTC
[GitHub] [incubator-seatunnel] ashulin opened a new pull request, #2179: [TBD][api] improve config options
ashulin opened a new pull request, #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
**To Be Done.**
## Purpose of this pull request
1. Provides more friendly options capabilities.
2. Used to verify whether the parameters configured by the user conform to the rules of the options;
3. Used for Web-UI to prompt user to configure option value;
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
## Check list
* [ ] Code changed are covered with tests, or it does not need tests for reason:
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927247052
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
Review Comment:
I think use jackson to deserialize config to `ReadonlyConfig` not a cool way. Why just iterate over all values in config, and put into map?
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
Review Comment:
`flatteningMap.size()` will convert to array size in map, not map can store data size. If you want set size in hashmap, please use
```suggestion
Map<String, String> result = new HashMap<>((float)flatteningMap.size()/0.75 + 1);
```
Or just remove set capacity (recommend).
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
+ for (Map.Entry<String, Object> entry : flatteningMap.entrySet()) {
+ result.put(entry.getKey(), convertToJsonString(entry.getValue()));
+ }
+ return result;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> Optional<T> getOptional(Option<T> option) {
+ if (option == null) {
+ throw new NullPointerException("Option not be null.");
+ }
+ String[] keys = option.key().split("\\.");
+ synchronized (this.confData) {
+ Map<String, Object> data = this.confData;
+ Object value = null;
+ for (int i = 0; i < keys.length; i++) {
+ value = data.get(keys[i]);
+ if (i < keys.length - 1) {
+ if (!((value instanceof Map))) {
+ return Optional.empty();
+ } else {
+ data = (Map<String, Object>) value;
+ }
+ }
+ }
+ if (value == null) {
+ return Optional.empty();
+ }
+ return Optional.of(convertValue(value, option.typeReference()));
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ for (String s : this.confData.keySet()) {
+ hash ^= s.hashCode();
+ }
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ } else if (obj instanceof ReadonlyConfig) {
+ Map<String, Object> otherConf = ((ReadonlyConfig) obj).confData;
+
+ for (Map.Entry<String, Object> e : this.confData.entrySet()) {
Review Comment:
Just use `map.equals` can solve the requirement.
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
+ for (Map.Entry<String, Object> entry : flatteningMap.entrySet()) {
+ result.put(entry.getKey(), convertToJsonString(entry.getValue()));
+ }
+ return result;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> Optional<T> getOptional(Option<T> option) {
+ if (option == null) {
+ throw new NullPointerException("Option not be null.");
+ }
+ String[] keys = option.key().split("\\.");
+ synchronized (this.confData) {
Review Comment:
getOptional use `synchronized` not a great idea. The performance must not good. Maybe you can use cache or something to precompute
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927476494
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
+ for (Map.Entry<String, Object> entry : flatteningMap.entrySet()) {
+ result.put(entry.getKey(), convertToJsonString(entry.getValue()));
+ }
+ return result;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> Optional<T> getOptional(Option<T> option) {
+ if (option == null) {
+ throw new NullPointerException("Option not be null.");
+ }
+ String[] keys = option.key().split("\\.");
+ synchronized (this.confData) {
Review Comment:
You have point here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927552816
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
Review Comment:
Check this: https://cloud.tencent.com/developer/article/1913508
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927822579
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
Review Comment:
I have tried to convert `config` without using jackson, but the `config` is more complicated, and there will be many problems in my own implementation. config provides `config.root().render(ConfigRenderOptions.concise())` for converting to json, and it has been well tested.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927475732
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
Review Comment:
I don't understand, this method doesn't change the size of map keys.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927470151
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
Review Comment:
Here the `typesafe config` is converted to a json string and parsed into the required map using jackson
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#issuecomment-1193325861
@Hisoka-X PTAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927552275
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
Review Comment:
> Why just iterate over all values in config, and put into map?
My fault, It should be `Why not just iterate over all values in config, and put into map`. If do that, we wouldn't use jackson to serialize and deserialize
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
Review Comment:
> Why just iterate over all values in config, and put into map?
My fault, It should be `Why not just iterate over all values in config, and put into map`. If do that, we wouldn't use jackson to serialize and deserialize
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] ashulin commented on a diff in pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
ashulin commented on code in PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179#discussion_r927825324
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/ReadonlyConfig.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.seatunnel.api.configuration;
+
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertToJsonString;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.convertValue;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.flatteningMap;
+import static org.apache.seatunnel.api.configuration.util.ConfigUtil.treeMap;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigRenderOptions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class ReadonlyConfig {
+
+ private static final ObjectMapper JACKSON_MAPPER = new ObjectMapper();
+
+ /**
+ * Stores the concrete key/value pairs of this configuration object.
+ */
+ protected final Map<String, Object> confData;
+
+ private ReadonlyConfig(Map<String, Object> confData) {
+ this.confData = confData;
+ }
+
+ public static ReadonlyConfig fromMap(Map<String, Object> map) {
+ return new ReadonlyConfig(treeMap(map));
+ }
+
+ public static ReadonlyConfig fromConfig(Config config) {
+ try {
+ return fromMap(JACKSON_MAPPER.readValue(
+ config.root().render(ConfigRenderOptions.concise()),
+ new TypeReference<Map<String, Object>>() {
+ }));
+ } catch (JsonProcessingException e) {
+ throw new IllegalArgumentException("Json parsing exception.");
+ }
+ }
+
+ public <T> T get(Option<T> option) {
+ return getOptional(option).orElseGet(option::defaultValue);
+ }
+
+ public Map<String, String> toMap() {
+ synchronized (this.confData) {
+ Map<String, Object> flatteningMap = flatteningMap(confData);
+ Map<String, String> result = new HashMap<>(flatteningMap.size());
Review Comment:
You're absolutely right. Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-seatunnel] Hisoka-X merged pull request #2179: [api] improve config options
Posted by GitBox <gi...@apache.org>.
Hisoka-X merged PR #2179:
URL: https://github.com/apache/incubator-seatunnel/pull/2179
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org