使用 Azure 数据工厂从 Google 云存储复制数据Copy data from Google Cloud Storage using Azure Data Factory

适用于:是 Azure 数据工厂是 Azure Synapse Analytics(预览版)APPLIES TO: yesAzure Data Factory yesAzure Synapse Analytics (Preview)

本文概述了如何从 Google 云存储复制数据。This article outlines how to copy data from Google Cloud Storage. 若要了解 Azure 数据工厂,请阅读介绍性文章To learn about Azure Data Factory, read the introductory article.

支持的功能Supported capabilities

以下活动支持此 Google 云存储连接器:This Google Cloud Storage connector is supported for the following activities:

具体而言,此 Google 云存储连接器支持按原样复制文件,或者使用受支持的文件格式和压缩编解码器分析文件。Specifically, this Google Cloud Storage connector supports copying files as-is or parsing files with the supported file formats and compression codecs.

Note

从 Google 云存储复制数据时会利用具有对应的自定义 S3 终结点的 Amazon S3 连接器,因为 Google 云存储提供了兼容 S3 的互操作性。Copying data from Google Cloud Storage leverages the Amazon S3 connector with corresponding custom S3 endpoint, as Google Cloud Storage provides S3-compatible interoperability.

先决条件Prerequisites

Google 云存储帐户需要进行以下设置:The following set-up is required on your Google Cloud Storage account:

  1. 为 Google 云存储帐户启用互操作性Enable interoperability for your Google Cloud Storage account
  2. 设置包含要复制的数据的默认项目Set the default project which contains the data you want to copy
  3. 创建访问密钥。Create an access key.

检索 Google 云存储的访问密钥

所需的权限Required permissions

若要从 Google 云存储复制数据,请确保已具有以下权限:To copy data from Google Cloud Storage, make sure you have been granted the following permissions:

  • 对于复制活动执行: 对象操作需要 s3:GetObjects3:GetObjectVersion 权限。For copy activity execution:: s3:GetObject and s3:GetObjectVersion for Object Operations.
  • 对于数据工厂 GUI 创作:测试连接以及浏览/导航文件路径等操作额外需要适用于 Bucket 操作的 s3:ListAllMyBucketss3:ListBucket/s3:GetBucketLocation 权限。For Data Factory GUI authoring: s3:ListAllMyBuckets and s3:ListBucket/s3:GetBucketLocation for Bucket Operations permissions are additionally required for operations like test connection and browse/navigate file paths. 如果不想授予这些权限,请跳过“链接服务创建”页面中的测试连接,并直接在“数据集设置”中指定路径。If you don't want to grant these permission, skip test connection in linked service creation page and specify the path directly in dataset settings.

入门Getting started

可以通过以下工具或 SDK 之一结合使用复制活动和管道。You can use one of the following tools or SDKs to use the copy activity with a pipeline. 选择链接,查看分步说明:Select a link for step-by-step instructions:

以下各部分详细介绍了定义特定于 Google 云存储的数据工厂实体时使用的属性。The following sections provide details about properties that are used to define Data Factory entities specific to Google Cloud Storage.

链接服务属性Linked service properties

Google 云存储链接服务支持以下属性:The following properties are supported for Google Cloud Storage linked service:

属性Property 说明Description 必须Required
typetype type 属性必须设置为 GoogleCloudStorageThe type property must be set to GoogleCloudStorage. Yes
accessKeyIdaccessKeyId 机密访问键 ID。ID of the secret access key. 若要查找访问密钥和机密,请参阅先决条件To find the access key and secret, see Prerequisites. Yes
secretAccessKeysecretAccessKey 机密访问键本身。The secret access key itself. 将此字段标记为 SecureString 以安全地将其存储在数据工厂中或引用存储在 Azure Key Vault 中的机密Mark this field as a SecureString to store it securely in Data Factory, or reference a secret stored in Azure Key Vault. Yes
serviceUrlserviceUrl 将自定义 S3 终结点指定为 https://storage.googleapis.comSpecify the custom S3 endpoint as https://storage.googleapis.com. Yes
connectViaconnectVia 用于连接到数据存储的集成运行时The Integration Runtime to be used to connect to the data store. 如果数据存储位于专用网络,则可以使用 Azure Integration Runtime 或自承载集成运行时。You can use Azure Integration Runtime or Self-hosted Integration Runtime (if your data store is located in private network). 如果未指定,则使用默认 Azure Integration Runtime。If not specified, it uses the default Azure Integration Runtime. No

