perl-rethinkdb icon indicating copy to clipboard operation
perl-rethinkdb copied to clipboard

Two systems treating numbers differently.

Open rob0101 opened this issue 7 years ago • 9 comments

I have a perl script that creates records to insert into rethink.

A simplified version of the code is $x->{‘y’} = 1;

r->db(‘a’)->table(‘b’)->insert($x)->run;

On my ubuntu box y is a string “1” On my mac y is a number 1

Where would this be triggered.

rob0101 avatar Feb 12 '18 12:02 rob0101

Can you get me the perl versions from each box?

I have more or less stopped working on this project since RethinkDB announced they were abandoning the project, but I'll see if I can find out what's up with this.

njlg avatar Feb 12 '18 14:02 njlg

Mac: This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level (with 2 registered patches, see perl -V for more detail)

Ubnuntu: This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-linux-gnu-thread-multi (with 60 registered patches, see perl -V for more detail)

I've worked around it by forcing to a string for consistency.

Thanks !

rob0101 avatar Feb 13 '18 11:02 rob0101

Weird. I'm not having this problem. Can you try running this script and give me the output?

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

use Rethinkdb;

my $x = {};

$x->{'y'} = 1;

r->connect->repl;
r->db_create('a')->run;
r->db('a')->table_create('b')->run;
r->db('a')->table('b')->insert($x)->run;

my $res = r->db('a')->table('b')->run;

print Dumper($res);

If it still appears like a string, try running the script like RDB_DEBUG=1 perl test.pl.

njlg avatar Feb 20 '18 20:02 njlg

Thought I'd add my observations: I've had the same problem with the just the JSON module and occasionally with Rethinkdb (everything I have runs on ubuntu atm). Sometimes no matter what I do it writes out a number quoted as a string, regardless of the source of the data, or any "magic" I tried to do, i.e. $data{key} = int(delete $data{key});, it still writes it out as a string. It's forced me to add extra conditions to my C++ code to compensate...

dwburke avatar Feb 20 '18 20:02 dwburke

I think @dwburke is correct. Looks like there is some issue with older versions of perl & JSON. https://rt.cpan.org/Public/Bug/Display.html?id=111634

Tho, the issue appears to be opposite of what @rob0101 is reporting. I found that both perl v5.18.2 & v.5.27.8 both seemed to work fine on my ubuntu machine.

Test

perl -MJSON -e '$x=1.1; print "$x\n"; warn encode_json [$x]'

Tho, perl 5.18.2 failed this test and the newer version was fine.

njlg avatar Feb 20 '18 21:02 njlg

Both produce a numeric with that script.

Weird.

rob0101 avatar Feb 21 '18 02:02 rob0101

Hey njlg, we(RethinkDB) returned as a community project, if you are interested in mantaining this driver, we can add it to the official organization

thelinuxlich avatar Oct 26 '18 15:10 thelinuxlich

@thelinuxlich Awesome! Yeah, I'll do some research and see what I need to do to bring this up-to-date.

njlg avatar Oct 26 '18 16:10 njlg

I will add you to the org, then you can move the repo there

thelinuxlich avatar Oct 26 '18 17:10 thelinuxlich