查詢 Azure Synapse Analytics 中的資料

您可以使用 Azure Synapse 連接器從 Azure Databricks 存取 Azure Synapse,該連接器會使用 COPY Azure Synapse 中的 語句,在 Azure Databricks 叢集與 Azure Synapse 實例之間有效率地傳輸大量數據,並使用 Azure Data Lake 儲存體 Gen2 儲存器帳戶進行暫存。

注意

您可能偏好使用 Lakehouse 同盟來管理 Azure Synapse 或 Azure 數據倉儲數據的查詢。 請參閱 什麼是 Lakehouse 同盟

Azure Synapse Analytics 是雲端式企業數據倉儲,利用大量平行處理 (MPP) 快速跨數 PB 的數據執行複雜的查詢。

重要

此連接器僅適用於 Synapse 專用集區實例,且與其他 Synapse 元件不相容。

注意

COPY僅適用於 Azure Data Lake 儲存體 Gen2 實例。 如果您要尋找使用 Polybase 的詳細資訊,請參閱使用 PolyBase 連線 Azure Databricks 和 Azure Synapse 與 PolyBase(舊版)。

Synapse 的範例語法

您可以在 Scala、Python、SQL 和 R 中查詢 Synapse。下列程式代碼範例使用記憶體帳戶密鑰,並將記憶體認證從 Azure Databricks 轉送至 Synapse。

注意

使用 Azure 入口網站 所提供的 連接字串,針對 Spark 驅動程式與 Azure Synapse 實例之間透過 JDBC 連線傳送的所有資料啟用安全套接字層 (SSL) 加密。 若要確認 SSL 加密已啟用,您可以在 連接字串 中搜尋 encrypt=true

重要

Unity 目錄中 定義的外部位置不支援作為 tempDir 位置。

Scala


// Set up the storage account access key in the notebook session conf.
spark.conf.set(
  "fs.azure.account.key.<your-storage-account-name>.dfs.core.windows.net",
  "<your-storage-account-access-key>")

// Get some data from an Azure Synapse table. The following example applies to Databricks Runtime 11.3 LTS and above.
val df: DataFrame = spark.read
  .format("sqldw")
  .option("host", "hostname")
  .option("port", "port") /* Optional - will use default port 1433 if not specified. */
  .option("user", "username")
  .option("password", "password")
  .option("database", "database-name")
  .option("dbtable", "schema-name.table-name") /* If schemaName not provided, default to "dbo". */
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")
  .option("forwardSparkAzureStorageCredentials", "true")
  .load()

// Get some data from an Azure Synapse table. The following example applies to Databricks Runtime 10.4 LTS and below.
val df: DataFrame = spark.read
  .format("com.databricks.spark.sqldw")
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>")
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")
  .option("forwardSparkAzureStorageCredentials", "true")
  .option("dbTable", "<your-table-name>")
  .load()

// Load data from an Azure Synapse query.
val df: DataFrame = spark.read
  .format("com.databricks.spark.sqldw")
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>")
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")
  .option("forwardSparkAzureStorageCredentials", "true")
  .option("query", "select x, count(*) as cnt from table group by x")
  .load()

// Apply some transformations to the data, then use the
// Data Source API to write the data back to another table in Azure Synapse.

df.write
  .format("com.databricks.spark.sqldw")
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>")
  .option("forwardSparkAzureStorageCredentials", "true")
  .option("dbTable", "<your-table-name>")
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")
  .save()

Python


# Set up the storage account access key in the notebook session conf.
spark.conf.set(
  "fs.azure.account.key.<your-storage-account-name>.dfs.core.windows.net",
  "<your-storage-account-access-key>")

# Get some data from an Azure Synapse table. The following example applies to Databricks Runtime 11.3 LTS and above.
df = spark.read
  .format("sqldw")
  .option("host", "hostname")
  .option("port", "port") # Optional - will use default port 1433 if not specified.
  .option("user", "username")
  .option("password", "password")
  .option("database", "database-name")
  .option("dbtable", "schema-name.table-name") # If schemaName not provided, default to "dbo".
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")
  .option("forwardSparkAzureStorageCredentials", "true")
  .load()

# Get some data from an Azure Synapse table. The following example applies to Databricks Runtime 10.4 LTS and below.
df = spark.read \
  .format("com.databricks.spark.sqldw") \
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>") \
  .option("forwardSparkAzureStorageCredentials", "true") \
  .option("dbTable", "<your-table-name>") \
  .load()

