如何使用Apache Sp仅流式传输文件的一部分

2024-09-29 21:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在pythonapi中使用sparkstreaming和sparksql。你知道吗

我有一个不断编辑的文件,每N秒随机添加一些行。你知道吗

这个文件可以是JSON、XML、CSV或TXT,甚至是SQL表:我完全可以根据自己的情况选择最佳解决方案。你知道吗

我有一定数量的字段,大约4-5个。以下表为例:

+-------+------+-------+--------------------+ 
| event |  id  | alert |      datetime      |
+-------+------+-------+--------------------+
| reg   |  1   | def1  | 06.06.17-17.24.30  |
+-------+------+-------+--------------------+
| alt   |  2   | def2  | 06.06.17-17.25.11  |
+-------+------+-------+--------------------+
| mot   |  3   | def5  | 06.06.17-17.26.01  |
+-------+------+-------+--------------------+
| mot   |  4   | def5  | 06.06.17-17.26.01  |
+-------+------+-------+--------------------+

我只想用Spark Streaming流新台词。因此,如果我添加了两个新行,下次我只想流式处理这两行,而不是整个文件(已经流式处理)

此外,我希望在每次找到新行时,对整个同一个文件过滤或计算sparksql查询。例如,我只想在事件"mot"在10分钟内出现两次时选择它,并且每次文件更改和新数据到达时都必须重新执行此查询。你知道吗

sparkstreaming和sparksql能处理这些情况吗?怎么做?你知道吗


Tags: 文件csvtxtjson编辑pythonapisql情况
1条回答
网友
1楼 · 发布于 2024-09-29 21:29:45

file sources Spark不支持它

Reads files written in a directory as a stream of data. Supported file formats are text, csv, json, orc, parquet. See the docs of the DataStreamReader interface for a more up-to-date list, and supported options for each file format. Note that the files must be atomically placed in the given directory, which in most file systems, can be achieved by file move operations

对于legacy streaming也是如此(注意2.2文档,但是实现没有改变)

The files must be created in the dataDirectory by atomically moving or renaming them into the data directory.

相关问题 更多 >

    热门问题