Guide (New 2022) Actual Databricks Associate-Developer-Apache-Spark Exam Questions [Q31-Q51]

Share

Guide (New 2022) Actual Databricks Associate-Developer-Apache-Spark Exam Questions

Associate-Developer-Apache-Spark Exam Dumps Pass with Updated 2022 Certified Exam Questions

NEW QUESTION 31
The code block displayed below contains an error. The code block should return a copy of DataFrame transactionsDf where the name of column transactionId has been changed to transactionNumber. Find the error.
Code block:
transactionsDf.withColumn("transactionNumber", "transactionId")

  • A. The arguments to the withColumn method need to be reordered and the copy() operator should be appended to the code block to ensure a copy is returned.
  • B. The method withColumn should be replaced by method withColumnRenamed and the arguments to the method need to be reordered.
  • C. Each column name needs to be wrapped in the col() method and method withColumn should be replaced by method withColumnRenamed.
  • D. The arguments to the withColumn method need to be reordered.
  • E. The copy() operator should be appended to the code block to ensure a copy is returned.

Answer: B

Explanation:
Explanation
Correct code block:
transactionsDf.withColumnRenamed("transactionId", "transactionNumber")
Note that in Spark, a copy is returned by default. So, there is no need to append copy() to the code block.
More info: pyspark.sql.DataFrame.withColumnRenamed - PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 2

 

NEW QUESTION 32
Which of the following describes characteristics of the Spark driver?

  • A. If set in the Spark configuration, Spark scales the Spark driver horizontally to improve parallel processing performance.
  • B. In a non-interactive Spark application, the Spark driver automatically creates the SparkSession object.
  • C. The Spark driver requests the transformation of operations into DAG computations from the worker nodes.
  • D. The Spark driver processes partitions in an optimized, distributed fashion.
  • E. The Spark driver's responsibility includes scheduling queries for execution on worker nodes.

Answer: B

Explanation:
Explanation
The Spark driver requests the transformation of operations into DAG computations from the worker nodes.
No, the Spark driver transforms operations into DAG computations itself.
If set in the Spark configuration, Spark scales the Spark driver horizontally to improve parallel processing performance.
No. There is always a single driver per application, but one or more executors.
The Spark driver processes partitions in an optimized, distributed fashion.
No, this is what executors do.
In a non-interactive Spark application, the Spark driver automatically creates the SparkSession object.
Wrong. In a non-interactive Spark application, you need to create the SparkSession object. In an interactive Spark shell, the Spark driver instantiates the object for you.

 

NEW QUESTION 33
Which of the following describes tasks?

  • A. Tasks get assigned to the executors by the driver.
  • B. Tasks transform jobs into DAGs.
  • C. A task is a collection of rows.
  • D. A task is a command sent from the driver to the executors in response to a transformation.
  • E. A task is a collection of slots.

Answer: A

Explanation:
Explanation
Tasks get assigned to the executors by the driver.
Correct! Or, in other words: Executors take the tasks that they were assigned to by the driver, run them over partitions, and report the their outcomes back to the driver.
Tasks transform jobs into DAGs.
No, this statement disrespects the order of elements in the Spark hierarchy. The Spark driver transforms jobs into DAGs. Each job consists of one or more stages. Each stage contains one or more tasks.
A task is a collection of rows.
Wrong. A partition is a collection of rows. Tasks have little to do with a collection of rows. If anything, a task processes a specific partition.
A task is a command sent from the driver to the executors in response to a transformation.
Incorrect. The Spark driver does not send anything to the executors in response to a transformation, since transformations are evaluated lazily. So, the Spark driver would send tasks to executors only in response to actions.
A task is a collection of slots.
No. Executors have one or more slots to process tasks and each slot can be assigned a task.

 

NEW QUESTION 34
Which of the following code blocks returns only rows from DataFrame transactionsDf in which values in column productId are unique?

  • A. transactionsDf.unique("productId")
  • B. transactionsDf.dropDuplicates(subset=["productId"])
  • C. transactionsDf.distinct("productId")
  • D. transactionsDf.dropDuplicates(subset="productId")
  • E. transactionsDf.drop_duplicates(subset="productId")

