Snowpark Migration Accelerator: Passo a passo da SMA CLI

The Snowpark Migration Accelerator (SMA) helps developers migrate their Python or Scala Spark code to Snowpark. It analyzes your code and:

  1. Avalia a compatibilidade com o Snowpark

  2. Converte automaticamente as chamadas compatíveis do Spark API para o Snowpark API

  3. Identifica o código que não pode ser convertido automaticamente

  4. Cria um inventário de importações de bibliotecas de terceiros a partir de scripts e notebooks

  5. Gera um relatório de compatibilidade editável comparando o código do Spark e do Snowpark

A Snowflake lançou uma interface de linha de comando (CLI) para o Snowpark Migration Accelerator (SMA). Este guia demonstrará como usar a CLI como uma ferramenta autônoma e dentro de um script.

Uso do CLI

You can download the Command Line Interface (CLI) from the Download and Access section. Select the version that matches your operating system. You can store the CLI in any accessible location on your machine or container.

Nota

NOTE: Embora este passo a passo use capturas de tela de um computador Mac, o processo é semelhante para usuários de Windows e Linux.

Depois de fazer o download do arquivo do pacote (formato .zip ou .tar), extraia seu conteúdo. A ferramenta Command Line Interface (CLI) está localizada na pasta «orchestrator» dentro dos arquivos extraídos.

SMA CLI no diretório Orchestrator

Abra um terminal ou prompt de comando na pasta de instalação e verifique a instalação da CLI executando o seguinte comando para verificar sua versão:

./sma –version

Você verá resultados parecidos com os seguintes:

Informações sobre a versão do SMA

The SMA Command Line Interface (CLI) is a local application that runs on your computer, similar to the SMA desktop application. To analyze your code files using the SMA CLI, these files must be stored on your local machine where the CLI can access them. The CLI supports the same file types as the regular SMA application. For a complete list of supported file types, refer to the supported filetypes in the SMA documentation.

Nota

NOTE: To test the CLI functionality, you can use the sample codebase provided in the Assessment section or refer to the Conversion walkthroughs in the SMA documentation.

A documentação do SMA contém uma lista completa dos argumentos da CLI. Vamos explorar os mais importantes nesta seção.

The SMA CLI runs in Conversion mode by default, rather than Assessment mode. To run the CLI in assessment mode, use the -a argument. For conversion operations, you’ll need a valid access code. To verify if you have a valid access code, use the following command:

./sma show-ac
Informações sobre a licença

Para executar uma conversão, você precisa fornecer:

  1. Diretório de entrada (obrigatório)

  2. Diretório de saída (obrigatório)

Se não tiver criado um arquivo de projeto antes, também precisará fornecer:

  • E-mail do usuário

  • Nome da organização

  • Nome do projeto

Depois de configurar esses parâmetros pela primeira vez, você só precisa especificar os diretórios de entrada e saída para futuras conversões.

./sma -i '/your/INput/directory/path/here' -o '/your/OUTput/directory/path/here' -e your@email.com -c Your-Organization -p Your-Project-Name

Essa tela exibe um resumo das configurações de execução e solicita que confirme se deseja continuar.

Seção de informações do projeto

Para ignorar o prompt de confirmação, adicione o parâmetro –yes ou -y. Isso é particularmente importante ao executar a CLI a partir de scripts automatizados.

A ferramenta fornece informações detalhadas sobre o progresso durante sua execução.

Informações sobre o projeto impressas

While the tool is running, it will continuously print output to the screen. When the process is complete, you will see the prompt again. The tool generates detailed output that includes all processes, issues, and completed or failed steps. You don’t need to read through all of this information while it’s running, as you can review it later in the Logs output folder.

Visualização da saída

A SMA CLI produz o mesmo resultado que o aplicativo SMA. Quando você executa a ferramenta, ela cria três pastas no diretório de saída especificado:

Diretório de saída do SMA

For detailed guidance on working with code that has been converted by the Snowpark Migration Accelerator (SMA), refer to the conversion walkthrough.

Using the Workspace Estimator

The SMA CLI includes a Workspace Estimator verb (we or workspace-estimator) that connects to a Databricks workspace, extracts metadata such as clusters, jobs, and runs, and optionally uploads the results to Snowflake for analysis.

Command hierarchy

The Workspace Estimator currently supports Databricks workspaces through the dbx subcommand. Running sma we dbx without a subcommand displays help listing the available subcommands:

  • sma we dbx run – Runs both extraction and upload in a single invocation.

  • sma we dbx extract – Extracts workspace metadata to a local .zip file only.

  • sma we dbx upload – Uploads a previously extracted .zip file to Snowflake.

Authentication

A Databricks Personal Access Token (PAT) is required for extraction. You can supply it in one of two ways:

  1. Pass it directly with -t / --token.

  2. Set the SMA_DBX_TOKEN environment variable. If --token is omitted, the CLI defaults to this variable.

Running extraction and upload together

When you provide all required options to sma we dbx run, the CLI extracts workspace metadata and uploads the resulting .zip file in a single step.

./sma we dbx run \
  -w https://adb-1234567890.azuredatabricks.net/ \
  -o ~/output/workspace-estimator \
  -n analytics-workspace \
  -c Example-Inc \
  -e user@example.com

The following table lists the available options for sma we dbx run:

Option

Short

Required

Default

Description

--workspace-url

-w

Yes

Databricks workspace URL (e.g. https://adb-1234.azuredatabricks.net).

--token

-t

No

SMA_DBX_TOKEN env var

Databricks Personal Access Token (PAT).

--output-dir

-o

No

Current directory

Directory where the extraction .zip file will be written.

--workspace-name

-n

Yes

Logical name for the workspace. Cannot be empty or whitespace.

--lookback-days

-l

No

30

Number of days to look back for cluster events (15, 30, or 60).

--log-level

No

Information

Minimum log level for diagnostic output (Trace, Debug, Information, Warning, Error, Critical).

--company-name

-c

Yes

Company name for this estimation. Cannot be empty or whitespace.

--email

-e

Yes

Email of the person performing the estimation. Must be a valid email address.

Running extraction only

To extract workspace metadata without uploading, use the extract subcommand. This produces a .zip file in the specified output directory.

./sma we dbx extract \
  -w https://adb-1234567890.azuredatabricks.net/ \
  -n analytics-workspace \
  -o ~/output/workspace-estimator

The extract subcommand accepts the same options listed in the run table above except --company-name and --email, which are only required for upload.

Uploading a previously extracted file

If you have already extracted workspace metadata to a .zip file, you can upload it separately using the upload subcommand.

./sma we dbx upload \
  -i ~/output/workspace-estimator/workspace-extraction.zip \
  -n analytics-workspace \
  -c Example-Inc \
  -e user@example.com

The following table lists the available options for sma we dbx upload:

Option

Short

Required

Default

Description

--input-zip

-i

Yes

Path to an existing .zip file to upload. The file must have a .zip extension.

--company-name

-c

Yes

Company name for this estimation. Cannot be empty or whitespace.

--email

-e

Yes

Email of the person performing the estimation. Must be a valid email address.

--workspace-name

-n

Yes

Logical name for the workspace. Cannot be empty or whitespace.

--log-level

No

Information

Minimum log level for diagnostic output (Trace, Debug, Information, Warning, Error, Critical).

Executando a CLI programaticamente

Em breve! A equipe do SMA fornecerá um script que permite executar a interface de linha de comando do SMA (CLI) automaticamente em vários diretórios.


Try out the Command Line Interface (CLI) today. If you need help or have questions, contact the Snowpark Migration Accelerator team at sma-support@snowflake.com.