# Load data from an Azure Synapse query.
df = spark.read \
  .format("com.databricks.spark.sqldw") \
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>") \
  .option("forwardSparkAzureStorageCredentials", "true") \
  .option("query", "select x, count(*) as cnt from table group by x") \
  .load()

# Apply some transformations to the data, then use the
# Data Source API to write the data back to another table in Azure Synapse.

df.write \
  .format("com.databricks.spark.sqldw") \
  .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
  .option("forwardSparkAzureStorageCredentials", "true") \
  .option("dbTable", "<your-table-name>") \
  .option("tempDir", "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>") \
  .save()

SQL


-- Set up the storage account access key in the notebook session conf.
SET fs.azure.account.key.<your-storage-account-name>.dfs.core.windows.net=<your-storage-account-access-key>;

-- Read data using SQL. The following example applies to Databricks Runtime 11.3 LTS and above.
CREATE TABLE example_table_in_spark_read
USING sqldw
OPTIONS (
  host '<hostname>',
  port '<port>' /* Optional - will use default port 1433 if not specified. */
  user '<username>',
  password '<password>',
  database '<database-name>'
  dbtable '<schema-name>.<table-name>', /* If schemaName not provided, default to "dbo". */
  forwardSparkAzureStorageCredentials 'true',
  tempDir 'abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>'
);

-- Read data using SQL. The following example applies to Databricks Runtime 10.4 LTS and below.
CREATE TABLE example_table_in_spark_read
USING com.databricks.spark.sqldw
OPTIONS (
  url 'jdbc:sqlserver://<the-rest-of-the-connection-string>',
  forwardSparkAzureStorageCredentials 'true',
  dbtable '<your-table-name>',
  tempDir 'abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>'
);

-- Write data using SQL.
-- Create a new table, throwing an error if a table with the same name already exists:

CREATE TABLE example_table_in_spark_write
USING com.databricks.spark.sqldw
OPTIONS (
  url 'jdbc:sqlserver://<the-rest-of-the-connection-string>',
  forwardSparkAzureStorageCredentials 'true',
  dbTable '<your-table-name>',
  tempDir 'abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>'
)
AS SELECT * FROM table_to_save_in_spark;

R

# Load SparkR
library(SparkR)

# Set up the storage account access key in the notebook session conf.
conf <- sparkR.callJMethod(sparkR.session(), "conf")
sparkR.callJMethod(conf, "set", "fs.azure.account.key.<your-storage-account-name>.dfs.core.windows.net", "<your-storage-account-access-key>")

# Get some data from an Azure Synapse table.
df <- read.df(
   source = "com.databricks.spark.sqldw",
   url = "jdbc:sqlserver://<the-rest-of-the-connection-string>",
   forward_spark_azure_storage_credentials = "true",
   dbTable = "<your-table-name>",
   tempDir = "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")

# Load data from an Azure Synapse query.
df <- read.df(
   source = "com.databricks.spark.sqldw",
   url = "jdbc:sqlserver://<the-rest-of-the-connection-string>",
   forward_spark_azure_storage_credentials = "true",
   query = "select x, count(*) as cnt from table group by x",
   tempDir = "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")

# Apply some transformations to the data, then use the
# Data Source API to write the data back to another table in Azure Synapse.

write.df(
  df,
  source = "com.databricks.spark.sqldw",
  url = "jdbc:sqlserver://<the-rest-of-the-connection-string>",
  forward_spark_azure_storage_credentials = "true",
  dbTable = "<your-table-name>",
  tempDir = "abfss://<your-container-name>@<your-storage-account-name>.dfs.core.windows.net/<your-directory-name>")

Azure Databricks 與 Synapse 之間的驗證如何運作?

Azure Synapse 連接器使用三種類型的網路連線:

  • Spark 驅動程式到 Azure Synapse
  • Spark 叢集至 Azure 記憶體帳戶
  • Azure Synapse 到 Azure 儲存體帳戶

設定 Azure 記憶體的存取權

Azure Databricks 和 Synapse 都需要具有特殊許可權的 Azure 記憶體帳戶存取權,才能用於暫存數據記憶體。

