Matlab Connect Databricks 标志

Matlab Connect Databricks

组织热门
matlab
matlab-connect-databricks

Connect MATLAB to Databricks via Spark (Databricks Connect) or JDBC (Database Toolbox). Use when setting up the MATLAB Interface for Databricks, configuring authentication (OauthU2M, OauthM2M, PAT), creating Spark sessions with getDatabricksSession(), reading Unity Catalog tables with server-side filtering, creating JDBC connections with databricks.JDBCConnection or StandaloneJDBCConnection, connecting to SQL Warehouses, selecting JDBC drivers (Simba/OSS), or writing data back to Databricks. Triggers on: Databricks Connect, Spark from MATLAB, getDatabricksSession, .databrickscfg, databricks.JDBCConnection, StandaloneJDBCConnection, SQLWarehouse, Databricks JDBC, Databricks cluster, large table server-side filtering.

概览

发布者matlab
代码仓库matlab-agentic-toolkit
技能名称matlab-connect-databricks
星标数
1.2K
复刻数
138
附带文件
4
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 4 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 matlab 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Matlab Connect Databricks AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/reporting-and-database-access/matlab-connect-databricks
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/reporting-and-database-access/matlab-connect-databricks .claude/skills/matlab-connect-databricks
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Matlab Connect Databricks,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Matlab Connect Databricks。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Matlab Connect Databricks 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Connect MATLAB to Databricks

Connect MATLAB to Databricks via Spark (Databricks Connect) or JDBC (Database Toolbox). This skill covers first-time setup, authentication, path selection, session/connection creation, and data operations through both paths.

When to Use

  • First-time setup of the MATLAB Interface for Databricks package
  • Configuring .databrickscfg and authentication (OauthU2M, OauthM2M, PAT)
  • Choosing between Spark and JDBC for a Databricks workflow
  • Reading large tables via Spark with server-side filtering (getDatabricksSession)
  • Creating JDBC connections to clusters or SQL Warehouses (databricks.JDBCConnection, SQLWarehouse.connect())
  • Standalone JDBC connectivity without the full package (StandaloneJDBCConnection)
  • Writing data back to Databricks (via Spark DataFrames or JDBC sqlwrite)
  • Selecting and configuring JDBC drivers (Simba vs. OSS)

When NOT to Use

  • Generic Database Toolbox operations after connection is established — use matlab-use-database
  • ODBC connections (databricks.ODBCConnection)
  • Databricks REST APIs (Clusters, Jobs, DBFS, Unity Catalog admin)
  • MLflow from MATLAB
  • Statement Execution REST API
  • Deploying compiled MATLAB code to Databricks clusters (Job workflow)
  • DuckDB — use matlab-use-duckdb
  • Databricks notebooks, Databricks CLI, or databricks-sdk Python workflows
  • PySpark without MATLAB context (pure Python Spark usage)

Decision Framework: Spark vs. JDBC

ScenarioPathWhy
Large table (millions of rows), need server-side filtering before pulling locallySparkDataFrame operations run on cluster; only filtered results transfer
SQL queries on small-to-medium datasetsJDBCDirect SQL via Database Toolbox; simpler setup
Need DataFrame transformations (withColumn, select, filter chains)SparkNative DataFrame API; operations stay on cluster
Writing large data with performance optimizationJDBCSimba driver's UseNativeQuery optimizes sqlwrite
No MATLAB Interface for Databricks package installedJDBCStandaloneJDBCConnection works with just Database Toolbox + driver jar
Need to use Database Explorer appJDBCsaveSource() + copyToken() integration
Reading files from Unity Catalog Volumes (CSV, Parquet, JSON)Sparkspark.read.format().load() with Volumes paths
Interactive exploration with sqlread/fetchJDBCStandard Database Toolbox workflow on j.Connection

Default: Use Spark when the user mentions large data, server-side filtering, or DataFrames. Use JDBC when the user mentions SQL queries, Database Toolbox, or small/medium datasets. If unclear, ask the user about their data size and preferred workflow.

Workflow

  1. Obtain the package — Ask if the user has the MATLAB Interface for Databricks. If not, direct them to https://www.mathworks.com/solutions/partners/databricks.html (or use StandaloneJDBCConnection for JDBC-only without the package)
  2. Setup — Run setup from the package's Software/MATLAB directory. It configures settings, .databrickscfg, and installs the Databricks Connect library via pip into a venv
  3. Startup — Run startup to add package paths (required once per MATLAB session)
  4. Choose path — Use the Decision Framework above to select Spark or JDBC
  5. Connect — Create a session (getDatabricksSession) or connection (databricks.JDBCConnection)
  6. Verify — Spark: table(spark.range(1)). JDBC: check j.Connection.Message is empty
  7. Operate — Read, filter, write data using the appropriate path's API
  8. Close — JDBC: close(j). Spark: sessions are managed automatically

Key Functions

Spark Path

