从 SQL Server 表读取数据


本页介绍了如何设置数据流水线以从 Microsoft SQL Server 表中读取数据。

准备工作

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Data Fusion, BigQuery, Cloud Storage, and Dataproc APIs.

    Enable the APIs

  7. 创建 Cloud Data Fusion 实例
  8. 您的 SQL Server 数据库必须接受来自 Cloud Data Fusion 的连接。出于安全考虑,请使用专用 Cloud Data Fusion 实例

打开您的 Cloud Data Fusion 实例

  1. 在 Google Cloud 控制台中,前往 Cloud Data Fusion 实例页面。

    转到“实例”

  2. 在实例的操作列中,点击查看实例,在 Cloud Data Fusion 中打开该实例。

将 SQL Server 密码存储为安全密钥

在 Cloud Data Fusion 实例中将 SQL Server 密码添加为安全密钥。

  1. 在 Cloud Data Fusion 中,点击系统管理员

  2. 点击配置标签页。

  3. 点击进行 HTTP 调用

    配置。

  4. 选择 PUT

  5. 在路径字段中,输入 namespaces/NAMESPACE_ID/securekeys/password

  6. 正文字段中,输入 {"data":"password"}。 将 password 替换为您的 SQL Server 密码。

  7. 点击发送

    密码。

响应必须具有状态代码 200,才能继续。

获取适用于 SQL Server 的 JDBC 驱动程序

您可以从 Hub 或 Cloud Data Fusion 的 Pipeline Studio 中获取该驱动程序。

Hub

  1. 在 Cloud Data Fusion 界面中,点击 Hub

  2. 在搜索栏中,输入 SQL Server JDBC Driver 并选择相应驱动程序。

  3. 点击下载。按照所示的下载步骤操作。

  4. 点击部署。上传上一步中的 JAR 文件。

  5. 点击 Finish

Pipeline Studio

  1. 前往 Microsoft.com

  2. 选择下载的内容,然后点击下载

  3. 在 Cloud Data Fusion 中,点击 Menu(菜单),然后前往 Pipeline Studio(流水线 Studio)页面。

  4. 点击 Add

  5. 对于驱动程序,请点击上传

  6. 选择位于 jre7 文件夹中的 JAR 文件。

  7. 点击下一步

  8. 如需配置驱动程序,请输入名称类名称

  9. 点击 Finish

部署 SQL Server 插件

  1. 在 Cloud Data Fusion 中,点击 Hub

  2. 在搜索栏中,输入 SQL Server Plugins

  3. 点击 SQL Server 插件

  4. 点击部署

  5. 点击 Finish

  6. 点击创建流水线

连接到 SQL Server

您可以在 Wrangler 或流水线 Studio 中通过 Cloud Data Fusion 连接到 SQL Server。

Wrangler

  1. 在 Cloud Data Fusion 中,点击 Menu(菜单),然后前往 Wrangler 页面。

  2. 点击添加连接

    系统随即会打开添加连接窗口。

  3. 点击 SQL Server 以验证是否已安装驱动程序。

    JAR 文件已上传。

  4. 在必填的连接字段中输入详细信息。在密码字段中,选择您之前存储的安全密钥。 这可确保使用 Cloud KMS 检索您的密码。

    设置密码。

  5. 如需检查是否可以与数据库建立连接,请点击测试连接

  6. 点击添加连接

在 SQL Server 数据库连接并且已创建一个从 SQL Server 表读取数据的流水线后,您可以应用转换,并将输出写入接收器。

Pipeline Studio

  1. 打开您的 Cloud Data Fusion 实例,然后前往 Pipeline Studio 页面。

  2. 展开来源菜单,然后点击 SQL Server

    SQL Server。

  3. SQL Server 节点上,点击属性

    属性。
  4. 引用名称字段中,输入用于标识 SQL Server 来源的名称。

  5. 数据库字段中,输入要连接到的数据库的名称。

  6. 导入查询字段中,输入要运行的查询。例如 SELECT * FROM table WHERE $CONDITIONS

  7. 点击验证

  8. 点击“关闭”图标

在 SQL Server 数据库连接并且已创建一个从 SQL Server 表读取数据的流水线后,添加任何所需的转换,并将输出写入接收器。

后续步骤