Azure Synapse 不支援使用 SAS 進行記憶體帳戶存取。 您可以執行下列其中一項來設定這兩項服務的存取:

  • 使用記憶體帳戶的帳戶的帳戶金鑰和秘密,並將 設定 forwardSparkAzureStorageCredentialstrue。 請參閱 設定 Spark 屬性以設定 Azure 認證來存取 Azure 記憶體
  • 搭配 OAuth 2.0 驗證使用 Azure Data Lake 儲存體 Gen2,並將 設定enableServicePrincipalAuthtrue。 請參閱 使用服務主體設定從 Azure Databricks 連線到 Synapse 與 OAuth 2.0 的連線。
  • 將您的 Azure Synapse 實體設定為具有受控服務識別,並將設定 useAzureMSItrue

必要的 Azure Synapse 許可權

由於它在背景中使用 COPY ,Azure Synapse 連接器會要求 JDBC 連線使用者有權在連線的 Azure Synapse 實例中執行下列命令:

如果目的地數據表不存在於 Azure Synapse 中,除了上述命令之外,還需要執行下列命令的許可權:

下表摘要說明使用 COPY寫入所需的權限:

權限 (插入現有資料表) 權限 (插入新資料表)
ADMINISTER DATABASE BULK OPERATIONS

INSERT
ADMINISTER DATABASE BULK OPERATIONS

INSERT

CREATE TABLE

ALTER ON SCHEMA :: dbo

網路設定

如果您在 Azure Synapse 上設定防火牆,則必須設定網路設定,以允許 Azure Databricks 連線到 Azure Synapse。 首先,在 Azure 虛擬網路中部署 Azure Databricks (VNet 插入)之後,請確定您的 Azure Databricks 工作區已部署在您自己的虛擬網路中。 接著,您可以在 Azure Synpase 上設定 IP 防火牆規則,以允許從子網連線到 Synapse 帳戶。 請參閱 Azure Synapse Analytics IP 防火牆規則

使用服務主體設定從 Azure Databricks 連線到 Synapse 與 OAuth 2.0 的連線

您可以使用具有基礎記憶體帳戶存取權的服務主體向 Azure Synapse Analytics 進行驗證。 如需使用服務主體認證來存取 Azure 記憶體帳戶的詳細資訊,請參閱 連線 至 Azure Data Lake 儲存體 Gen2 和 Blob 儲存體。 您必須在enableServicePrincipalAuth連線設定 Azure Databricks Synapse 連接器選項參考中將 選項設定為 true ,讓連接器能夠向服務主體進行驗證。

您可以選擇性地針對 Azure Synapse Analytics 連線使用不同的服務主體。 下列範例會設定記憶體帳戶的服務主體認證,以及 Synapse 的選擇性服務主體認證:

ini

; Defining the Service Principal credentials for the Azure storage account
fs.azure.account.auth.type OAuth
fs.azure.account.oauth.provider.type org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider
fs.azure.account.oauth2.client.id <application-id>
fs.azure.account.oauth2.client.secret <service-credential>
fs.azure.account.oauth2.client.endpoint https://login.microsoftonline.com/<directory-id>/oauth2/token

; Defining a separate set of service principal credentials for Azure Synapse Analytics (If not defined, the connector will use the Azure storage account credentials)
spark.databricks.sqldw.jdbc.service.principal.client.id <application-id>
spark.databricks.sqldw.jdbc.service.principal.client.secret <service-credential>

Scala

