Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Certified Associate Developer for Apache Spark All Questions

View all questions & answers for the Certified Associate Developer for Apache Spark exam

Exam Certified Associate Developer for Apache Spark topic 1 question 85 discussion

The code block shown below contains an error. The code block intended to create a single-column DataFrame from Scala List years which is made up of integers. Identify the error.

Code block:

spark.createDataset(years)

  • A. The years list should be wrapped in another list like List(years) to make clear that it is a column rather than a row.
  • B. The data type is not specified – the second argument to createDataset should be IntegerType.
  • C. There is no operation createDataset – the createDataFrame operation should be used instead.
  • D. The result of the above is a Dataset rather than a DataFrame – the toDF operation must be called at the end.
  • E. The column name must be specified as the second argument to createDataset.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
bublitz
1 month, 1 week ago
Selected Answer: D
It should be D. Scala has a createDataset function which returns a dataset - where then toDF has to be called. Doc: https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/Dataset.html
upvoted 1 times
...
Dharma49
4 months ago
Correct answer is D: spark.createDataset() creates a Dataset, not a DataFrame. To convert a Dataset to a DataFrame, you use toDF().
upvoted 2 times
...
deadbeef38
4 months, 3 weeks ago
Since this is a scala question, the correct syntax would be : spark.createDataset(years).toDF("year") but that isn't one of the options
upvoted 1 times
...
Sowwy1
7 months, 2 weeks ago
Official Databricks tests (where answer is A) Question 44 Which of the following code blocks creates a single-column DataFrame from Scala Listyears which is made up of integers? A. spark.createDataset(years).toDF B. spark.createDataFrame(years, IntegerType) C. spark.createDataset(years) D. spark.DataFrame(years, IntegerType) E. spark.createDataFrame(years)
upvoted 1 times
Sowwy1
7 months, 2 weeks ago
Hence I'll go for D.
upvoted 1 times
...
...
tangerine141
9 months ago
Selected Answer: C
C. There is no operation createDataset – the createDataFrame operation should be used instead. The correct method to create a DataFrame in Spark using Scala is createDataFrame, not createDataset. The correct syntax would be: scala Copy code val df = spark.createDataFrame(years.map(Tuple1.apply)).toDF("columnName") This assumes that years is a List of integers, and the resulting DataFrame will have a single column named "columnName".
upvoted 1 times
...
zozoshanky
1 year, 3 months ago
C is the answer
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...