深入解析Spark3 Catalog扩展机制:从TableCatalog到DelegatingCatalogExtension

【无标题】 动态 DAG 让 Agent 能够并行规划与条件执行,但它本身不提供可靠性。持久化事实 → 原子状态与图变更 → 可靠通知 → 合法执行所有权 → 意图绑定的幂等副作用 → Checkpoint 恢复 → 周期性对账 → 可重复故障验证。PostgreSQL 事务状态机、边判定事实与 Transactional Outbox;Lease/Epoch/Fencing 与陈旧回调拒绝;稳定、不可变和远端查询对账。它们决定系统在最坏故障时刻能否安全地继续执行,而不是只会从头再跑一遍。 阅读详情

1. 为什么你需要了解Spark Catalog扩展机制?

如果你用过Spark SQL,肯定对CREATE TABLE、SHOW TABLES这些命令不陌生。你有没有想过,当你执行这些命令时,Spark是怎么知道去哪里找表,怎么管理这些表的元数据的?这背后的大管家,就是Catalog。

简单来说,Catalog就是一个元数据仓库,它记录了所有数据库、表、视图、函数的位置、结构等信息。你可以把它想象成一个图书馆的索引系统。默认情况下,Spark使用一个内置的Catalog来管理这些信息。但是,当你的数据源不再仅仅是Hive或者本地文件,而是分散在多个云厂商的对象存储、关系型数据库、甚至消息队列(如Kafka)里时,这个默认的“图书管理员”可能就有点力不从心了。

这时候,自定义Catalog扩展机制就派上了用场。它允许你“教会”Spark,如何与这些五花八门的外部数据源打交道,让Spark能够像查询本地表一样,无缝地查询这些外部数据。比如,你可以实现一个JDBCCatalog,让Spark直接通过JDBC连接MySQL、PostgreSQL,把远程数据库里的表映射成Spark SQL里的表;或者实现一个IcebergCatalog、DeltaCatalog,来支持更高级的湖仓一体表格式。

在Spark 3中,这套扩展机制被设计得更加清晰和强大,核心围绕着两个关键接口:TableCatalog 和 DelegatingCatalogExtension。理解它们,就等于拿到了打开Spark数据源扩展大门的钥匙。接下来,我就带你从零开始,把这套机制掰开揉碎了讲清楚。

2. 庖丁解牛:Spark Catalog的核心接口与继承关系

要搞懂扩展机制,首先得明白Spark Catalog的“家谱”。别被那一堆类名吓到,我们用一个生活中的例子来类比。

想象一下,你要开一家连锁咖啡店(Spark SQL)。你需要一个**总部管理系统(CatalogPlugin)**来管理所有分店。每家分店(Namespace)都需要向总部注册。CatalogPlugin就是这个最顶层的总部接口,它规定每家分店必须有一个名字(name())和一套默认的管理区域(defaultNamespace())。

但是,总部只管理分店还不够,具体到每家分店内部,还有咖啡豆库存管理(TableCatalog)。TableCatalog接口就是专门用来管理“货物”(表)的。它定义了核心的“进货”、“查货”、“改货单”、“下架”操作:

  • loadTable():根据标识(比如“意式拼配#1号仓”)找到对应的咖啡豆(表)。
  • createTable():新进一批咖啡豆,并登记入库。
  • alterTable():修改某批咖啡豆的产地或烘焙度信息。
  • dropTable():某批咖啡豆售罄,从库存中移除。

在Spark的默认实现里,有一个非常能干的“职业经理人”叫V2SessionCatalog。它自己并不直接去仓库搬货,而是有一个得力的助手——SessionCatalog(或者其子类如HiveSessionCatalog)。V2SessionCatalog主要负责对接Spark SQL的V2 API,然后把具体的脏活累活(比如和Hive Metastore交互)都委托给SessionCatalog去干。这就好比经理(V2SessionCatalog)接到客户订单(SQL查询),然后指挥仓库管理员(SessionCatalog)去实际找货。

那么,如果我们想在不替换这个能干经理的前提下,给他增加一些新技能,比如自动从合作的咖啡庄园(外部数据源)直接调货,该怎么办?这时候,DelegatingCatalogExtension就登场了。

DelegatingCatalogExtension是一个“增强插件”。它本身也实现了TableCatalog接口,但它内部持有一个“被代理”的Catalog实例(默认就是那个V2SessionCatalog)。它的设计非常巧妙:所有TableCatalog接口的方法,它都提供了默认实现——直接调用被代理对象(delegate)的对应方法。这样一来,你想增强哪个功能,就重写哪个方法,在方法里先调用super.xxx()执行原有逻辑,然后再加入你的自定义逻辑;或者完全重写,实现全新的逻辑。

我们来看一下Delta Lake项目中的DeltaCatalog,它就是继承DelegatingCatalogExtension的经典案例。它重写了loadTable、createTable等方法,在原有表操作的基础上,增加了读写Delta格式事务日志、保证ACID语义等能力,而对用户来说,操作表和以前没有任何区别。

注意:CatalogExtension是一个抽象类,它继承了TableCatalog并定义了setDelegateCatalog方法。DelegatingCatalogExtension是它的一个具体实现,为我们做好了“默认转发”的一切铺垫。所以,在大多数自定义扩展场景下,我们直接继承DelegatingCatalogExtension是最省事、最安全的选择。

总结一下这个“家谱”关系:

  • 想从零创建一个全新的Catalog(比如管理一套全新的存储系统),直接实现CatalogPlugin和TableCatalog接口。
  • 想
别只刷题了!我用834分经验告诉你,华为HCIP大数据考试(H13-723)这样准备更高效 本文分享了华为HCIP大数据认证(H13-723)834分通关的高效备考经验。通过分析考试动态、题库验证技巧和章节优先级策略,帮助考生超越单纯刷题,系统化掌握核心知识点。特别强调实时流处理和离线批处理等重点章节,提供黄金90分钟临场发挥策略,助力考生一次性通过考试。 阅读详情

相关推荐

20道SpringSecurity常见面试题汇总(超详细回答 !!!)

本文中,我们将探讨一些与 Spring Security 相关的面试问题。Spring Security 是一款流行的 Java 应用程序安全框架,它提供了一套全面且易于使用的安全解决方案。

小斜同学的博客 3080

PCIe扫盲(三)

需要特别注意的是,PCIe的Spec中明确规定只有Root有权限发起配置请求(Originate Configuration Requests),也就是说PCIe系统里面的其他设备是不允许去配置其他设备的配置空间的,即peer-to-peer的配置请求是不允许的。当配置请求进行BDF路由的时候,正是依靠这些信息来确定要找的设备的。前面的文章还介绍过,Root和Switch的每一个端口中都包含一个P2P桥,并且知道桥的配置空间头(Configuration Space Header)是Type1型的。

Liuqz2009的专栏 2422

(P2)PALM软件的基本使用流程

上一篇介绍了PALM在Ubuntu系统上的下载安装及安装后的目录文件结构,这一篇以自带的案例介绍软件的基本操作流程。(请转至example_cbl项目) 输入 声明:官网均有各个变量的说明,以下代码来自软件自带案例 palm的最小输入文件是p3d文件,以下是example_cbl_p3d的详细说明。(文件语言格式Fortran,请自行先学习下语言的基本语法。笔者也是新学者,有非常多的问题,很多参数也不能准确的说出是什么意思,还请不吝赐教,谢谢!!!) !几点说明 !1、该运行文件基本由三大块组成:1)in

