How do I convert (or cast) a String value to an Integer value?

Summary:
Apache Spark's SQL has partial compatibility with Apache Hive. So, most SQL that can be written in Hive can be written in Spark SQL.

Detail:
To convert a STRING to a specific numeric type like INT, a cast may be used. The cast consists of wrapping the target with parenthesis and preceding the parenthesis with the type to which it is to be changed. For example, the cast might look like this:

INT(someStringValue)

So, to make the SQL in the original posted question work, it needs to be changed to look like this (replacing the original function named "TO_NUMBER" with "INT"):

SELECT name AS geohashPrefix3, INT(Sum_GN_POP) AS totalPopulation, INT(Count1) AS landMass
  FROM wayne_geohash3
 WHERE (LENGTH(name) = 3)

You can get it as Integer from the csv file using the option inferSchema like this :

val df = spark.read.option("inferSchema", true).csv("file-location")

That being said : the inferSchema option do make mistakes sometimes and put the type as String. if so you can use the cast operator on Column

Dataframe/Dataset Implemetation :

val df2 = df.withColumn("Count1", $"Count1" cast "Int" as "landMass").withColumn("Count1", $"Sum_GN_POP" cast "Int" as "totalPopulation")

SQL Implemetation :

SELECT name AS geohashPrefix3, CAST(Sum_GN_POP as INT) AS totalPopulation, CAST(Count1 AS INT) AS landMass
    FROM wayne_geohash3
   WHERE (LENGTH(name) = 3)