Spark读取Hive的三种方式

spark读取hive数据-java 需求:将hive中的数据读取出来,写入es中。 环境:spark 2.0.2 1. SparkSession里设置enableHiveSupport() SparkConf conf = new SparkConf().setAppName("appName").setMaster("local[*]"); SparkSession spark = SparkSession ... 阅读详情

Spark读取Hive的三种方式

  • 直接读数据源
  • HiveJDBC
  • 配置文件

直接读数据源

因为hive只是起到映射的作用,所以最简单、直观的方式就是直接读取数据的存储组件(HDFS\HBASE)

HiveJDBC

spark读hive的jdbc没写过,不过应该和mysql的差不多,直接贴代码

val properties = new Properties()
properties.put("user",HIVE_USER)
properties.put("password",HIVE_PASSWORD)
properties.put("driver",HIVE_DRIVER)
spark.read.jdbc("jdbc:hive2://IP:10000/bigdata",sql,properties)

看起来毫无问题,拿mysql做实验也能准确读出数据,下面看读hive的输出:

+----+------+-----+------+--------+
|c.id|c.name|c.age|c.city|c.s_date|
+----+------+-----+------+--------+
|c.id|c.name|c.age|c.city|c.s_date|
|c.id|c.name|c.age|c.city|c.s_date|
|c.id|c.name|c.age|c.city|c.s_date|
|c.id|c.name|c.age|c.city|c.s_date|
+----+------+-----+------+--------+

看起来不太对劲,跟代码进去,看看执行了什么操作,于是:

select "c.id","c.name","c.age","c.city","c.s_date" from c
spark读取hive数据的两种方式 spark读取hive数据常用的有两种方式 一是通过访问hive metastore的方式,这种方式通过访问hive的metastore元数据的方式获取表结构信息和该表数据所存放的HDFS路径,这种方式的特点是效率高、数据量大、使用spark操作起来更加友好。 二是通过spark jdbc的方式访问,就是通过链接hiveserver2的方式获取数据,这种方式底层大题上跟spark链接其他rdbms上一样,可以采用sql的方式先在其数据库中查询出来结果再获取其结果数据,这样大部分数据计算的压力就放在了数. 阅读详情

相关推荐

Spark读写Hive

环境:CDH5.8,Spark:1.6.0;Hadoop:2.6.0,Intellij IDEA14 ,jdk1.8,sdk:2.10.6 ,maven:3.3.3;工程下载地址:1. Spark读取HiveSpark读取Hive,使用的是HiveContext,第一步使用sc生成一个HiveContext,然后其他操作就是在HiveContext里面操作了;比如使用HiveContext的tab

fansy1990的专栏 1万+

Spark读取Hive的方式以及出现的雷坑

