hive修改字段后查询不了数据

Hive修改Parquet存储的表字段类型 Hive数据表的存储支持多种方式,纯文本和Parque其中的两种。 纯文本的优势在于简单,可读,缺点在于无压缩,效率;Parque的优势在于计算高效,可压缩的列存储模式,缺点在于比纯文本多了一层定义带来的复杂性。 Hive数据表的字段修改,可以通过 alter table name change column column_name new_column_name type; 进行重命名和(或)类型修改。 文本文件由于其天然的简单性,数据中不含有类型信息,完全为数据本身,类型信息完全由Hive进行维护,所 阅读详情

情况描述

hive版本为: apache-hive-2.1.0
hadoop版本为: apache-hadoop-2.6.0-cdh-5.13.3

修改添加两个字段删除一个字段,但跟日志文件数据是一一对应的。
发现修改后,在hive中用mapreduce查询这两个新加的字段,值为null。
而用hive中用spark引擎却可以找到字段的值。

hive修改字段

通过alert table tablename add column(旧字段1,旧字段2,…,旧字段N,新字段1,新字段2)
修改。

修改

在hive中,修改后发现查询旧字段时正常的,而新加的字段1,字段2值为null。
使用spark引擎,发现该数据查询正常。

解决

分区按日期分,重新关联hdfs。
写个执行脚本,从开始日期的日志当最新的日志

脚本

	#!/bin/sh
	begin = $(date +%s -d "20151101")
	end = $(date +%s -d "20191101")
	db=sss
	tmpfile = /tmp/tmp.sql
	while[ $begin -le $end ]
	do
		dt = $(date +%Y%m%d -d @begin)
		echo "alert table tablename drop partition(date=$dt);alert table $db.tablename add
		partition(pdate=$dt) location '/$db/$dt/';" >> $tmpfile
		begin=$((begin+86400))
	done
	hive -f $tmpfile
hive修改字段名后数据丢失 1. 内部表Parquet测试 CREATE TABLE `test.user_active_all_parquet_inner`( `imp_date` date COMMENT '活跃日期', `user_id` string COMMENT '用户id') COMMENT '用户每日活跃列表' PARTITIONED BY (`dt` string) stored as parquet hive.exec.dynamic.partition.mode=nonstric; insert into . 阅读详情

相关推荐

HIVE实战处理(七) hive 新增字段 联级(cascade)和json格式的hive表

问题描述: 实际应用中,常常存在修改数据表结构的需求,比如:增加一个新字段。 如果使用一般的add columns(col1 string)的语句增加字段的话,对于旧分区中的col1将为空且无法更新,即便insert overwrite该分区也不会生效。 1、准备一个分区表test_partition 2、测试数据新增字段 alter table temp.test_partition add columns (hour string); 3、插入数据 插入失败,所以原来的插入方式对以前分分区是不生

sheep8521的博客 6624

hive表添加字段/修改字段导致的查询报错

一般由于业务需要,会对hive的表有增加字段的操作,如下: ALTER TABLE 库名.表名 add columns (字段名 字段类型 comment '注释') ; 但是上面这种语法只能是对表的当前和以后新的分区生效,若存在历史分区,那么MySQL上的元数据信息没有修改。 若查询历史分区,就会报上面的return code 2 解决方案: 1、直接在添加字段的时候加上 CASCADE ALTER TABLE 库名.表名 add columns (字段名 字段类型 comment '注释') .

一定要努力努力再努力的博客 5860

Hive 表中数据的增删查改

通过本文对 Hive 表中数据的增删查改操作的详细介绍,我们了解了各种操作的具体语法、适用场景以及一些注意事项。在实际使用 Hive 进行大数据处理时,需要根据业务需求灵活选择合适的操作方法,并且要时刻注意数据的准确性和操作的安全性,避免因误操作带来的数据丢失等问题。希望读者能通过本文更好地掌握 Hive 数据操作的相关技能,在大数据分析和管理工作中更加得心应手。希望以上内容对你有所帮助,如果你还有其他需求,比如对文中代码再详细注释、增加更多实际案例等,可以继续向我提问。

xjiet的博客 2101

分区表无法查询手动put进hdfs的数据问题

向hive表对应hdfs中新建目录,put数据后,在hive命令行查询,查不到put进分区的数据,下面记录处理方法: 分区既然是HDFS目录,那就可以通过hdfs put命令直接向HDFS添加分区。然而,元存储拥有所有表的元数据,它不会自动识别这些直接被添加到HDFS的分区。Hive提供了命令MSCK REPAIR TABLE tableName;,可以自动地更新元存储来恢复分区。如果基

