Question 61

In which order should the code blocks shown below be run in order to create a table of all values in column attributes next to the respective values in column supplier in DataFrame itemsDf?
1. itemsDf.createOrReplaceView("itemsDf")
2. spark.sql("FROM itemsDf SELECT 'supplier', explode('Attributes')")
3. spark.sql("FROM itemsDf SELECT supplier, explode(attributes)")
4. itemsDf.createOrReplaceTempView("itemsDf")
  • Question 62

    The code block displayed below contains an error. The code block below is intended to add a column itemNameElements to DataFrame itemsDf that includes an array of all words in column itemName. Find the error.
    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.withColumnRenamed("itemNameElements", split("itemName"))
    itemsDf.withColumnRenamed("itemNameElements", split("itemName"))
  • Question 63

    The code block displayed below contains an error. The code block should create DataFrame itemsAttributesDf which has columns itemId and attribute and lists every attribute from the attributes column in DataFrame itemsDf next to the itemId of the respective row in itemsDf. Find the error.
    A sample of DataFrame itemsDf is below.

    Code block:
    itemsAttributesDf = itemsDf.explode("attributes").alias("attribute").select("attribute", "itemId")
  • Question 64

    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?
  • Question 65

    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")