You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2026/05/07 06:37:05 UTC

[I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

lidavidm opened a new issue, #804:
URL: https://github.com/apache/arrow-go/issues/804

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   This limits the usefulness of RecordFromJSON for testing, and implies we may have been writing incorrect tests.
   
   You silently get wrong data:
   
   ```go
   package main
   
   import (
   	"bytes"
   	"fmt"
   	"log"
   
   	"github.com/apache/arrow-go/v18/arrow"
   	"github.com/apache/arrow-go/v18/arrow/array"
   	"github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
   	mem := memory.DefaultAllocator
   	dt := arrow.FixedWidthTypes.Duration_s
   	record, _, err := array.FromJSON(mem, dt, bytes.NewReader([]byte("[9223372036854775807]")))
   	if err != nil {
   		log.Fatal(err)
   	}
   	fmt.Println(record)
   }
   ```
   
   Result:
   
   ```
   [-9223372036854775808]
   ```
   
   Commonly, large integers are represented as strings in JSON to get around this. That doesn't work:
   
   ```go
   package main
   
   import (
   	"bytes"
   	"fmt"
   	"log"
   
   	"github.com/apache/arrow-go/v18/arrow"
   	"github.com/apache/arrow-go/v18/arrow/array"
   	"github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
   	mem := memory.DefaultAllocator
   	dt := arrow.FixedWidthTypes.Duration_s
   	record, _, err := array.FromJSON(mem, dt, bytes.NewReader([]byte(`["9223372036854775807"]`)))
   	if err != nil {
   		log.Fatal(err)
   	}
   	fmt.Println(record)
   }
   ```
   
   Result:
   
   ```
   2026/05/07 15:36:14 json: cannot unmarshal 9223372036854775807 into Go value of type arrow.Duration
   exit status 1
   ```
   
   ### Component(s)
   
   Other


-- 
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@arrow.apache.org.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4401684663

   Is there any reason not to enable that by default? Silently corrupting data seems bad...


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4410140898

   Mostly that it does have a slight effect on performance potentially, though unless you're converting very large json blobs you probably wouldn't notice. Essentially using `json.Number` will keep it as a string and parse on the fly rather than creating the float64 during the json.Unmarshal in the first place. So it would cause a bunch of extra allocations/string parsing if you don't need it. 
   
   I suppose we could deprecate the `WithUseNumber` option, make it a no-op, add a new `WithNoUseNumber` option and make using the json.Number the default.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4410690333

   I guess it's workable then. I'll just adjust the test utilities.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade closed issue #804: [Go] RecordFromJSON does not handle integer values not representable by double
URL: https://github.com/apache/arrow-go/issues/804


-- 
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@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4398200675

   Have you tried using the https://pkg.go.dev/github.com/apache/arrow-go/v18/arrow/array#WithUseNumber option? That should solve the issue for most cases (unless we missed one)


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4454244067

   Ok, this _is_ broken, because RecordBuilder.UnmarshalJSON creates its own decoder which doesn't have the option set. 


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4398312846

   Ah, it looks like the string handling expects it to be in the form "3h2m5s" etc. for go's `ParseDuration` rather than being a number, that's why it fails in the string case.
   
   Using `WithUseNumber` does fix the first case though.
   
   ```go
   package main
   
   import (
   	"bytes"
   	"fmt"
   	"log"
   
   	"github.com/apache/arrow-go/v18/arrow"
   	"github.com/apache/arrow-go/v18/arrow/array"
   	"github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
   	mem := memory.DefaultAllocator
   	dt := arrow.FixedWidthTypes.Duration_s
   	record, _, err := array.FromJSON(mem, dt, bytes.NewReader([]byte("[9223372036854775807]")), array.WithUseNumber())
   	if err != nil {
   		log.Fatal(err)
   	}
   	fmt.Println(record)
   }
   ```
   
   ```
   [9223372036854775807]
   ```
   


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm closed issue #804: [Go] RecordFromJSON does not handle integer values not representable by double
URL: https://github.com/apache/arrow-go/issues/804


-- 
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@arrow.apache.org

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


Re: [I] [Go] RecordFromJSON does not handle integer values not representable by double [arrow-go]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on issue #804:
URL: https://github.com/apache/arrow-go/issues/804#issuecomment-4454258126

   ```go
   package main
   
   import (
   	"bytes"
   	"fmt"
   	"log"
   
   	"github.com/apache/arrow-go/v18/arrow"
   	"github.com/apache/arrow-go/v18/arrow/array"
   	"github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
   	mem := memory.DefaultAllocator
   	schema := arrow.NewSchema([]arrow.Field{
   		{Name: "a", Type: arrow.FixedWidthTypes.Duration_s},
   	}, nil)
   	json := `[{"a": -9223372036854775808}, {"a": 9223372036854775807}]`
   	record, _, err := array.RecordFromJSON(mem, schema, bytes.NewReader([]byte(json)), array.WithUseNumber())
   	if err != nil {
   		log.Fatal(err)
   	}
   	fmt.Println(record)
   }
   ```
   
   ```
   record:
     schema:
     fields: 1
       - a: type=duration[s]
     rows: 2
     col[0][a]: [-9223372036854775808 -9223372036854775808]
   ```


-- 
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: github-unsubscribe@arrow.apache.org

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