Answer: B

Explanation:
Explanation
Although the question suggests using a method called unique() here, that method does not actually exist in PySpark. In PySpark, it is called distinct(). But then, this method is not the right one to use here, since with distinct() we could filter out unique values in a specific column.
However, we want to return the entire rows here. So the trick is to use dropDuplicates with the subset keyword parameter. In the documentation for dropDuplicates, the examples show that subset should be used with a list. And this is exactly the key to solving this question: The productId column needs to be fed into the subset argument in a list, even though it is just a single column.
More info: pyspark.sql.DataFrame.dropDuplicates - PySpark 3.1.1 documentation Static notebook | Dynamic notebook: See test 1

 

NEW QUESTION 35
Which of the following code blocks generally causes a great amount of network traffic?

  • A. DataFrame.coalesce()
  • B. DataFrame.rdd.map()
  • C. DataFrame.collect()
  • D. DataFrame.count()
  • E. DataFrame.select()

Answer: C

Explanation:
Explanation
DataFrame.collect() sends all data in a DataFrame from executors to the driver, so this generally causes a great amount of network traffic in comparison to the other options listed.
DataFrame.coalesce() just reduces the number of partitions and generally aims to reduce network traffic in comparison to a full shuffle.
DataFrame.select() is evaluated lazily and, unless followed by an action, does not cause significant network traffic.
DataFrame.rdd.map() is evaluated lazily, it does therefore not cause great amounts of network traffic.
DataFrame.count() is an action. While it does cause some network traffic, for the same DataFrame, collecting all data in the driver would generally be considered to cause a greater amount of network traffic.

 

NEW QUESTION 36
Which of the following code blocks returns a one-column DataFrame for which every row contains an array of all integer numbers from 0 up to and including the number given in column predError of DataFrame transactionsDf, and null if predError is null?
Sample of DataFrame transactionsDf:
1.+-------------+---------+-----+-------+---------+----+
2.|transactionId|predError|value|storeId|productId| f|
3.+-------------+---------+-----+-------+---------+----+
4.| 1| 3| 4| 25| 1|null|
5.| 2| 6| 7| 2| 2|null|
6.| 3| 3| null| 25| 3|null|
7.| 4| null| null| 3| 2|null|
8.| 5| null| null| null| 2|null|
9.| 6| 3| 2| 25| 2|null|
10.+-------------+---------+-----+-------+---------+----+

  • A. 1.def count_to_target(target):
    2. if target is None:
    3. return
    4.
    5. result = list(range(target))
    6. return result
    7.
    8.count_to_target_udf = udf(count_to_target)
    9.
    10.transactionsDf.select(count_to_target_udf('predError'))
  • B. 1.def count_to_target(target):
    2. if target is None:
    3. return
    4.
    5. result = list(range(target))
    6. return result
    7.
    8.transactionsDf.select(count_to_target(col('predError')))
  • C. 1.def count_to_target(target):
    2. if target is None:
    3. return
    4.
    5. result = [range(target)]
    6. return result
    7.
    8.count_to_target_udf = udf(count_to_target, ArrayType[IntegerType])
    9.
    10.transactionsDf.select(count_to_target_udf(col('predError')))
  • D. 1.def count_to_target(target):
    2. if target is None:
    3. return
    4.
    5. result = list(range(target))
    6. return result
    7.
    8.count_to_target_udf = udf(count_to_target, ArrayType(IntegerType()))
    9.
    10.transactionsDf.select(count_to_target_udf('predError'))
    (Correct)
  • E. 1.def count_to_target(target):
    2. result = list(range(target))
    3. return result
    4.
    5.count_to_target_udf = udf(count_to_target, ArrayType(IntegerType()))
    6.
    7.df = transactionsDf.select(count_to_target_udf('predError'))

Answer: D