spark读取Hive的三种方式 1.HiveJDBC 2.通过服务的方式 直接读数据源 因为hive只是起到映射的作用,所以最简单、直观的方式就是直接读取数据的存储组件(HDFS\HBASE) 1.HiveJDBC 方式一: val spark = pec.get[SparkSession]() val dbtable = "( " + sql + ") AS Temp" val jdbcDF = spark.read.format("jdbc") .option("url", jdbc

Alex的博客 3734

《炬丰科技-半导体工艺》用于半导体的RCA清洁技术

书籍:《炬丰科技-半导体工艺》 文章:用于半导体的RCA清洁技术 编号:JFKJ-21-1073 引言 RCA清洗技术是用于清洗硅晶圆等的技术,由于其高可靠性,30多年来一直被用于半导体和平板显示器(FPD)领域的清洗。其基础是以除去颗粒为目的的氨水-过氧化氢溶液组成的SC―1洗涤和以除去金属杂质为目的的盐酸-过氧化氢溶液组成的SC―2洗涤相结合的洗涤技术。SC-1洗涤的机理说明如下。首先,用过氧化氢氧化硅晶片的表面,用作为碱的氨蚀刻氧化硅,并通过剥离去除各种颗粒。此外,如图1所示,在pH 10.5附近的S

jfkj2021的博客 774

Arcmap计算土方量教程

1. 创建现状TIN 结果数据: 2. 创建设计TIN 结果数据: 注意:现状TIN和设计TIN构建时候的坐标系不同,设置坐标系见最后的注意事项第1点,就是import(导入)那步骤,现状TIN构建时选择高程点数据或者等高线数据,设计TIN构建时候选择洱海面数据 3. TIN转栅格 改成你要存的数据库,注意中间不要有汉字 结果数据(设计TIN转栅格的同理) 4. 裁剪现状TIN转成的栅格 结果数据: 5. 计算土方量 结果数据: ...

欢迎关注,共同进步! 5024

文献计量VOSviewer分析知网文献基本操作及实用技巧

本教程旨在为读者提供一个关于VOS viewer的初级使用指南。VOS viewer是一个强大的科学研究可视化工具,主要用于构建和可视化科学地图。它能够处理大规模的科研数据,包括文献引用、共引、共词、共作者等信息。无论你是科研人员,还是数据分析师,甚至是研究生,都能在这个教程中找到使用VOS viewer的有效方法。我们将一步步教你如何使用这个软件,以及如何利用它进行科研数据的可视化。

Jia_n的博客 8781

360加固DEX解密与ELF修复技术解析

本文深入解析了360加固APK的逆向分析技术,重点探讨了其DEX解密与ELF文件修复的核心流程。通过动态调试与Frida脚本,详细拆解了壳的启动机制、反调试绕过、自实现Linker技术,并还原了基于RC4和自定义算法的多层DEX解密过程,为移动安全研究人员提供了实用的实战分析思路。

alice7model的博客 709

Silvaco二极管、三极管、CMOS的制备

Silvaco二极管和三极管的制备

yytu231的博客 5760

安卓刷Windows太难?这款手机平板双系统刷机工具,小白也能轻松拿捏!(小白福音!手机平板专用,一键搞定安卓刷 Windows 双系统!)

安卓刷Windows太难?这款手机平板双系统刷机工具,小白也能轻松拿捏!(小白福音!手机平板专用,一键搞定安卓刷 Windows 双系统!)

XiaoqiangClub的博客 4703

【教程4>第1章>第12节】通过Verilog读取txt格式数据进行测试并将结果导入到matlab

我们在verilog的testbench中,调用txt文件,将上述正弦样本数据作为测试激励输入到verilog模块中。通过这个方法,可以将一些较为复杂的数据导入到verilog中,进行FPGA数据处理模块的开发。即通过w方式打开一个新的txt文件,然后将verilog的输出保存到XY1.txt文件中。这个部分是txt文件的路径,实际使用时,修改为您自己的路径,或者将txt文件放在和我一样的路径中。这个是数据长度,matlab产生的txt多少长度,这个参数就修改为多少长度。这个txt就是保存这段数据的文件。

FPGA/MATLAB学习教程/源码/项目合作开发 1403

目前最强的价格行为技术分析AI!大A也能用!还免费!

有球友推荐了一个历史最强的价格行为技术分析AI工具,使用下来确实很惊艳,解决了 很多AI工具黑盒过程,难以回溯的问题,他的决策过程可解释,提供决策树、诊断结果、原始响应、调试信息和未来走势预期。用户能够看到模型为什么选择“做多、做空或不下单”。会检查置信度、入场条件、盈亏比、结构失效和冷却期。最大的优点不是“预测一定准确”,而是把主观的价格行为分析整理成了可重复、可解释、可校验、可持续跟踪的工程化流程。本文记录本项目在 Windows 上的实际部署与启动方法。

木头大左的博客 92

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

深度学习工具包 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")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

m0_37948565
博客等级 码龄10年 3粉丝 1原创
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值