我正在对Hive可用的存储格式进行一些测试,并使用Parquet和ORC作为主要选项.我使用默认压缩包含ORC一次,使用Snappy包含一次.
我已经阅读了许多文件,说明Parquet在时间/空间复杂性方面比ORC更好,但我的测试与我经历的文件相反.
关注我的数据的一些细节.
Table A- Text File Format- 2.5GB
Table B - ORC - 652MB
Table C - ORC with Snappy - 802MB
Table D - Parquet - 1.9 GB
Run Code Online (Sandbox Code Playgroud)
就我的桌子的压缩而言,实木复合地板是最糟糕的.
我对上表的测试得出以下结果.
行计数操作
Text Format Cumulative CPU - 123.33 sec
Parquet Format Cumulative CPU - 204.92 sec
ORC Format Cumulative CPU - 119.99 sec
ORC with SNAPPY Cumulative CPU - 107.05 sec
Run Code Online (Sandbox Code Playgroud)
列操作的总和
Text Format Cumulative CPU - 127.85 sec
Parquet Format Cumulative CPU - 255.2 sec
ORC Format Cumulative …Run Code Online (Sandbox Code Playgroud) 我想知道是否有某种方法可以为多列上的spark数据帧指定自定义聚合函数.
我有一个类似这样的表(名称,项目,价格):
john | tomato | 1.99
john | carrot | 0.45
bill | apple | 0.99
john | banana | 1.29
bill | taco | 2.59
Run Code Online (Sandbox Code Playgroud)
至:
我想将每个人的项目和成本汇总到这样的列表中:
john | (tomato, 1.99), (carrot, 0.45), (banana, 1.29)
bill | (apple, 0.99), (taco, 2.59)
Run Code Online (Sandbox Code Playgroud)
这在数据帧中是否可行?我最近了解到collect_list它,但它似乎只适用于一个专栏.
如果表是ORC show create table,则在执行a 然后执行结果create table语句时发出问题.
使用show create table,你得到这个:
STORED AS INPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcInputFormat’
OUTPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat’
Run Code Online (Sandbox Code Playgroud)
但是如果使用这些子句创建表,则在选择时会出现转换错误.错误喜欢:
异常java.io.IOException失败:java.lang.ClassCastException:org.apache.hadoop.hive.ql.io.orc.OrcStruct无法强制转换为org.apache.hadoop.io.BinaryComparable
要解决这个问题,只需将create table语句更改为STORED AS ORC
But,正如答案在类似问题中所述:
在Hive中'InputFormat,OutputFormat'和'Stored as'之间有什么区别?.
我无法弄清楚原因.
是否可以将 Pandas 数据帧从 ORC 文件转换为 ORC 文件?我可以在 parquet 文件中转换 df,但该库似乎没有 ORC 支持。Python 有可用的解决方案吗?如果不是,最好的策略是什么?一种选择是使用外部工具将镶木地板文件转换为 ORC,但我不知道在哪里可以找到它。
在之前的版本中,我们曾经在RDD上使用'saveAsOrcFile()'方法.现在已经不见了!如何以ORC文件格式保存DataFrame中的数据?
def main(args: Array[String]) {
println("Creating Orc File!")
val sparkConf = new SparkConf().setAppName("orcfile")
val sc = new SparkContext(sparkConf)
val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
val people = sc.textFile("/apps/testdata/people.txt")
val schemaString = "name age"
val schema = StructType(schemaString.split(" ").map(fieldName => {if(fieldName == "name") StructField(fieldName, StringType, true) else StructField(fieldName, IntegerType, true)}))
val rowRDD = people.map(_.split(",")).map(p => Row(p(0), new Integer(p(1).trim)))
//# Infer table schema from RDD**
val peopleSchemaRDD = hiveContext.createDataFrame(rowRDD, schema)
//# Create a table from schema**
peopleSchemaRDD.registerTempTable("people")
val results = hiveContext.sql("SELECT * FROM …Run Code Online (Sandbox Code Playgroud) 我有一个映射在Hive(EMR-5.11.0上的v2.3.2)的外部表,我需要每周更新一次新数据.合并包含条件upsert语句.
表的位置在s3中,数据始终存在(创建一次,我们只需要用新数据更新它).
我已经阅读了这篇博客,关于在事务表(https://dzone.com/articles/update-hive-tables-the-easy-way-part-2-hortonworks)上使用ACID功能在Hive中合并数据,但是我可以看到,唯一的解决方案是将我的外部表复制到临时Hive内部表,即集群和事务,然后只在该表上我可以进行合并并使用新的合并后覆盖我的原始数据.
这个表非常大(大约10GB的数据),所以我想避免在每次合并操作之前复制它.
有没有办法创建内部表并将其映射到现有数据?还是有另一种方法,除了合并语句,在Hive外部表上执行upsert?
非常感谢提前!
我正在使用 Spark 1.6.1,我正在尝试将数据帧保存为 orc 格式。
我面临的问题是save方法非常慢,每个执行器上50M的orc文件大约需要6分钟。这就是我保存数据框的方式
dt.write.format("orc").mode("append").partitionBy("dt").save(path)
Run Code Online (Sandbox Code Playgroud)
我尝试对也使用 orc 格式的 hive 表使用 saveAsTable,这似乎快了大约 20% 到 50%,但这种方法有它自己的问题 - 似乎当任务失败时,重试总是会失败,因为文件已经存在。这就是我保存数据框的方式
dt.write.format("orc").mode("append").partitionBy("dt").saveAsTable(tableName)
Run Code Online (Sandbox Code Playgroud)
保存方法如此缓慢是否有原因?难道我做错了什么?
这是一个简单的程序:
searchArgument)来读取文件问题:
read(..)方法似乎返回所有记录,完全忽略了searchArguments.这是为什么?笔记:
我无法找到任何有用的单元测试来演示谓词下推如何在Orc(Orc on GitHub)中工作.我也无法找到有关此功能的任何明确文档.尝试看Spark和Presto代码,但我找不到任何有用的东西.
以下代码是https://github.com/melanio/codecheese-blog-examples/tree/master/orc-examples/src/main/java/codecheese/blog/examples/orc的修改版本
public class TestRoundTrip {
public static void main(String[] args) throws IOException {
final String file = "tmp/test-round-trip.orc";
new File(file).delete();
final long highestX = 10000L;
final Configuration conf = new Configuration();
write(file, highestX, conf);
read(file, highestX, conf);
}
private static void read(String file, long highestX, Configuration conf) throws IOException {
Reader reader = OrcFile.createReader(
new Path(file), …Run Code Online (Sandbox Code Playgroud) 从spark启用orc索引的选项是什么?
df
.write()
.option("mode", "DROPMALFORMED")
.option("compression", "snappy")
.mode("overwrite")
.format("orc")
.option("index", "user_id")
.save(...);
Run Code Online (Sandbox Code Playgroud)
我正在编写.option("index", uid),我还要把它放在那里从orc索引列"user_id".
我正在尝试使用 Spark Structured Streaming - writeStreamAPI 写入外部分区 Hive 表。
CREATE EXTERNAL TABLE `XX`(
`a` string,
`b` string,
`b` string,
`happened` timestamp,
`processed` timestamp,
`d` string,
`e` string,
`f` string )
PARTITIONED BY (
`year` int, `month` int, `day` int)
CLUSTERED BY (d)
INTO 6 BUCKETS
STORED AS ORC
TBLPROPERTIES (
'orc.compress'='ZLIB',
'orc.compression.strategy'='SPEED',
'orc.create.index'='true',
'orc.encoding.strategy'='SPEED');
Run Code Online (Sandbox Code Playgroud)
在 Spark 代码中,
val hiveOrcWriter: DataStreamWriter[Row] = event_stream
.writeStream
.outputMode("append")
.format("orc")
.partitionBy("year","month","day")
//.option("compression", "zlib")
.option("path", _table_loc)
.option("checkpointLocation", _table_checkpoint)
Run Code Online (Sandbox Code Playgroud)
我看到在非分区表上,记录被插入到 Hive 中。但是,在使用分区表时,spark 作业不会失败或引发异常,但不会将记录插入到 Hive 表中。
感谢任何处理过类似问题的人的评论。 …
hive apache-spark orc hive-partitions spark-structured-streaming