File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 1
- from pyspark .sql import SparkSession
2
1
import time
2
+ from pyspark .sql import SparkSession
3
3
4
4
# Initialize Spark session
5
- spark = SparkSession .builder \
6
- .appName ("Fibonacci with Spark" ) \
7
- .getOrCreate ()
5
+ spark = SparkSession .builder .appName ("Fibonacci with Spark" ).getOrCreate ()
6
+
8
7
9
8
# Function to calculate Fibonacci numbers
10
9
def fibonacci (n ):
11
- a , b = 0 , 1
12
- for _ in range (n ):
13
- yield a
14
- a , b = b , a + b
10
+ a , b = 0 , 1
11
+ for _ in range (n ):
12
+ yield a
13
+ a , b = b , a + b
14
+
15
15
16
16
# Create an RDD with the range of Fibonacci numbers to calculate
17
17
n = 10 # Number of Fibonacci numbers to generate
@@ -23,11 +23,11 @@ def fibonacci(n):
23
23
# Introduce a unlimit loop with a sleep time to keep spark WebUI running
24
24
# We actually dont' want to calculate fibonacci :)
25
25
while True :
26
- time .sleep (1 )
26
+ time .sleep (1 )
27
27
28
28
# Collect and print the Fibonacci numbers
29
29
for result in fibonacci_result .collect ():
30
- print (result )
30
+ print (result )
31
31
32
32
# Stop the Spark session
33
- spark .stop ()
33
+ spark .stop ()
You can’t perform that action at this time.
0 commit comments