Source: eclairjs/RangePartitioner.js

  1. /*
  2. * Copyright 2015 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. (function () {
  17. var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
  18. var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
  19. var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');
  20. var logger = Logger.getLogger("RangePartitioner_js");
  21. /**
  22. * @constructor
  23. * @memberof module:eclairjs
  24. * @classdesc A {@link Partitioner} that partitions sortable records by range into roughly
  25. * equal ranges. The ranges are determined by sampling the content of the RDD passed in.
  26. *
  27. * Note that the actual number of partitions created by the RangePartitioner might not be the same
  28. * as the `partitions` parameter, in the case where the number of sampled records is less than
  29. * the value of `partitions`.
  30. *
  31. */
  32. var RangePartitioner = function (partitions, rdd, ascending) {
  33. var jvmObject = new org.apache.spark.RangePartitioner(partitions, rdd, ascending);
  34. JavaWrapper.call(this, jvmObject);
  35. };
  36. RangePartitioner.prototype = Object.create(JavaWrapper.prototype);
  37. RangePartitioner.prototype.constructor = RangePartitioner;
  38. RangePartitioner.prototype.numPartitions = function () {
  39. return this.getJavaObject().numPartitions();
  40. }
  41. RangePartitioner.prototype.getPartition = function (key) {
  42. return this.getJavaObject().getPartition(key);
  43. }
  44. RangePartitioner.prototype.equals = function (other) {
  45. var other_uw = Utils.unwrapObject(other);
  46. return this.getJavaObject().equals(other_uw);
  47. }
  48. RangePartitioner.prototype.hashCode = function () {
  49. return this.getJavaObject().hashCode();
  50. }
  51. module.exports = RangePartitioner;
  52. })();