↑ ↓ to move, Enter to open, Esc to close

    DBX-ADASAssociate Developer for Apache Spark

    Switch exam

    Microsoft Azure

    aws Amazon Web Services

    Google Cloud

    ServiceNow

    Databricks

    Cisco

    Salesforce

    All exams and search

    Exams / DBX-ADAS / D1 Developing Apache Spark™ DataFrame/DataSet API Applications

    D1.1

    Developing Apache Spark™ DataFrame/DataSet API Applications (part 1 of 6)

    • 1 min read
    • 5 sections
    • 31 questions
    • Free preview
    • Exam domain: Developing Apache Spark™ DataFrame/DataSet API Applications
    You are reading a free preview. The rest of the DBX-ADAS course unlocks with an Exam pass or All access.See plans

    Reading and writing data

    Task Pattern
    Write JSON df.write.json(path) (write is a property: no parentheses)
    Write Parquet, partitioned df.write.mode("overwrite").partitionBy("country").parquet(path)
    Managed table df.write.saveAsTable("catalog.schema.table")
    Read with a known schema spark.read.schema(structType).json(path) (skips inference)
    Nested folders option("recursiveFileLookup", "true")

    Save modes: "By default if data exists at the specified path the write operation fails." overwrite replaces data, append adds, ignore silently skips, and the default (error/errorifexists) fails.

    Columns and rows

    Need Code
    New or replaced column withColumn("c", expr): the value must be a Column
    Constant lit("PHYSICAL")
    Cast col("storeId").cast(StringType())
    Drop columns df.drop("a", "b")
    Fill nulls df.na.fill(30000, Seq("sqft")) (Scala)
    Drop null rows df.na.drop(how="all") drops only all-null rows
    Deduplicate dropDuplicates() (all columns) or distinct()
    Union union by position, unionByName by name
    Sort sort/orderBy, ascending by default
    Aggregate groupBy(...) returns GroupedData, then agg
    First row value df.first().sqft
    Conditional count agg(count_if(cond)) (3.5.0)

    Joins

    how defaults to inner; pass "outer" explicitly. on can be a name, a list of names, or boolean expressions (a list of bare col() is invalid).

    Partitions and broadcast

    coalesce vs repartition

    broadcast the small side

    UDFs

    "The default return type is StringType." Declare T.DoubleType() / IntegerType() to match what the function returns.

    Exam traps

    • df.write() and .paquet are typos or invalid syntax.
    • describe takes names, not col().
    • coalesce can only reduce partitions and does not shuffle.
    • Create one SparkSession per application.

    Docs

    The rest of this chapter is part of the DBX-ADAS premium course

    Unlock every chapter, all 342 questions and spaced review with All access or a 90-day exam pass. Every Fundamentals exam stays free, and the first chapter of every exam is open.

    Chapters