hive-TextInputformat自定义分隔符

hive自定义行分隔符 首先交代一下背景: 通过spring消费RMQ的数据写到hdfs,从一开始就预料到直接写textfile会有错行乱行的问题,所以一开始的方案是写parquet,经过验证后发现写parquet会有很多小文件(parquet文件落地后不能修改,不能追加),会对name node造成额外的压力,所以最终妥协写textfile 加自定义行分割符 查看hive默认的textfile 的inputformat 默认的TextInputFormat在hadoop-mapreduce-client-core包里面 阅读详情

hive-TextInputformat自定义分隔符

原创  2015年06月03日 11:38:27
  • 3440

前言

在一次利用sqoop将关系型数据库Oracle中的数据导入到hive的测试中,出现了一个分割符的问题。oracle中有字段中含有\n换行符,由于hive默认是以’\n’作为换行分割符的,所以用sqoop将oracle中数据导入到hive中导致hive中的数据条目跟原始数据库不一致,当时的处理方式是数据在导入到HDFS之前,用sqoop的参数将字段中的换行符都替换掉。

Sqoop在将数据从关系型数据库导入到HDFS时,支持将\n替换成自定义换行符(支持单字符自定义换行符),但是在hive中建表时用语句<row format delimited lines terminated by>指定自定义换行符会提示如下错误:

< linesterminated by>参数目前仅支持’\n’。不能指定自定义换行符,这样自定义换行符的数据就不能导入到hive中,基于以上考虑,本文简单说明了如何让hive实现自定义多个字符的换行和字段分割符,供大家参考。如有不足请批评指正。

环境

  • Hadoop:2.2
  • Hive:0.12(星环inceptor,支持原生hive)

目标

  • 分析hive自定义多字符串换行符;
  • 实现hive自定义多字符串字段分隔符;
  • 实现hivetextinputformat自定义编码格式的设置。

1.hive的序列化与反序列化

Hive中,默认使用的是TextInputFormat,一行表示一条记录。在每条记录(一行中),默认使用^A分割各个字段。

在有些时候,我们往往面对多行,结构化的文档,并需要将其导入Hive处理,此时,就需要自定义InputFormat、OutputFormat,以及SerDe了。

首先来理清这三者之间的关系,我们直接引用Hive官方说法:

SerDe is a short name for “Serializer and Deserializer.”

Hive uses SerDe (and !FileFormat) to read and write table rows.

HDFS files –> InputFileFormat –> <key, value> –> Deserializer –> Row object

Row object –> Serializer –> <key, value> –> OutputFileFormat –> HDFS files

总结一下,面对一个HDFS上的文件,Hive将如下处理(以读为例):

(1) 调用InputFormat,将文件切成不同的文档。每篇文档即一行(Row)。

(2) 调用SerDe的Deserializer,将一行(Row),切分为各个字段。

 

当HIVE执行INSERT操作,将Row写入文件时,主要调用OutputFormat、SerDe的Seriliazer,顺序与读取相反。

针对含有自定义换行符和字段分隔符的HDFS文件,本文仅介绍hive读取的过程的修改。

2 Hive默认采用的TextInputFormat类

首先建一个简单的表,然后用<describe  extended >命令查看该表的详细信息。

[sql]  view plain  copy
  1. transwarp> create table test1(id int);  
  2. OK  
  3. Time taken: 0.062seconds  
  4. transwarp>describe extended test1;  
  5. OK  
  6. id                  int                   None                 
  7.                     
  8. Detailed Table Information       
  9. Table(tableName:test1, dbName:default, owner:root,createTime:1409300219, lastAccessTime:0, retention:0,  
  10. sd:StorageDescriptor(  
  11. cols:[FieldSchema(name:id, type:int,comment:null)],location:hdfs://leezq-vm3:8020/inceptor1/user/hive/warehouse/test1,  
  12. inputFormat:org.apache.hadoop.mapred.TextInputFormat,outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat,  
  13. compressed:false,  
  14. numBuckets:-1,  
  15. serdeInfo:SerDeInfo(  
  16. name:null,  
  17. serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe,  
  18. parameters:{serialization.format=1}),  
  19. bucketCols:[], sortCols:[], parameters:{},skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[],skewedColValueLocationMaps:{}), storedAsSubDirectories:false),partitionKeys:[],  
  20. parameters:{transient_lastDdlTime=1409300219},  
  21. viewOriginalText:null, viewExpandedText:null,tableType:MANAGED_TABLE  
  22. )         
  23. Time taken: 0.121 seconds, Fetched: 3 row(s)  