Explanation:
Explanation
Correct code block:
def count_to_target(target):
if target is None:
return
result = list(range(target))
return result
count_to_target_udf = udf(count_to_target, ArrayType(IntegerType()))
transactionsDf.select(count_to_target_udf('predError'))
Output of correct code block:
+--------------------------+
|count_to_target(predError)|
+--------------------------+
| [0, 1, 2]|
| [0, 1, 2, 3, 4, 5]|
| [0, 1, 2]|
| null|
| null|
| [0, 1, 2]|
+--------------------------+
This question is not exactly easy. You need to be familiar with the syntax around UDFs (user-defined functions). Specifically, in this question it is important to pass the correct types to the udf method - returning an array of a specific type rather than just a single type means you need to think harder about type implications than usual.
Remember that in Spark, you always pass types in an instantiated way like ArrayType(IntegerType()), not like ArrayType(IntegerType). The parentheses () are the key here - make sure you do not forget those.
You should also pay attention that you actually pass the UDF count_to_target_udf, and not the Python method count_to_target to the select() operator.
Finally, null values are always a tricky case with UDFs. So, take care that the code can handle them correctly.
More info: How to Turn Python Functions into PySpark Functions (UDF) - Chang Hsin Lee - Committing my thoughts to words.
Static notebook | Dynamic notebook: See test 3

 

NEW QUESTION 37
Which of the following code blocks efficiently converts DataFrame transactionsDf from 12 into 24 partitions?

  • A. transactionsDf.repartition()
  • B. transactionsDf.repartition(24, boost=True)
  • C. transactionsDf.repartition("itemId", 24)
  • D. transactionsDf.repartition(24)
  • E. transactionsDf.coalesce(24)

Answer: D

Explanation:
Explanation
transactionsDf.coalesce(24)
No, the coalesce() method can only reduce, but not increase the number of partitions.
transactionsDf.repartition()
No, repartition() requires a numPartitions argument.
transactionsDf.repartition("itemId", 24)
No, here the cols and numPartitions argument have been mixed up. If the code block would be transactionsDf.repartition(24, "itemId"), this would be a valid solution.
transactionsDf.repartition(24, boost=True)
No, there is no boost argument in the repartition() method.

 

NEW QUESTION 38
Which is the highest level in Spark's execution hierarchy?

  • A. Executor
  • B. Task
  • C. Slot
  • D. Job
  • E. Stage

Answer: D

 

NEW QUESTION 39
The code block shown below should add a column itemNameBetweenSeparators to DataFrame itemsDf. The column should contain arrays of maximum 4 strings. The arrays should be composed of the values in column itemsDf which are separated at - or whitespace characters. Choose the answer that correctly fills the blanks in the code block to accomplish this.
Sample of DataFrame itemsDf:
1.+------+----------------------------------+-------------------+
2.|itemId|itemName |supplier |
3.+------+----------------------------------+-------------------+
4.|1 |Thick Coat for Walking in the Snow|Sports Company Inc.|
5.|2 |Elegant Outdoors Summer Dress |YetiX |
6.|3 |Outdoors Backpack |Sports Company Inc.|
7.+------+----------------------------------+-------------------+
Code block:
itemsDf.__1__(__2__, __3__(__4__, "[\s\-]", __5__))

  • A. 1. withColumn
    2. "itemNameBetweenSeparators"
    3. split
    4. "itemName"
    5. 5
  • B. 1. withColumnRenamed
    2. "itemName"
    3. split
    4. "itemNameBetweenSeparators"
    5. 4
  • C. 1. withColumn
    2. itemNameBetweenSeparators
    3. str_split
    4. "itemName"
    5. 5
  • D. 1. withColumnRenamed
    2. "itemNameBetweenSeparators"
    3. split
    4. "itemName"
    5. 4
  • E. 1. withColumn
    2. "itemNameBetweenSeparators"
    3. split
    4. "itemName"
    5. 4
    (Correct)

Answer: E

