Databricks Certified Associate Developer for Apache Spark Practice Test Questions and Exam Dumps Part6 Q101-120

View Full Databricks Certified Associate Developer for Apache Spark Exam Dumps  and Practice Test Dumps

 

Question 101.

Which Spark SQL function can return the month number from a date or timestamp column?

  1. month()
    2. months_between()
    3. add_months()
    4. date_format()

Correct Answer: 1. month()

Explanation:

month() extracts the month number from a date or timestamp expression, typically returning values from 1 through 12. It is useful for grouping, filtering, and creating calendar-based features. months_between() calculates the difference between dates in months, add_months() shifts a date by a number of months, and date_format() converts dates or timestamps into formatted strings. month() is therefore the most direct function when only the month component is required.

Question 102.

Which Spark SQL function returns the day of the month from a date or timestamp?

  1. dayofweek()
    2. dayofmonth()
    3. weekofyear()
    4. date_add()

Correct Answer: 2. dayofmonth()

Explanation:

dayofmonth() extracts the day number within the month from a date or timestamp expression. For example, a date representing the fifteenth day of a month returns 15. dayofweek() returns the weekday position, weekofyear() returns the week number, and date_add() shifts a date forward. dayofmonth() is useful when creating calendar features or filtering records by specific days within each month.

Question 103.

Which Spark SQL function can return the week number within a year?

  1. year()
    2. month()
    3. weekofyear()
    4. dayofmonth()

Correct Answer: 3. weekofyear()

Explanation:

weekofyear() returns the week number associated with a date or timestamp. It is useful when grouping events, transactions, or metrics into weekly reporting periods. year() extracts the year, month() extracts the month number, and dayofmonth() extracts the day within the month. weekofyear() is therefore the appropriate function when weekly calendar grouping is needed.

Question 104.

Which function returns the last day of the month for a given date?

  1. trunc()
    2. add_months()
    3. date_sub()
    4. last_day()

Correct Answer: 4. last_day()

Explanation:

last_day() returns the final calendar date of the month containing the input date. It is useful for month-end reporting, billing periods, and financial calculations. trunc() can reduce a date to a broader calendar unit, add_months() shifts by months, and date_sub() subtracts days. last_day() is the direct function for identifying the month-end date associated with a record.

Question 105.

Which Spark SQL function can return the next specified weekday after a given date?

  1. next_day()
    2. current_date()
    3. dayofweek()
    4. date_format()

Correct Answer: 1. next_day()

Explanation:

next_day() returns the first specified weekday that occurs after a given date. It can be useful in scheduling, reporting, and business-calendar calculations. current_date() returns today’s date, dayofweek() identifies the weekday of a date, and date_format() formats a date as text. next_day() is therefore the appropriate function when a future weekday relative to a date must be identified.

Question 106.

Which function is used to truncate a date to a specified unit such as month or year?

  1. date_format()
    2. trunc()
    3. datediff()
    4. last_day()

Correct Answer: 2. trunc()

Explanation:

trunc() returns a date truncated to a specified unit such as month or year. For example, truncating a date to month generally returns the first day of that month. date_format() converts dates to strings, datediff() calculates differences in days, and last_day() returns the last day of a month. trunc() is useful for grouping dates into standardized calendar boundaries.

Question 107.

Which Spark SQL function can return the hour component from a timestamp?

  1. minute()
    2. second()
    3. hour()
    4. current_timestamp()

Correct Answer: 3. hour()

Explanation:

hour() extracts the hour component from a timestamp expression. It is useful for analyzing activity by time of day, creating hourly aggregations, or building time-based features. minute() and second() extract different timestamp components, while current_timestamp() returns the current date and time. hour() is therefore the direct function when the hour portion of a timestamp is needed.

Question 108.

Which function extracts the minute component from a timestamp?

  1. hour()
    2. second()
    3. unix_timestamp()
    4. minute()

Correct Answer: 4. minute()

Explanation:

minute() extracts the minute component from a timestamp value. It is useful when creating fine-grained time-based analysis or validating timestamp fields. hour() extracts the hour, second() extracts the seconds portion, and unix_timestamp() is associated with Unix time representation. minute() is the appropriate function when only the minute value is required.

Question 109.

Which Spark SQL function can extract the seconds component from a timestamp?

  1. second()
    2. minute()
    3. hour()
    4. datediff()

Correct Answer: 1. second()

Explanation:

second() extracts the seconds component from a timestamp expression. It is useful for detailed time analysis, timestamp parsing validation, or event-processing logic. minute() and hour() return other timestamp components, while datediff() compares dates in days. second() provides the most direct way to retrieve the seconds portion of a timestamp.

Question 110.

Which function can convert a timestamp to Unix time measured in seconds?

  1. to_timestamp()
    2. unix_timestamp()
    3. current_timestamp()
    4. date_format()

Correct Answer: 2. unix_timestamp()

Explanation:

unix_timestamp() can convert a timestamp or compatible string representation to the number of seconds since the Unix epoch. It is useful for time arithmetic and interoperability with systems that store timestamps numerically. to_timestamp() converts values into Spark TimestampType, current_timestamp() returns the current time, and date_format() formats timestamp values as strings. unix_timestamp() is therefore the appropriate choice for obtaining epoch-based seconds.

Question 111.

Which Spark SQL function can convert Unix time in seconds back into a formatted timestamp string?

  1. current_date()
    2. to_date()
    3. from_unixtime()
    4. datediff()

Correct Answer: 3. from_unixtime()

