HomeInterview QuestionsDefine a schema. Can you use a struct type to defi…

Define a schema. Can you use a struct type to define a schema?

🟢 Easy Conceptual Fresher level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

A schema is a formal definition of the structure, data types, and constraints of a dataset. It describes what fields exist, their types (e.g., integer, string, date), and any rules such as nullability or value ranges. Using a struct type to define a schema is common in languages like Scala, Java, or frameworks like Apache Spark. For example, in Spark you can write:

scala
case class Person(name: String, age: Int, address: Address)
case class Address(street: String, city: String, zip: String)

Here, Person and Address are structs that form a nested schema. When reading data, Spark infers this schema and enforces type safety, enabling efficient query planning and validation. Structs are especially useful for representing hierarchical data, such as JSON objects or nested tables, and they allow developers to work with strongly typed objects rather than raw key‑value maps.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500