Skip to content

Commit 9ef664f

Browse files
committed
Edited to have parent stage id
1 parent 2b7fd56 commit 9ef664f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

stage/stage.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
type Stage struct {
3030
// Id is used to uniquely identify a stage. It is usually the file name without its directory path and extension.
3131
Id string `json:"-"`
32+
// ParentStageId is used to keep track of the parent stage of this child stage.
33+
ParentStageId string `json:"-"`
3234
// The values in Catalog, Schema, and SessionParams are inherited by the descendant stages. Please note that if
3335
// they have new values assigned in a stage, those values are NOT applied tn the Presto client until a stage
3436
// creates its own client by setting StartOnNewClient = true.
@@ -525,7 +527,7 @@ func (s *Stage) runQuery(ctx context.Context, query *Query) (result *QueryResult
525527
)
526528
if *s.SaveOutput {
527529
queryOutputFile, err = os.OpenFile(
528-
filepath.Join(s.States.OutputPath, s.Id, querySourceStr)+".output",
530+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".output",
529531
utils.OpenNewFileFlags, 0644)
530532
if err != nil {
531533
return result, err

stage/stage_utils.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (s *Stage) saveQueryJsonFile(result *QueryResult) {
290290
querySourceStr := s.querySourceString(result)
291291
{
292292
queryJsonFile, err := os.OpenFile(
293-
filepath.Join(s.States.OutputPath, s.Id, querySourceStr)+".json",
293+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".json",
294294
utils.OpenNewFileFlags, 0644)
295295
checkErr(err)
296296
if err == nil {
@@ -302,7 +302,7 @@ func (s *Stage) saveQueryJsonFile(result *QueryResult) {
302302
}
303303
if result.QueryError != nil {
304304
queryErrorFile, err := os.OpenFile(
305-
filepath.Join(s.States.OutputPath, s.Id, querySourceStr)+".error.json",
305+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".error.json",
306306
utils.OpenNewFileFlags, 0644)
307307
checkErr(err)
308308
if err == nil {
@@ -332,7 +332,7 @@ func (s *Stage) saveColumnMetadataFile(qr *presto.QueryResults, result *QueryRes
332332
}
333333
}()
334334
columnMetadataFile, ioErr := os.OpenFile(
335-
filepath.Join(s.States.OutputPath, s.Id, querySourceStr)+".cols.json",
335+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".cols.json",
336336
utils.OpenNewFileFlags, 0644)
337337
if ioErr != nil {
338338
return ioErr
@@ -374,11 +374,10 @@ func (s *Stage) querySourceString(result *QueryResult) (sourceStr string) {
374374
}
375375

376376
func (s *Stage) createNextStagesOutputDirectories() {
377-
parentOutputPath := s.States.OutputPath
378-
utils.PrepareOutputDirectory(filepath.Join(parentOutputPath, s.Id))
377+
parentStageId := s.Id
379378
for _, nextStage := range s.NextStages {
380-
nextStage.States.OutputPath = filepath.Join(parentOutputPath, nextStage.Id)
381-
utils.PrepareOutputDirectory(nextStage.States.OutputPath)
379+
nextStage.ParentStageId = parentStageId
380+
stageOutputPath := filepath.Join(s.States.OutputPath, s.Id, nextStage.Id)
381+
utils.PrepareOutputDirectory(stageOutputPath)
382382
}
383-
s.States.OutputPath = parentOutputPath
384383
}

0 commit comments

Comments
 (0)