FunctionPurpose
getDatabricksSession()Creates a Spark session (classic compute)
getDatabricksSession(serverless=true)Creates a serverless session (no cluster, 10-min timeout)
spark.read().table("catalog.schema.table")Reads a Unity Catalog table as a DataFrame
spark.read.format(fmt).load(path)Reads files from Volumes (csv, parquet, json)
DF.filter(expr)Server-side row filtering
DF.select(cols)Server-side column selection
DF.limit(n)Server-side row limiting
DF.withColumn(name, col)Adds/transforms a column (requires Column objects)
table(DF)Converts DataFrame to MATLAB table (pulls data locally)
matlab.sparkutils.table2dataset(T, spark)Converts MATLAB table back to Spark DataFrame
DF.write.mode(m).format(f).saveAsTable(name)Writes DataFrame to Unity Catalog table
matlab.pyspark.sql.functions.col(name)Creates a Column reference
matlab.pyspark.sql.functions.lit(value)Creates a literal Column constant

JDBC Path

FunctionPurpose
databricks.JDBCConnection()Creates a JDBC connection (full package)
StandaloneJDBCConnection()Creates a JDBC connection (no package dependencies)
databricks.SQLWarehouse.connect()Connects to a SQL Warehouse by ID
j.ConnectionThe database.jdbc.connection object for Database Toolbox functions
j.testConnection()Verifies connection is working
j.saveSource()Saves connection as a Database Toolbox data source
close(j)Closes connection and releases resources

Patterns

First-Time Setup

Run setup from the package's Software/MATLAB directory. It is interactive — follow prompts for host URL, auth method, cluster ID, and Databricks Connect library installation.

The Databricks Connect library is downloaded via pip into Software/MATLAB/Connect/<version>/venv/. Requires Python 3.10-3.12. If the download fails repeatedly, ask the user to check with their IT team — do not retry with modified arguments.

matlab
cd('/path/to/databricks-package/Software/MATLAB')
setup
startup

After setup, MATLAB's pyenv must point to the venv Python. If getDatabricksSession fails with "databricks.connect package is not installed":

matlab
terminate(pyenv);
pyenv(Version="/path/to/databricks-package/Software/MATLAB/Connect/17.3/venv/bin/python");

Warning: If Python is already loaded InProcess, terminate(pyenv) fails. A full MATLAB restart is required. Do not attempt to switch pyenv mid-session after Python has been used.

For authentication configuration details (.databrickscfg format, profiles, environment variables, token caching), see references/authentication.md — consult when configuring auth methods or troubleshooting credential issues.

Spark: Read and Filter a Table

Data stays on the cluster until explicitly collected. Filter server-side first, then collect.

matlab
spark = getDatabricksSession(authMethod="PAT");
DF = spark.read().table("catalog.schema.sensor_readings");
filtered = DF.filter("temperature > 100 AND event_date > '2024-01-01'");
T = table(filtered);

Spark: Serverless Session

No cluster needed. Starts instantly with 10-minute inactivity timeout. Requires Python 3.11-3.12 and Databricks Connect >= 15.4.

matlab
spark = getDatabricksSession(serverless=true);
DF = spark.read().table("catalog.schema.events");
T = table(DF.limit(50));

Spark: Add Computed Columns

withColumn requires Column objects — not raw scalars. Use col() for references and lit() for constants.

matlab
import matlab.pyspark.sql.functions.col
import matlab.pyspark.sql.functions.lit

DF = spark.read().table("catalog.schema.measurements");
DF2 = DF.withColumn("temp_fahrenheit", col("temp_celsius") * lit(9/5) + lit(32));

Spark: Write Back to Databricks

Always specify .mode() — without it, writes fail if the target exists.

matlab
DF_new = matlab.sparkutils.table2dataset(T, spark);
DF_new.write.mode("overwrite").format("delta").saveAsTable("catalog.schema.output_table");

Spark: Read Files from Volumes

matlab
DF = spark.read.format("csv").option("header", "true").load("/Volumes/catalog/schema/volume/data.csv");
T = table(DF.limit(1000));

JDBC: Cluster Connection

matlab
j = databricks.JDBCConnection(catalog="mycatalog", schema="myschema");
data = sqlread(j.Connection, "mytable");
close(j);

JDBC: SQL Warehouse Connection

warehouse.connect() returns a database.jdbc.connection directly — pass it to sqlread/fetch without .Connection.

matlab
warehouse = databricks.SQLWarehouse;
warehouse.id = "abc123def456";
conn = warehouse.connect();
data = fetch(conn, "SELECT * FROM mycatalog.myschema.mytable LIMIT 10");
close(conn);

JDBC: Standalone (No Package)

When the user does NOT have the MATLAB Interface for Databricks, use StandaloneJDBCConnection. Requires Database Toolbox and the Simba driver jar only. See references/standalone-jdbc.md for setup and JSON template.

