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

feat(save): support custom timestamps on commit #1594

Merged
merged 2 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions base/dsfs/compute_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ func (cff *computeFieldsFile) handleRows(ctx context.Context) {
}

cff.Lock()
// assign timestamp early. saving process on large files can take many minutes
cff.ds.Commit.Timestamp = Timestamp()
if cff.ds.Commit.Timestamp.IsZero() {
// assign timestamp early. saving process on large files can take many minutes
cff.ds.Commit.Timestamp = Timestamp()
} else {
cff.ds.Commit.Timestamp = cff.ds.Commit.Timestamp.In(time.UTC)
}
cff.acc = dsstats.NewAccumulator(st)
cff.Unlock()

Expand Down
2 changes: 2 additions & 0 deletions base/dsfs/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func DerefDataset(ctx context.Context, store qfs.Filesystem, ds *dataset.Dataset

// SaveSwitches represents options for saving a dataset
type SaveSwitches struct {
// Use a custom timestamp, defaults to time.Now if unset
Time time.Time
// Replace is whether the save is a full replacement or a set of patches to previous
Replace bool
// Pin is whether the dataset should be pinned
Expand Down
29 changes: 28 additions & 1 deletion base/dsfs/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func TestLoadDataset(t *testing.T) {
continue
}
}

}

func TestCreateDataset(t *testing.T) {
Expand Down Expand Up @@ -297,6 +296,34 @@ func TestCreateDataset(t *testing.T) {
// case: previous dataset isn't valid
}

func TestDatasetSaveCustomTimestamp(t *testing.T) {
ctx := context.Background()
fs := qfs.NewMemFS()
privKey := testPeers.GetTestPeerInfo(10).PrivKey

// use a custom timestamp in local zone. should be converted to UTC for saving
ts := time.Date(2100, 1, 2, 3, 4, 5, 6, time.Local)

ds := &dataset.Dataset{
Commit: &dataset.Commit{
Timestamp: ts,
},
Structure: &dataset.Structure{Format: "json", Schema: dataset.BaseSchemaArray},
}
ds.SetBodyFile(qfs.NewMemfileBytes("/body.json", []byte(`[]`)))

path, err := CreateDataset(ctx, fs, fs, ds, nil, privKey, SaveSwitches{})
if err != nil {
t.Fatal(err)
}

got, err := LoadDataset(ctx, fs, path)

if !ts.In(time.UTC).Equal(got.Commit.Timestamp) {
t.Errorf("result timestamp mismatch.\nwant: %q\ngot: %q", ts.In(time.UTC), got.Commit.Timestamp)
}
}

// BaseTabularSchema is the base schema for tabular data
// NOTE: Do not use if possible, prefer github.com/qri-io/dataset/tabular
// TODO(dustmop): Possibly move this to tabular package
Expand Down
1 change: 0 additions & 1 deletion cmd/testdata/movies/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"commit": {
"qri": "cm:0",
"timestamp": "2017-03-01T01:00:00.000Z",
"title": "removing rows",
"message": "removing rows for test purposes"
},
Expand Down
1 change: 0 additions & 1 deletion repo/test/testdata/cities/input.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"qri": "ds:0",
"commit": {
"qri": "cm:0",
"timestamp": "2017-01-01T01:00:00.000Z",
"title": "initial commit"
},
"meta": {
Expand Down
1 change: 0 additions & 1 deletion repo/test/testdata/counter/input.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"qri": "ds:0",
"commit": {
"qri": "cm:0",
"timestamp": "2017-02-01T01:00:00.000Z",
"title": "initial commit"
},
"meta": {
Expand Down
3 changes: 1 addition & 2 deletions repo/test/testdata/craigslist/input.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"qri": "ds:0",
"commit" : {
"qri" : "cm:0",
"title" : "initial commit",
"timestamp": "2017-04-01T01:00:00.000Z"
"title" : "initial commit"
},
"structure": {
"checksum": "QmPT7t4GQaBN4uxCdv3PD8A5vWaJ1ELCKCaZEjYYvUhe4W",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"commit" : {
"qri" : "cm:0",
"title" : "initial commit",
"timestamp": "2017-05-01T01:00:00.000Z"
"title" : "initial commit"
},
"meta" : {
"title" : "Fluorinated Compounds in U.S. Fast Food Packaging",
Expand Down
1 change: 0 additions & 1 deletion repo/test/testdata/movies/input.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"commit": {
"qri": "cm:0",
"timestamp": "2017-03-01T01:00:00.000Z",
"title": "initial commit"
},
"structure": {
Expand Down
1 change: 0 additions & 1 deletion repo/test/testdata/sitemap/input.dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"commit": {
"qri": "cm:0",
"timestamp": "2017-06-01T01:00:00.000Z",
"title": "initial commit"
},
"structure": {
Expand Down