我想使用 Apache Arrow 将数据从 Django 后端发送到 Angular 前端。我想使用数据帧/表的字典作为消息中的有效负载。pyarrow 可以在 python 微服务之间以这种方式共享数据,但我找不到箭头的 javascript 实现的方法。
有没有办法反序列化/序列化一个字典,字符串作为键,数据帧/表作为箭头在javascript端的值?
我有一些使用 PyArrow (Apache Arrow) 用 Python 编写的 Parquet 文件:
pyarrow.parquet.write_table(table, "example.parquet")
Run Code Online (Sandbox Code Playgroud)
现在我想使用 Java 程序读取这些文件(最好是获取一个箭头表)。
在 Python 中,我可以简单地使用以下命令从 Parquet 文件中获取一个箭头表:
table = pyarrow.parquet.read_table("example.parquet")
Run Code Online (Sandbox Code Playgroud)
Java 中是否有等效且简单的解决方案?
我真的找不到任何好的/工作示例或任何有用的 Java 文档(仅适用于 Python)。或者一些示例没有提供所有需要的 Maven 依赖项。我也不想使用 Hadoop 文件系统,我只想使用本地文件。
注意:我还发现我不能使用“Apache Avro”,因为我的 Parquet 文件包含带有符号的列名[,]并且$它们在 Apache Avro 中是无效字符。
另外,如果您的解决方案使用 Maven,您能否提供 Maven 依赖项。
我在 Windows 上使用 Eclipse。
更新(2020 年 11 月):我从未找到合适的解决方案,只是在我的用例中坚持使用 Python。
Apache Arrow 和 Apache Spark 之间有什么区别?Apache Arrow 会取代 Hadoop 吗?
我正在运行一项工作pyspark,我曾在其中使用分组聚合 Pandas UDF。这会导致以下(此处为缩写)错误:
org.apache.arrow.vector.util.OversizedAllocationException: Unable to expand the buffer
Run Code Online (Sandbox Code Playgroud)
我相当确定这是因为 Pandas UDF 接收的组之一很大,如果我减少数据集并删除足够的行,我可以毫无问题地运行我的 UDF。但是,我想使用我的原始数据集运行,即使我在具有 192.0 GiB RAM 的机器上运行此 spark 作业,我仍然会遇到相同的错误。(并且 192.0 GiB 应该足以将整个数据集保存在内存中。)
我怎样才能给 spark 足够的内存来运行需要大量内存的分组聚合 Pandas UDF?
例如,是否有一些我错过的火花配置可以为 apache 箭头提供更多内存?
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
in
----> 1 device_attack_result.count()
2
3
4
/usr/lib/spark/python/pyspark/sql/dataframe.py in count(self)
520 2
521 """
--> 522 return int(self._jdf.count())
523
524 @ignore_unicode_prefix
/usr/lib/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py in __call__(self, *args)
1255 answer = self.gateway_client.send_command(command)
1256 return_value = get_return_value(
-> 1257 answer, self.gateway_client, …Run Code Online (Sandbox Code Playgroud) 当我在 R 和 Python 中保存 parquet 文件(使用 pyarrow)时,我得到一个保存在元数据中的箭头模式字符串。
\n\n如何读取元数据?是Flatbuffer编码的数据吗?模式的定义在哪里?它没有列在箭头文档网站上。
\n\n元数据是一个键值对,如下所示
\n\nkey: "ARROW:schema"\n\nvalue: "/////5AAAAAQAAAAAAAKAAwABgAFAAgACgAAAAABAwAEAAAAyP///wQAAAABAAAAFAAAABAAGAAIAAYABwAMABAAFAAQAAAAAAABBUAAAAA4AAAAEAAAACgAAAAIAAgAAAAEAAgAAAAMAAAACAAMAAgABwA\xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n\n用 R 写的结果
\n\nkey: "ARROW:schema"\n\nvalue: "/////5AAAAAQAAAAAAAKAAwABgAFAAgACgAAAAABAwAEAAAAyP///wQAAAABAAAAFAAAABAAGAAIAAYABwAMABAAFAAQAAAAAAABBUAAAAA4AAAAEAAAACgAAAAIAAgAAAAEAAgAAAAMAAAACAAMAAgABwA\xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n 如何将 pandas 数据帧以.arrow格式写入磁盘?我希望能够将箭头文件读入 Arquero,如此处所示。
我在 julia 中有以下函数,用于读取 Arrow 文件(使用 Arrow.jl)以从磁盘读取数据并处理它:
function getmembershipsdays(fromId, toId)
memberships = Arrow.Table("HouseholdMemberships.arrow") |> DataFrame
filter!([:IndividualId] => id -> id >= fromId && id <= toId, memberships)
...
end
> Error: ERROR: LoadError: MethodError: no method matching
> deleteat!(::Arrow.Primitive{Int64,Array{Int64,1}}, ::Array{Int64,1})
The DataFrame has the following structure:
123226x10 DataFrame
Row | MembershipId | IndividualId | HouseholdId | ...
| Int64 | Int64 | Int64 |
Run Code Online (Sandbox Code Playgroud)
函数中用于单步执行 Dataframe 的其余代码有效,但如果添加过滤条件,则会出现此错误。就好像 Dataframe 列没有转换为底层的 julia 类型。
如果我做
m = filter([:IndividualId] => id -> id >= fromId …Run Code Online (Sandbox Code Playgroud) 阿帕奇之箭的目的是什么?它从一种二进制格式转换为另一种二进制格式,但为什么我需要它?如果我有一个 Spark 程序,那么 Spark 可以读取镶木地板,那么为什么我需要在处理过程中将其转换为另一种格式?是将内存中的数据传递给另一种语言(如 python 或 java),而不必将其写入 text/json 格式吗?
我知道如何将 Parquet 文件读入Vec<Row>.
extern crate parquet;
use parquet::file::reader::{FileReader, SerializedFileReader};
use std::{fs, sync::Arc};
use parquet::column::writer::ColumnWriter;
use parquet::{
file::{
properties::WriterProperties,
writer::{FileWriter, SerializedFileWriter},
},
schema::parser::parse_message_type,
schema::types::TypePtr
};
use parquet::record::Row;
use parquet::record::RowAccessor;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::path::PathBuf;
fn read_parquet(in_path: &Path) -> (Vec<Row>, TypePtr) {
// Read Parquet input file. Return a vector of rows and the Schema
let file = File::open(in_path).unwrap();
let reader = SerializedFileReader::new(file).unwrap();
let row_iter = reader.get_row_iter(None).unwrap();
let num_rows = reader.metadata().file_metadata().num_rows();
let rows: Vec<Row> = row_iter.collect();
println!("num …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 C++ 读取包含浮点数列表的镶木地板文件中的数据。
\n我使用以下 python 代码生成了一个简单的镶木地板文件:
\nimport polars as pl\nimport struct\nimport random\nimport pyarrow.parquet as pq\n\nfloatlist = []\nfor _ in range(10):\n lstlen = random.choice([3, 4, 5])\n floatlist.append([random.random() for _ in range(lstlen)])\n\ndf = pl.DataFrame({"float_list": floatlist})\n\nfile_out_path = \'test.parquet\'\ndf.write_parquet(file_out_path)\nprint(pl.read_parquet(file_out_path))\nRun Code Online (Sandbox Code Playgroud)\n结果看起来非常合理:
\nshape: (10, 1)\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 float_list \xe2\x94\x82\n\xe2\x94\x82 --- \xe2\x94\x82\n\xe2\x94\x82 list[f64] \xe2\x94\x82\n\xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1\n\xe2\x94\x82 [0.863913, 0.831073, 0.264516] \xe2\x94\x82\n\xe2\x94\x82 [0.51377, 0.434267, \xe2\x80\xa6 0.131684] \xe2\x94\x82\n\xe2\x94\x82 [0.978071, 0.251396, \xe2\x80\xa6 0.142218] \xe2\x94\x82\n\xe2\x94\x82 [0.495616, 0.628793, 0.434872] \xe2\x94\x82\n\xe2\x94\x82 \xe2\x80\xa6 \xe2\x94\x82\n\xe2\x94\x82 [0.19035, 0.68318, \xe2\x80\xa6 0.778707] \xe2\x94\x82\n\xe2\x94\x82 [0.103636, 0.08755, \xe2\x80\xa6 0.526014] \xe2\x94\x82\n\xe2\x94\x82 [0.803863, …Run Code Online (Sandbox Code Playgroud)