从上面可以看出,默认状态下,hive的输入和输出调用的类分别为:

[java]  view plain  copy
  1. inputFormat:org.apache.hadoop.mapred.TextInputFormat,  
  2. outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat,  

虽然现在现在hadoop现在升级到2.X版本,hive依然采用老版的mapred接口。

我们要改写的就是类TextInputFormat。

2.1类 TextInputFormat

类TextInputFormat在hadoop-mapreduce-client-core-2.2.0.jar中。

重点看类中getRecordReader方法,该方法返回LineRecordReader对象。并且该方法中已经实现了接收自定义字符串作为换行符的代码,只要建表前在hive的CLI界面上输入set textinputformat.record.delimiter=<自定义换行字符串>;即可实现自定义多字符换行符。


2.2类LineRecordReader

为了进一步查看其实现原理,我们进一步看LineRecordReader(package org.apache.hadoop.mapred. LineRecordReader)类。


查看该类的构造函数,该类调用org.apache.hadoop.util.LineReader(在包hadoop-common-2.2.0.jar中)获取每行的数据,把参数recordDelimiter传给类对象LineReader,类LineReader中的readLine(Text str, int maxLineLength, intmaxBytesToConsume)方法负责按照用户自定义分隔符返回每行的长度,如果用户不设定 textinputformat.record.delimiter的值, recordDelimiter的值为null,这时readLine方法就会按照默认’\n’分割每行。readLine的代码如下:


通过读源码可以看到,原始的hive可以通过设置参数的方法实现多字符自定义换行符(textFile的存储方式),通过上图中readCustomLine方法获得用户自定义换行符的字符串实现自动换行,每行最大可支持2147483648大小。但是要想实现自定义多字符的字段分隔符和自定义编码格式的设置,还需要对源码进行改写。下面就讲一下改写的步骤。

3 自定义TextInputFormat

  • 实现自定义多字符串的字段分割符
  • 实现自定义编码格式的设置

首先建一个空的java工程,添加必须的五个包


然后新建两个类SQPTextInputFormat和SQPRecordReader,将TextInputFormat和LineRecordReader的代码分别拷贝过来。

在SQPTextInputFormat中添加对自定义编码格式的设置。(对换行符的参数进行了更名,将textinputformat.record.delimiter改成了textinputformat.record.linesep)

[java]  view plain  copy
  1. //======================================================  
  2.   String delimiter = job.get("textinputformat.record.linesep");  
  3.   this.encoding = job.get("textinputformat.record.encoding",defaultEncoding);  
  4.   byte[] recordDelimiterBytes = null;  
  5.   if (null != delimiter) {//Charsets.UTF_8  
  6.     recordDelimiterBytes = delimiter.getBytes(this.encoding);  
  7.   }  
  8.   return new SQPRecordReader(job, (FileSplit)genericSplit, recordDelimiterBytes);  
  9.    

在SQPRecordReader构造函数中添加对字段分隔符和编码格式的设置。

[java]  view plain  copy
  1. //======================================================  
  2.     this.FieldSep = job.get("textinputformat.record.fieldsep",defaultFSep);  
  3. this.encoding = job.get("textinputformat.record.encoding",defaultEncoding);  
  4.    

在SQPRecordReader的next()方法中添加对字段分割符的替换和对编码格式的设置。

