The code block displayed below contains an error. The code block should write DataFrame transactionsDf as a parquet file to location filePath after partitioning it on column storeId. Find the error.
Code block:
transactionsDf.write.partitionOn("storeId").parquet(filePath)
No method partitionOn() exists for the DataFrame class, partitionBy() should be used instead.
Correct! Find out more about partitionBy() in the documentation (linked below).
The operator should use the mode() option to configure the DataFrameWriter so that it replaces any existing files at location filePath.
No. There is no information about whether files should be overwritten in the question.
The partitioning column as well as the file path should be passed to the write() method of DataFrame transactionsDf directly and not as appended commands as in the code block.
Incorrect. To write a DataFrame to disk, you need to work with a DataFrameWriter object which you get access to through the DataFrame.writer property - no parentheses involved.
Column storeId should be wrapped in a col() operator.
No, this is not necessary - the problem is in the partitionOn command (see above).
The partitionOn method should be called before the write method.
Wrong. First of all partitionOn is not a valid method of DataFrame. However, even assuming partitionOn would be replaced by partitionBy (which is a valid method), this method is a method of
DataFrameWriter and not of DataFrame. So, you would always have to first call DataFrame.write to get access to the DataFrameWriter object and afterwards call partitionBy.
More info: pyspark.sql.DataFrameWriter.partitionBy --- PySpark 3.1.2 documentation
Static notebook | Dynamic notebook: See test 3, Question: 33 (Databricks import instructions)
Galen
21 days agoIvan
22 days agoKristel
4 days agoDarnell
24 days agoRhea
25 days agoTwila
26 days agoEvangelina
1 days agoCarmela
4 days agoLai
7 days agoCaprice
1 months agoCristal
15 days agoTracie
18 days agoJohnson
25 days agoFelice
1 months agoTerrilyn
15 days agoRodrigo
18 days agoAlline
24 days agoTeddy
2 months agoCorazon
1 months agoShaniqua
1 months agoDelbert
1 months agoAlbert
2 months agoRene
2 months agoGeorgiana
2 months ago