CSVファイル形式で`copy into <table>`コマンドを使用する場合、`match_by_column_name`パラメータはどのように動作しますか?
正解:B
Option B is the best design to meet the requirements because it uses Snowpipe to ingest the data continuously and efficiently as new records arrive in the object storage, leveraging event notifications. Snowpipe is a service that automates the loading of data from external sources into Snowflake tables1. It also uses streams and tasks to orchestrate transformations on the ingested data. Streams are objects that store the change history of a table, and tasks are objects that execute SQL statements on a schedule or when triggered by another task2.
Option B also uses an external function to do model inference with Amazon Comprehend and write the final records to a Snowflake table. An external function is a user-defined function that calls an external API, such as Amazon Comprehend, to perform computations that are not natively supported by Snowflake3. Finally, option B uses the Snowflake Marketplace to make the de-identified final data set available publicly for advertising companies who use different cloud providers in different regions. The Snowflake Marketplace is a platform that enables data providers to list and share their data sets with data consumers, regardless of the cloud platform or region they use4.
Option A is not the best design because it uses copy into to ingest the data, which is not as efficient and continuous as Snowpipe. Copy into is a SQL command that loads data from files into a table in a single transaction. It also exports the data into Amazon S3 to do model inference with Amazon Comprehend, which adds an extra step and increases the operational complexity and maintenance of the infrastructure.
Option C is not the best design because it uses Amazon EMR and PySpark to ingest and transform the data, which also increases the operational complexity and maintenance of the infrastructure. Amazon EMR is a cloud service that provides a managed Hadoop framework to process and analyze large-scale data sets.
PySpark is a Python API for Spark, a distributed computing framework that can run on Hadoop. Option C also develops a python program to do model inference by leveraging the Amazon Comprehend text analysis API, which increases the development effort.
Option D is not the best design because it is identical to option A, except for the ingestion method. It still exports the data into Amazon S3 to do model inference with Amazon Comprehend, which adds an extra step and increases the operational complexity and maintenance of the infrastructure.
References: 1: Snowpipe Overview 2: Using Streams and Tasks to Automate Data Pipelines 3: External Functions Overview 4: Snowflake Data Marketplace Overview : [Loading Data Using COPY INTO] : [What is Amazon EMR?] : [PySpark Overview]
* The copy into <table> command is used to load data from staged files into an existing table in Snowflake. The command supports various file formats, such as CSV, JSON, AVRO, ORC, PARQUET, and XML1.
* match_by_column_name パラメータは、半構造化データを、ソースデータで表現されている対応する列と一致するターゲットテーブルの個別の列にロードできるようにするコピーオプションです。このパラメータには、次のいずれかの値を指定できます。
* CASE_SENSITIVE: ソースデータの列名は、ターゲットテーブルの列名と大文字・小文字を含めて完全に一致する必要があります。これがデフォルト値です。
* CASE_INSENSITIVE: ソースデータの列名はターゲットテーブルの列名と一致する必要がありますが、大文字と小文字は区別されません。
* なし: ソースデータの列名は無視され、ターゲットテーブルの列の順序に基づいてデータがロードされます。
* match_by_column_name パラメータは、JSON、AVRO、ORC、PARQUET、XML などの半構造化データにのみ適用されます。構造化データとみなされる CSV データには適用されません。
* CSVファイル形式で<table>にコピーするコマンドを使用する場合、match_by_column_nameパラメータは次のように動作します2:
* CSVファイルにはヘッダーが存在する必要があり、そのヘッダーは大文字小文字を区別するテーブルの列名と照合されます。つまり、CSVファイルの最初の行には列名が含まれている必要があり、その列名は対象テーブルの列名と大文字小文字を含めて完全に一致している必要があります。ヘッダーが存在しない場合、または一致しない場合は、コマンドはエラーを返します。
* このパラメータは、NONE に設定されている場合でも無視されません。コマンドは、CSV ファイル内の列名と対象テーブルの列名を照合しようとし、一致しない場合はエラーを返します。
* このコマンドは、ファイルに一致しない列があることを示す警告を返しません。列名が一致する場合はデータが正常にロードされ、一致しない場合はエラーが返されます。
参考文献:
* 1: COPY INTO <table> | Snowflakeドキュメント
* 2: MATCH_BY_COLUMN_NAME | Snowflake ドキュメント