This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
remote_file_input_reader.go
65 lines (50 loc) · 1.79 KB
/
remote_file_input_reader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ioutils
import (
"context"
"github.com/lyft/flytestdlib/errors"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
"github.com/lyft/flytestdlib/storage"
"github.com/lyft/flyteplugins/go/tasks/pluginmachinery/io"
)
const (
ErrFailedRead string = "READ_FAILED"
)
var (
// Ensure we get an early build break if interface changes and these classes do not conform.
_ io.InputFilePaths = SimpleInputFilePath{}
_ io.InputReader = RemoteFileInputReader{}
)
type RemoteFileInputReader struct {
io.InputFilePaths
store storage.ProtobufStore
}
func (r RemoteFileInputReader) Get(ctx context.Context) (*core.LiteralMap, error) {
d := &core.LiteralMap{}
if err := r.store.ReadProtobuf(ctx, r.InputFilePaths.GetInputPath(), d); err != nil {
// TODO change flytestdlib to return protobuf unmarshal errors separately. As this can indicate malformed output and we should catch that
return nil, errors.Wrapf(ErrFailedRead, err, "failed to read data from dataDir [%v].", r.InputFilePaths.GetInputPath())
}
return d, nil
}
func NewRemoteFileInputReader(_ context.Context, store storage.ProtobufStore, inputPaths io.InputFilePaths) RemoteFileInputReader {
return RemoteFileInputReader{
InputFilePaths: inputPaths,
store: store,
}
}
type SimpleInputFilePath struct {
pathPrefix storage.DataReference
store storage.ReferenceConstructor
}
func (s SimpleInputFilePath) GetInputPrefixPath() storage.DataReference {
return s.pathPrefix
}
func (s SimpleInputFilePath) GetInputPath() storage.DataReference {
return constructPath(s.store, s.pathPrefix, InputsSuffix)
}
func NewInputFilePaths(_ context.Context, store storage.ReferenceConstructor, inputPathPrefix storage.DataReference) SimpleInputFilePath {
return SimpleInputFilePath{
store: store,
pathPrefix: inputPathPrefix,
}
}