You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "WZhuo (via GitHub)" <gi...@apache.org> on 2025/12/30 08:12:10 UTC

[PR] refactor: move url encoder from rest catalog to `util` for common use [iceberg-cpp]

WZhuo opened a new pull request, #457:
URL: https://github.com/apache/iceberg-cpp/pull/457

   The url encode and decode function will be used for generating partitions' path, so move it to the common util for later use.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] refactor: move url encoder from rest catalog to `util` for common use [iceberg-cpp]

Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2652841777


##########
src/iceberg/CMakeLists.txt:
##########
@@ -103,26 +104,30 @@ set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
 
 list(APPEND
      ICEBERG_STATIC_BUILD_INTERFACE_LIBS
+     cpr::cpr

Review Comment:
   ```
   Result<std::string>  LocationProvider::NewDataLocation(const PartitionSpec& spec,
                                                 const PartitionValues& partition_data,
                                                 const std::string& filename) = 0;
   ```
   In LocationProvider::NewDataLocation, we must do url encoding for partition names and partition values.
   If not import `cpr` to iceberg core, maybe we need implement Url encode/decode by ourselves.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2657497219


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;

Review Comment:
   `std::stringstream` may be slow. Can we directly use a string with a maximum preserved length?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2660170765


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {

Review Comment:
   Results of `isalnum` in `<cctype>` will also be effected by `std::setlocale`. I suggest to use this:
   ```cpp
   std::locale loc1("C");
   std::isalnum(c, loc1);
   ```



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] refactor: move url encoder from rest catalog to `util` for common use [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2652506589


##########
src/iceberg/CMakeLists.txt:
##########
@@ -103,26 +104,30 @@ set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
 
 list(APPEND
      ICEBERG_STATIC_BUILD_INTERFACE_LIBS
+     cpr::cpr

Review Comment:
   Can we avoid adding `cpr` to the core iceberg library? Why is it needed to generate partition path?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2660793460


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {

Review Comment:
   Sorry. After I looked into their implementations, I think manually writing an isalnum might be best.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: add simple url encoder & decoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#issuecomment-3708763724

   Rewrite the code translate from curl_easy_escape, curl_easy_unescape


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2657495194


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {

Review Comment:
   On the contrary, I think we should stick to the one in `cctype` as per the RFC 3986. Other locales may result in unencoded non-ASCII characters.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] refactor: move url encoder from rest catalog to `util` for common use [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2653106480


##########
src/iceberg/CMakeLists.txt:
##########
@@ -103,26 +104,30 @@ set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
 
 list(APPEND
      ICEBERG_STATIC_BUILD_INTERFACE_LIBS
+     cpr::cpr

Review Comment:
   Got it. According to prior discussions in the community, we should keep minimal dependencies of `libiceberg`. If the only reason is to escape partition path, should we implement our own utility function? IIUC, partition name and value can only use a limited set of characters.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2657502493


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
+      escaped << c;
+    } else {
+      escaped << '%' << std::setw(2) << static_cast<int>(c) << std::setfill('0');
+    }
+  }
+  return escaped.str();
+}
+
+std::string UrlEncoder::Decode(std::string_view str_to_decode) {
+  std::string result;
+  result.reserve(str_to_decode.size());
+
+  for (size_t i = 0; i < str_to_decode.size(); ++i) {
+    char c = str_to_decode[i];
+    if (c == '%' && i + 2 < str_to_decode.size()) {
+      std::string hex(str_to_decode.substr(i + 1, 2));
+      try {
+        char decoded = static_cast<char>(std::stoi(hex, nullptr, 16));

Review Comment:
   +1. `from_chars` can also help eliminate the try-catch flow which might be slow.



##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
+      escaped << c;
+    } else {
+      escaped << '%' << std::setw(2) << static_cast<int>(c) << std::setfill('0');

Review Comment:
   What about using a prebuilt lookup table for the hex conversion?



##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
+      escaped << c;
+    } else {
+      escaped << '%' << std::setw(2) << static_cast<int>(c) << std::setfill('0');
+    }
+  }
+  return escaped.str();
+}
+
+std::string UrlEncoder::Decode(std::string_view str_to_decode) {
+  std::string result;
+  result.reserve(str_to_decode.size());
+
+  for (size_t i = 0; i < str_to_decode.size(); ++i) {
+    char c = str_to_decode[i];
+    if (c == '%' && i + 2 < str_to_decode.size()) {
+      std::string hex(str_to_decode.substr(i + 1, 2));

Review Comment:
   This line may introduce a lot of string allocations and hurt the performance. Can we directly manipulate the string_view?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2655059366


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {

Review Comment:
   I suggest to use `template< class CharT > bool isalnum( CharT ch, const locale& loc )` in `<locale>` instead of `int isalnum( int ch )` in `<cctype>`.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2655059366


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {

Review Comment:
   I suggest to use `template< class CharT > bool isalnum( CharT ch, const locale& loc )` in `<locale>` instead of `int isalnum( int ch );` in `<cctype>`.



##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace iceberg {
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  std::stringstream escaped;
+  escaped.fill('0');
+  escaped << std::hex;
+
+  for (unsigned char c : str_to_encode) {
+    // reserve letters, numbers and -._~
+    if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
+      escaped << c;
+    } else {
+      escaped << '%' << std::setw(2) << static_cast<int>(c) << std::setfill('0');
+    }
+  }
+  return escaped.str();
+}
+
+std::string UrlEncoder::Decode(std::string_view str_to_decode) {
+  std::string result;
+  result.reserve(str_to_decode.size());
+
+  for (size_t i = 0; i < str_to_decode.size(); ++i) {
+    char c = str_to_decode[i];
+    if (c == '%' && i + 2 < str_to_decode.size()) {
+      std::string hex(str_to_decode.substr(i + 1, 2));
+      try {
+        char decoded = static_cast<char>(std::stoi(hex, nullptr, 16));

Review Comment:
   Use `std::from_chars` instead.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: a simple implement of url encoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#discussion_r2660886574


##########
src/iceberg/util/url_encoder.cc:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+#include "iceberg/util/url_encoder.h"
+
+#include <locale>
+
+namespace iceberg {
+
+namespace {
+
+bool IsUnreserved(unsigned char c) {
+  return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+         c == '-' || c == '.' || c == '_' || c == '~';
+}
+
+// Helper: convert hex char to int (0–15), returns -1 if invalid
+constexpr int8_t FromHex(char c) {
+  if (c >= '0' && c <= '9') return c - '0';
+  if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+  if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+  return -1;
+}
+
+}  // namespace
+
+std::string UrlEncoder::Encode(std::string_view str_to_encode) {
+  static const char* hex_chars = "0123456789ABCDEF";
+  std::string result;
+  result.reserve(str_to_encode.size() * 3 / 2 /* Heuristic reservation */);
+
+  for (char c : str_to_encode) {
+    if (IsUnreserved(c)) {
+      result += c;
+    } else {
+      result += '%';
+      result += hex_chars[c >> 4];
+      result += hex_chars[c & 0xF];
+    }
+  }
+
+  return result;
+}

Review Comment:
   ```suggestion
   std::string UrlEncoder::Encode(std::string_view str_to_encode) {
     static const char* kHexChars = "0123456789ABCDEF";
     std::string result;
     result.reserve(str_to_encode.size() * 3 / 2 /* Heuristic reservation */);
   
     for (char c : str_to_encode) {
       if (IsUnreserved(c)) {
         result += c;
       } else {
         result += '%';
         result += kHexChars[c >> 4];
         result += kHexChars[c & 0xF];
       }
     }
   
     return result;
   }
   ```



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] feat: add simple url encoder & decoder [iceberg-cpp]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #457:
URL: https://github.com/apache/iceberg-cpp/pull/457#issuecomment-3710245234

   Thanks @WZhuo for working on this and @HuaHuaY for the review!


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org