以下是示例:Here is an example:

{
    "name": "GoogleCloudStorageLinkedService",
    "properties": {
        "type": "GoogleCloudStorage",
        "typeProperties": {
            "accessKeyId": "<access key id>",
            "secretAccessKey": {
                "type": "SecureString",
                "value": "<secret access key>"
            },
            "serviceUrl": "https://storage.googleapis.com"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

数据集属性Dataset properties

Azure 数据工厂支持以下文件格式。Azure Data Factory support the following file formats. 请参阅每一篇关于基于格式的设置的文章。Refer to each article on format-based settings.

基于格式的数据集中 location 设置下的 Google 云存储支持以下属性:The following properties are supported for Google Cloud Storage under location settings in format-based dataset:

属性Property 说明Description 必须Required
typetype 数据集中 location 下的 type 属性必须设置为 AmazonS3LocationThe type property under location in dataset must be set to AmazonS3Location. Yes
bucketNamebucketName S3 存储桶的名称。The S3 bucket name. Yes
folderPathfolderPath 给定存储桶下的文件夹路径。The path to folder under the given bucket. 如果要使用通配符筛选文件夹,请跳过此设置并在活动源设置中指定。If you want to use wildcard to filter folder, skip this setting and specify in activity source settings. No
fileNamefileName 给定存储桶 + folderPath 下的文件名。The file name under the given bucket + folderPath. 如果要使用通配符筛选文件,请跳过此设置并在活动源设置中指定。If you want to use wildcard to filter files, skip this setting and specify in activity source settings. No

示例:Example:

{
    "name": "DelimitedTextDataset",
    "properties": {
        "type": "DelimitedText",
        "linkedServiceName": {
            "referenceName": "<Google Cloud Storage linked service name>",
            "type": "LinkedServiceReference"
        },
        "schema": [ < physical schema, optional, auto retrieved during authoring > ],
        "typeProperties": {
            "location": {
                "type": "AmazonS3Location",
                "bucketName": "bucketname",
                "folderPath": "folder/subfolder"
            },
            "columnDelimiter": ",",
            "quoteChar": "\"",
            "firstRowAsHeader": true,
            "compressionCodec": "gzip"
        }
    }
}

复制活动属性Copy activity properties

有关可用于定义活动的各部分和属性的完整列表,请参阅管道一文。For a full list of sections and properties available for defining activities, see the Pipelines article. 本部分提供了 Google 云存储源支持的属性列表。This section provides a list of properties supported by Google Cloud Storage source.

Google 云存储用作源Google Cloud Storage as source

Azure 数据工厂支持以下文件格式。Azure Data Factory support the following file formats. 请参阅每一篇关于基于格式的设置的文章。Refer to each article on format-based settings.

基于格式的复制源中 storeSettings 设置下的 Google 云存储支持以下属性:The following properties are supported for Google Cloud Storage under storeSettings settings in format-based copy source:

属性Property 说明Description 必须Required
typetype storeSettings 下的 type 属性必须设置为 AmazonS3ReadSettingsThe type property under storeSettings must be set to AmazonS3ReadSettings. Yes
recursiverecursive 指示是要从子文件夹中以递归方式读取数据,还是只从指定的文件夹中读取数据。Indicates whether the data is read recursively from the subfolders or only from the specified folder. 请注意,当 recursive 设置为 true 且接收器是基于文件的存储时,将不会在接收器上复制或创建空的文件夹或子文件夹。Note that when recursive is set to true and the sink is a file-based store, an empty folder or subfolder isn't copied or created at the sink. 允许的值为 true(默认值)和 falseAllowed values are true (default) and false. No
前缀prefix 在数据集中配置的给定存储桶下的 S3 对象键的前缀,用于筛选源对象。Prefix for the S3 object key under the given bucket configured in dataset to filter source objects. 已选中其键以该前缀开头的对象。Objects whose keys start with this prefix are selected. 仅当未指定 wildcardFolderPathwildcardFileName 属性时适用。Applies only when wildcardFolderPath and wildcardFileName properties are not specified.
wildcardFolderPathwildcardFolderPath 数据集中配置的给定存储桶下包含通配符的文件夹路径,用于筛选源文件夹。The folder path with wildcard characters under the given bucket configured in dataset to filter source folders.
允许的通配符为:*(匹配零个或更多个字符)和 ?(匹配零个或单个字符);如果实际文件夹名称中包含通配符或此转义字符,请使用 ^ 进行转义。Allowed wildcards are: * (matches zero or more characters) and ? (matches zero or single character); use ^ to escape if your actual folder name has wildcard or this escape char inside.
请参阅文件夹和文件筛选器示例中的更多示例。See more examples in Folder and file filter examples.
No
wildcardFileNamewildcardFileName 给定的存储桶 + folderPath/wildcardFolderPath 下带有通配符的文件名,用于筛选源文件。The file name with wildcard characters under the given bucket + folderPath/wildcardFolderPath to filter source files.
允许的通配符为:*(匹配零个或更多个字符)和 ?(匹配零个或单个字符);如果实际文件夹名称中包含通配符或此转义字符,请使用 ^ 进行转义。Allowed wildcards are: * (matches zero or more characters) and ? (matches zero or single character); use ^ to escape if your actual folder name has wildcard or this escape char inside. 请参阅文件夹和文件筛选器示例中的更多示例。See more examples in Folder and file filter examples.
如果未在数据集中指定 fileName 并且未指定 prefix,则为“是”Yes if fileName in dataset and prefix are not specified
modifiedDatetimeStartmodifiedDatetimeStart 基于属性“上次修改时间”的文件筛选器。Files filter based on the attribute: Last Modified. 如果文件的上次修改时间在 modifiedDatetimeStartmodifiedDatetimeEnd 之间的时间范围内,则将选中这些文件。The files will be selected if their last modified time are within the time range between modifiedDatetimeStart and modifiedDatetimeEnd. 该时间应用于 UTC 时区,格式为“2018-12-01T05:00:00Z”。The time is applied to UTC time zone in the format of "2018-12-01T05:00:00Z".
属性可以为 NULL,这意味着不向数据集应用任何文件特性筛选器。The properties can be NULL which mean no file attribute filter will be applied to the dataset. 如果 modifiedDatetimeStart 具有日期/时间值,但 modifiedDatetimeEnd 为 NULL,则意味着将选中“上次修改时间”属性大于或等于该日期/时间值的文件。When modifiedDatetimeStart has datetime value but modifiedDatetimeEnd is NULL, it means the files whose last modified attribute is greater than or equal with the datetime value will be selected. 如果 modifiedDatetimeEnd 具有日期/时间值,但 modifiedDatetimeStart 为 NULL,则意味着将选中“上次修改时间”属性小于该日期/时间值的文件。When modifiedDatetimeEnd has datetime value but modifiedDatetimeStart is NULL, it means the files whose last modified attribute is less than the datetime value will be selected.
No
modifiedDatetimeEndmodifiedDatetimeEnd 同上。Same as above. No
maxConcurrentConnectionsmaxConcurrentConnections 可以同时连接到存储库的连接数。The number of the connections to connect to storage store concurrently. 仅在要限制与数据存储的并发连接时指定。Specify only when you want to limit the concurrent connection to the data store. No

示例:Example:

"activities":[
    {
        "name": "CopyFromGoogleCloudStorage",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<Delimited text input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "DelimitedTextSource",
                "formatSettings":{
                    "type": "DelimitedTextReadSettings",
                    "skipLineCount": 10
                },
                "storeSettings":{
                    "type": "AmazonS3ReadSettings",
                    "recursive": true,
                    "wildcardFolderPath": "myfolder*A",
                    "wildcardFileName": "*.csv"
                }
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

文件夹和文件筛选器示例Folder and file filter examples

本部分介绍使用通配符筛选器生成文件夹路径和文件名的行为。This section describes the resulting behavior of the folder path and file name with wildcard filters.

Bucketbucket keykey recursiverecursive 源文件夹结构和筛选器结果(用粗体表示的文件已检索)Source folder structure and filter result (files in bold are retrieved)
Bucketbucket Folder*/* falsefalse Bucketbucket
    FolderA    FolderA
        File1.csv        File1.csv
        File2.json        File2.json
        Subfolder1        Subfolder1
            File3.csv            File3.csv
            File4.json            File4.json
            File5.csv            File5.csv
    AnotherFolderB    AnotherFolderB
        File6.csv        File6.csv
Bucketbucket Folder*/* true Bucketbucket
    FolderA    FolderA
        File1.csv        File1.csv
        File2.json        File2.json
        Subfolder1        Subfolder1
            File3.csv            File3.csv
            File4.json            File4.json
            File5.csv            File5.csv
    AnotherFolderB    AnotherFolderB
        File6.csv        File6.csv
Bucketbucket Folder*/*.csv falsefalse Bucketbucket
    FolderA    FolderA
        File1.csv        File1.csv
        File2.json        File2.json
        Subfolder1        Subfolder1
            File3.csv            File3.csv
            File4.json            File4.json
            File5.csv            File5.csv
    AnotherFolderB    AnotherFolderB
        File6.csv        File6.csv
Bucketbucket Folder*/*.csv true Bucketbucket
    FolderA    FolderA
        File1.csv        File1.csv
        File2.json        File2.json
        Subfolder1        Subfolder1
            File3.csv            File3.csv
            File4.json            File4.json
            File5.csv            File5.csv
    AnotherFolderB    AnotherFolderB
        File6.csv        File6.csv

Lookup 活动属性Lookup activity properties

若要了解有关属性的详细信息,请查看 Lookup 活动To learn details about the properties, check Lookup activity.

GetMetadata 活动属性GetMetadata activity properties

若要了解有关属性的详细信息,请查看 GetMetadata 活动To learn details about the properties, check GetMetadata activity

Delete 活动属性Delete activity properties

若要了解有关属性的详细信息,请查看 Delete 活动To learn details about the properties, check Delete activity

旧模型Legacy models

Note

仍按原样支持以下模型,以实现向后兼容性。The following models are still supported as-is for backward compatibility. 建议你以后使用前面部分中提到的新模型,ADF 创作 UI 已经切换到生成新模型。You are suggested to use the new model mentioned in above sections going forward, and the ADF authoring UI has switched to generating the new model.

旧数据集模型Legacy dataset model

属性Property 说明Description 必须Required
typetype 数据集的 type 属性必须设置为:AmazonS3Object The type property of the dataset must be set to: AmazonS3Object Yes
bucketNamebucketName S3 存储桶的名称。The S3 bucket name. 不支持通配符筛选器。Wildcard filter is not supported. 对于复制/查找活动,为“是”;对于 GetMetadata 活动,为“否”Yes for Copy/Lookup activity, No for GetMetadata activity
keykey 指定存储桶下的 S3 对象键的“名称或通配符筛选器” 。The name or wildcard filter of S3 object key under the specified bucket. 仅当未指定“prefix”属性时应用。Applies only when "prefix" property is not specified.

文件夹部分和文件名部分都支持通配符筛选器。The wildcard filter is supported for both folder part and file name part. 允许的通配符为:*(匹配零个或更多字符)和 ?(匹配零个或单个字符)。Allowed wildcards are: * (matches zero or more characters) and ? (matches zero or single character).
- 示例 1:"key": "rootfolder/subfolder/*.csv"- Example 1: "key": "rootfolder/subfolder/*.csv"
- 示例 2:"key": "rootfolder/subfolder/???20180427.txt"- Example 2: "key": "rootfolder/subfolder/???20180427.txt"
请参阅文件夹和文件筛选器示例中的更多示例。See more examples in Folder and file filter examples. 如果实际文件夹/文件名内具有通配符或此转义符,请使用 ^ 进行转义。Use ^ to escape if your actual folder/file name has wildcard or this escape char inside.
No
前缀prefix S3 对象键的前缀。Prefix for the S3 object key. 已选中其键以该前缀开头的对象。Objects whose keys start with this prefix are selected. 仅当未指定“key”属性时应用。Applies only when "key" property is not specified. No
版本version 启用 S3 版本控制时 S3 对象的版本。The version of the S3 object, if S3 versioning is enabled. No
modifiedDatetimeStartmodifiedDatetimeStart 基于属性“上次修改时间”的文件筛选器。Files filter based on the attribute: Last Modified. 如果文件的上次修改时间在 modifiedDatetimeStartmodifiedDatetimeEnd 之间的时间范围内,则将选中这些文件。The files will be selected if their last modified time are within the time range between modifiedDatetimeStart and modifiedDatetimeEnd. 该时间应用于 UTC 时区,格式为“2018-12-01T05:00:00Z”。The time is applied to UTC time zone in the format of "2018-12-01T05:00:00Z".

属性可以为 NULL,这意味着不向数据集应用任何文件特性筛选器。The properties can be NULL which mean no file attribute filter will be applied to the dataset. 如果 modifiedDatetimeStart 具有日期/时间值,但 modifiedDatetimeEnd 为 NULL,则意味着将选中“上次修改时间”属性大于或等于该日期/时间值的文件。When modifiedDatetimeStart has datetime value but modifiedDatetimeEnd is NULL, it means the files whose last modified attribute is greater than or equal with the datetime value will be selected. 如果 modifiedDatetimeEnd 具有日期/时间值,但 modifiedDatetimeStart 为 NULL,则意味着将选中“上次修改时间”属性小于该日期/时间值的文件。When modifiedDatetimeEnd has datetime value but modifiedDatetimeStart is NULL, it means the files whose last modified attribute is less than the datetime value will be selected.
No
modifiedDatetimeEndmodifiedDatetimeEnd 基于属性“上次修改时间”的文件筛选器。Files filter based on the attribute: Last Modified. 如果文件的上次修改时间在 modifiedDatetimeStartmodifiedDatetimeEnd 之间的时间范围内,则将选中这些文件。The files will be selected if their last modified time are within the time range between modifiedDatetimeStart and modifiedDatetimeEnd. 该时间应用于 UTC 时区,格式为“2018-12-01T05:00:00Z”。The time is applied to UTC time zone in the format of "2018-12-01T05:00:00Z".

属性可以为 NULL,这意味着不向数据集应用任何文件特性筛选器。The properties can be NULL which mean no file attribute filter will be applied to the dataset. 如果 modifiedDatetimeStart 具有日期/时间值,但 modifiedDatetimeEnd 为 NULL,则意味着将选中“上次修改时间”属性大于或等于该日期/时间值的文件。When modifiedDatetimeStart has datetime value but modifiedDatetimeEnd is NULL, it means the files whose last modified attribute is greater than or equal with the datetime value will be selected. 如果 modifiedDatetimeEnd 具有日期/时间值,但 modifiedDatetimeStart 为 NULL,则意味着将选中“上次修改时间”属性小于该日期/时间值的文件。When modifiedDatetimeEnd has datetime value but modifiedDatetimeStart is NULL, it means the files whose last modified attribute is less than the datetime value will be selected.
No
formatformat 如果想要在基于文件的存储之间按原样复制文件 (二进制副本),可以在输入和输出数据集定义中跳过格式节。If you want to copy files as-is between file-based stores (binary copy), skip the format section in both input and output dataset definitions.

若要分析或生成具有特定格式的文件,以下是受支持的文件格式类型:TextFormat、JsonFormat、AvroFormat、OrcFormat、ParquetFormat 。If you want to parse or generate files with a specific format, the following file format types are supported: TextFormat, JsonFormat, AvroFormat, OrcFormat, ParquetFormat. 请将格式中的“type”属性设置为上述值之一 。Set the type property under format to one of these values. 有关详细信息,请参阅文本格式Json 格式Avro 格式Orc 格式Parquet 格式部分。For more information, see Text Format, Json Format, Avro Format, Orc Format, and Parquet Format sections.
否(仅适用于二进制复制方案)No (only for binary copy scenario)
compressioncompression 指定数据的压缩类型和级别。Specify the type and level of compression for the data. 有关详细信息,请参阅受支持的文件格式和压缩编解码器For more information, see Supported file formats and compression codecs.
支持的类型包括:GZipDeflateBZip2ZipDeflateSupported types are: GZip, Deflate, BZip2, and ZipDeflate.
支持的级别为:“最佳”和“最快” 。Supported levels are: Optimal and Fastest.
No

Tip

要复制文件夹下的所有文件,请指定存储桶的“bucketName”和文件夹部分的“prefix” 。To copy all files under a folder, specify bucketName for bucket and prefix for folder part.
要复制具有给定名称的单个文件,请指定存储桶的“bucketName” 和文件夹部分及文件名的“key” 。To copy a single file with a given name, specify bucketName for bucket and key for folder part plus file name.
要复制文件夹下的文件子集,请指定存储桶的“bucketName”和文件夹部分及通配符筛选器的“key” 。To copy a subset of files under a folder, specify bucketName for bucket and key for folder part plus wildcard filter.

示例:使用前缀Example: using prefix

{
    "name": "GoogleCloudStorageDataset",
    "properties": {
        "type": "AmazonS3Object",
        "linkedServiceName": {
            "referenceName": "<linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties": {
            "bucketName": "testbucket",
            "prefix": "testFolder/test",
            "modifiedDatetimeStart": "2018-12-01T05:00:00Z",
            "modifiedDatetimeEnd": "2018-12-01T06:00:00Z",
            "format": {
                "type": "TextFormat",
                "columnDelimiter": ",",
                "rowDelimiter": "\n"
            },
            "compression": {
                "type": "GZip",
                "level": "Optimal"
            }
        }
    }
}

旧复制活动源模型Legacy copy activity source model

属性Property 说明Description 必须Required
typetype 复制活动 source 的 type 属性必须设置为:FileSystemSource The type property of the copy activity source must be set to: FileSystemSource Yes
recursiverecursive 指示是要从子文件夹中以递归方式读取数据,还是只从指定的文件夹中读取数据。Indicates whether the data is read recursively from the sub folders or only from the specified folder. 当 recursive 设置为 true 且接收器是基于文件的存储时,将不会在接收器上复制/创建空的文件夹/子文件夹。Note when recursive is set to true and sink is file-based store, empty folder/sub-folder will not be copied/created at sink.
允许的值为:true(默认)、false Allowed values are: true (default), false
No
maxConcurrentConnectionsmaxConcurrentConnections 可以同时连接到存储库的连接数。The number of the connections to connect to storage store concurrently. 仅在要限制与数据存储的并发连接时指定。Specify only when you want to limit the concurrent connection to the data store. No

示例:Example:

"activities":[
    {
        "name": "CopyFromGoogleCloudStorage",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "FileSystemSource",
                "recursive": true
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

后续步骤Next steps

有关 Azure 数据工厂中的复制活动支持作为源和接收器的数据存储的列表,请参阅支持的数据存储For a list of data stores that are supported as sources and sinks by the copy activity in Azure Data Factory, see supported data stores.