score:4

Accepted answer

All that an import statement does is to bring a name into scope so you can refer to it by its unqualified name. That is, importing DataFrame allows you to write just DataFrame instead of having to write its full name org.apache.spark.sql.DataFrame.

So if you're okay with writing the full name or you're not writing the name at all, you don't need the import. In your first code the latter is the case.

PS: You don't need a return statement at the end of your method. The last expression in a method is returned automatically.

score:1

def foo(path:String) : org.apache.spark.sql.DataFrame  = {
    val df = ...
    return df
}

will work without import. You need to import only if you want to use short names.


Related Query

More Query from same tag