men子烦高的烂笔头 3606

Hive分区表新增字段后插入数据显示为null

对Hive分区表进行新增字段后,会出现一个奇怪的情况,就是往 已经存在的 分区中装载数据后,某些字段的值显示为null,但实际情况是数据文件中对应的字段值其实是有值的。 下面我们重现该问题: 创建一个分区表 往表中装载数据 给表新增分区 再往表中装载数据并查询 数据装载成功后,通过查询可以看出,新创建的分区中数据显示正常,但是已经存在的time=20171010分区中新增数...

gxd520的专栏 3491

HIVE外部表删除重建指定HDFS目录后查询不到数据

HIVE外部表删除重建指定HDFS目录后查询不到数据,怎么办 删除了外部表,没有删除hdfs文件 重建了外部表又关联到之前的hdfs目录之后,select查询却没有数据 需要MSCK REPAIR TABLE+tablename,之后查询,数据就回来了。 MSCK REPAIR TABLE命令是做啥的 MSCK REPAIR TABLE命令主要是用来解决通过hdfs dfs -put或者hdfs api写入hive分区表的数据在hive中无法被查询到的问题。 hive有个服务叫metastore,

数据库 4631

Hive如何删除、添加、修改表中的字段

1、添加字段: alter table table_name add columns (column_1 string,column_2 string) 添加之后字段由于hive底层是文件和系列化的设计因此查数据会发现新增的列在所有已有列的后面 2、修改字段 alter table table_name change 已有列 修改名称 类型 comment ''; 3、删除列 Hive不能直接删除列,不然底层系列化就乱了,我们可以通过replace来替换字段,达到同样的效果 alter table ta

别人笑我太疯癫,我笑他人看不穿。 3万+

PacketTacer烟雾传感器读数为0的解决方法

PacketTacer烟雾传感器读数为0的解决方法

ChloeMax_的博客 1902

Hive数据查询异常,部分字段为Null

数据查询异常,部分字段为Null

编程技术、独立开发、技术资讯以及编程感悟等内容 967

微生物测序分析LEfSe

LEfse分析定义 LEfse分析即LDA Effect Size分析,可以实现多个分组之间的比较,还进行分组比较的内部进行亚组比较分析,从而找到组间在丰度上有显著差异的物种(即biomaker);

宁生信 5万+

Rust练手:从零手撸RISC-V架构虚拟机(一)(附完整代码)

使用Rust实现一个简单的RISC-V架构的CPU雏形,支持add,sub,addi三个指令。

qq_45983373的博客 2569

hive中 map字段的查询问题

在进行hive sql查询map字段值时报错: NoViableAltException(314@[225:12: ( KW_OVER ws= window_specification )?]) 仔细分析报错原因后再检查sql发现,sql中使用了关键字values,修改字段别名vals或使用上撇号引起来即可解决。 hive (sparktest)> select name,size(family) size,family['father'] father,family['sister'] .

manbufenglin的专栏 1105

软考29-上午题-【数据结构】-排序

数据结构7种排序

qq_31532983的博客 1579

hive 表创建及字段信息管理

1. 修改字段名或字段类型 hive表,能增加列,不可以删除列,但可以改列名; 对于分区表,要使用cascade才会对所有分区生效,否则,历史分区不会生效。 --修改字段名 alter table tablename change value1 value1_new string [cascade]; --修改字段类型 alter table tablename change column value1 value1 int [cascade]; --增加新字段 alter table tablen

MusicDancing的博客 1万+

无线Mesh组网全攻略:从原理、部署到调优与排障

对于布线困难的大户型、复式楼或园区,传统的无线中继往往面临带宽减半和链路不稳定的问题。无线Mesh网络通过多跳转发与自组织路由,让每个节点无需网线即可协作扩展覆盖,并依靠动态路径选择实现自愈。其核心技术涉及802.11s、HWMP路由协议,以及802.11k/v/r协同的无缝漫游,能有效提升终端切换体验。在实际部署中,设备选型、回程频段规划与布点位置直接决定网络质量。围绕无线Mesh的组网原理、设备选型、配置调优与故障排查,提供一套工程实践参考,帮助用户在复杂环境下构建稳定高效的无缝覆盖。

weixin_34098209的博客 271

RouterOS网桥VLAN实战:从零构建安全隔离的二层虚拟网络

