execução de consultas federadas em outro site Databricks workspace
Este artigo descreve como configurar o Lakehouse Federation para executar consultas federadas em dados Databricks em outro Databricks workspace. Para saber mais sobre a lakehouse Federation, consulte O que é a lakehouse Federation?
Databricks-to-Databricks A lakehouse Federation é uma boa ferramenta para executar consultas em dados gerenciados por outro metastore Databricks workspace 's Hive ou AWS Glue . Para a maioria dos outros cenários, outros Databricks fluxos de trabalho são mais eficientes:
- Se o espaço de trabalho Databricks compartilhar o mesmo metastore Unity Catalog, o senhor poderá gerenciar consultas cruzadasworkspace usando consultas padrão Unity Catalog e ferramentas de governança de dados.
- Se o senhor quiser ter acesso somente leitura aos dados em um Databricks workspace anexado a um metastore Unity Catalog diferente, seja no seu Databricks account ou não, o Delta Sharing é a melhor opção.
Não há necessidade de configurar a Lakehouse Federation em nenhum desses cenários.
Para se conectar a um catálogo Databricks em outro workspace usando a Lakehouse Federation, o senhor deve criar o seguinte no metastore Databricks Unity Catalog :
- Um agrupamento ou SQL warehouse em um Databricks workspace.
- Uma conexão com o clustering ou SQL warehouse.
- Um catálogo externo em seu Unity Catalog metastore que espelha o outro Databricks catálogo acessível a partir do clustering ou SQL warehouse para que o senhor possa usar a sintaxe de consulta Unity Catalog e as ferramentas de governança de dados para gerenciar o Databricks acesso do usuário aos dados.
Antes de começar
Requisitos do workspace:
- Espaço de trabalho preparado para o Catálogo do Unity.
Requisitos de computação:
- Conectividade de rede do seu recurso compute para os sistemas de banco de dados de destino. Veja as recomendações do Networking para a Lakehouse Federation.
- Databricks compute O senhor deve usar Databricks Runtime 13.3 LTS ou acima e o modo de acesso Standard ou Dedicated .
- Os SQL warehouse devem ser Pro ou Serverless e devem utilizar a versão 2023.40 ou superior.
Permissões necessárias:
- Para criar uma conexão, é preciso ser administrador de metastore ou usuário com o privilégio
CREATE CONNECTION
no metastore do Unity Catalog anexado ao espaço de trabalho. - Para criar um catálogo externo é preciso ter a permissão
CREATE CATALOG
no metastore e ser proprietário da conexão ou ter o privilégioCREATE FOREIGN CATALOG
na conexão.
Outros requisitos de permissão são definidos em cada seção baseada em tarefa a seguir.
Também é necessário ter um clustering ativo ou SQL warehouse no Databricks workspace que o senhor está usando para configurar a conexão.
Crie uma conexão
A conexão especifica um caminho e as credenciais para acessar um sistema de banco de dados externo. Para criar uma conexão, você pode usar o Catalog Explorer ou o comando CREATE CONNECTION
do SQL em um Notebook do Databricks ou no editor de consultas SQL do Databricks.
O senhor também pode usar a API REST da Databricks ou a CLI da Databricks para criar uma conexão. Veja POST /api/2.1/unity-catalog/connections e Unity Catalog comando.
Permissões necessárias: Administrador do Metastore ou usuário com o privilégio CREATE CONNECTION
.
- Catalog Explorer
- SQL
-
In your Databricks workspace, click
Catalog.
-
At the top of the Catalog pane, click the
Add icon and select Add a connection from the menu.
Alternatively, from the Quick access page, click the External data > button, go to the Connections tab, and click Create connection.
-
On the Connection basics page of the Set up connection wizard, enter a user-friendly Connection name.
-
Select a Connection type of Databricks.
-
(Optional) Add a comment.
-
Click Next.
-
On the Authentication page, enter the following connection properties for the other Databricks instance:
- Host: Workspace instance name. To learn how to get the workspace instance name, see Get identifiers for workspace objects.
- Personal access token: A Databricks personal access token that enables access to the target workspace.. To learn how to get a token, see Databricks personal access token authentication. For connections, Databricks recommends using a personal access token for a service principal.
- HTTP path: The HTTP path for your SQL warehouse. To get the path, go to SQL > SQL Warehouses in the sidebar, select the SQL warehouse, go to the Connection details tab, and copy the value for HTTP path.
-
Click Create connection.
-
On the Catalog basics page, enter the catalog name in the other Databricks workspace that can be mapped to a catalog object in this metastore.
-
(Optional) Click Test connection to confirm that it works.
-
Click Create catalog.
-
On the Access page, select the workspaces in which users can access the catalog you created. You can select All workspaces have access, or click Assign to workspaces, select the workspaces, and then click Assign.
-
Change the Owner who will be able to manage access to all objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.
-
Grant Privileges on the catalog. Click Grant:
- Specify the Principals who will have access to objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.
- Select the Privilege presets to grant to each principal. All account users are granted
BROWSE
by default.- Select Data Reader from the drop-down menu to grant
read
privileges on objects in the catalog. - Select Data Editor from the drop-down menu to grant
read
andmodify
privileges on objects in the catalog. - Manually select the privileges to grant.
- Select Data Reader from the drop-down menu to grant
- Click Grant.
-
Click Next.
-
On the Metadata page, specify tags key-value pairs. For more information, see Apply tags to Unity Catalog securable objects.
-
(Optional) Add a comment.
-
Click Save.
Run the following command in a notebook or the Databricks SQL query editor, replacing the following:
<connection-name>
: User-friendly name for the connection you’re creating.<workspace-instance>
: The target workspace instance. To learn how to get the workspace instance name, see Get identifiers for workspace objects.<sql-warehouse-path>
: The HTTP path for your SQL warehouse. To get the path, go to SQL > SQL Warehouses in the sidebar, select the SQL warehouse, go to the Connection details tab, and copy the value for HTTP path.<personal-access-token>
: A Databricks personal access token that enables access to the target workspace. To learn how to get a token, see Databricks personal access token authentication. For connections, Databricks recommends that you use a service principal’s personal access token.
CREATE CONNECTION <connection-name> TYPE databricks
OPTIONS (
host '<workspace-instance>',
httpPath '<sql-warehouse-path>',
personalAccessToken '<personal-access-token>'
);
We recommend that you use Databricks secrets instead of plaintext strings for sensitive values like credentials. For example:
CREATE CONNECTION <connection-name> TYPE databricks
OPTIONS (
host '<workspace-instance>',
httpPath '<sql-warehouse-path>',
personalAccessToken secret ('<secret-scope>','<secret-key-password>')
)
For information about setting up secrets, see Secret management.
Crie um catálogo estrangeiro
Se o senhor usar a interface do usuário para criar uma conexão com a fonte de dados, a criação do catálogo externo estará incluída e o senhor poderá ignorar essa etapa.
Um catálogo externo espelha um catálogo no site externo Databricks workspace para que o senhor possa consultar e gerenciar o acesso aos dados nesse catálogo externo Databricks como se fosse um catálogo em seu próprio local de trabalho. Para criar um catálogo externo, o senhor usa uma conexão com o site externo Databricks workspace que já foi definido.
Para criar um catálogo externo, o senhor pode usar o Catalog Explorer ou o comando CREATE FOREIGN CATALOG
SQL em um Notebook Databricks ou o editor de consultas Databricks SQL. O senhor também pode usar a API REST da Databricks ou a CLI da Databricks para criar um catálogo. Veja POST /api/2.1/unity-catalog/catalogs e Unity Catalog comando.
Permissões necessárias: permissão CREATE CATALOG
na metastore e propriedade da conexão ou o privilégio CREATE FOREIGN CATALOG
na conexão.
- Catalog Explorer
- SQL
-
In your Databricks workspace, click
Catalog to open Catalog Explorer.
-
At the top of the Catalog pane, click the
Add icon and select Add a catalog from the menu.
Alternatively, from the Quick access page, click the Catalogs button, and then click the Create catalog button.
-
Follow the instructions for creating foreign catalogs in Create catalogs.
Run the following SQL command in a notebook or Databricks SQL editor. Items in brackets are optional. Replace the placeholder values:
<catalog-name>
: Name for the foreign catalog that you are creating.<connection-name>
: The connection object that specifies the data source, path, and access credentials.<external-catalog-name>
: Name of the catalog in the external Databricks workspace that you are mirroring.
CREATE FOREIGN CATALOG [IF NOT EXISTS] <catalog-name> USING CONNECTION <connection-name>
OPTIONS (catalog '<external-catalog-name>');
Pushdowns suportados
Os seguintes pushdowns são suportados em todos os sites compute:
- Filtros
- Projeções
- Limite
- Funções: somente expressões de filtro são compatíveis (funções de cadeias de caracteres, funções matemáticas, funções de dados, tempo e registro de data e hora e outras funções diversas, como Alias, Cast, SortOrder).
Os seguintes pushdowns são suportados em Databricks Runtime 13.3 LTS e acima e SQL warehouse compute:
- Agregados
- Os seguintes operadores Boolean: =, <, <=, >, >=, <=>
- As seguintes funções matemáticas (não suportadas se o ANSI estiver desativado): +, -, *,%,/
- Os seguintes operadores diversos: ^, |, ~
- Classificação, quando usada com limite
Os seguintes pushdowns não são suportados:
- unir-se
- Funções do Windows