[java]  view plain  copy
  1. //======================================================  
  2.     if (encoding.compareTo(defaultEncoding) != 0) {  
  3.               String str = new String(value.getBytes(), 0,value.getLength(), encoding);  
  4.               value.set(str);  
  5.          }  
  6.       if (FieldSep.compareTo(defaultFSep) != 0) {  
  7.               String replacedValue = value.toString().replace(FieldSep, defaultFSep);  
  8.               value.set(replacedValue);  

详细的代码如下:

[java]  view plain  copy
  1. package com.learn.util.hadoop;  
  2.   
  3. //import com.google.common.base.Charsets;  
  4.   
  5. import java.io.IOException;  
  6.   
  7. import org.apache.hadoop.fs.FileSystem;  
  8. import org.apache.hadoop.fs.Path;  
  9. import org.apache.hadoop.io.LongWritable;  
  10. import org.apache.hadoop.io.Text;  
  11. import org.apache.hadoop.io.compress.CompressionCodec;  
  12. import org.apache.hadoop.io.compress.CompressionCodecFactory;  
  13. import org.apache.hadoop.io.compress.SplittableCompressionCodec;  
  14. import org.apache.hadoop.mapred.*;  
  15.   
  16. public class SQPTextInputFormat extends FileInputFormat<LongWritable, Text>  
  17. implements JobConfigurable  
  18. {  
  19. private CompressionCodecFactory compressionCodecs = null;  
  20. private final static String defaultEncoding = "UTF-8";//"US-ASCII""ISO-8859-1""UTF-8""UTF-16BE""UTF-16LE""UTF-16"  
  21. private String encoding = null;  
  22.   
  23. public void configure(JobConf conf) {  
  24.   this.compressionCodecs = new CompressionCodecFactory(conf);  
  25. }  
  26.   
  27. protected boolean isSplitable(FileSystem fs, Path file) {  
  28.   CompressionCodec codec = this.compressionCodecs.getCodec(file);  
  29.   if (null == codec) {  
  30.     return true;  
  31.   }  
  32.   return codec instanceof SplittableCompressionCodec;  
  33. }  
  34.   
  35. public RecordReader<LongWritable, Text> getRecordReader(InputSplit genericSplit, JobConf job, Reporter reporter)  
  36.   throws IOException  
  37. {  
  38.   reporter.setStatus(genericSplit.toString());  
  39.   String delimiter = job.get("textinputformat.record.linesep");  
  40.   this.encoding = job.get("textinputformat.record.encoding",defaultEncoding);  
  41.   byte[] recordDelimiterBytes = null;  
  42.   if (null != delimiter) {//Charsets.UTF_8  
  43.     recordDelimiterBytes = delimiter.getBytes(this.encoding);  
  44.   }  
  45.   return new SQPRecordReader(job, (FileSplit)genericSplit, recordDelimiterBytes);  
  46. }  
  47. }  


[java]  view plain  copy
  1. package com.learn.util.hadoop;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.InputStream;  
  5.   
  6. import org.apache.commons.logging.Log;  
  7. import org.apache.commons.logging.LogFactory;  
  8. import org.apache.hadoop.classification.InterfaceAudience.LimitedPrivate;  
  9. import org.apache.hadoop.classification.InterfaceStability.Unstable;  
  10. import org.apache.hadoop.conf.Configuration;  
  11. import org.apache.hadoop.fs.FSDataInputStream;  
  12. import org.apache.hadoop.fs.FileSystem;  
  13. import org.apache.hadoop.fs.Path;  
  14. import org.apache.hadoop.fs.Seekable;  
  15. import org.apache.hadoop.io.LongWritable;  
  16. import org.apache.hadoop.io.Text;  
  17. import org.apache.hadoop.io.compress.CodecPool;  
  18. import org.apache.hadoop.io.compress.CompressionCodec;  
  19. import org.apache.hadoop.io.compress.CompressionCodecFactory;  
  20. import org.apache.hadoop.io.compress.Decompressor;  
  21. import org.apache.hadoop.io.compress.SplitCompressionInputStream;  
  22. import org.apache.hadoop.io.compress.SplittableCompressionCodec;  
  23. import org.apache.hadoop.io.compress.SplittableCompressionCodec.READ_MODE;  
  24. import org.apache.hadoop.util.LineReader;  
  25. import org.apache.hadoop.mapred.RecordReader;  
  26. import org.apache.hadoop.mapred.FileSplit;  
  27.   
  28. //@InterfaceAudience.LimitedPrivate({"MapReduce", "Pig"})  
  29. //@InterfaceStability.Unstable  
  30. public class SQPRecordReader  
  31.   implements RecordReader<LongWritable, Text>  
  32. {  
  33.   private static final Log LOG = LogFactory.getLog(SQPRecordReader.class.getName());  
  34.   
  35.   private CompressionCodecFactory compressionCodecs = null;  
  36.   private long start;  
  37.   private long pos;  
  38.   private long end;  
  39.   private LineReader in;  
  40.   private FSDataInputStream fileIn;  
  41.   private final Seekable filePosition;  
  42.   int maxLineLength;  
  43.   private CompressionCodec codec;  
  44.   private Decompressor decompressor;  
  45.   private String FieldSep;          //field separator  
  46.   private static final String defaultFSep="\001";  
  47.   private final static String defaultEncoding = "UTF-8";//"US-ASCII""ISO-8859-1""UTF-8""UTF-16BE""UTF-16LE""UTF-16"  
  48.   private String encoding = null;  
  49.   
  50.   public SQPRecordReader(Configuration job, FileSplit split)  
  51.     throws IOException  
  52.   {  
  53.     this(job, split, null);  
  54.   }  
  55.   
  56.   public SQPRecordReader(Configuration job, FileSplit split, byte[] recordDelimiter) throws IOException  
  57.   {  
  58.     this.maxLineLength = job.getInt("mapreduce.input.linerecordreader.line.maxlength", 2147483647);  
  59.     this.FieldSep = job.get("textinputformat.record.fieldsep",defaultFSep);  
  60.     this.encoding = job.get("textinputformat.record.encoding",defaultEncoding);  
  61.     this.start = split.getStart();  
  62.     this.end = (this.start + split.getLength());  
  63.     Path file = split.getPath();  
  64.     this.compressionCodecs = new CompressionCodecFactory(job);  
  65.     this.codec = this.compressionCodecs.getCodec(file);  
  66.   
  67.     FileSystem fs = file.getFileSystem(job);  
  68.     this.fileIn = fs.open(file);  
  69.     if (isCompressedInput()) {  
  70.       this.decompressor = CodecPool.getDecompressor(this.codec);  
  71.       if ((this.codec instanceof SplittableCompressionCodec)) {  
  72.         SplitCompressionInputStream cIn = ((SplittableCompressionCodec)this.codec).createInputStream(this.fileIn, this.decompressor, this.start, this.end, SplittableCompressionCodec.READ_MODE.BYBLOCK);  
  73.   
  74.         this.in = new LineReader(cIn, job, recordDelimiter);  
  75.         this.start = cIn.getAdjustedStart();  
  76.         this.end = cIn.getAdjustedEnd();  
  77.         this.filePosition = cIn;  
  78.       } else {  
  79.         this.in = new LineReader(this.codec.createInputStream(this.fileIn, this.decompressor), job, recordDelimiter);  
  80.         this.filePosition = this.fileIn;  
  81.       }  
  82.     } else {  
  83.       this.fileIn.seek(this.start);  
  84.       this.in = new LineReader(this.fileIn, job, recordDelimiter);  
  85.       this.filePosition = this.fileIn;  
  86.     }  
  87.   
  88.     if (this.start != 0L) {  
  89.       this.start += this.in.readLine(new Text(), 0, maxBytesToConsume(this.start));  
  90.     }  
  91.     this.pos = this.start;  
  92.   }  
  93.   
  94.   public SQPRecordReader(InputStream in, long offset, long endOffset, int maxLineLength)  
  95.   {  
  96.     this(in, offset, endOffset, maxLineLength, null);  
  97.   }  
  98.   
  99.   public SQPRecordReader(InputStream in, long offset, long endOffset, int maxLineLength, byte[] recordDelimiter)  
  100.   {  
  101.     this.maxLineLength = maxLineLength;  
  102.     this.in = new LineReader(in, recordDelimiter);  
  103.     this.start = offset;  
  104.     this.pos = offset;  
  105.     this.end = endOffset;  
  106.     this.filePosition = null;  
  107.   }  
  108.   
  109.   public SQPRecordReader(InputStream in, long offset, long endOffset, Configuration job)  
  110.     throws IOException  
  111.   {  
  112.     this(in, offset, endOffset, job, null);  
  113.   }  
  114.   
  115.   public SQPRecordReader(InputStream in, long offset, long endOffset, Configuration job, byte[] recordDelimiter)  
  116.     throws IOException  
  117.   {  
  118.     this.maxLineLength = job.getInt("mapreduce.input.linerecordreader.line.maxlength", 2147483647);  
  119.   
  120.     this.in = new LineReader(in, job, recordDelimiter);  
  121.     this.start = offset;  
  122.     this.pos = offset;  
  123.     this.end = endOffset;  
  124.     this.filePosition = null;  
  125.   }  
  126.   
  127.   public LongWritable createKey() {  
  128.     return new LongWritable();  
  129.   }  
  130.   
  131.   public Text createValue() {  
  132.     return new Text();  
  133.   }  
  134.   
  135.   private boolean isCompressedInput() {  
  136.     return this.codec != null;  
  137.   }  
  138.   
  139.   private int maxBytesToConsume(long pos) {  
  140.     return isCompressedInput() ? 2147483647 : (int)Math.min(2147483647L, this.end - pos);  
  141.   }  
  142.   
  143.   private long getFilePosition()  
  144.     throws IOException  
  145.   {  
  146.     long retVal;  
  147.     if ((isCompressedInput()) && (null != this.filePosition))  
  148.       retVal = this.filePosition.getPos();  
  149.     else {  
  150.       retVal = this.pos;  
  151.     }  
  152.     return retVal;  
  153.   }  
  154.   
  155.   public synchronized boolean next(LongWritable key, Text value)  
  156.     throws IOException  
  157.   {  
  158.     while (getFilePosition() <= this.end) {  
  159.       key.set(this.pos);  
  160.   
  161.       int newSize = this.in.readLine(value, this.maxLineLength, Math.max(maxBytesToConsume(this.pos), this.maxLineLength));  
  162.         
  163.       if (newSize == 0) {  
  164.         return false;  
  165.       }  
  166.         
  167.       if (encoding.compareTo(defaultEncoding) != 0) {  
  168.             String str = new String(value.getBytes(), 0, value.getLength(), encoding);  
  169.             value.set(str);  
  170.         }  
  171.         
  172.       if (FieldSep.compareTo(defaultFSep) != 0) {  
  173.             String replacedValue = value.toString().replace(FieldSep, defaultFSep);  
  174.             value.set(replacedValue);  
  175.         }  
  176.         
  177.       this.pos += newSize;  
  178.       if (newSize < this.maxLineLength) {  
  179.         return true;  
  180.       }  
  181.   
  182.       LOG.info("Skipped line of size " + newSize + " at pos " + (this.pos - newSize));  
  183.     }  
  184.   
  185.     return false;  
  186.   }  
  187.   
  188.   public synchronized float getProgress()  
  189.     throws IOException  
  190.   {  
  191.     if (this.start == this.end) {  
  192.       return 0.0F;  
  193.     }  
  194.     return Math.min(1.0F, (float)(getFilePosition() - this.start) / (float)(this.end - this.start));  
  195.   }  
  196.   
  197.   public synchronized long getPos() throws IOException  
  198.   {  
  199.     return this.pos;  
  200.   }  
  201.   
  202.   public synchronized void close() throws IOException {  
  203.     try {  
  204.       if (this.in != null)  
  205.         this.in.close();  
  206.     }  
  207.     finally {  
  208.       if (this.decompressor != null)  
  209.         CodecPool.returnDecompressor(this.decompressor);  
  210.     }  
  211.   }  
  212. }  

4 自定义InputFormat的使用

1.      将程序打成jar包,放在/usr/lib/hive/lib和各个节点的/usr/lib/hadoop-mapreduce目录下。

在hvie的CLI命令行界面可以设置如下参数,分别修改编码格式、自定义字段分隔符和自定义换行符。

[sql]  view plain  copy
  1. set textinputformat.record.encoding=UTF-8;  
  2. //"US-ASCII""ISO-8859-1""UTF-8""UTF-16BE""UTF-16LE""UTF-16"  
  3. set textinputformat.record.fieldsep=,;  
  4. set textinputformat.record.linesep=|+|;  


2.      建表,标示采用的Inputformat和OutputFormat,其中org.apach…noreKeyTextOutputFormat 是hive默认的OutputFormat分隔符。

[sql]  view plain  copy
  1. create table test  
  2. (  
  3. id string,  
  4. name string  
  5. )  
  6. stored as  
  7. INPUTFORMAT'com.learn.util.hadoop.SQPTextInputFormat'  
  8. OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'  

3.      Load 语句加载数据

实例

测试数据:


测试数据中有一个字段中含有换行符。字段分隔符和行分隔符分别为’,’和“|+|”。

分别设置字段分隔符和行分割符,并建表指定Inputformat和outputformat如下图所示,


Select  * 查询如下:


Select count(*)如下:


结果是3行,正确。

Select  id  from test1如下:


Select  name from test1:


Select  count(name) from test1:



结果正确。

Select  name,id from test1:


Select  id,name from test1;


Id和name两个字段单独查没问题,但是调用mapreduce一起查的时候带有‘\n’的字段显示上出了问题。

Select  id,name from test1 where id=13:


单独查询每个字段时候和查询总行数的时候都是没问题的,这说明改写的InputFormat起作用了,上面的出现的NULL问题应该是hive显示的问题。



hive使基本使用 创建表 create table test2 (id int,name string)row format delimited fields terminated by ','; load本地数据到表 load data local inpath &amp;amp;amp;amp;amp;amp;amp;quot;/inceptor1/tmp/bb.txt&amp;amp;amp;amp;amp;amp;amp;quot; overwrite into table test; 阅读详情

相关推荐

数据分析项目:直播电商用户流失分析

其中,'Tenure'(在网时长)可能是影响用户流失的关键因素,意味着用户在平台上的停留时间越长,流失的可能性可能越低,这提示平台应注重提高用户粘性,增加用户在平台上的活跃度和停留时间。)的分析,挖掘用户流失的原因和模式,分析发现用户投诉处理效率(Complain)、距上次消费时长(DaySinceLastOrder)、会员生命周期(Tenure)等8项核心指标对流失预测贡献度达87%,模型准确率94.58%,并提出相应的建议。重视用户的满意度,及时处理用户的投诉和反馈,不断改进平台的服务和功能。

