Skip to content

Conversation

@vglavnyy
Copy link
Contributor

@vglavnyy vglavnyy commented Jan 2, 2021

This commit improves the workaround for #5928.

@mustiikhalil
Copy link
Collaborator

@vglavnyy I created a pr to resolve the swift CI issue #6378

@vglavnyy
Copy link
Contributor Author

vglavnyy commented Jan 2, 2021

@mustiikhalil thank you.

@vglavnyy
Copy link
Contributor Author

vglavnyy commented Jan 2, 2021

CI failed with PHP and with clang-format. Both are not related to the changes.

ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
ECHECK(atot(field->value.constant.c_str(), *this, &valdef)); \
builder_.AddElement(field_value.offset, val, valdef); \
if(field->key) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand how this fixes it.. this may fix it for JSON data but the problem is still there when using binary data created elsewhere?

I assumed that the fix had to be in the actual sorting code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This problem arises in Parser::ParseVector only.
Binary data never use SimpleQsort.
CreateVectorOfSortedTables and CreateVectorOfSortedStructs use std::sort with comparators.
https://github.com/google/flatbuffers/blob/0800976533ac2b54790635a5eef8b5d9dbc5e8eb/include/flatbuffers/flatbuffers.h#L1982-L-1987.

But you are right, the Parser::ParseTable isn't a good place for this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think key fields should be implicitly declared as required fields (both string and scalars).
At least it should be required if a struct or a table is used inside Vector container.
We can set it as required in FBS-2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved key checking into Parser::ParseVector.
CI failure doesn't connect with these changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, key implying required makes a lot of sense for strings. For scalars, it shouldn't really matter, though if it simplifies our key lookup, let's do it.

@vglavnyy vglavnyy force-pushed the fixes_for_sorted_by_key branch from 818e9e3 to 1a6e42e Compare January 5, 2021 18:22
@aardappel
Copy link
Collaborator

Is this otherwise ready to land?

This commit fixes handling of default and NULL `key` fields in `Parser::ParseVector` (google#5928).

The JSON generator updated. It outputs `key` fields even if the `--force-defaults` option is inactive.

Additional test cases for `key` added.
@vglavnyy vglavnyy force-pushed the fixes_for_sorted_by_key branch from 1a6e42e to 6a740a9 Compare January 6, 2021 01:54
@vglavnyy
Copy link
Contributor Author

vglavnyy commented Jan 6, 2021

It is ready.

@aardappel
Copy link
Collaborator

Thanks!

@aardappel aardappel merged commit 83ce29c into google:master Jan 7, 2021
@vglavnyy vglavnyy deleted the fixes_for_sorted_by_key branch March 13, 2021 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants