Giter Club home page Giter Club logo

bson's People

Contributors

bbkr avatar japhb avatar jonathanstowe avatar martimm avatar samcv avatar zoffixznet avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bson's Issues

BSON should convert Rat to Num where possible

When floats/doubles are serialized to JSON then converted to Perl numbers, they're re-interpreted as Rat. Rat can't be handled by the database and gives an error.

Suggested solution: if Rat can be converted to Num without loss of data, do it. This will let BSON work with data that has been serialized without truncating data. (Verify that $n.Num.Rat == $n first.)

It would also be nice if BSON had an option that enabled truncating all floating point types to a type that is allowed in the database, even if some precision is lost. Perhaps $doc.accept-numbers, analogous to accept-hash which permits order information loss.

#23

support for timestamp

bson type 0x11 for timestamps. It was assumed that it was for internal use but newer servers are returning a timestamp field in the ismaster now.

threadpool exhaustion

Need to be more careful when using threads for encoding and decoding documents. In some project of mine, the process runs into a lock waiting for a promise to finish. An answer from Jnthn at SO. The quick fix mentioned didn't help (yet).

Dates created by '$currentDate' are parsed incorrectly

To see the problem, run the following script. If the server is running on localhost, a date created by DateTime.new(now) should be almost the same as a time created by the MongoDB $currentDate operator. This script prints the difference. The desired result should be less than 1 second. The actual result is thousands of years.

#! env perl6

use BSON::Document;
use MongoDB::Client;

my MongoDB::Client $client .= new(:uri("mongodb://127.0.0.1"));
my $db = $client.database('test');

my DateTime $startTime;

sub record-time() {
	$startTime = DateTime.new(now);
	my BSON::Document $req .= new: (
		update => 'timetest',
		updates => [ (
			q => (name => 'time-test',),
			u => ('$currentDate' => (lastModified => True),),
			upsert => True,
		  ),
		],
	);
	my $response = $db.run-command($req);
	say $response;
}

sub check-time {
	my $response = $db.collection('timetest').find(
		:number-to-return(1),
		:criteria(name => 'time-test', lastModified => ('$exists' => True),),
	).fetch;

	say 'Time between request and DB action: '~($response<lastModified>-$startTime);
}

record-time;
check-time;

Double trouble

After upgrade of perl I have suddenly problems encoding and decoding the Num type to/from BSON Double precision.

Funny enough there was also a bug in the test program and never surfaced until now.

Use of Nil in numeric context in block

Installed but complained on OSX.

$ panda install BSON
==> Fetching BSON
==> Building BSON
Compiling lib/BSON/Exception.pm6 to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON/ObjectId.pm to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON/Regex.pm to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON/Javascript.pm to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON/Binary.pm to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON.pm to mbc
===SORRY!===
Missing or wrong version of dependency '&encode_int32' (from 'lib/BSON/Binary.pm')
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
Compiling lib/BSON/EDC-Tools.pm6 to mbc
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Builder.pm:125
==> Testing BSON
t/103-string.t .... ok
t/102-int.t ....... ok
t/101-binary.t .... ok
t/100-double.t .... ok
t/600-extended.t .. ok
t/500-native.t .... ok
All tests successful.
Files=6, Tests=113,  7 wallclock secs ( 0.07 usr  0.02 sys + 17.73 cusr  0.66 csys = 18.48 CPU)
Result: PASS
Use of Nil in numeric context  in block  at /Users/gabor/rakudo-star-2015.06/install/share/perl6/lib/Panda/Tester.pm:36
==> Installing BSON
...
==> Successfully installed BSON

Documentation outdated - BSON.new is not possible on package.

Hi

perl6 -e 'use BSON; BSON.new;'
You cannot create an instance of this type
  in block <unit> at -e:1

Previously BSON was Role and it could be used as standalone object instance.
Now it is a package, but documentation still says in SYNOPSIS that BSON.new is valid usage.

Documents should support destructuring

In function signatures, sub-elements of objects can be mapped to variables:

sub print-id(% (:_id($id))) { say $id; }
print-id $(_id => 4);
# output: 4
my %doc := BSON::Document.new: (_id => 4,)
print-id %doc;
# output: (Any)

As you can see, this fails. Since documents are used like Hash, they should implement this feature as well. I'll make a pull request that implements this shortly.

undefined

Thinking about undefined, it is deprecated in BSON. I can code this in some way or another or leave the key-value out all together. When back in perl it will just show the value as (Any) (a typed undefined value) no matter if the key was in the document or not. So in the last case it will save space and time leaving the pair out.

Parallelize processing

Whole parallelization can be implemented in e_list type (hashes are also treated as arrays).

multi method _e_list ( @p ) {

    return Buf.new unless @p;
    return [~]( @p>>.map: { self._element( $_ ) } );
}

So far in Rakudo:

Once those issues are resolved parallelization can be implemented.

Roadmap

Current BSON implementation is pushed as far as Perl6 Rakudo allows.

  • once we get pack/unpack in Rakudo we can implement 8 bytes (64-bit IEEE 754 floating point) and push such MongoDB features like authentication

Rakudo Star 2012.08 test faild

Faild test in Rakudo Start 2012.08:

t/native.t .... 1/18 No such method 'bytes' for invocant of type 'Str'
in method _string at lib/BSON.pm:281
in block at lib/BSON.pm:85
in method _element at lib/BSON.pm:72
in method _e_list at lib/BSON.pm:54
in method _document at lib/BSON.pm:24
in method encode at lib/BSON.pm:8
in block at t/native.t:60

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.