Skip to content

Commit

Permalink
Fix the imports and reformat the spark fingerprinting example.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 729061087
Change-Id: I87a2a5515c3a69951ab949d06ea4250136590196
  • Loading branch information
tooryx authored and copybara-github committed Feb 20, 2025
1 parent 131c8f4 commit e02446c
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from pyspark.sql import SparkSession
import time
from pyspark.sql import SparkSession

# Initialize Spark session
spark = SparkSession.builder \
.appName("Fibonacci with Spark") \
.getOrCreate()
spark = SparkSession.builder.appName("Fibonacci with Spark").getOrCreate()


# Function to calculate Fibonacci numbers
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b


# Create an RDD with the range of Fibonacci numbers to calculate
n = 10 # Number of Fibonacci numbers to generate
Expand All @@ -23,11 +23,11 @@ def fibonacci(n):
# Introduce a unlimit loop with a sleep time to keep spark WebUI running
# We actually dont' want to calculate fibonacci :)
while True:
time.sleep(1)
time.sleep(1)

# Collect and print the Fibonacci numbers
for result in fibonacci_result.collect():
print(result)
print(result)

# Stop the Spark session
spark.stop()
spark.stop()

0 comments on commit e02446c

Please sign in to comment.