Certified Associate Developer for Apache Spark Practice Test
Certified Associate Developer for Apache Spark Practice Test practice questions, page 9 of 14, with answer review and explanations.
Question 41
The code block shown below should create and register a SQL UDF named "ASSESS_PERFORMANCE" using the Python function assessPerformance() and apply it to column customerSatisfaction in table stores. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block: spark._1_._2_(_3_, _4_) spark.sql("SELECT customerSatisfaction, _5_(customerSatisfaction) AS result FROM stores")
The code block shown below contains an error. The code block is intended to create a Python UDF assessPerformanceUDF() using the integer-returning Python function assessPerformance() and apply it to column customerSatisfaction in DataFrame storesDF. Identify the error. Code block: assessPerformanceUDF – udf(assessPerformance) storesDF.withColumn("result", assessPerformanceUDF(col("customerSatisfaction")))
The assessPerformance() operation is not properly registered as a UDF.
The withColumn() operation is not appropriate here – UDFs should be applied by iterating over rows instead.
UDFs can only be applied vie SQL and not through the DataFrame API.
The return type of the assessPerformanceUDF() is not specified in the udf() operation.
The assessPerformance() operation should be used on column customerSatisfaction rather than the assessPerformanceUDF() operation.
Question 43
The code block shown below contains an error. The code block is intended to use SQL to return a new DataFrame containing column storeId and column managerName from a table created from DataFrame storesDF. Identify the error. Code block: storesDF.createOrReplaceTempView("stores") storesDF.sql("SELECT storeId, managerName FROM stores")
The createOrReplaceTempView() operation does not make a Dataframe accessible via SQL.
The sql() operation should be accessed via the spark variable rather than DataFrame storesDF.
There is the sql() operation in DataFrame storesDF. The operation query() should be used instead.
This cannot be accomplished using SQL – the DataFrame API should be used instead.
The createOrReplaceTempView() operation should be accessed via the spark variable rather than DataFrame storesDF.
Question 44
The code block shown below should create a single-column DataFrame from Python list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block: _1_._2_(_3_, _4_)
1. spark 2. createDataFrame 3. years 4. IntegerType
1. spark 2. createDataFrame 3. years 4. IntegertType()
Question 45
The code block shown below contains an error. The code block is intended to cache DataFrame storesDF only in Spark’s memory and then return the number of rows in the cached DataFrame. Identify the error. Code block: storesDF.cache().count()
The cache() operation caches DataFrames at the MEMORY_AND_DISK level by default – the storage level must be specified to MEMORY_ONLY as an argument to cache().
The cache() operation caches DataFrames at the MEMORY_AND_DISK level by default – the storage level must be set via storesDF.storageLevel prior to calling cache().
The storesDF DataFrame has not been checkpointed – it must have a checkpoint in order to be cached.
DataFrames themselves cannot be cached – DataFrame storesDF must be cached as a table.
The cache() operation can only cache DataFrames at the MEMORY_AND_DISK level (the default) – persist() should be used instead.