Nervousr的博客 2459

hadoop之TextInputFormat

打发士大夫

Hao_JunJie的博客 931

【STM32G474实战】RS485通信的DMA优化策略与性能对比

本文深入探讨了在STM32G474微控制器上优化RS485通信的DMA策略。通过对比轮询、中断和DMA三种数据传输方式的代码实现与性能,揭示了DMA在解放CPU、降低占用率方面的巨大优势。文章提供了详细的DMA配置指南、高级应用技巧(如结合空闲中断)以及一个高可靠通信框架的实战思路,旨在帮助开发者构建高效、实时的工业控制系统。

weixin_29268331的博客 304

Hive中的InputFormat、OutputFormat与SerDe

自定义多行分隔,列分隔 转载:http://www.coder4.com/archives/4031

An342647823的专栏 1万+

银河麒麟V10开机卡Logo?别慌,手把手教你进单用户模式修复(附详细命令)

本文详细解析银河麒麟V10操作系统启动时卡Logo的故障原因,并提供进入单用户模式的完整解决方案。通过GRUB引导菜单修改启动参数,执行文件系统检查、图形服务修复等关键命令,帮助用户快速恢复系统正常运行,适用于运维人员和普通用户应对紧急启动问题。

weixin_30522183的博客 393

基于Sentinel-2(哨兵2)遥感卫星的植被覆盖度提取

