[C Data] Format.asString emits locale dependent digits in format strings

未关闭 适合新手
#1,300 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
data

调研方向

从 c/src/main/java/org/apache/arrow/c/Format.java 中 issue 所链接的 String.format 调用开始,然后使用 ar-EG 区域设置运行提供的复现。完成标准是 Format.asString 为 FixedSizeList、FixedSizeBinary 和 Decimal 参数输出 ASCII 数字,同时现有的 Java 导入行为保持兼容。

由索引模型根据 Issue 内容生成。

描述

Type: bug
Describe the bug, including details regarding any error messages, version, and platform.

Format.asString builds the parameterised format strings with String.format("+w:%d", ...) and no explicit Locale. java.util.Formatter localises the digits of %d with Locale.getDefault(Locale.Category.FORMAT), so on a JVM whose default locale uses digits outside ASCII (ar-EG, fa-IR, bn-BD, mr-IN, 98 of the 1069 locales available on JDK 21) a FixedSizeList(8) is exported as +w:٨ instead of +w:8. The same applies to FixedSizeBinary and Decimal.

https://github.com/apache/arrow-java/blob/b410fb26d01c7cefc4c6e3443a53562164001371/c/src/main/java/org/apache/arrow/c/Format.java#L66
https://github.com/apache/arrow-java/blob/b410fb26d01c7cefc4c6e3443a53562164001371/c/src/main/java/org/apache/arrow/c/Format.java#L68-L69
https://github.com/apache/arrow-java/blob/b410fb26d01c7cefc4c6e3443a53562164001371/c/src/main/java/org/apache/arrow/c/Format.java#L96
https://github.com/apache/arrow-java/blob/b410fb26d01c7cefc4c6e3443a53562164001371/c/src/main/java/org/apache/arrow/c/Format.java#L91

Other implementations parse the parameter as an ASCII integer and reject the string. arrow-rs fails at https://github.com/apache/arrow-rs/blob/58.0.0/arrow-schema/src/ffi.rs#L494-L503 with C Data interface error: The FixedSizeList type requires an integer parameter representing number of elements per list. The Java importer reads the parameter with Integer.parseInt (https://github.com/apache/arrow-java/blob/v19.0.0/c/src/main/java/org/apache/arrow/c/Format.java#L352-L354), which accepts Unicode digits, so a Java to Java round trip does not expose the problem.

Reproduction (arrow-java 19.0.0 and 18.1.0, Temurin 21.0.6, run with --add-opens=java.base/java.nio=ALL-UNNAMED):

import java.nio.charset.StandardCharsets;
import java.util.HexFormat;
import java.util.List;
import java.util.Locale;
import org.apache.arrow.c.ArrowSchema;
import org.apache.arrow.c.Data;
import org.apache.arrow.c.NativeUtil;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.types.FloatingPointPrecision;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;

public class FormatLocale {
  public static void main(String[] args) {
    Locale.setDefault(Locale.forLanguageTag("ar-EG"));
    Field item = new Field("item",
        FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)), null);
    Field vec = new Field("vec", FieldType.nullable(new ArrowType.FixedSizeList(8)), List.of(item));
    try (BufferAllocator allocator = new RootAllocator()) {
      ArrowSchema schema = ArrowSchema.allocateNew(allocator);
      Data.exportField(allocator, vec, null, schema);
      String format = NativeUtil.toJavaString(schema.snapshot().format);
      System.out.println(format + "  "
          + HexFormat.ofDelimiter(" ").formatHex(format.getBytes(StandardCharsets.UTF_8)));
      System.out.println("Java import: " + Data.importField(allocator, schema, null).getType());
    }
  }
}
+w:٨  2b 77 3a d9 a8
Java import: FixedSizeList(8)

With Locale.US the first line is +w:8 2b 77 3a 38.

主要语言
Java
星标
95
派生
154
平均合并
2 天 16 小时
30 天内合并 PR
9

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/arrow-java 的其他 Issue

查看 apache/arrow-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。