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

Implements group_by, projection and offset on datastore Query. #282

Merged

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Oct 22, 2014

In addition, __eq__ was implemented on datastore.key.Key to allow for easy comparison.

See #281 for some context. As mentioned there, I looked and didn't see any equivalent bugs for these features.

@tseaver
Copy link
Contributor

tseaver commented Oct 22, 2014

How is this PR different from #281?

@tseaver tseaver added the api: datastore Issues related to the Datastore API. label Oct 22, 2014
@dhermes
Copy link
Contributor Author

dhermes commented Oct 22, 2014

From #281:

As new Query features are outside the scope of functional / regression testing, I am going
to peel them off into a separate PR and then rebase this one onto it after that is reviewed.
However, please feel free to dig into this review.

This PR has only the new features and none of the regression tests.

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch 2 times, most recently from 8dcf9f4 to 104345a Compare October 22, 2014 21:33
@dhermes
Copy link
Contributor Author

dhermes commented Oct 22, 2014

Rebased after the Travis fix.

@tseaver PTAL

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch from 104345a to 8df6f41 Compare October 22, 2014 21:53
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 8df6f41 on dhermes:implement-groupby-projection-offset into 9884f77 on GoogleCloudPlatform:master.

@tseaver
Copy link
Contributor

tseaver commented Oct 22, 2014

Implementation LGTM, although I don't know these bits of the API at all. Does 'offset()' conflict with the cursor stuff?

@dhermes
Copy link
Contributor Author

dhermes commented Oct 23, 2014

No, they are complimentary. We can get final sign-off from one of the datastore folks if you like?

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch from 8df6f41 to 3d4ce5d Compare October 23, 2014 00:50
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 3d4ce5d on dhermes:implement-groupby-projection-offset into 2da8654 on GoogleCloudPlatform:master.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 23, 2014

@tseaver while fixing some failures in #281 I realized #274 made key equality a bit of a different animal.

I added b61ba2e to address some corner cases.

You'll notice that this is a bit unpleasant. ISTM we should work harder to make the underlying representation of a Key simpler. /cc @pcostell

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling b61ba2e on dhermes:implement-groupby-projection-offset into 2da8654 on GoogleCloudPlatform:master.

@tseaver
Copy link
Contributor

tseaver commented Oct 23, 2014

I still don't see why two keys, each with 'dataset_id == None' but having the same path, should be unequal (they are both in the "default" dataset for the application's connection).

Likewise for when both keys have 'namespace == None' but the same path.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 23, 2014

They would both be equal. See test_key___eq__.

The failures happen if (dataset as an example)

        if not (self._dataset_id == other._dataset_id or
                self._dataset_id is None or other._dataset_id is None):

which is equivalent to

        if (self._dataset_id != other._dataset_id and
            self._dataset_id is not None and other._dataset_id is not None):

In other words, failure only occurs if the values don't match AND both values are non-null.

@tseaver
Copy link
Contributor

tseaver commented Oct 23, 2014

I don't understand why it isn't just:

if self._dataset_id != other._dataset_id:

If they are both None, they will be equal; if either is not None but the other is, they won't be equal. None compares for equality fine with arbitrary objects.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 23, 2014

To give a simplified idea of what is happening in test_post_with_generated_id, test_post_with_id and test_post_with_name:

>>> import regression.regression_utils
>>> dataset = regression.regression_utils.get_dataset()
>>> entity = dataset.entity(kind='SomeKind')
>>> entity['key'] = 'value'
>>> key = entity.key().name('some_name')  # Same for partial key or key id.
>>> entity = entity.key(key)
>>> entity.save()
<Entity[{'kind': 'SomeKind', 'name': 'some_name'}] {'key': 'value'}>
>>> retrieved_entity = dataset.get_entity(entity.key())

then we'll have

>>> entity.key().path()
[{'kind': 'SomeKind', 'name': 'some_name'}]
>>> retrieved_entity.key().path()
[{'kind': u'SomeKind', 'name': u'some_name'}]
>>> 
>>> print entity.key()._dataset_id
None
>>> retrieved_entity.key()._dataset_id
u's~redacted-dataset-id'
>>>
>>> print entity.key()._namespace
None
>>> retrieved_entity.key()._namespace
u''

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch from b61ba2e to c27a8d5 Compare October 23, 2014 18:38
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling c27a8d5 on dhermes:implement-groupby-projection-offset into 09859db on GoogleCloudPlatform:master.

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch from c27a8d5 to 330ffc5 Compare October 23, 2014 20:40
@dhermes
Copy link
Contributor Author

dhermes commented Oct 23, 2014

Rebased after #289.

@tseaver does the explanation above make sense for allowing null values in __eq__? Do you think we should do some more work to make these values actually agree?

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 330ffc5 on dhermes:implement-groupby-projection-offset into 8a21978 on GoogleCloudPlatform:master.

@tseaver
Copy link
Contributor

tseaver commented Oct 23, 2014

Yes, I see what you are trying to accomplish now. WRT the key's _datset_id, I'm not positive we want None to compare equal to one with an ID set by the back-end: it is sort of like comparing a naive datetime to a zoned one: they will be the same now, but later (if multi-dataset access comes into play) they might not be.

WRT namespace: we could switch the default value from None to '', and then just compare them naturally.