基于Sentinel-2(哨兵2)遥感卫星的植被覆盖度提取 一、Sentinel-2简单介绍 哨兵-2系列卫星的主要载荷多光谱成像仪拥有13个谱段,从可见光到近红外再到短波红外,空间分辨率从10m到60m,能实现全所未有的陆地海洋监测水平。其幅宽高达290KM,且A、B双星组合,覆盖能力比美国Landsat8卫星强很多。目前哨兵-2A和哨兵-2B已经实现了5天的重访时间,即使在之前仅有单颗卫星时,...

weixin_44143671的博客 2万+

Hive 多字符分隔列或行

Hive 的默认分隔符为: 字段:\001 行:\n 当数据中包含了例如 \001、\n 时,就需要自定义分隔符了。并且,自定义的分隔符要为多字符,单字符重复的概率太高了。 Hive 的 MultiDelimitSerDe 只支持字段的多字符分隔,行的换行符不支持自定义修改。 这里重写 TextInputFormat ,用来支持行的多字符分隔。 依赖 <dependencies> <dependency> <groupId>

mc的博客 975

2025年VSCode AI插件实战:如何用Devika+Continue+Tabby三件套10倍提升开发效率

本文详细介绍了2025年VSCode AI插件Devika、Continue和Tabby的三件套组合,如何通过智能开发工作流10倍提升开发效率。从项目架构生成到上下文感知辅助,再到本地化智能编码,这套方案实现了从需求分析到代码生成的全流程自动化,特别适合中大型项目开发。