Explanation:
Explanation
This question deals with the parameters of Spark's split operator for strings.
To solve this question, you first need to understand the difference between DataFrame.withColumn() and DataFrame.withColumnRenamed(). The correct option here is DataFrame.withColumn() since, according to the question, we want to add a column and not rename an existing column. This leaves you with only 3 answers to consider.
The second gap should be filled with the name of the new column to be added to the DataFrame. One of the remaining answers states the column name as itemNameBetweenSeparators, while the other two state it as "itemNameBetweenSeparators". The correct option here is
"itemNameBetweenSeparators", since the other option would let Python try to interpret itemNameBetweenSeparators as the name of a variable, which we have not defined. This leaves you with 2 answers to consider.
The decision boils down to how to fill gap 5. Either with 4 or with 5. The question asks for arrays of maximum four strings. The code in gap 5 relates to the limit parameter of Spark's split operator (see documentation linked below). The documentation states that "the resulting array's length will not be more than limit", meaning that we should pick the answer option with 4 as the code in the fifth gap here.
On a side note: One answer option includes a function str_split. This function does not exist in pySpark.
More info: pyspark.sql.functions.split - PySpark 3.1.2 documentation
Static notebook | Dynamic notebook: See test 3

 

NEW QUESTION 40
The code block displayed below contains an error. The code block should save DataFrame transactionsDf at path path as a parquet file, appending to any existing parquet file. Find the error.
Code block:

  • A. save() is evaluated lazily and needs to be followed by an action.
  • B. The code block is missing a bucketBy command that takes care of partitions.
  • C. The mode option should be omitted so that the command uses the default mode.
  • D. The code block is missing a reference to the DataFrameWriter.
  • E. transactionsDf.format("parquet").option("mode", "append").save(path)
  • F. Given that the DataFrame should be saved as parquet file, path is being passed to the wrong method.

Answer: D

Explanation:
Explanation
Correct code block:
transactionsDf.write.format("parquet").option("mode", "append").save(path)

 

NEW QUESTION 41
Which of the following code blocks reorders the values inside the arrays in column attributes of DataFrame itemsDf from last to first one in the alphabet?
1.+------+-----------------------------+-------------------+
2.|itemId|attributes |supplier |
3.+------+-----------------------------+-------------------+
4.|1 |[blue, winter, cozy] |Sports Company Inc.|
5.|2 |[red, summer, fresh, cooling]|YetiX |
6.|3 |[green, summer, travel] |Sports Company Inc.|
7.+------+-----------------------------+-------------------+

  • A. itemsDf.withColumn("attributes", sort_array("attributes", asc=False))
  • B. itemsDf.withColumn('attributes', sort_array(col('attributes').desc()))
  • C. itemsDf.withColumn('attributes', sort(col('attributes'), asc=False))
  • D. itemsDf.withColumn('attributes', sort_array(desc('attributes')))
  • E. itemsDf.select(sort_array("attributes"))

Answer: A

Explanation:
Explanation
Output of correct code block:
+------+-----------------------------+-------------------+
|itemId|attributes |supplier |
+------+-----------------------------+-------------------+
|1 |[winter, cozy, blue] |Sports Company Inc.|
|2 |[summer, red, fresh, cooling]|YetiX |
|3 |[travel, summer, green] |Sports Company Inc.|
+------+-----------------------------+-------------------+
It can be confusing to differentiate between the different sorting functions in PySpark. In this case, a particularity about sort_array has to be considered: The sort direction is given by the second argument, not by the desc method. Luckily, this is documented in the documentation (link below). Also, for solving this question you need to understand the difference between sort and sort_array. With sort, you cannot sort values in arrays. Also, sort is a method of DataFrame, while sort_array is a method of pyspark.sql.functions.
More info: pyspark.sql.functions.sort_array - PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 2

 

NEW QUESTION 42
Which of the following describes the conversion of a computational query into an execution plan in Spark?

  • A. The catalog assigns specific resources to the physical plan.
  • B. Depending on whether DataFrame API or SQL API are used, the physical plan may differ.
  • C. The catalog assigns specific resources to the optimized memory plan.
  • D. Spark uses the catalog to resolve the optimized logical plan.
  • E. The executed physical plan depends on a cost optimization from a previous stage.

