Skip to content

Commit 40fa866

Browse files
committed
Fix PR comments
1 parent b16ea54 commit 40fa866

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/src/main/scala/io/github/datacatering/datacaterer/core/ui/plan/PlanRepository.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,14 @@ object PlanRepository {
410410
}
411411
}
412412

413+
private def createSparkSession(): SparkSession = {
414+
new SparkProvider(DEFAULT_MASTER, DEFAULT_RUNTIME_CONFIG).getSparkSession
415+
}
416+
413417
private def generateFromTaskFile(request: TaskFileSampleRequest): SampleResponse = {
414418
LOGGER.debug(s"Generating sample from task file: ${request.taskYamlPath}, step: ${request.stepName}")
415419
try {
420+
implicit val sparkSession: SparkSession = createSparkSession()
416421
FastSampleGenerator.generateFromTaskFile(request)
417422
} catch {
418423
case ex: Throwable =>
@@ -428,6 +433,7 @@ object PlanRepository {
428433
private def generateFromTaskYaml(request: TaskYamlSampleRequest): SampleResponse = {
429434
LOGGER.debug(s"Generating sample from task YAML content, step: ${request.stepName}")
430435
try {
436+
implicit val sparkSession: SparkSession = createSparkSession()
431437
FastSampleGenerator.generateFromTaskYaml(request)
432438
} catch {
433439
case ex: Throwable =>
@@ -443,6 +449,7 @@ object PlanRepository {
443449
private def generateFromSchema(request: SchemaSampleRequest): SampleResponse = {
444450
LOGGER.debug(s"Generating sample from inline fields: ${request.fields.size} fields")
445451
try {
452+
implicit val sparkSession: SparkSession = createSparkSession()
446453
FastSampleGenerator.generateFromSchema(request)
447454
} catch {
448455
case ex: Throwable =>
@@ -459,7 +466,7 @@ object PlanRepository {
459466
LOGGER.debug("Starting up Spark")
460467
setUiRunning
461468
try {
462-
implicit val sparkSession: SparkSession = new SparkProvider(DEFAULT_MASTER, DEFAULT_RUNTIME_CONFIG).getSparkSession
469+
implicit val sparkSession: SparkSession = createSparkSession()
463470
//run some dummy query
464471
sparkSession.sql("SELECT 1").collect()
465472

app/src/main/scala/io/github/datacatering/datacaterer/core/ui/sample/FastSampleGenerator.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ object FastSampleGenerator {
1717

1818
private val LOGGER = Logger.getLogger(getClass.getName)
1919
private val MAX_SAMPLE_SIZE = 100
20-
private implicit val sparkSession: SparkSession = new SparkProvider(DEFAULT_MASTER, DEFAULT_RUNTIME_CONFIG).getSparkSession
2120

22-
def generateFromTaskFile(request: TaskFileSampleRequest): SampleResponse = {
21+
def generateFromTaskFile(request: TaskFileSampleRequest)(implicit sparkSession: SparkSession): SampleResponse = {
2322
LOGGER.info(s"Generating sample from task file: ${request.taskYamlPath}, step: ${request.stepName}")
2423

2524
Try {
@@ -47,7 +46,7 @@ object FastSampleGenerator {
4746
}
4847
}
4948

50-
def generateFromSchema(request: SchemaSampleRequest): SampleResponse = {
49+
def generateFromSchema(request: SchemaSampleRequest)(implicit sparkSession: SparkSession): SampleResponse = {
5150
LOGGER.info(s"Generating sample from inline fields: ${request.fields.size} fields")
5251

5352
Try {
@@ -60,7 +59,7 @@ object FastSampleGenerator {
6059
}
6160
}
6261

63-
def generateFromTaskYaml(request: TaskYamlSampleRequest): SampleResponse = {
62+
def generateFromTaskYaml(request: TaskYamlSampleRequest)(implicit sparkSession: SparkSession): SampleResponse = {
6463
LOGGER.info(s"Generating sample from task YAML content, step: ${request.stepName}")
6564

6665
Try {
@@ -89,7 +88,7 @@ object FastSampleGenerator {
8988
}
9089

9190

92-
private def generateSample(fields: List[Field], sampleSize: Int, fastMode: Boolean): SampleResponse = {
91+
private def generateSample(fields: List[Field], sampleSize: Int, fastMode: Boolean)(implicit sparkSession: SparkSession): SampleResponse = {
9392
val startTime = System.currentTimeMillis()
9493
val executionId = generateId()
9594

app/src/test/resources/sample/task/file/csv-customer-task.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ steps:
1414
- name: "product_name"
1515
options:
1616
regex: "product_[0-9]{8}"
17-
- name: "products"
17+
- name: "customers"
1818
type: "csv"
1919
options:
2020
path: "/tmp/custom/csv/multi-relationship/customers"
@@ -31,7 +31,7 @@ steps:
3131
- name: "last_name"
3232
options:
3333
expression: "#{Name.lastName}"
34-
- name: "products"
34+
- name: "accounts"
3535
type: "csv"
3636
options:
3737
path: "/tmp/custom/csv/multi-relationship/accounts"
@@ -61,7 +61,7 @@ steps:
6161
- name: "country_code"
6262
options:
6363
expression: "#{Address.countryCode}"
64-
- name: "products"
64+
- name: "customer_access"
6565
type: "csv"
6666
options:
6767
path: "/tmp/custom/csv/multi-relationship/customer-access"

0 commit comments

Comments
 (0)