weixin_26911099的博客 273

Hive的列分隔符和行分隔符

在创建Hive表时,默认行分隔符"^A",列分隔符"\n",这两项也是可以设置的。在实际开发中,一般默认使用默认的分隔符,当然有些场景下也会自定义分隔符。 创建表1: spark-hive use test_db; # 创建外部表 CREATE EXTERNAL TABLE test_tb ( user_id bigint COMMENT '用户ID', user_name string ...

数据与工程工作,AI大模型应用 1万+

基于容积卡尔曼滤波的弹目相对姿态估计算法及其在导弹末端制导中的应用

本文针对导弹末端制导中的强非线性姿态估计问题,提出了一种基于容积卡尔曼滤波(CKF)的弹目相对姿态估计算法。通过建立包含视线角、角速率和相对距离的6维状态模型,利用三阶球面-相径容积准则精确逼近非线性状态分布,避免了传统EKF的线性化误差。在MATLAB/Simulink仿真中,CKF表现出比EKF更高的视线角速率估计精度和更快的收敛速度,最终显著减小了脱靶量,验证了其在提升导弹末端制导精度方面的有效性。该算法计算复杂度适中,适合工程实现,为高精度非线性姿态估计提供了新思路。

AI的内部世界的博客 105

Jetson Orin 上拉取 GMSL 相机流并保存在 DMA 内存中

