我正在尝试读取由HIVE表创建的HDFS文件。该文件为文本格式。当我打开文件时,我惊讶地发现这些行没有任何字段分隔符。
蜂巢可以读取文件...但非常非常慢。因此,我想使用火花作业阅读内容。
为了理解表的模式,我做了一个
describe extended foo
我看到这个输出
Detailed Table Information Table(tableName:foo, dbName:bar, owner:me,
createTime:1456445643, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:
[FieldSchema(name:some_ts, type:int, comment:null), FieldSchema(name:id,
type:string, comment:null), FieldSchema(name:t_p_ref, type:string,
comment:null) location:hdfs://nameservice1/user/hive/bar.db/ft,
inputFormat:org.apache.hadoop.mapred.TextInputFormat,
outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat,
compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null,
serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:
{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{},
skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[],
skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[],
parameters:{numFiles=79, COLUMN_STATS_ACCURATE=true,
transient_lastDdlTime=1456446229, totalSize=8992777753, numRows=20776467,
rawDataSize=8972001286}, viewOriginalText:null, viewExpandedText:null,
tableType:MANAGED_TABLE)
因此,输出根本不显示"delim"。那么我该如何读取此文件呢?有些字段是URL,因此很难尝试将其读取为固定宽度的文件类型
为什么不通过 spark sql 读取数据 - 它很高兴使用 HiveContext
读取 Hive 表? 在这种情况下,您也可以从数据帧正确设置数据类型。
所以像
val hc = new HiveContext(sc)
val df = hc.sql("select * from foo limit 10")
// perform operations on your dataframe ..