@dhermes dhermes force-pushed the implement-groupby-projection-offset branch from 330ffc5 to 95528d2 Compare October 23, 2014 23:01
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 95528d2 on dhermes:implement-groupby-projection-offset into b6d3e74 on GoogleCloudPlatform:master.

dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Oct 23, 2014
@dhermes
Copy link
Contributor Author

dhermes commented Oct 24, 2014

@tseaver it turns out we weren't handling namespaces quite perfectly. See #292.

As for dataset ID, the comment I added in Entity.save() to #292 may be the best strategy (i.e. if the key starts implicit, it should stay implicit).

To fully support this, we'd (at least) need to change Dataset.get_entities since it just creates each entity via helpers.entity_from_protobuf without any regard to the original values in keys().

A simple solution to this could be changing

        for entity_pb in entity_pbs:
            entities.append(helpers.entity_from_protobuf(
                entity_pb, dataset=self))

to

        for entity_pb, curr_key in zip(entity_pbs, keys):
            curr_entity = helpers.entity_from_protobuf(
                entity_pb, dataset=self)
            # If original key was implicit, maintain this on the
            # returned entity.
            if curr_key._dataset_id is None:
                curr_entity.key()._dataset_id = None
            else:
                if curr_entity.key() != curr_key:
                    raise ValueError('Key returned disagrees with key used '
                                     'in query.')
            entities.append(curr_entity)

parthea pushed a commit that referenced this pull request Jun 4, 2023
Source-Link: googleapis/synthtool@571ee2c
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:660abdf857d3ab9aabcd967c163c70e657fcc5653595c709263af5f3fa23ef67
parthea added a commit that referenced this pull request Jun 4, 2023
fix(deps): require proto-plus >= 1.22.0
parthea added a commit that referenced this pull request Jun 4, 2023
* fix(deps): allow protobuf 3.19.5

* explicitly exclude protobuf 4.21.0
parthea pushed a commit that referenced this pull request Jun 4, 2023
Source-Link: googleapis/synthtool@c4dd595
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ce3c1686bc81145c81dd269bd12c4025c6b275b22d14641358827334fddb1d72
parthea pushed a commit that referenced this pull request Jun 4, 2023
…splay_name" (#282)

- [ ] Regenerate this pull request now.

docs: Update documentation for the Mute fields on Findings

PiperOrigin-RevId: 429148908

Source-Link: googleapis/googleapis@c93764c

Source-Link: googleapis/googleapis-gen@8810468
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODgxMDQ2ODhmZmYzN2M2N2ZmNzJhZGRiNzNmM2ZlNjFkMTlkYzg1YSJ9
parthea pushed a commit that referenced this pull request Jun 4, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Jul 6, 2023
)

Source-Link: googleapis/synthtool@c1dd87e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2d13c2172a5d6129c861edaa48b60ead15aeaf58aa75e02d870c4cbdfa63aaba

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Aug 15, 2023
Source-Link: googleapis/synthtool@6fab84a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe
parthea pushed a commit that referenced this pull request Aug 15, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/909573ce9da2819eeb835909c795d29aea5c724e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ddf4551385d566771dc713090feb7b4c1164fb8a698fe52bbe7670b24236565b
parthea pushed a commit that referenced this pull request Sep 20, 2023
…p/templates/python_library/.kokoro (#282)

Source-Link: https://github.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
vchudnov-g pushed a commit that referenced this pull request Sep 20, 2023
chore: add SECURITY.md
parthea pushed a commit that referenced this pull request Sep 22, 2023
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 459095142

Source-Link: googleapis/googleapis@4f1be99

Source-Link: googleapis/googleapis-gen@ae686d9
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWU2ODZkOWNkZTRmYzNlMzZkMGFjMDJlZmI4NjQzYjE1ODkwYzFlZCJ9

feat: add audience parameter
PiperOrigin-RevId: 456827138

Source-Link: googleapis/googleapis@23f1a15

Source-Link: googleapis/googleapis-gen@4075a85
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDA3NWE4NTE0ZjY3NjY5MWVjMTU2Njg4YTViYmYxODNhYTk4OTNjZSJ9
parthea pushed a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@69fabae
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:562802bfac02e012a6ac34eda282f81d06e77326b82a32d7bbb1369ff552b387
parthea pushed a commit that referenced this pull request Sep 22, 2023
parthea pushed a commit that referenced this pull request Sep 22, 2023
* chore: Update gapic-generator-python to v1.11.2

PiperOrigin-RevId: 546510849

Source-Link: googleapis/googleapis@736073a

Source-Link: googleapis/googleapis-gen@deb64e8
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZGViNjRlOGVjMTlkMTQxZTMxMDg5ZmU5MzJiM2E5OTdhZDU0MWM0ZCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@56da63e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:993a058718e84a82fda04c3177e58f0a43281a996c7c395e0a56ccc4d6d210d7
parthea added a commit that referenced this pull request Sep 22, 2023
fix(deps): require proto-plus>=1.15.0
parthea pushed a commit that referenced this pull request Oct 21, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Oct 21, 2023
This adds region tags in order to support the Cloud Code API Explorer pilot
parthea added a commit that referenced this pull request Oct 21, 2023
parthea pushed a commit that referenced this pull request Oct 22, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/352b9d4c068ce7c05908172af128b294073bf53c
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:3e3800bb100af5d7f9e810d48212b37812c1856d20ffeafb99ebe66461b61fc7
parthea pushed a commit that referenced this pull request Oct 22, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants