This post will show you how to use Scala with Spark SQL to define variables and assign values to them.
Variables are just reserved memory locations where values can be stored. This means that when you create a variable, you reserve some memory for it. The compiler allocates memory and decides what can be stored in reserved memory based on the data type of a variable. As a result, you can store integers, decimals, or characters in variables by assigning multiple data types to them. Additionally, the data type of the variable will be determined by the value assigned to it.
Let’s see practically how to declare the variables and assign values to them.
scala> var x=20
x: Int = 20
scala> var y=30
y: Int = 30
res6: Int = 50
res7: Int = -10
res8: Int = 600
res9: Int = 5
Variables X and Y were identified as integers in the preceding example based on the values provided to them. See the below examples-
scala> var x : String = “Hello”
x: String = Hello
scala> var y : String = “World”
y: String = World
In the above example, we specified the data-types for the variables “x” and “y”.
Hope you find this article helpful.
Please follow us for more interesting updates.