ysqzhatian的博客 3266

x86架构学习之中断

外部中断,一般是由CPU的外部引脚电信号触发,这些引脚留给硬件厂商去定义中断,例如主板厂商可以将USB中断挂载70号中断引脚上,MCU厂商可以将片上外设(SPI、I2C等)的中断挂载在指定中断线上。中断描述符主要用于说明该中断的入口地址,中断描述符表则是将中断描述符一项一项管理在一个数组中,每一项中断描述符占用8个字节(64位模式下,占用16字节),其。简称中断,后文如果没特别说明,中断都指外部中断,由外部IO事件触发,由于时钟源来自CPU外部,与CPU时钟不同源,因此是异步事件。

qq_26962739的博客 1576

14、Java 中 TAF 和 FCF 的使用及 Oracle 数据库升级与迁移指南

本文详细介绍了Java中实现高可用性的TAF(透明应用故障转移)和FCF(快速连接故障转移)技术,以及如何将Oracle 9iR2 RAC环境升级到10gR2 RAC,并将数据从OCFS迁移到ASM。通过示例代码和操作步骤,帮助开发者和数据库管理员更好地应对数据库故障和数据迁移问题,提升系统的可用性和性能。

egg99的博客 115

osgearth添加经纬度网格,并显示鼠标所指经纬高度信息

一、代码 osgearth官方例子 #include <osg/Notify> #include <osgGA/StateSetManipulator> #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgEarth/MapNode> #include <osgEarthUtil/EarthManipulator> #

ljjjjjjjjjjj的博客 3568

非结构化数据在大数据湖中的应用实践

想象一下,你正在整理一个杂乱的书房。有些书整整齐齐地放在书架上,每本书都有明确的标题、作者和出版日期——这些就是结构化数据,它们像数据库中的表格,有固定的格式和字段。但书房里还有更多东西:散落的照片、手写的笔记、录音带、视频光盘、甚至还有画作。这些物品没有固定的格式,每件都独一无二——这就是非结构化数据。在技术术语中,非结构化数据是指没有预定义数据模型或组织形式的信息。文本文档(Word、PDF、TXT)电子邮件和社交媒体内容图像和照片(JPG、PNG)音频文件(MP3、WAV)

软件工程实践的博客 364

36. 在 SAP Integration Suite 里打通入站 HTTP:iFlow 端点鉴权、角色授权与多节点 403 排障实战

本文探讨了SAP Cloud Integration中HTTP入站连接的认证与授权机制。在Cloud Foundry环境下,认证(证明身份)和授权(权限控制)需分开处理:认证可采用Basic、OAuth或mTLS等方式,授权则通过角色实现。文章详细解析了两种主流配置路径:基于IdP用户的Basic认证(需配置Role Collection)和基于OAuth Client/Service Instance的系统调用(通过Service Key管理权限)。特别指出ABAP系统在多节点环境下可能因cookie编码

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 325

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

上一篇: 避免踩坑!微信小程序encryptedData解密常见错误及解决方案
下一篇: 深入解析Tricore TC1.6.2内核MPU机制:从Protection Ranges到安全实践
moss5
博客等级 码龄4年 52粉丝 1534原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值