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

better set_body #42

Merged
merged 4 commits into from
May 16, 2019
Merged

better set_body #42

merged 4 commits into from
May 16, 2019

Conversation

b5
Copy link
Member

@b5 b5 commented May 16, 2019

set_body wasn't doing the right thing when it comes to determining the destination datset structure for writing a body. We now inherit structure from existing dataset data, and only fall back to json if no structure exists.

The general problem here is a separation of concerns between data in the starlark runtime and dataset serialization formats. Those should always be seperate, with set_body giving qri the data it wants serialized, or skipping serialization with ds.set_body(data, parse_as='format'

b5 added 3 commits May 16, 2019 11:22
set_body wasn't doing the right thing when it comes to determining the
destination datset structure for writing a body. We now inherit structure
from existing dataset data, and only fall back to json if no structure
exists.

The general problem here is a separation of concerns between data in the
starlark runtime and dataset serialization formats. Those should always
be seperate.

closes qri-io/qri#756
the mental model behind 'raw' and 'data_format' is off. 'data_format' implies
that we're changing the ultimate data format, which is not the case.

Now set_body has only one optional argument: 'parse_as', which defaults to the
empty string. By default qri assumes the data value provided to set_body is
an iterable starlark data structure (tuple, set, list, dict). When parse_as
is set, set_body assumes the provided body value will be a string of serialized
structured data in the given format. valid parse_as values are "json", "csv",
"cbor", "xlsx".

We'll need more tests to confirm each format works properly, but all this is
doing under the hood is overriding all parsing and setting body bytes directly,
which is analogous to "qri save --body file.[parse_as] me/dataset".

BREAKING CHANGE:
ds.set_body raw and data_format params have been replaced by parse_as
@b5 b5 added the fix label May 16, 2019
@b5 b5 self-assigned this May 16, 2019
@ghost ghost added the in progress label May 16, 2019
@b5 b5 requested review from dustmop and ramfox May 16, 2019 19:03
@b5 b5 mentioned this pull request May 16, 2019
2 tasks
Copy link
Contributor

@dustmop dustmop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Have just a few tiny suggestions


# csv_ds is a global variable provided by dataset_test.go
# "cycling" csv data through starlark shouldn't have significant effects on the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about "round-tripping" instead of "cycling"

ds/dataset.go Outdated
}

return starlark.None, fmt.Errorf("expected raw data for body to be a string")
d.write.SetBodyFile(qfs.NewMemfileBytes(fmt.Sprintf("data.%s", df), []byte(string(str))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "body.%s" instead of "data.%s".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally. makes me want this more: qri-io/dataset#188

},
},
}
ds.SetBodyFile(qfs.NewMemfileBytes("data.csv", []byte(text)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "body.csv" instead of "data.csv"

@b5 b5 merged commit b30516e into master May 16, 2019
@b5 b5 deleted the fix_set_body branch May 16, 2019 20:37
@ghost ghost removed the in progress label May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants