Spark Scala Interview Question
Spark Scala Interview Question
𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻: Find the date on which maximum number of rooms were searched along with
their count.
#key #takeaways
#Approach:
𝟭. split: room_type column to get Array of rooms
𝘀𝗽𝗹𝗶𝘁(𝗰𝗼𝗹("𝗳𝗶𝗹𝘁𝗲𝗿_𝗿𝗼𝗼𝗺_𝘁𝘆𝗽𝗲𝘀"), ",")
𝟰. 𝗼𝗿𝗱𝗲𝗿𝗕𝘆("𝗰𝗼𝘂𝗻𝘁") descending and 𝗹𝗶𝗺𝗶𝘁 𝟭 to get the row with highest number of rooms
searched.
object AirBnB_Room_Type_Search {
private val spark = SparkSession.builder
.appName("AirBnB_Room_Type_Search")
.master("yarn")
.getOrCreate()
def main(args: Array[String]): Unit = {
val schema = new StructType(
Array(
StructField("user_id", IntegerType, nullable = true),
StructField("date_searched", DateType, nullable = true),
StructField("filter_room_types", StringType, nullable = true)
)
)
resultDF.show(truncate=false)
}
}
#credits
Ankit Bansal
OnlineLearningCenter
Suraz G.
Shashank Mishra 🇮🇳