Created on 04-09-2020 07:48 PM - last edited on 04-10-2020 06:36 AM by cjervis
In Data Science Workbench, I would like to create one file with a number of types/functions defined. Then, in a separate file, I'd like to be able to import those types/functions (the first file is essentially acting as a library that can be shared among many other scripts.) How do I go about this? In the docs, I see a mention of it being possible, but no example and the few obvious things I've tried haven't worked, so I'm clearly overlooking something simple.
Thanks in advance for any help!
- J.
Created 04-15-2020 01:02 PM
Thank you, Paul. That's what I've been doing up to this point. I was hoping (but not expecting) there might be a way to import definitions from file A without going through the "Run All" step. The reason is to be able to kick off an experiment that runs file B without having to manually copy definitions from A to B.
I'm guessing that's not possible, which is fine. I just didn't want to start copying stuff from file to file if it could be avoided. For more established code, I'll probably wind up building a jar. I was just hoping for something with a little quicker turnaround time for now.
Thanks,
- J.
Created on 04-14-2020 03:22 PM - edited 04-14-2020 04:20 PM
Within a CDSW project, you have the option to manually upload files from your computer or import them from a github repository by pulling from it.
Once you have created a project, you can access project files from the Overview Page, the Files page, or from within a terminal window if you launch a CDSW session. The project files are automatically loaded to the /home/cdsw directory but you can create additional directories at will.
This quickstart guide will give you some more details on the above steps. https://docs.cloudera.com/documentation/data-science-workbench/1-7-x/topics/cdsw_quickstart.html
Once you have created a project, create two scala files by clicking on "new session" and selecting the Scala Engine Kernel. I recommend leaving the default Workbench editor for the purposes of this example. Next, you can put your methods etc. in your first file, and import them from the second file. Finally, run the second file within the Scala session by clicking "Run" -> "Run All".
I would recommend following this short tutorial example and creating project directories and files in CDSW https://www.cs.helsinki.fi/u/wikla/OTS/Sisalto/examples/html/ch13.html#sec2
Created 04-15-2020 01:02 PM
Thank you, Paul. That's what I've been doing up to this point. I was hoping (but not expecting) there might be a way to import definitions from file A without going through the "Run All" step. The reason is to be able to kick off an experiment that runs file B without having to manually copy definitions from A to B.
I'm guessing that's not possible, which is fine. I just didn't want to start copying stuff from file to file if it could be avoided. For more established code, I'll probably wind up building a jar. I was just hoping for something with a little quicker turnaround time for now.
Thanks,
- J.
Created 04-29-2020 07:35 PM
I think this answer may have been edited since I originally looked at it. I don't recall seeing that link to the Scala tutorial and the suggestion that importing should work.
This still does not work for me. If I follow the code in that tutorial, I get:
import bobsdelights.Fruit
Name: Unknown Error
Message: <console>:80: error: not found: value bobsdelights
import bobsdelights.Fruit
^
Have you confirmed that you are able to import local Scala code from one file to another without first executing that first file in the shell? The intention is to be able to run an experiment and I can only submit one script via the experiment UI.