本文介绍了在NVIDIA Jetson Orin平台上实现GMSL相机DMA内存共享的低延迟采集方案。通过V4L2+NvBufSurface技术,将相机数据直接存入DMA缓冲区,避免传统流程中的CPU拷贝开销。文章详细说明了设备初始化、DMA缓冲区分配、V4L2绑定等关键步骤,并展示了调用示例。该方案支持零拷贝访问,适用于AI推理、硬件编码等场景,能显著提升车载视觉系统的实时性能,为多路GMSL相机接入和低延迟处理提供了高效解决方案。

J。 696

hive指定行分割符和列分隔符

指定行分割符和列分隔符 由于默认的是能指定列分隔符,但是不可以指定行分隔符,所以这个时候,我们存在hdfs上的数据有的可能是\001是列分隔符,和\002是分隔符这个时候就得重写一下inputformat来使用了。    package com.hcr.hadoop.hive; import java.io.IOException; import java.io.UnsupportedE

幸运小侯子 1万+

Camera HAL Camx — DRQ总结

Camera HAL — DRQ(延迟请求队列)总结 DRQ是CAMX核心层的依赖驱动延迟执行调度器,解决Node处理请求时依赖未就绪的问题。其主要特点包括: 核心功能:当Node处理请求时缺少必要输入(property/metadata/fence),DRQ将其挂起并在依赖满足后重新调度,避免阻塞流水线或丢帧。 系统架构:Session持有主DRQ实例,管理该Session下所有Pipeline Node的依赖;CHI context另有独立DRQ实例专门处理Chi fence同步。 关键数据结构: De

DU_YULIN的博客 76

