cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Esteemed Contributor III
Esteemed Contributor III

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

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!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.