Databricks Data Engineer Associate Question 97
Select 3You are working with a CSV file stored in a Databricks workspace at the path '/mnt/data/sales.csv'. You need to create a reference to this file for querying purposes and decide to use a view, a temporary view, and a common table expression (CTE). Which of the following statements correctly create these references?
- A
CREATE OR REPLACE VIEW sales_view AS SELECT * FROM csv.
/mnt/data/sales.csv; - B
CREATE OR REPLACE TEMP VIEW sales_temp_view AS SELECT * FROM csv.
/mnt/data/sales.csv; - C
WITH sales_cte AS (SELECT * FROM csv.
/mnt/data/sales.csv) SELECT * FROM sales_cte; - D
CREATE TABLE sales_table AS SELECT * FROM csv.
/mnt/data/sales.csv;
Show answer and explanation
Correct answers: A, B, C
Explanation
Creating views, temporary views, and CTEs are common methods to reference external data sources like files in Databricks. Persistent views are stored in the metastore, temporary views are session-scoped, and CTEs are query-scoped, but all can reference a CSV file as shown. The CREATE TABLE statement, however, physically materializes data and does not meet the requirement for creating a reference to the file.
- A. Correct.
This is correct. The
CREATE OR REPLACE VIEWsyntax is used to create a persistent view in Databricks, and thecsv.format allows querying the CSV file directly. - B. Correct.
This is correct. The
CREATE OR REPLACE TEMP VIEWsyntax creates a temporary view that lasts only for the duration of the session and can reference the CSV file directly. - C. Correct.
This is correct. A common table expression (CTE) uses the
WITHkeyword to define a temporary, reusable query structure, which can reference external data sources like a CSV file. - D. Incorrect.
This is incorrect. The
CREATE TABLEstatement creates a physical table in Databricks and is not a method for creating a view, temporary view, or CTE. It materializes the data instead of referencing it.