下载thor文件,运行ecl脚本并下载其结果。
hpycc的Python项目详细描述
hpycc包旨在简化存储在hpcc上的数据的使用,并通过基本的python调用让用户和其他服务器都可以轻松地使用它。它的长期目标是使hpcc数据的访问和操作与任何其他类型的系统一样快速和容易。
文档
以下自述文件和软件包文档可在https://hpycc.readthedocs.io/en/latest/
包的github位于:https://github.com/OdinProAgrica/hpycc
此软件包是在gnu gplv3许可证下发布的:https://www.gnu.org/licenses/gpl-3.0.en.html
想在R里用这个吗?那么网状包裹就是你的朋友!保存为csv并读回。那个 或者您可以使用带有python块的r笔记本。
安装
安装时使用:
pip安装hpycc
或者,如果你还是一个有点老的学校:
python-m pip安装hpycc
当前状态
在windows 10下测试并使用hpcc v6.4.2和python 3.5.2。已在Linux系统上使用,但未进行广泛测试。
依赖关系
包本身主要使用核心python,输出数据帧需要pandas。
客户端工具依赖于运行ECL脚本(您需要ecl.exe和eclcc.exe)。 确保为hpcc版本安装正确的客户端工具,并将dir添加到系统路径, 例如c:\程序文件(x86)\ hpccsystems\x.x.x\clienttools\bin。
测试和Docker容器功能要求Docker启动HPCC环境。
主要功能
下面总结了关键功能和非可选参数。有关具体参数,请参见 函数的文档。注意,当检索文件是一个多线程进程时,运行一个脚本 而得到结果却不是。因此,如果文件很大,最好保存 使用run.run_script()和thor文件输出的脚本的结果,然后使用 获取.get_thor_file()。
连接(username,server=“localhost”,port=8010,repo=none,password=“password”,legacy=false,test_conn=true)
创建到新HPCC实例的连接。然后传递给任何接口函数。
获取输出(连接,脚本,…)&save输出(连接,脚本,路径,…)
运行给定的ecl脚本,然后将第一个结果作为pandas数据帧返回,或者将其保存到文件中。
获取输出(连接、脚本…)
运行给定的ecl脚本并将所有结果作为pandas数据帧的dict返回或保存到文件中。
获取目录文件(连接,逻辑文件,路径,…)&save目录文件(连接,逻辑文件,路径,…)
获取一个逻辑文件,然后作为pandas数据帧返回或将其保存到文件中。
运行脚本(连接,脚本,…)
运行给定的ecl脚本。将返回10行,但它们将被转储,不提供输出。
喷洒文件(连接、源文件、逻辑文件…)
将csv或pandas数据帧喷入hpcc。
docker_tools.hpcccontainer(tag=“6.4.26-1”,…)
为我们的测试而设计,但通常是可用的,用于运行和管理的函数集合 也提供HPCC Docker容器。上面的函数启动一个容器,请参阅帮助文件以关闭 和其他管理任务。
示例
下面的代码给出了一个功能示例:
import hpycc import pandas as pd from hpycc.utils import docker_tools from os import remove # Start an HPCC docker image for testing docker_tools.HPCCContainer(tag="6.4.26-1") # Setup stuff username = 'HPCC_dev' test_file = 'test.csv' f_hpcc_1 = '~temp::testfile1' f_hpcc_2 = '~temp::testfile2' ecl_script = 'ecl_script.ecl' # Let's create a connection object so we can interface with HPCC. # up with Docker conn = hpycc.Connection(username, server="localhost") try: # So, let's spray up some data: pd.DataFrame({'col1': [1, 2, 3, 4], 'col2': ['a', 'b', 'c', 'd']}).to_csv(test_file, index=False) hpycc.spray_file(conn, test_file, f_hpcc_1, expire=7) # Lovely, we can now extract that as a Thor file: df = hpycc.get_thor_file(conn, f_hpcc_1) print(df) # Note __fileposition__ column. This will be drop-able in future versions. ################################# # col1 col2 \__fileposition__# # 0 1 a 0 # # 1 3 c 20 # # 2 2 b 10 # # 3 4 d 30 # ################################# # If preferred data can also be extracted using an ECL script. with open(ecl_script, 'w') as f: f.writelines("DATASET('%s', {STRING col1; STRING col2;}, THOR);" % f_hpcc_1) # Note, all columns are currently string-ified by default df = hpycc.get_output(conn, ecl_script) print(df) ################ # col1 col2 # # 0 1 a # # 1 3 c # # 2 2 b # # 3 4 d # ############## # # get_thor_file() is optimised for large files, get_output is not (yet). To run a script and # download a large result you should therefore save a thor file and grab that. with open(ecl_script, 'w') as f: f.writelines("a := DATASET('%s', {STRING col1; STRING col2;}, THOR);" "OUTPUT(a, , '%s');" % (f_hpcc_1, f_hpcc_2)) hpycc.run_script(conn, ecl_script) df = hpycc.get_thor_file(conn, f_hpcc_2) print(df) ################################# # col1 col2 \__fileposition__# # 0 1 a 0 # # 1 3 c 20 # # 2 2 b 10 # # 3 4 d 30 # ################################# finally: # Shutdown our docker container docker_tools.HPCCContainer(pull=False, start=False).stop_container() remove(ecl_script) remove(test_file)