Using CommonJS module in Riak mapreduce/pre-commit hook

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using CommonJS module in Riak mapreduce/pre-commit hook

briche arnaud
Hi,
   I just want to know if one can import CommonJS modulesin Riak mapreduce or pre-commit hook function.
By the way, the goal is to share json schema validation code between the client and Riak pre-commit hook, if there
another strategy I hadn't thought.

Thanks.

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Using CommonJS module in Riak mapreduce/pre-commit hook

bryan-basho
Administrator
On Mon, Oct 24, 2011 at 12:08 PM, briche arnaud <[hidden email]> wrote:
> Hi,
>    I just want to know if one can import CommonJS modulesin Riak mapreduce
> or pre-commit hook function.

Hi, Briche.  I'm unfamiliar with how the CommonJS modules are
structured, but if they're available as a simple collections of .js
files, you can have Riak load them at startup by following the
directions given here:

https://help.basho.com/entries/321385-how-do-i-load-3rd-party-javascript-libraries-for-use-in-map-reduce-functions#overview

(essentially: toss the files in a directory, and point to it by
setting 'js_source_dir' in the riak_kv section of your app.config)

-Bryan

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Using CommonJS module in Riak mapreduce/pre-commit hook

Jon Brisbin


>    I just want to know if one can import CommonJS modulesin Riak mapreduce
> or pre-commit hook function.

Hi, Briche.  I'm unfamiliar with how the CommonJS modules are
structured, but if they're available as a simple collections of .js
files, you can have Riak load them at startup by following the
directions given here:

https://help.basho.com/entries/321385-how-do-i-load-3rd-party-javascript-libraries-for-use-in-map-reduce-functions#overview

(essentially: toss the files in a directory, and point to it by
setting 'js_source_dir' in the riak_kv section of your app.config)
Sorry to barge in, but I don't think it's as simple as all that. :) CommonJS has a specification about how modules are structured that needs to be followed so that the appropriate stuff is registered correctly.

http://www.commonjs.org/specs/modules/1.0/

To have "proper" commonjs support in Riak, one would need to bootstrap modules so that the right "require" and "exports" is defined at the right time.

I pretty sure you can't just make sure commonjs modules are available to the JS interpreter because you don't want every module available all the time. The idea is that you have some bootstrap mechanism to load the right JS modules when you need them. Some M/R jobs would need module X while other M/R jobs would need module Y. Quite possibly you don't want both modules X and Y available all the time to all jobs.

Clear as mud? :)

Thanks!

Jon Brisbin
http//jbrisbin.com

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com