cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I run a scala command line in databricks?

pret
New Contributor II

I wish to run a scala command, which I believe would normally be run from a scala command line rather than from within a notebook.

It happens to be:

scala [-cp scalatest-<version>.jar:...] org.scalatest.tools.Runner [arguments]

(scalatest_2.12__3.0.8.jar is included within the databricks runtime)

Can this be run within a scala notebook from databricks, or by some other means within databricks, eg (and ideally) as a job?

I have tried various ways of running this command from within a notebook without success. I'm not sure if its possible or if I need to structure the syntax in such a way for it to work.

Thanks

4 REPLIES 4

Debayan
Databricks Employee
Databricks Employee

Hi @David Vardy​ , from notebooks you can try using Scala, ref: https://docs.databricks.com/notebooks/notebooks-use.html#mix-languages.

You can use the language magic command %<language> at the beginning of a cell. The supported magic commands are: 

%python

%r

%scala

%sql

pret
New Contributor II

Hi @Debayan Mukherjee​ , thanks, I understand I can write Scala scripts in the notebook, which I already do, but I'm not sure how I can run a scala command line command in databricks? For example, using a 7.3 LTS runtime and the following scala in a notebook:

import org.scalatest._
import org.scalatest.tools.Runner
 
class DBtestSuite extends FeatureSpec with GivenWhenThen {
 
  feature("feature...") {
    scenario("scenario...") {
      Given("given...")
      When("when")
      Then("then...")
      assert(1==2)
    }
  }
}
 
scala -classpath "scalatest_2.12__3.0.8.jar" org.scalatest.tools.Runner -s DBtestSuite

results in error:

error: ';' expected but string literal found.
scala -classpath "scalatest_2.12__3.0.8.jar" org.scalatest.tools.Runner -s DBtestSuite

Debayan
Databricks Employee
Databricks Employee

Anonymous
Not applicable

Hi @David Vardy​ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group