Explanation:

from_unixtime() converts a Unix timestamp expressed in seconds into a human-readable timestamp string, optionally using a specified format. It is useful when source systems store time as epoch values. current_date() returns the current date, to_date() converts expressions to DateType, and datediff() returns the number of days between dates. from_unixtime() is therefore the appropriate function for translating epoch seconds into readable date-time values.

Question 112.

Which Spark SQL function can convert a timestamp from UTC to another time zone?

  1. to_utc_timestamp()
    2. date_format()
    3. current_timestamp()
    4. from_utc_timestamp()

Correct Answer: 4. from_utc_timestamp()

Explanation:

from_utc_timestamp() converts a timestamp interpreted in UTC into the specified target time zone. This is useful when globally stored UTC timestamps need to be presented in regional local time. to_utc_timestamp() performs the reverse direction, converting a local-time interpretation toward UTC. date_format() changes presentation, while current_timestamp() returns the current timestamp. Time-zone conversion is important in distributed systems that process data generated across multiple regions.

Question 113.

Which Spark SQL function converts a timestamp from a specified local time zone to UTC?

  1. to_utc_timestamp()
    2. from_utc_timestamp()
    3. unix_timestamp()
    4. current_date()

Correct Answer: 1. to_utc_timestamp()

Explanation:

to_utc_timestamp() converts a timestamp interpreted in a specified local time zone into UTC. It is useful when normalizing timestamp data from multiple geographic regions into a common reference zone. from_utc_timestamp() performs the opposite conversion, while unix_timestamp() represents time as epoch seconds. current_date() returns only the current date. Standardizing timestamps to UTC can simplify comparisons and distributed data processing.

Question 114.

Which Spark SQL function is commonly used to parse a JSON string into a structured column based on a schema?

  1. to_json()
    2. from_json()
    3. get_json_object()
    4. explode()

Correct Answer: 2. from_json()

Explanation:

from_json() parses a JSON string according to a provided schema and returns a structured value such as a struct or array. This enables nested JSON fields to be accessed using standard DataFrame expressions. to_json() performs the reverse transformation, get_json_object() extracts JSON content using a path expression, and explode() expands nested collections into rows. from_json() is especially useful when ingesting semi-structured JSON stored inside string columns.

Question 115.

Which Spark SQL function converts a struct, array, or map column into a JSON string?

  1. from_json()
    2. schema_of_json()
    3. to_json()
    4. json_tuple()

Correct Answer: 3. to_json()

Explanation:

to_json() converts supported complex Spark SQL values such as structs, arrays, or maps into JSON-formatted strings. It is useful when preparing structured data for APIs, message systems, files, or downstream systems expecting JSON text. from_json() parses JSON into structured values, schema_of_json() can derive schema information, and json_tuple() extracts selected fields. to_json() is therefore the direct function for serialization to JSON text.

Question 116.

Which function can extract a JSON value using a JSONPath-style expression?

  1. from_json()
    2. to_json()
    3. struct()
    4. get_json_object()

Correct Answer: 4. get_json_object()

Explanation:

get_json_object() extracts a portion of a JSON string using a path expression. It is useful for retrieving a particular nested value without fully parsing the entire JSON object into a structured schema. from_json() performs schema-based parsing, to_json() serializes structures into JSON, and struct() constructs a nested Spark struct. get_json_object() can be convenient for lightweight extraction from JSON text columns.

Question 117.

Which function is commonly used to flatten an array column by producing one row per array element?

  1. explode()
    2. array()
    3. collect_list()
    4. struct()

Correct Answer: 1. explode()

Explanation:

explode() transforms each element of an array or map into a separate output row. It is widely used to flatten nested data before further filtering, aggregation, or joins. array() creates array-valued columns, collect_list() aggregates multiple rows into an array, and struct() creates nested records. explode() is therefore the standard function when nested collection elements must be expanded into individual rows.

Question 118.

Which variant of explode() preserves rows even when the array or map is null or empty?

  1. posexplode()
    2. explode_outer()
    3. inline()
    4. flatten()

Correct Answer: 2. explode_outer()

Explanation:

explode_outer() behaves similarly to explode() but preserves a row when the input collection is null or empty by producing null output values as appropriate. This can be important when flattening optional nested data without unintentionally dropping source records. posexplode() also provides element positions, inline() works with arrays of structs, and flatten() combines nested arrays. explode_outer() is useful when row preservation matters during nested-data processing.

Question 119.

Which function can combine an array of arrays into a single array?

  1. explode()
    2. array_union()
    3. flatten()
    4. collect_set()

Correct Answer: 3. flatten()

Explanation:

flatten() converts an array containing nested arrays into a single-level array. For example, an array of several arrays can be collapsed so their elements appear in one combined array. explode() creates rows from array elements, array_union() combines two arrays while eliminating duplicates, and collect_set() aggregates unique values across rows. flatten() is therefore the appropriate function for removing one level of array nesting.

Question 120.

Which function returns an array containing the distinct union of two input arrays?

  1. concat()
    2. flatten()
    3. arrays_overlap()
    4. array_union()

Correct Answer: 4. array_union()

Explanation:

array_union() combines two arrays and returns the distinct set of elements that appear in either input array. Duplicate values are removed from the result. concat() can combine arrays but does not provide the same set-style semantics, flatten() removes a nesting level, and arrays_overlap() checks whether two arrays share at least one element. array_union() is therefore useful when merging array-valued data while avoiding duplicate elements.