matlab
j = StandaloneJDBCConnection(schema="myschema", catalog="mycatalog");
data = fetch(j.Connection, "SELECT * FROM mytable LIMIT 10");
close(j);

JDBC: On-Databricks (Browser MATLAB)

The JDBC driver's OAuth flow cannot open a browser when MATLAB runs on a Databricks cluster. Use package-managed auth instead.

matlab
if databricks.internal.isOnDatabricks()
    j = databricks.JDBCConnection(authMethod="OauthU2M", useDriverAuth=false);
else
    j = databricks.JDBCConnection();
end
data = fetch(j.Connection, "SELECT * FROM mycatalog.myschema.mytable LIMIT 10");
close(j);

JDBC: Write-Optimized Connection

Simba driver write performance improves with native query mode (enabled by default).

matlab
j = databricks.JDBCConnection(catalog="main", schema="telemetry");
sqlwrite(j.Connection, "measurements", data);
close(j);

Connection Cleanup

Use onCleanup to guarantee closure even when operations fail.

matlab
j = databricks.JDBCConnection(catalog="main", schema="analytics");
cleanup = onCleanup(@() close(j));
data = fetch(j.Connection, "SELECT * FROM large_table WHERE id > 1000");

For Spark stale sessions:

matlab
clear spark
spark = getDatabricksSession(forceNewSession=true);

Conventions

  • Always filter DataFrames server-side before calling table(DF) — pulling millions of unfiltered rows wastes bandwidth and memory
  • Use three-level names for Unity Catalog tables: "catalog.schema.table"
  • Use getDatabricksSession() for Spark — never construct sessions manually or mimic PySpark builder patterns
  • Use databricks.JDBCConnection or StandaloneJDBCConnection for JDBC — never manually construct JDBC URLs with database()
  • Always pass authMethod explicitly — the default chain may trigger unexpected browser prompts
  • Never hardcode tokens or secrets in MATLAB code — use .databrickscfg or environment variables
  • Always call close(j) when done with JDBC connections
  • Use forceNewSession=true for stale Spark sessions, not clear all
  • For JDBC driver selection details, see references/driver-selection.md — consult when choosing between Simba and OSS drivers or configuring Java

Common Mistakes

MistakeWhy It's WrongCorrect Approach
Manually building JDBC URLs with database()Fragile, error-prone, exposes secrets, misses automatic URL construction, driver classpath management, unified auth chain, and write optimizationUse databricks.JDBCConnection() or StandaloneJDBCConnection()
Inventing PySpark builder: databricks.spark.Session.builder().remote()Does not exist in MATLABUse getDatabricksSession()
Calling table(DF) on unfiltered large tablesTransfers entire dataset locallyApply .filter() / .select() / .limit() first
Passing scalars to withColumn: DF.withColumn("x", 2)Second argument must be a Column objectUse DF.withColumn("x", lit(2))
Writing without .mode(): DF.write.save(path)Fails if target existsUse .mode("overwrite") or .mode("append")
Using driver auth on-clusterBrowser OAuth fails in browser-based MATLABUse useDriverAuth=false
Hardcoding tokens in source codeSecurity risk; tokens expireStore in .databrickscfg or environment variables
Calling getDatabricksSession() without authMethodDefault chain may trigger unwanted browser promptPass authMethod="PAT" or other method explicitly
Mismatched Python version for SparkSession creation failsMatch local Python to runtime (e.g., 3.12 for runtime 17.3)
Using OSS driver with Java 8OSS requires Java 11+Set Java 11+ via jenv first (requires MATLAB restart)
Passing DataFrame args to chained methods: DF.unionAll(DF2)MATLAB Spark wrapper doesn't support DataFrame method argumentsUse spark.sql() with SQL UNION ALL instead

Copyright 2026 The MathWorks, Inc.


附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Matlab Connect Databricks AI 技能有什么作用?

Connect MATLAB to Databricks via Spark (Databricks Connect) or JDBC (Database Toolbox). Use when setting up the MATLAB Interface for Databricks, configuring authentication (OauthU2M, OauthM2M, PAT), creating Spark sessions with getDatabricksSession(), reading Unity Catalog tables with server-side filtering, creating JDBC connections with databricks.JDBCConnection or StandaloneJDBCConnection, connecting to SQL Warehouses, selecting JDBC drivers (Simba/OSS), or writing data back to Databricks. Triggers on: Databricks Connect, Spark from MATLAB, getDatabricksSession, .databrickscfg, databricks...

为什么在 TypingMind 中使用 Matlab Connect Databricks?

因为您只需安装一次,就能搭配任何模型使用。Matlab Connect Databricks 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Matlab Connect Databricks?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/reporting-and-database-access/matlab-connect-databricks。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Matlab Connect Databricks?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Matlab Connect Databricks 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Matlab Connect Databricks 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Matlab Connect Databricks AI 技能免费吗?

matlab 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