// Defining the Service Principal credentials for the Azure storage account
spark.conf.set("fs.azure.account.auth.type", "OAuth")
spark.conf.set("fs.azure.account.oauth.provider.type",  "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
spark.conf.set("fs.azure.account.oauth2.client.id", "<application-id>")
spark.conf.set("fs.azure.account.oauth2.client.secret", "<service-credential>")
spark.conf.set("fs.azure.account.oauth2.client.endpoint", "https://login.microsoftonline.com/<directory-id>/oauth2/token")

// Defining a separate set of service principal credentials for Azure Synapse Analytics (If not defined, the connector will use the Azure storage account credentials)
spark.conf.set("spark.databricks.sqldw.jdbc.service.principal.client.id", "<application-id>")
spark.conf.set("spark.databricks.sqldw.jdbc.service.principal.client.secret", "<service-credential>")

Python

# Defining the service principal credentials for the Azure storage account
spark.conf.set("fs.azure.account.auth.type", "OAuth")
spark.conf.set("fs.azure.account.oauth.provider.type",  "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
spark.conf.set("fs.azure.account.oauth2.client.id", "<application-id>")
spark.conf.set("fs.azure.account.oauth2.client.secret", "<service-credential>")
spark.conf.set("fs.azure.account.oauth2.client.endpoint", "https://login.microsoftonline.com/<directory-id>/oauth2/token")

# Defining a separate set of service principal credentials for Azure Synapse Analytics (If not defined, the connector will use the Azure storage account credentials)
spark.conf.set("spark.databricks.sqldw.jdbc.service.principal.client.id", "<application-id>")
spark.conf.set("spark.databricks.sqldw.jdbc.service.principal.client.secret", "<service-credential>")

R

# Load SparkR
library(SparkR)
conf <- sparkR.callJMethod(sparkR.session(), "conf")

# Defining the service principal credentials for the Azure storage account
sparkR.callJMethod(conf, "set", "fs.azure.account.auth.type", "OAuth")
sparkR.callJMethod(conf, "set", "fs.azure.account.oauth.provider.type",  "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
sparkR.callJMethod(conf, "set", "fs.azure.account.oauth2.client.id", "<application-id>")
sparkR.callJMethod(conf, "set", "fs.azure.account.oauth2.client.secret", "<service-credential>")
sparkR.callJMethod(conf, "set", "fs.azure.account.oauth2.client.endpoint", "https://login.microsoftonline.com/<directory-id>/oauth2/token")

# Defining a separate set of service principal credentials for Azure Synapse Analytics (If not defined, the connector will use the Azure storage account credentials)
sparkR.callJMethod(conf, "set", "spark.databricks.sqldw.jdbc.service.principal.client.id", "<application-id>")
sparkR.callJMethod(conf, "set", "spark.databricks.sqldw.jdbc.service.principal.client.secret", "<service-credential>")

批次寫入支持的儲存模式

Azure Synapse 連接器支援 ErrorIfExistsIgnoreAppendOverwrite 儲存模式,預設模式為 ErrorIfExists。 如需 Apache Spark 中支援之儲存模式的詳細資訊,請參閱 儲存模式的 Spark SQL 檔。

Azure Databricks Synapse 連接器選項參考

OPTIONS Spark SQL 中提供的 支援下列設定:

參數 必要 預設 備註
dbTable 是,除非 query 已指定 無預設值 在 Azure Synapse 中建立或讀取的數據表。 將數據儲存回 Azure Synapse 時,需要此參數。

您也可以使用 {SCHEMA NAME}.{TABLE NAME} 來存取指定架構中的數據表。 如果未提供架構名稱,則會使用與 JDBC 使用者相關聯的預設架構。

先前支援的 dbtable 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。
query 是,除非 dbTable 已指定 無預設值 在 Azure Synapse 中讀取的查詢。

對於查詢中參考的數據表,您也可以使用 {SCHEMA NAME}.{TABLE NAME} 來存取指定架構中的資料表。 如果未提供架構名稱,則會使用與 JDBC 使用者相關聯的預設架構。
user No 無預設值 Azure Synapse 用戶名稱。 必須與 選項搭配 password 使用。 只有在使用者和密碼未傳入 URL 時,才能使用。 傳遞這兩者會導致錯誤。
password No 無預設值 Azure Synapse 密碼。 必須與 選項搭配 user 使用。 只有在使用者和密碼未傳入 URL 時,才能使用。 傳遞這兩者會導致錯誤。
url Yes 無預設值 設定為子程式之 sqlserver JDBC URL。 建議使用 Azure 入口網站 所提供的 連接字串。 設定
encrypt=true 強烈建議使用 ,因為它會啟用 JDBC 連線的 SSL 加密。 如果 userpassword 分別設定,您就不需要將它們包含在URL中。
jdbcDriver No 由 JDBC URL 的子項目決定 要使用的 JDBC 驅動程式類別名稱。 這個類別必須位於 classpath 上。 在大部分情況下,不應該指定這個選項,因為適當的驅動程式 classname 應該由 JDBC URL 的子項目自動決定。

先前支援的 jdbc_driver 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。
tempDir Yes 無預設值 abfss URI。 建議您針對 Azure Synapse 使用專用的 Blob 記憶體容器。

先前支援的 tempdir 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。

您無法使用 Unity 目錄中 定義的外部位置做為 tempDir 位置。
tempCompression No SNAPPY 要用來編碼/譯碼 Spark 和 Azure Synapse 暫存的壓縮演算法。 目前支援的值包括: UNCOMPRESSEDSNAPPYGZIP
forwardSparkAzureStorageCredentials No false 如果 true為 ,連結庫會自動探索 Spark 用來連線到 Blob 記憶體容器的記憶體帳戶存取密鑰認證,並透過 JDBC 將這些認證轉送至 Azure Synapse。 這些認證會作為 JDBC 查詢的一部分傳送。 因此,強烈建議您在使用此選項時啟用 JDBC 連線的 SSL 加密。

設定記憶體驗證時,您必須將 和 的確切設定useAzureMSIforwardSparkAzureStorageCredentialstrue。 或者,您可以將 設定 enableServicePrincipalAuthtrue ,並使用服務主體進行 JDBC 和記憶體驗證。 此選項 forwardSparkAzureStorageCredentials 不支援使用受控服務識別或服務主體對記憶體進行驗證。 僅支援記憶體帳戶存取金鑰。

先前支援的 forward_spark_azure_storage_credentials 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。
useAzureMSI No false 如果 true為 ,連結庫將會針對它所建立的資料庫範圍認證指定 IDENTITY = 'Managed Service Identity' ,而否 SECRET

設定記憶體驗證時,您必須將 和 的確切設定useAzureMSIforwardSparkAzureStorageCredentialstrue。 或者,您可以將 設定 enableServicePrincipalAuthtrue ,並使用服務主體進行 JDBC 和記憶體驗證。
enableServicePrincipalAuth No false 如果 true為 ,連結庫會使用所提供的服務主體認證,透過 JDBC 連線到 Azure 記憶體帳戶和 Azure Synapse Analytics。

forward_spark_azure_storage_credentials如果 或 useAzureMSI 設定為 true,該選項會優先於記憶體驗證中的服務主體。
tableOptions No CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = ROUND_ROBIN 建立透過 dbTable設定的 Azure Synapse 資料表時,用來指定資料表選項的字串。 此字串會以字面方式傳遞至 WITH 針對 Azure Synapse 發出的 SQL 語句子句 CREATE TABLE

先前支援的 table_options 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。
preActions No 沒有預設值 (空字串) ; 將數據寫入 Azure Synapse 實例之前,要於 Azure Synapse 中執行之 SQL 命令的分隔清單。 這些 SQL 命令必須是 Azure Synapse 接受的有效命令。

如果上述任何命令失敗,則會將其視為錯誤,而且不會執行寫入作業。
postActions No 沒有預設值 (空字串) ;連接器成功將數據寫入 Azure Synapse 實例之後,要在 Azure Synapse 中執行的 SQL 命令分隔清單。 這些 SQL 命令必須是 Azure Synapse 接受的有效命令。

如果上述任何命令失敗,則會將其視為錯誤,而且在成功將數據寫入 Azure Synapse 實例之後,您會收到例外狀況。
maxStrLength No 256 StringType 在Spark中,會對應至 NVARCHAR(maxStrLength) Azure Synapse 中的類型。 您可以使用 maxStrLength 來設定資料表中具有名稱之所有 NVARCHAR(maxStrLength) 類型資料行的字串長度
dbTable 在 Azure Synapse 中。

先前支援的 maxstrlength 變體已被取代,未來版本將會忽略。 請改用「駱駝大小寫」名稱。
applicationName No Databricks-User-Query 每個查詢的連接標記。 如果未指定或值是空字串,則標記的預設值會新增 JDBC URL。 預設值可防止 Azure DB 監視工具針對查詢引發虛假的 SQL 插入式警示。
maxbinlength No 無預設值 控制數據行的數據 BinaryType 行長度。 此參數會轉譯為 VARBINARY(maxbinlength)
identityInsert No false 將 設定為 true 啟用 IDENTITY_INSERT 模式,這會在 Azure Synapse 數據表的識別數據行中插入 DataFrame 提供的值。

請參閱 將值明確插入 IDENTITY 資料行
externalDataSource No 無預設值 預先布建的外部數據源,可從 Azure Synapse 讀取數據。 外部數據源只能與 PolyBase 搭配使用,並移除 CONTROL 許可權需求,因為連接器不需要建立範圍認證和外部數據源來載入數據。

如需使用外部數據源時所需的使用方式和許可權清單,請參閱 具有外部數據源選項的 PolyBase 必要 Azure Synapse 許可權。
maxErrors No 0 在載入作業取消之前,可以在讀取和寫入期間拒絕的數據列數目上限。 將會忽略拒絕的數據列。 例如,如果十分之二的記錄有錯誤,則只會處理八筆記錄。

請參閱 COPY 中的 CREATE EXTERNAL TABLE 和 MAXERRORS 檔中的REJECT_VALUE檔。
inferTimestampNTZType No false 如果 true為 ,則 Azure Synapse TIMESTAMP 類型的值會在讀取期間解譯為 TimestampNTZType (不含時區的時間戳)。 否則,不論基礎 Azure Synapse 資料表中的類型為何,所有時間戳都會解譯為 TimestampType

注意

  • tableOptionspreActionspostActionsmaxStrLength 只有在將資料從 Azure Databricks 寫入 Azure Synapse 中的新數據表時才會相關。
  • 儘管所有數據源選項名稱不區分大小寫,但建議您在「駱駝大小寫」中指定它們,以便清楚起見。

查詢下推至 Azure Synapse

Azure Synapse 連接器會實作一組優化規則,將下列操作員向下推送至 Azure Synapse:

  • Filter
  • Project
  • Limit

ProjectFilter 運算子支援下列運算式:

  • 大部分布爾邏輯運算元
  • 比較
  • 基本算術運算
  • 數值和字串轉換

Limit針對運算符,只有在沒有指定順序時,才支援下推。 例如:

SELECT TOP(10) * FROM table,但不是 SELECT TOP(10) * FROM table ORDER BY col

注意

Azure Synapse 連接器不會向下推低在字串、日期或時間戳上運作的表達式。

默認會啟用使用 Azure Synapse 連接器建置的查詢下推。 您可以將 設定 spark.databricks.sqldw.pushdownfalse來停用它。

暫存數據管理

Azure Synapse 連接器 不會 刪除它在 Azure 記憶體容器中建立的暫存盤。 Databricks 建議您定期刪除使用者提供 tempDir 位置下的臨時檔。

為了方便數據清理,Azure Synapse 連接器不會直接儲存在 下的 tempDir數據檔,而是會建立窗體的子目錄: <tempDir>/<yyyy-MM-dd>/<HH-mm-ss-SSS>/<randomUUID>/。 您可以設定定期作業(使用 Azure Databricks 作業 功能或其他方式)以遞歸方式刪除比指定臨界值還舊的任何子目錄(例如 2 天),假設沒有 Spark 作業執行的時間超過該臨界值。

更簡單的替代方案是定期卸除整個容器,並建立具有相同名稱的新容器。 這需要您將專用的容器用於 Azure Synapse 連接器所產生的暫存數據,而且您可以找到一個時間範圍,以確保沒有涉及連接器的查詢正在執行。

暫存物件管理

Azure Synapse 連接器會將 Azure Databricks 叢集與 Azure Synapse 實例之間的數據傳輸自動化。 若要從 Azure Synapse 數據表讀取數據,或查詢或將數據寫入 Azure Synapse 數據表,Azure Synapse 連接器會建立暫存物件,包括 DATABASE SCOPED CREDENTIALEXTERNAL DATA SOURCEEXTERNAL FILE FORMATEXTERNAL TABLE 幕後。 這些物件只會在對應 Spark 作業的期間內持續存在,而且會自動卸除。

當叢集使用 Azure Synapse 連接器執行查詢時,如果 Spark 驅動程式進程當機或已強制重新啟動,或叢集已強制終止或重新啟動,則可能不會卸除暫存物件。 為了方便識別和手動刪除這些物件,Azure Synapse 連接器會在 Azure Synapse 實例中建立的所有中繼暫存物件名稱前面加上格式為: tmp_databricks_<yyyy_MM_dd_HH_mm_ss_SSS>_<randomUUID>_<internalObject>

建議您定期使用查詢來尋找流失的物件,如下所示:

  • SELECT * FROM sys.database_scoped_credentials WHERE name LIKE 'tmp_databricks_%'
  • SELECT * FROM sys.external_data_sources WHERE name LIKE 'tmp_databricks_%'
  • SELECT * FROM sys.external_file_formats WHERE name LIKE 'tmp_databricks_%'
  • SELECT * FROM sys.external_tables WHERE name LIKE 'tmp_databricks_%'