Answer: E

Explanation:
Explanation
The executed physical plan depends on a cost optimization from a previous stage.
Correct! Spark considers multiple physical plans on which it performs a cost analysis and selects the final physical plan in accordance with the lowest-cost outcome of that analysis. That final physical plan is then executed by Spark.
Spark uses the catalog to resolve the optimized logical plan.
No. Spark uses the catalog to resolve the unresolved logical plan, but not the optimized logical plan. Once the unresolved logical plan is resolved, it is then optimized using the Catalyst Optimizer.
The optimized logical plan is the input for physical planning.
The catalog assigns specific resources to the physical plan.
No. The catalog stores metadata, such as a list of names of columns, data types, functions, and databases.
Spark consults the catalog for resolving the references in a logical plan at the beginning of the conversion of the query into an execution plan. The result is then an optimized logical plan.
Depending on whether DataFrame API or SQL API are used, the physical plan may differ.
Wrong - the physical plan is independent of which API was used. And this is one of the great strengths of Spark!
The catalog assigns specific resources to the optimized memory plan.
There is no specific "memory plan" on the journey of a Spark computation.
More info: Spark's Logical and Physical plans ... When, Why, How and Beyond. | by Laurent Leturgez | datalex | Medium

 

NEW QUESTION 43
Which of the following describes Spark's way of managing memory?

  • A. Storage memory is used for caching partitions derived from DataFrames.
  • B. Spark uses a subset of the reserved system memory.
  • C. Disabling serialization potentially greatly reduces the memory footprint of a Spark application.
  • D. As a general rule for garbage collection, Spark performs better on many small objects than few big objects.
  • E. Spark's memory usage can be divided into three categories: Execution, transaction, and storage.

Answer: A

Explanation:
Explanation
Spark's memory usage can be divided into three categories: Execution, transaction, and storage.
No, it is either execution or storage.
As a general rule for garbage collection, Spark performs better on many small objects than few big objects.
No, Spark's garbage collection runs faster on fewer big objects than many small objects.
Disabling serialization potentially greatly reduces the memory footprint of a Spark application.
The opposite is true - serialization reduces the memory footprint, but may impact performance in a negative way.
Spark uses a subset of the reserved system memory.
No, the reserved system memory is separate from Spark memory. Reserved memory stores Spark's internal objects.
More info: Tuning - Spark 3.1.2 Documentation, Spark Memory Management | Distributed Systems Architecture, Learning Spark, 2nd Edition, Chapter 7

 

NEW QUESTION 44
The code block shown below should return only the average prediction error (column predError) of a random subset, without replacement, of approximately 15% of rows in DataFrame transactionsDf. Choose the answer that correctly fills the blanks in the code block to accomplish this.
transactionsDf.__1__(__2__, __3__).__4__(avg('predError'))

  • A. 1. fraction
    2. 0.15
    3. True
    4. where
  • B. 1. sample
    2. 0.85
    3. False
    4. select
  • C. 1. fraction
    2. False
    3. 0.85
    4. select
  • D. 1. sample
    2. False
    3. 0.15
    4. select
  • E. 1. sample
    2. True
    3. 0.15
    4. filter

Answer: D

Explanation:
Explanation
Correct code block:
transactionsDf.sample(withReplacement=False, fraction=0.15).select(avg('predError')) You should remember that getting a random subset of rows means sampling. This, in turn should point you to the DataFrame.sample() method. Once you know this, you can look up the correct order of arguments in the documentation (link below).
Lastly, you have to decide whether to use filter, where or select. where is just an alias for filter(). filter() is not the correct method to use here, since it would only allow you to filter rows based on some condition. However, the question asks to return only the average prediction error. You can control the columns that a query returns with the select() method - so this is the correct method to use here.
More info: pyspark.sql.DataFrame.sample - PySpark 3.1.2 documentation
Static notebook | Dynamic notebook: See test 2

 

