crud icon indicating copy to clipboard operation
crud copied to clipboard

Problem with inserting integers to double field even with ffi.cast('double', value)

Open GRISHNOV opened this issue 3 years ago • 2 comments
trafficstars

Consider a space test with the following format:

> crud.select('test')['metadata']

[
    {'name': 'id', 'type': 'unsigned'},
    {'name': 'bucket_id', 'type': 'unsigned'},
    {'type': 'double', 'name': 'data', 'is_nullable': false}
]

When trying to insert integer data into the third field with the recommended cast via ffi.cast('double', value), we get an error:

> crud.insert('test', {1, 1, ffi.cast('double', 0)})

- null
- line: 111
  class_name: InsertError
  err: 'Failed to insert: Tuple field 3 (data) type does not match one required by
    operation: expected double, got unsigned'
  file: /Users/i.grishnov/Desktop/git_all/crud/crud/insert.lua
  str: 'InsertError: Failed to insert: Tuple field 3 (data) type does not match one
    required by operation: expected double, got unsigned'

> crud.insert('test', {1, 1, ffi.cast('double', 1)})

- null
- line: 111
  class_name: InsertError
  err: 'Failed to insert: Tuple field 3 (data) type does not match one required by
    operation: expected double, got unsigned'
  file: /Users/i.grishnov/Desktop/git_all/crud/crud/insert.lua
  str: 'InsertError: Failed to insert: Tuple field 3 (data) type does not match one
    required by operation: expected double, got unsigned'

Despite the ffi.cast('double', INT_VALUE), we get expected double, got unsigned

GRISHNOV avatar May 31 '22 17:05 GRISHNOV

I confirm the problem, but consider it as the problem on tarantool's side.

It is not easy to workaround it on the crud's side. At least, without extra data traversal on storage (especially in case of update/upsert), allocating new objects and so on.

I'll consider this problem as blocked on related tarantool's issue: https://github.com/tarantool/tarantool/issues/5933.

My suggestion is to use number instead of double in a space format and/or an index key part for a while.

Totktonada avatar Jun 01 '22 01:06 Totktonada

I think this issue may be considered "solved" after adding a test which runs with patched tarantool (https://github.com/tarantool/tarantool/commit/50554b94846b40b98885c3a3ef719ef2a8e001b3).

DifferentialOrange avatar Jun 13 '23 15:06 DifferentialOrange