Last active
April 8, 2021 22:34
-
-
Save Jeffwan/e10c08dcd4aa2751c361e136896bc35f to your computer and use it in GitHub Desktop.
raydp-spark.py
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
import os | |
import ray | |
import raydp | |
HEAD_SERVICE_IP_ENV = "EXAMPLE_CLUSTER_RAY_HEAD_SERVICE_HOST" | |
HEAD_SERVICE_CLIENT_PORT_ENV = "EXAMPLE_CLUSTER_RAY_HEAD_SERVICE_PORT_CLIENT" | |
head_service_ip = os.environ[HEAD_SERVICE_IP_ENV] | |
client_port = os.environ[HEAD_SERVICE_CLIENT_PORT_ENV] | |
ray.util.connect(f"{head_service_ip}:{client_port}") | |
spark = raydp.init_spark('word_count', | |
num_executors=2, | |
executor_cores=2, | |
executor_memory='1G') | |
df = spark.createDataFrame([('look',), ('spark',), ('tutorial',), ('spark',), ('look', ), ('python', )], ['word']) | |
df.show() | |
word_count = df.groupBy('word').count() | |
word_count.show() | |
raydp.stop_spark() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ray.util.connect(f"{head_service_ip}:{client_port}")
ray.init(address="auto")