本文详细讲解了如何在RouterOS上利用网桥和VLAN功能,从零开始构建安全隔离的二层虚拟网络。通过分步实战演示,涵盖核心概念、网桥创建、PVID设置、VLAN规则配置及安全过滤,帮助网络管理员实现办公、访客与服务器网络的逻辑隔离与灵活管理,提升网络安全性。

u9v0w的博客 504

hive 添加字段_Hive分区表动态添加字段

场景描述:公司埋点项目,数据从接口服务写入kafka集群,再从kafka集群消费写入HDFS文件系统,最后通过Hive进行查询输出。这其中存在一个问题就是:埋点接口中的数据字段是变化,后续会有少量字段添加进来。这导致Hive表结构也需要跟着变化,否则无法通过Hive查询到最新添加字段的数据。解决办法:为数据表添加字段,字段必须添加到已有字段的最后面。因为已经存在的数据是按照之前的表结构写入到HDF...

weixin_39738667的博客 3687

YOLOv8推理程序

YOLOv8单独推理,有时候我们自定义的模块算子无法正常转换为其他框架,而且需要做成应用,因此需要一个单独推理的程序,返回的是识别后的照片还有各个类别及其对应数量。文章最后给出Flask封装为Server以及调用的实例还有Client请求代码,支持几十路多线程并发,只需加载一次模型,后边推理即可。

AIOT魔法师 698

解决 Spark2.X 查询Hive分区表修改后的字段为null?

在 Spark 2.3 以后, Spark 增加参数, 设定 ORC 文件使用采用向量化 Reader, 但是会引申由于 Spark SQL 无法与 Hive SQL 采用同一 SerDe 从而对 Parquet/Hive 数据表产生处理上的不同, 因此需要限定如下参数从而让 Spark 使用 Hive 的SerDe.

一个写湿的程序猿 1762

【乐企文件生成工程】关于乐企文件生成工程的详细介绍

发票文件生成方式有两种思路:1、根据已有的OFD模板,动态替换ofd模板内容;之后将ofd转pdf(局限:单行问题不大)详情可以在此处了解2、根据html模板动态占位:该工程就是这种方式 ,目前效果良好,可看下图。拿去即用的源码!无任何保留,当然也并不是所有票种都支持(时间有限、精力有限、已经连着转了,要冒烟了…)

九七的博客 2031

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

4.Hive表更新字段信息,一次讲明白

Hive表更新字段是比较常见的操作,这里结合工作中的使用情况,进行了详细的介绍和演示。

每天进步一点点 6600

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

hivesql修改字段类型_Hive SQL基本使用详解

一:简介Hive是一个数据仓库基础的应用工具,在Hadoop中用来处理结构化数据,它架构在Hadoop之上,通过SQL来对数据进行操作。Hive 查询操作过程严格遵守Hadoop MapReduce 的作业执行模型,Hive 将用户的Hive SQL 语句通过解释器转换为MapReduce 作业提交到Hadoop 集群上,Hadoop 监控作业执行过程,然后返回作业执行结果给用户。Hive 并非为...

weixin_35323550的博客 3975

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hive 指定字段插入数据_Hive insert 字段表错位踩坑

1 问题描述往 Hive 表 insert 数据后,查询时出现个别行字段错位,插入语句如下:insert overwrite table A select col1,col2,col3 from table B where dayid = '';首先测试源表数据查询:select col1,col2,col3 from B查询来的数据没发现有什么异常;照理说逐字段查出来没问题,再逐字段插入应该不会...

weixin_39873177的博客 3026

Hive修改与字段名后Spark读取不到字段

方案一: 前提是有元数据库的权限 问题重现(例) 当我将数据存储格式改变,或者增加一列的时候,我习惯使用了alter table add …来实现 原来的表: ALTER TABLE test ADD COLUMNS (weight STRING) CASCADE 1 加上一列weight字段后(这里使用cascade就是为了同步到hivemetastore),我用spark向表插入一个带有weight字段的表,此时抛出异常 Exception in thread "main" org.

onway_goahead的博客 2466

Hive内表修改字段类型及注意事项

对于Hive内表,如果数据目录中已经存在数据,且不能改动的的情况下,如何修改表结构,以及处理此问题需要注意的问题

Yore - Home 965
上一篇: Linux awk 查找日志中某个字段长度最大的记录
下一篇: jdk1.7环境使用presto
SW_LCC
博客等级 码龄11年 4粉丝 114原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值