使用Arrow管理数据

在之前的数据挖掘:是时候更新一下TCGA的数据了推文中,保存TCGA的数据就是使用Arrow格式,因为占空间小,读写速度快,多语言支持(我主要使用的3种语言都支持)

 

Format

https://arrow.apache.org

 

Apache Arrow defines a language-independent columnar memory format for flat and hierarchical data, organized for efficient analytic operations on modern hardware like CPUs and GPUs. The Arrow memory format also supports zero-copy reads for lightning-fast data access without serialization overhead.

 

Language Supported

Arrow's libraries implement the format and provide building blocks for a range of use cases, including high performance analytics. Many popular projects use Arrow to ship columnar data efficiently or as the basis for analytic engines.

 

Libraries are available for C, C++, C#, Go, Java, JavaScript, Julia, MATLAB, Python, R, Ruby, and Rust.

 

Ecosystem

Apache Arrow is software created by and for the developer community. We are dedicated to open, kind communication and consensus decisionmaking. Our committers come from a range of organizations and backgrounds, and we welcome all to participate with us.

 

R

install.packages("arrow")

library(arrow)

# write iris to iris.arrow and compressed by zstd

arrow::write_ipc_file(iris,'iris.arrow', compression = "zstd",compression_level=1)

# read iris.arrow as DataFrame

iris=arrow::read_ipc_file('iris.arrow')

 

python

# conda install -y pandas pyarrow

import pandas as pd

# read iris.arrow as DataFrame

iris=pd.read_feather('iris.arrow')

# write iris to iris.arrow and compressed by zstd

iris.to_feather('iris.arrow',compression='zstd', compression_level=1)

 

Julia

using Pkg

Pkg.add(["Arrow","DataFrames"])

 

using Arrow, DataFrames

# read iris.arrow as DataFrame

iris = Arrow.Table("iris.arrow") |> DataFrame

# write iris to iris.arrow, using 8 threads and compressed by zstd

Arrow.write("iris.arrow",iris,compress=:zstd,ntasks=8)

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spark SQL 数据类型转换 在 Spark SQL 中,可以使用 cast 函数将一个数据类型转换为另一个数据类型。 例如,我们可以将字符串类型转换为整数类型: ``` SELECT CAST("42" AS INT) ``` 这将输出整数值 42。 类似地,我们还可以将整数类型转换为字符串类型: ``` SELECT CAST(42 AS STRING) ``` 这将输出字符串值 "42"。 除了整数和字符串类型之外,Spark SQL 还支持其他一些数据类型转换,例如日期和时间类型。 如何管理 Spark 的分区 Spark 的分区是将数据集拆分成更小的块,以便并行处理。分区的数量可以手动设置,也可以由 Spark 自动确定。 以下是一些管理 Spark 分区的常见方法: 1. 手动设置分区数量:可以使用 repartition 或 coalesce 函数来手动设置分区数量。repartition 函数将数据集重新分区,而 coalesce 函数将数据集合并为更少的分区。 2. 自动确定分区数量:Spark 可以根据数据集的大小和集群的可用资源来自动确定分区数量。可以使用 spark.sql.shuffle.partitions 属性来设置默认分区数量。 3. 控制分区大小:可以使用 mapPartitions 函数来控制每个分区的大小。此函数将应用于每个分区,并返回一个新分区。 4. 手动设置分区的键:可以使用 partitionBy 函数手动设置分区的键。这将根据指定的列将数据集分区。 5. 更改默认的分区策略:可以使用 spark.sql.execution.arrow.enabled 属性来更改默认的分区策略。Arrow 是一种高效的数据格式,它可以减少网络传输和序列化时间,从而提高性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值