Skip to content

Commit

Permalink
Core: Fix unicode handling in HTTPClient
Browse files Browse the repository at this point in the history
fixes apache#7821

Without the fix, tests would fail with
```
expected: struct<1: id: required int (unique ID 🤪), 2: data: required string>
 but was: struct<1: id: required int (unique ID ?), 2: data: required string>
```
  • Loading branch information
nastra committed Jul 12, 2023
1 parent 13295ce commit 34d262f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
Expand Up @@ -24,6 +24,7 @@
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -471,13 +472,13 @@ public HTTPClient build() {

private StringEntity toJson(Object requestBody) {
try {
return new StringEntity(mapper.writeValueAsString(requestBody));
return new StringEntity(mapper.writeValueAsString(requestBody), StandardCharsets.UTF_8);
} catch (JsonProcessingException e) {
throw new RESTException(e, "Failed to write request body: %s", requestBody);
}
}

private StringEntity toFormEncoding(Map<?, ?> formData) {
return new StringEntity(RESTUtil.encodeFormData(formData));
return new StringEntity(RESTUtil.encodeFormData(formData), StandardCharsets.UTF_8);
}
}
Expand Up @@ -73,19 +73,19 @@ public abstract class CatalogTests<C extends Catalog & SupportsNamespaces> {
// Schema passed to create tables
protected static final Schema SCHEMA =
new Schema(
required(3, "id", Types.IntegerType.get(), "unique ID"),
required(3, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(4, "data", Types.StringType.get()));

// This is the actual schema for the table, with column IDs reassigned
private static final Schema TABLE_SCHEMA =
new Schema(
required(1, "id", Types.IntegerType.get(), "unique ID"),
required(1, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(2, "data", Types.StringType.get()));

// This is the actual schema for the table, with column IDs reassigned
private static final Schema REPLACE_SCHEMA =
new Schema(
required(2, "id", Types.IntegerType.get(), "unique ID"),
required(2, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(3, "data", Types.StringType.get()));

// another schema that is not the same
Expand Down

0 comments on commit 34d262f

Please sign in to comment.