NEW QUESTION 45
The code block displayed below contains multiple errors. The code block should remove column transactionDate from DataFrame transactionsDf and add a column transactionTimestamp in which dates that are expressed as strings in column transactionDate of DataFrame transactionsDf are converted into unix timestamps. Find the errors.
Sample of DataFrame transactionsDf:
1.+-------------+---------+-----+-------+---------+----+----------------+
2.|transactionId|predError|value|storeId|productId| f| transactionDate|
3.+-------------+---------+-----+-------+---------+----+----------------+
4.| 1| 3| 4| 25| 1|null|2020-04-26 15:35|
5.| 2| 6| 7| 2| 2|null|2020-04-13 22:01|
6.| 3| 3| null| 25| 3|null|2020-04-02 10:53|
7.+-------------+---------+-----+-------+---------+----+----------------+ Code block:
1.transactionsDf = transactionsDf.drop("transactionDate")
2.transactionsDf["transactionTimestamp"] = unix_timestamp("transactionDate", "yyyy-MM-dd")

  • A. Column transactionDate should be dropped after transactionTimestamp has been written. The withColumn operator should be used instead of the existing column assignment. Column transactionDate should be wrapped in a col() operator.
  • B. Column transactionDate should be dropped after transactionTimestamp has been written. The string indicating the date format should be adjusted. The withColumn operator should be used instead of the existing column assignment.
  • C. Column transactionDate should be dropped after transactionTimestamp has been written. The string indicating the date format should be adjusted. The withColumn operator should be used instead of the existing column assignment. Operator to_unixtime() should be used instead of unix_timestamp().
  • D. The string indicating the date format should be adjusted. The withColumnReplaced operator should be used instead of the drop and assign pattern in the code block to replace column transactionDate with the new column transactionTimestamp.
  • E. Column transactionDate should be wrapped in a col() operator.

Answer: B

Explanation:
Explanation
This question requires a lot of thinking to get right. For solving it, you may take advantage of the digital notepad that is provided to you during the test. You have probably seen that the code block includes multiple errors. In the test, you are usually confronted with a code block that only contains a single error. However, since you are practicing here, this challenging multi-error question will make it easier for you to deal with single-error questions in the real exam.
You can clearly see that column transactionDate should be dropped only after transactionTimestamp has been written. This is because to generate column transactionTimestamp, Spark needs to read the values from column transactionDate.
Values in column transactionDate in the original transactionsDf DataFrame look like 2020-04-26 15:35. So, to convert those correctly, you would have to pass yyyy-MM-dd HH:mm. In other words:
The string indicating the date format should be adjusted.
While you might be tempted to change unix_timestamp() to to_unixtime() (in line with the from_unixtime() operator), this function does not exist in Spark. unix_timestamp() is the correct operator to use here.
Also, there is no DataFrame.withColumnReplaced() operator. A similar operator that exists is DataFrame.withColumnRenamed().
Whether you use col() or not is irrelevant with unix_timestamp() - the command is fine with both.
Finally, you cannot assign a column like transactionsDf["columnName"] = ... in Spark. This is Pandas syntax (Pandas is a popular Python package for data analysis), but it is not supported in Spark.
So, you need to use Spark's DataFrame.withColumn() syntax instead.
More info: pyspark.sql.functions.unix_timestamp - PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 3

 

NEW QUESTION 46
The code block shown below should read all files with the file ending .png in directory path into Spark.
Choose the answer that correctly fills the blanks in the code block to accomplish this.
spark.__1__.__2__(__3__).option(__4__, "*.png").__5__(path)

  • A. 1. read()
    2. format
    3. "binaryFile"
    4. "recursiveFileLookup"
    5. load
  • B. 1. open
    2. as
    3. "binaryFile"
    4. "pathGlobFilter"
    5. load
  • C. 1. read
    2. format
    3. binaryFile
    4. pathGlobFilter
    5. load
  • D. 1. open
    2. format
    3. "image"
    4. "fileType"
    5. open
  • E. 1. read
    2. format
    3. "binaryFile"
    4. "pathGlobFilter"
    5. load