hive指定多个字符作为列分隔符的问题说明

1、问题:HDFS文件上列分隔符是##,hive建表时直接用##,发现输出的字段和文件不一致。       建表语句如下:       ROW FORMAT DELIMITED FIELDS TERMINATED BY '##' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORM

医疗影像检索 8998

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

6、Hive的特殊分隔符处理

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33805992的博客 361

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Hive建表出现 LINES TERMINATED BY only supports newline '\n' right now.解决办法

Hive建表语句如下: CREATE EXTERNAL TABLE IF NOT EXISTS students ( id int, name string, gender string, birthday Date, clazz string, phone string, loc string) COMMENT 'student details' ROW FORMAT DELIMITED...

养猪少年日记的博客 7471

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Hive中的自定义分隔符(包含Hadoop和Hive详细安装)

导出到 HDFS 或者本地的数据文件,需要直接导入 Hive 时,有时包含特殊字符,按照给定的字段单字符分隔符或者默认换行分隔符,插入到 Hive 的数据可能不是我们预期的,此时需要我们自定义 Hive 的分隔符。同时Hive默认只支持单字符,如果需要支持多字符作为分隔符,可以按照如下方式重写输入格式化类来自定义分割符,也可以进行一些设置,并在建表时声明出来分割方式。下面会分别介绍这两种方式。在介绍之前先准备环境,介绍一下Hadoop和Hive的安装。

Yore - Home 3858

Hive 实际开发问题:||分割符,特殊分隔符处理

今天遇到一个问题,上游给过来的建表

光脚虾的博客 3314

Hive--建表以及表字段分隔符

Hive建表以及表字段分隔符 Tips: 1.最后一个字段不需要加逗号; 2.external 是外部表的标志,不加关键字则是内部表,外部表删不掉数据。一般做测试表的话建议建内部表,删除方便; 3.分区字段 partition by('XXXX' TYPE,'OOOO' TYPE...)不能出现在创建表时的字段中,换句话说,分区字段字段也是新的字段,在别的表中用的时候和普通字段使用方法是一样的; 建表语句示例: CREATE external TABLE `table1`( `name` str

修行的博客 3897

hive多分隔符的解决方案

题记:   近期在做某个大型银行的大数据项目,当在处理非结构化数据时,却发现他们给的数据并不符合hive和pig的处理要求,数据每行必须需要多个分割符才能完美处理,一下午也没有想到完美的办法解决,今天重新审视了一下整个过程。看来hive的命令行没法搞定了。于是乎,只能通过代码来搞定。 1、重新实现hive的InputFormat了,别急放码过来 1 package ...

diaojiao1307的博客 244

hive不支持多个字符作为分隔符的解决方案

题记:   近期在做某个大型银行的大数据项目,当在处理非结构化数据时,却发现他们给的数据并不符合hive和pig的处理要求,数据每行必须需要多个分割符才能完美处理,一下午也没有想到完美的办法解决,今天重新审视了一下整个过程。看来hive的命令行没法搞定了。于是乎,只能通过代码来搞定。 1、重新实现hive的InputFormat了,别急放码过来 package hiveStre...

diaojiao1307的博客 302

0026-Hive使用十六进制分隔符异常分析

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34415923的博客 344

疯狂Hive之DDL操作一(二)

DDL操作 Hive中的表如何与HDFS上文件中的数据产生映射关系? 在HDFS上创建映射文件 在node01上创建文件夹:mkdir hivedata 在hivedata中新建一个文件1.txt文件: cd hivedata vi 1.txt 在1.txt中编写如下数据 将1.txt文件上传到HDFS上的hivedata目录中 HDFS新建hivedata目录:hadoop fs -mkdir /hivedata 上传1.txt文件到hivedata目录:hado...

关注我!带你一路 "狂飙" 到底! 1089

hive自定义InputFormat

自定义分隔符 package com.lwz.inputf; import java.io.IOException; import java.io.InputStream; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import or...

疯狂的矩阵 797
上一篇: Hive实战案例3——级联求和accumulate
下一篇: Hive2.0中HiveServer2的WEB UI界面
王树民
博客等级 码龄10年 912粉丝 560原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值