Source: eclairjs/ml/util/MLWriter.js

  1. /*
  2. * Copyright 2016 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. /**
  21. * @classdesc
  22. * Utility classes that can save ML instances.
  23. * @class
  24. * @memberof module:eclairjs/ml/util
  25. */
  26. var MLWriter = function (jvmObject) {
  27. this.logger = Logger.getLogger("ml_util_MLWriter_js");
  28. JavaWrapper.call(this, jvmObject);
  29. };
  30. MLWriter.prototype = Object.create(JavaWrapper.prototype);
  31. MLWriter.prototype.constructor = MLWriter;
  32. /**
  33. * Saves the ML instances to the input path.
  34. * @param {string} path
  35. */
  36. MLWriter.prototype.save = function (path) {
  37. this.getJavaObject().save(path);
  38. };
  39. /**
  40. * Overwrites if the output path already exists.
  41. * @returns {module:eclairjs/ml/util.MLWriter}
  42. */
  43. MLWriter.prototype.overwrite = function () {
  44. var javaObject = this.getJavaObject().overwrite();
  45. return new MLWriter(javaObject);
  46. };
  47. /**
  48. * @param {module:eclairjs/sql.SQLContext} sqlContext
  49. * @returns {module:eclairjs/ml/util.MLWriter}
  50. */
  51. MLWriter.prototype.context = function (sqlContext) {
  52. var sqlContext_uw = Utils.unwrapObject(sqlContext);
  53. var javaObject = this.getJavaObject().context(sqlContext_uw);
  54. return new MLWriter(javaObject);
  55. };
  56. /**
  57. * @param {module:eclairjs/sql.SparkSession} sparkSession
  58. * @returns {module:eclairjs/ml/util.MLWriter}
  59. */
  60. MLWriter.prototype.session = function(sparkSession) {
  61. var sparkSession_uw = Utils.unwrapObject(sparkSession);
  62. var javaObject = this.getJavaObject().session(sparkSession_uw);
  63. return new MLWriter(javaObject);
  64. };
  65. module.exports = MLWriter;
  66. })();