You are working with a Snowpark DataFrame containing customer data, including a 'phone_number' column. Some phone numbers are missing or have incorrect formats. You want to impute missing values with a default phone number '000-000-0000' and remove any phone numbers that do not match the pattern 'XXX-XXX-XXXX' using Snowpark Python. Which of the following code snippets achieves this most efficiently?
Correct Answer: E
Option E is correct. It uses 'when' with 'isnull' to impute missing phone numbers and 'regexp_like' to filter out invalid formats. Options A and B are similar but less explicit. Option C omits 'lit', which makes the code incorrect as it won't work with Snowpark. Option D does not use 'lit' and also 'fillna' will give an exception if datatypes doesnt match
Question 72
When using key pair authentication with Snowpark, what security best practices should you implement to protect your private key? (Select all that apply)
Correct Answer: B,C,E
Storing the private key directly in the code repository (A) is a major security risk. Encrypting the private key at rest (B) provides an additional layer of security. Storing the private key in an environment variable or secure secret management system (C) is the recommended approach. Granting broad access (D) increases the risk of compromise. Regularly rotating the key pair (E) limits the impact if a key is compromised. Options B,C and E are the most secure ones.
Question 73
You have a Snowpark DataFrame named with the following schema: 'product_id' (INTEGER), (STRING), 'category' (STRING), 'price' (FLOAT), and 'description' (STRING). You want to perform several data cleaning and transformation steps. Which of the following operations can be efficiently chained together using Snowpark DataFrames to clean null values in 'description', replace special characters in 'product_name' and standardize 'category' values? Select all that apply:
Correct Answer: A,B,D
Options A, B, and D can be efficiently chained using Snowpark DataFrame operations. Option A Cna.fill()') is a built-in method for handling null values. Option B is a SQL function available in Snowpark for string manipulation. Option D ('coalesce()') effectively fills null values from another column if present. Option C, using a UDF for string standardization, is viable but potentially less efficient than using built-in functions if possible. Option E is extremely inefficient as it forces data transfer to the client and row-by-row processing instead of leveraging Snowflake's parallel processing capabilities. Chaining operations allows Snowpark to optimize the execution plan and potentially perform these transformations in a single pass over the data. UDF execution might introduce overhead.
Question 74
You are working with a Snowpark DataFrame containing website traffic data'. The DataFrame has columns like 'date' , 'page_url', and 'visit_count'. You need to calculate the cumulative sum of visit counts for each 'page_url' over time (i.e., ordered by 'date'). However, you only want to consider data from the last 30 days for each calculation. Which of the following Snowpark code snippets will correctly achieve this using window functions with a frame specification?
Correct Answer: B
Option B is correct because it uses 'rangeBetween(-30, 0)' which specifies a frame that includes all rows within a range of 30 days preceding the current row, based on the ordering defined by the "date" column. Since 'date' column is used for ordering, we need to use rangeBetween' and NOT 'rowsBetween' . Also, we need to use 'sf.sum()' for Snowflake functions'. If the column is of Timestamp type, 'rangeBetween' represents days only, and in case it's numeric type represents numeric interval. Option A calculates the cumulative sum from the beginning of time for each page URL. Option C doesn't correctly specify the end of the frame. Option D has incorrect syntax and may not work. Option E uses incorrect sum function as well, as it misses sf prefix.
Question 75
Consider a Snowpark DataFrame with a containing date values, some of which are corrupted (e.g., invalid date formats or out-of-range values). You need to identify and either remove or correct these corrupted date values. Which of the following approaches can be effectively used in Snowpark Python to handle such scenarios? (Select all that apply)
Correct Answer: A,B,D
Options A, B, and D are valid approaches. Option A allows converting the column to date, setting incorrect values as NULL, which can then be filtered. Option B (UDF) provides flexibility for custom date parsing and error handling. Option D is valid as well, as it filters out data which doesn't match the expression. Option C is incorrect. The 'to_date' function in Snowpark does not have an 'IGNORE' keyword to replace invalid dates with NULL automatically. If it fails to convert to date, it will throw an error. Option E assumes that the corrupted dates can be pre-identified, which is generally not the case as the process aims to identify the dates that are corrupt, thus making it an incorrect answer.