Answer: E

Explanation:
Explanation
Correct code block:
spark.read.format("binaryFile").option("recursiveFileLookup", "*.png").load(path) Spark can deal with binary files, like images. Using the binaryFile format specification in the SparkSession's read API is the way to read in those files. Remember that, to access the read API, you need to start the command with spark.read. The pathGlobFilter option is a great way to filter files by name (and ending). Finally, the path can be specified using the load operator - the open operator shown in one of the answers does not exist.

 

NEW QUESTION 47
Which of the following code blocks silently writes DataFrame itemsDf in avro format to location fileLocation if a file does not yet exist at that location?

  • A. itemsDf.write.format("avro").mode("ignore").save(fileLocation)
  • B. itemsDf.write.avro(fileLocation)
  • C. spark.DataFrameWriter(itemsDf).format("avro").write(fileLocation)
  • D. itemsDf.write.format("avro").mode("errorifexists").save(fileLocation)
  • E. itemsDf.save.format("avro").mode("ignore").write(fileLocation)

Answer: B

Explanation:
Explanation
The trick in this question is knowing the "modes" of the DataFrameWriter. Mode ignore will ignore if a file already exists and not replace that file, but also not throw an error. Mode errorifexists will throw an error, and is the default mode of the DataFrameWriter. The question NO:
explicitly calls for the DataFrame to be "silently" written if it does not exist, so you need to specify mode("ignore") here to avoid having Spark communicate any error to you if the file already exists.
The `overwrite' mode would not be right here, since, although it would be silent, it would overwrite the already-existing file. This is not what the question asks for.
It is worth noting that the option starting with spark.DataFrameWriter(itemsDf) cannot work, since spark references the SparkSession object, but that object does not provide the DataFrameWriter.
As you can see in the documentation (below), DataFrameWriter is part of PySpark's SQL API, but not of its SparkSession API.
More info:
DataFrameWriter: pyspark.sql.DataFrameWriter.save - PySpark 3.1.1 documentation SparkSession API: Spark SQL - PySpark 3.1.1 documentation Static notebook | Dynamic notebook: See test 1

 

NEW QUESTION 48
The code block shown below should convert up to 5 rows in DataFrame transactionsDf that have the value 25 in column storeId into a Python list. Choose the answer that correctly fills the blanks in the code block to accomplish this.
Code block:
transactionsDf.__1__(__2__).__3__(__4__)

  • A. 1. filter
    2. col("storeId")==25
    3. take
    4. 5
  • B. 1. filter
    2. "storeId"==25
    3. collect
    4. 5
  • C. 1. filter
    2. col("storeId")==25
    3. toLocalIterator
    4. 5
  • D. 1. select
    2. storeId==25
    3. head
    4. 5
  • E. 1. filter
    2. col("storeId")==25
    3. collect
    4. 5

Answer: A

Explanation:
Explanation
The correct code block is:
transactionsDf.filter(col("storeId")==25).take(5)
Any of the options with collect will not work because collect does not take any arguments, and in both cases the argument 5 is given.
The option with toLocalIterator will not work because the only argument to toLocalIterator is prefetchPartitions which is a boolean, so passing 5 here does not make sense.
The option using head will not work because the expression passed to select is not proper syntax. It would work if the expression would be col("storeId")==25.
Static notebook | Dynamic notebook: See test 1
(https://flrs.github.io/spark_practice_tests_code/#1/24.html ,
https://bit.ly/sparkpracticeexams_import_instructions)

 

NEW QUESTION 49
Which of the following code blocks reads the parquet file stored at filePath into DataFrame itemsDf, using a valid schema for the sample of itemsDf shown below?
Sample of itemsDf:
1.+------+-----------------------------+-------------------+
2.|itemId|attributes |supplier |
3.+------+-----------------------------+-------------------+
4.|1 |[blue, winter, cozy] |Sports Company Inc.|
5.|2 |[red, summer, fresh, cooling]|YetiX |
6.|3 |[green, summer, travel] |Sports Company Inc.|
7.+------+-----------------------------+-------------------+

  • A. 1.itemsDfSchema = StructType([
    2. StructField("itemId", IntegerType()),
    3. StructField("attributes", StringType()),
    4. StructField("supplier", StringType())])
    5.
    6.itemsDf = spark.read.schema(itemsDfSchema).parquet(filePath)
  • B. 1.itemsDfSchema = StructType([
    2. StructField("itemId", IntegerType()),
    3. StructField("attributes", ArrayType([StringType()])),
    4. StructField("supplier", StringType())])
    5.
    6.itemsDf = spark.read(schema=itemsDfSchema).parquet(filePath)
  • C. 1.itemsDf = spark.read.schema('itemId integer, attributes <string>, supplier string').parquet(filePath)
  • D. 1.itemsDfSchema = StructType([
    2. StructField("itemId", IntegerType),
    3. StructField("attributes", ArrayType(StringType)),
    4. StructField("supplier", StringType)])
    5.
    6.itemsDf = spark.read.schema(itemsDfSchema).parquet(filePath)
  • E. 1.itemsDfSchema = StructType([
    2. StructField("itemId", IntegerType()),
    3. StructField("attributes", ArrayType(StringType())),
    4. StructField("supplier", StringType())])
    5.
    6.itemsDf = spark.read.schema(itemsDfSchema).parquet(filePath)

Answer: E

Explanation:
Explanation
The challenge in this question comes from there being an array variable in the schema. In addition, you should know how to pass a schema to the DataFrameReader that is invoked by spark.read.
The correct way to define an array of strings in a schema is through ArrayType(StringType()). A schema can be passed to the DataFrameReader by simply appending schema(structType) to the read() operator. Alternatively, you can also define a schema as a string. For example, for the schema of itemsDf, the following string would make sense: itemId integer, attributes array<string>, supplier string.
A thing to keep in mind is that in schema definitions, you always need to instantiate the types, like so:
StringType(). Just using StringType does not work in pySpark and will fail.
Another concern with schemas is whether columns should be nullable, so allowed to have null values. In the case at hand, this is not a concern however, since the question just asks for a
"valid"
schema. Both non-nullable and nullable column schemas would be valid here, since no null value appears in the DataFrame sample.
More info: Learning Spark, 2nd Edition, Chapter 3
Static notebook | Dynamic notebook: See test 3

 

NEW QUESTION 50
Which of the following describes properties of a shuffle?

  • A. Shuffles belong to a class known as "full transformations".
  • B. Shuffles involve only single partitions.
  • C. Operations involving shuffles are never evaluated lazily.
  • D. In a shuffle, Spark writes data to disk.
  • E. A shuffle is one of many actions in Spark.

Answer: D

Explanation:
Explanation
In a shuffle, Spark writes data to disk.
Correct! Spark's architecture dictates that intermediate results during a shuffle are written to disk.
A shuffle is one of many actions in Spark.
Incorrect. A shuffle is a transformation, but not an action.
Shuffles involve only single partitions.
No, shuffles involve multiple partitions. During a shuffle, Spark generates output partitions from multiple input partitions.
Operations involving shuffles are never evaluated lazily.
Wrong. A shuffle is a costly operation and Spark will evaluate it as lazily as other transformations. This is, until a subsequent action triggers its evaluation.
Shuffles belong to a class known as "full transformations".
Not quite. Shuffles belong to a class known as "wide transformations". "Full transformation" is not a relevant term in Spark.
More info: Spark - The Definitive Guide, Chapter 2 and Spark: disk I/O on stage boundaries explanation - Stack Overflow

 

NEW QUESTION 51
......

Pass Guaranteed Quiz 2022 Realistic Verified Free Databricks: https://www.exam4pdf.com/Associate-Developer-Apache-Spark-dumps-torrent.html

Associate-Developer-Apache-Spark Exam Questions - Real & Updated Questions PDF: https://drive.google.com/open?id=1I-1PwysaieyYUH9VlTZCrf7HnbiBxSPx