From fc35b02c84c94d5965a8317df6312c9a3ececc68 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 27 Dec 2024 22:20:18 +0100 Subject: Fix creds on Main class --- co-purchase-analysis/src/main/scala/Main.scala | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/co-purchase-analysis/src/main/scala/Main.scala b/co-purchase-analysis/src/main/scala/Main.scala index ec113b3..8c3e907 100644 --- a/co-purchase-analysis/src/main/scala/Main.scala +++ b/co-purchase-analysis/src/main/scala/Main.scala @@ -75,15 +75,21 @@ object CoPurchaseAnalysis { * Configured SparkSession instance */ def createSparkSession(appName: String, master: String): SparkSession = { - SparkSession.builder + var session = SparkSession.builder .appName(appName) .config("spark.master", master) - .config("spark.hadoop.google.cloud.auth.service.account.enable", "true") - .config( - "spark.hadoop.google.cloud.auth.service.account.json.keyfile", - System.getenv("GOOGLE_APPLICATION_CREDENTIALS") - ) - .getOrCreate() + + val creds = System.getenv("GOOGLE_APPLICATION_CREDENTIALS") + if (creds != null) { + session + .config("spark.hadoop.google.cloud.auth.service.account.enable", "true") + .config( + "spark.hadoop.google.cloud.auth.service.account.json.keyfile", + creds + ) + } + + session.getOrCreate() } /** Parses a single line from the input file into an OrderProduct instance. -- cgit v1.2.3-18-g5258