Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATA-3441 Update data export command #4596

Merged
merged 34 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9df72a5
Update API version and add deprecation nolints #DATA-3441
katiepeters Dec 2, 2024
c391e5e
Split binary and tabular into separate subcommands #DATA-3441
katiepeters Dec 3, 2024
b90725c
Fix duplicate flag; add new flag names #DATA-3441
katiepeters Dec 3, 2024
337a368
Create POC streaming download #DATA-3441
katiepeters Dec 3, 2024
94ee605
Remove 'data' folder; use temporary file until stream completes #DATA…
katiepeters Dec 3, 2024
b7cf33c
Add ExportTabularData to testutils #DATA-3441
katiepeters Dec 3, 2024
95d1e80
Re-create 'actions' for easier testing #DATA-3441
katiepeters Dec 3, 2024
359d405
Start updating tabular client tests #DATA-3441
katiepeters Dec 3, 2024
54d4ce6
Merge with main; resolve conflicts #DATA-3441
katiepeters Dec 5, 2024
12384c1
Update API version #DATA-3441
katiepeters Dec 5, 2024
78ecee1
Finish updating tests #DATA-3441
katiepeters Dec 5, 2024
e86d4bb
Update data service client to match go sdk PR #DATA-3441
katiepeters Dec 5, 2024
e95e161
Remove file if program exits early #DATA-3441
katiepeters Dec 5, 2024
98e5621
Split up tabularData func into smaller functions #DATA-3441
katiepeters Dec 5, 2024
404ab76
Remove stream close (not needed) #DATA-3441
katiepeters Dec 5, 2024
e751eeb
Adjust the logic #DATA-3441
katiepeters Dec 6, 2024
a5f6732
Merge with main and resolve conflicts #DATA-3441
katiepeters Dec 10, 2024
9db0b4d
Create separate success/error cases #DATA-3441
katiepeters Dec 10, 2024
f26d47b
Remove timeout flag #DATA-3441
katiepeters Dec 10, 2024
e6f4df6
Move newline creation #DATA-3441
katiepeters Dec 10, 2024
592df9b
Update tests to account for newline #DATA-3441
katiepeters Dec 10, 2024
0f79105
Bump api version #DATA-3441
katiepeters Dec 10, 2024
ca98423
Lint/small tweaks #DATA-3441
katiepeters Dec 10, 2024
1d40a29
Merge with main and resolve conflicts #DATA-3441
katiepeters Dec 13, 2024
31f27df
Add correct args #DATA-3441
katiepeters Dec 13, 2024
2ce78bd
Remove shouldNotBeNil tests #DATA-3441
katiepeters Dec 13, 2024
0967465
Fix usage text #DATA-3441
katiepeters Dec 13, 2024
bde1971
Lint #DATA-3441
katiepeters Dec 13, 2024
2989eec
Remove nil check #DATA-3441
katiepeters Dec 13, 2024
8e5a816
Correct flag typo #DATA-3441
katiepeters Dec 16, 2024
542886f
Pull out capture interval logic #DATA-3441
katiepeters Dec 16, 2024
283c86a
Use size instead of number of writes for flushing #DATA-3441
katiepeters Dec 16, 2024
d415a79
Improve messaging around timestamps #DATA-3441
katiepeters Dec 16, 2024
fa26414
Remove unnecessary uint conversion DATA-3441
katiepeters Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ var commonFilterFlags = []cli.Flag{
},
&cli.StringFlag{
Name: dataFlagStart,
Usage: "ISO-8601 timestamp indicating the start of the interval filter",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the start of the interval filter",
},
&cli.StringFlag{
Name: dataFlagEnd,
Usage: "ISO-8601 timestamp indicating the end of the interval filter",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the end of the interval filter",
},
&cli.StringSliceFlag{
Name: dataFlagBboxLabels,
Expand Down Expand Up @@ -641,7 +641,7 @@ var app = &cli.App{
Usage: "download tabular data",
UsageText: createUsageText("data export tabular", []string{
dataFlagDestination,
dataFlagPartName,
dataFlagPartID,
dataFlagResourceName,
dataFlagResourceSubtype,
dataFlagMethod,
Expand Down Expand Up @@ -674,11 +674,11 @@ var app = &cli.App{
},
&cli.StringFlag{
Name: "start",
Usage: "ISO-8601 timestamp indicating the start of the interval",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the start of the interval",
},
&cli.StringFlag{
Name: "end",
Usage: "ISO-8601 timestamp indicating the end of the interval",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the end of the interval",
},
},
Action: createCommandWithT[dataExportTabularArgs](DataExportTabularAction),
Expand All @@ -703,12 +703,12 @@ var app = &cli.App{
&cli.StringFlag{
Name: dataFlagStart,
Required: true,
Usage: "ISO-8601 timestamp indicating the start of the interval filter",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the start of the interval filter",
},
&cli.StringFlag{
Name: dataFlagEnd,
Required: true,
Usage: "ISO-8601 timestamp indicating the end of the interval filter",
Usage: "ISO-8601 timestamp in RFC3339 format indicating the end of the interval filter",
},
&cli.StringSliceFlag{
Name: dataFlagLocationIDs,
Expand Down
63 changes: 27 additions & 36 deletions cli/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,13 @@ func createDataFilter(c *cli.Context) (*datapb.Filter, error) {
if len(args.BBoxLabels) != 0 {
filter.BboxLabels = args.BBoxLabels
}
var start *timestamppb.Timestamp
var end *timestamppb.Timestamp
timeLayout := time.RFC3339
if args.Start != "" {
t, err := time.Parse(timeLayout, args.Start)
if err != nil {
return nil, errors.Wrap(err, "could not parse start flag")
}
start = timestamppb.New(t)
}
if args.End != "" {
t, err := time.Parse(timeLayout, args.End)
if args.Start != "" || args.End != "" {
interval, err := createCaptureInterval(args.Start, args.End)
if err != nil {
return nil, errors.Wrap(err, "could not parse end flag")
}
end = timestamppb.New(t)
}
if start != nil || end != nil {
filter.Interval = &datapb.CaptureInterval{
Start: start,
End: end,
return nil, err
}

filter.Interval = interval
}
return filter, nil
}
Expand All @@ -312,29 +297,40 @@ func createExportTabularRequest(c *cli.Context) (*datapb.ExportTabularDataReques
request.MethodName = args.Method
}

interval, err := createCaptureInterval(args.Start, args.End)
if err != nil {
return nil, err
}

request.Interval = interval

return request, nil
}

func createCaptureInterval(startStr, endStr string) (*datapb.CaptureInterval, error) {
var start *timestamppb.Timestamp
var end *timestamppb.Timestamp
timeLayout := time.RFC3339
if args.Start != "" {
t, err := time.Parse(timeLayout, args.Start)

if startStr != "" {
t, err := time.Parse(timeLayout, startStr)
if err != nil {
return nil, errors.Wrap(err, "could not parse start flag")
}
start = timestamppb.New(t)
}
if args.End != "" {
t, err := time.Parse(timeLayout, args.End)
if endStr != "" {
t, err := time.Parse(timeLayout, endStr)
if err != nil {
return nil, errors.Wrap(err, "could not parse end flag")
}
end = timestamppb.New(t)
}
request.Interval = &datapb.CaptureInterval{

return &datapb.CaptureInterval{
Start: start,
End: end,
}

return request, nil
}, nil
}

func (c *viamClient) dataExportBinaryAction(cCtx *cli.Context, args dataExportBinaryArgs) error {
Expand Down Expand Up @@ -720,7 +716,6 @@ func (c *viamClient) tabularData(dest string, request *datapb.ExportTabularDataR
}

writer := bufio.NewWriter(dataFile)
numWrites := uint64(0)

dataRowChan := make(chan []byte)
vijayvuyyuru marked this conversation as resolved.
Show resolved Hide resolved
errChan := make(chan error, 1)
Expand Down Expand Up @@ -792,7 +787,7 @@ func (c *viamClient) tabularData(dest string, request *datapb.ExportTabularDataR
return nil
}

if err = writeData(writer, dataRow, &numWrites); err != nil {
if err = writeData(writer, dataRow); err != nil {
exportErr = errors.Wrap(err, "error writing data")
return exportErr
}
Expand All @@ -817,9 +812,7 @@ func (c *viamClient) tabularData(dest string, request *datapb.ExportTabularDataR
return nil
}

func writeData(writer *bufio.Writer, dataRow []byte, numWrites *uint64) error {
*numWrites++

func writeData(writer *bufio.Writer, dataRow []byte) error {
_, err := writer.Write(dataRow)
if err != nil {
return err
Expand All @@ -831,12 +824,10 @@ func writeData(writer *bufio.Writer, dataRow []byte, numWrites *uint64) error {
}

// Periodically flush to keep buffer size down.
n0nick marked this conversation as resolved.
Show resolved Hide resolved
if *numWrites == uint64(10_000) {
if uint64(writer.Size()) > uint64(10_000_000) {
n0nick marked this conversation as resolved.
Show resolved Hide resolved
if err = writer.Flush(); err != nil {
return err
}

*numWrites = 0
}

return nil
Expand Down
Loading