-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd87f3a
commit c17d413
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from os import environ | ||
from pyarrow import field, schema, struct, int32 | ||
from ray import init | ||
from ray.data import read_datasource | ||
from ray_elasticsearch import ElasticsearchDatasource | ||
|
||
init() | ||
source = ElasticsearchDatasource( | ||
index=environ["ELASTICSEARCH_INDEX"], | ||
client_kwargs=dict( | ||
hosts=environ["ELASTICSEARCH_HOST"], | ||
http_auth=( | ||
environ["ELASTICSEARCH_USERNAME"], | ||
environ["ELASTICSEARCH_PASSWORD"], | ||
), | ||
), | ||
schema=schema([ | ||
field( | ||
name="_source", | ||
type=struct([ | ||
field(name="id", type=int32(), nullable=False) | ||
]), | ||
nullable=False, | ||
) | ||
]) | ||
) | ||
print(f"Num rows: {source.num_rows()}") | ||
res = read_datasource(source)\ | ||
.map(lambda x: x["_source"])\ | ||
.sum("id") | ||
print(f"Read complete. Sum: {res}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters