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

Field path class #4392

Merged
merged 4 commits into from
Mar 6, 2018
Merged

Conversation

chemelnucfin
Copy link
Contributor

@jba please see if this is the desired behavior you wanted or feel free to give me any comments.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 14, 2017
@chemelnucfin chemelnucfin changed the title #4378 - Field Path Firestore: Field Path Nov 14, 2017
@jba
Copy link
Contributor

jba commented Nov 14, 2017

@schmidt-sebastian, please take a look.

invalid_characters = '~*/[]'
if len(parts) == 1:
parts = parts[0]
if isinstance(parts, basestring):

This comment was marked as spam.

for part in parts:
if (not part
or not isinstance(part, basestring)
or part in invalid_characters):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

else:
part_ans += letter
ans.append('`' + part_ans + '`')
return '.'.join(ans)

This comment was marked as spam.


def test_empty_string_inside_string_fails(self):
with self.assertRaises(ValueError):
field_path = self._make_one('a..b')

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


def __init__(self, *parts):
invalid_characters = '~*/[]'
if len(parts) == 1:

This comment was marked as spam.

if (not part
or not isinstance(part, basestring)
or part in invalid_characters):
raise ValueError

This comment was marked as spam.


Returns: string representation of the path stored within
"""
pattern = re.compile(r'[A-Za-z_][A-Za-z_0-9]*')

This comment was marked as spam.

if match:
ans.append(part)
else:
part_ans = ''

This comment was marked as spam.

@chemelnucfin chemelnucfin added api: spanner Issues related to the Spanner API. api: firestore Issues related to the Firestore API. and removed api: spanner Issues related to the Spanner API. labels Nov 14, 2017
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Nov 15, 2017
@chemelnucfin chemelnucfin force-pushed the 4378-fieldpathclass branch 3 times, most recently from dcdfd4e to 6425b42 Compare November 15, 2017 17:36
@chemelnucfin chemelnucfin added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 15, 2017
@chemelnucfin
Copy link
Contributor Author

@jba @schmidt-sebastian PTAL.

I used the string replace method like node. Please check my tests to see that they are still the desired behavior.

In addition, what about unicode?

I will work on the update and query methods in a separate PR.

@chemelnucfin
Copy link
Contributor Author

I will wait on updating update and query methods until I get more confirmation about the unicode issue.

@chemelnucfin chemelnucfin force-pushed the 4378-fieldpathclass branch 4 times, most recently from 1b4a259 to dd1ff57 Compare November 20, 2017 02:05
@chemelnucfin
Copy link
Contributor Author

chemelnucfin commented Nov 20, 2017

@jba @schmidt-sebastian
So I'm looking through the different languages, and I see different things for each language. For example, the function api_repr that I was implementing is called
toServiceFieldPathComponent in Go and C#,
but canonicalString in Java and Node

I understand each language has different quirks and that each user would probably not be using cross language. However, shouldn't something like this be consistent across all languages?

Also, according to the docs that was here:
https://cloud.google.com/firestore/docs/reference/rest/v1beta1/Document
it doesn't seem like unicode is allowed, but is there a reason for that?

Thanks.

@jba
Copy link
Contributor

jba commented Nov 20, 2017

The doc is now at https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.Document and it explicitly allows unicode keys (it refers to UTF-8).

It's not important that the names of unexposed functions are the same across languages. We only care about the exposed surface and the behavior.


@classmethod
def from_string(cls, string):
""" Creates a FieldPath with a string representation.

This comment was marked as spam.

self.parts = tuple(parts)

@classmethod
def from_string(cls, string):

This comment was marked as spam.

return FieldPath(*string)

def to_api_repr(self):
""" Returns string representation of the FieldPath

This comment was marked as spam.

parts: (one or more strings)
Indicating path of the key to be used.
"""
pattern = re.compile(r'[A-Za-z_][A-Za-z_0-9]*')

This comment was marked as spam.

field_path = self._make_one(parts)
self.assertEqual(r'`\\\\`', field_path.to_api_repr())

def test_to_api_repr_underscore_valid(self):

This comment was marked as spam.

This comment was marked as spam.

with self.assertRaises(ValueError):
field_path = self._make_one(parts)

def test_key(self):

This comment was marked as spam.

This comment was marked as spam.

def __hash__(self):
return hash(self.to_api_repr())

def __eq__(self, other):

This comment was marked as spam.

"""
invalid_characters = '~*/[]'
string = string.split('.')
for part in string:

This comment was marked as spam.

@chemelnucfin chemelnucfin force-pushed the 4378-fieldpathclass branch 6 times, most recently from 0d0e214 to 0a379dd Compare December 21, 2017 19:59
@chemelnucfin
Copy link
Contributor Author

@schmidt-sebastian I moved the validation and did the empty string check in the constructor. Please take a look at my 3rd review changes (4th commit) and see if that's what you meant. Line 135 did not check for an empty string before.

@schmidt-sebastian
Copy link

@schmidt-sebastian I moved the validation and did the empty string check in the constructor. Please take a look at my 3rd review changes (4th commit) and see if that's what you meant. Line 135 did not check for an empty string before.

Looks good to me. Thanks.

@chemelnucfin
Copy link
Contributor Author

@dhermes?

@dhermes
Copy link
Contributor

dhermes commented Jan 10, 2018

Sorry I don't have cycles for this right now. @tseaver can you tap in? (In particular, we want to avoid re-inventing the wheel for code that already does this.)

@chemelnucfin
Copy link
Contributor Author

@dhermes it's ok. I am just trying to clean out some issues/prs.

@chemelnucfin chemelnucfin added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Jan 15, 2018
@chemelnucfin chemelnucfin changed the title Firestore: Field path Field path class Feb 20, 2018
@chemelnucfin chemelnucfin force-pushed the 4378-fieldpathclass branch from 9fb3721 to ed6e22e Compare March 6, 2018 01:11
@chemelnucfin chemelnucfin force-pushed the 4378-fieldpathclass branch from ed6e22e to 3d2631b Compare March 6, 2018 01:40
@chemelnucfin
Copy link
Contributor Author

I'm going to go ahead and merge this in. Let me know if there are any issues.

@chemelnucfin chemelnucfin merged commit 96309fc into googleapis:master Mar 6, 2018
@chemelnucfin chemelnucfin deleted the 4378-fieldpathclass branch March 26, 2018 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the Firestore API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants