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

Expressions for use with maps #89

Closed
MMcM opened this issue Oct 28, 2018 · 1 comment
Closed

Expressions for use with maps #89

MMcM opened this issue Oct 28, 2018 · 1 comment

Comments

@MMcM
Copy link
Contributor

MMcM commented Oct 28, 2018

Since map is just shorthand for a repeated message with two fields numbered 1 and 2 (named key and value -- but I do not believe that is guaranteed), I think this means variants of FieldKeyExpression and BaseField that take field numbers instead of field names, plus support in the planner for matching the two where it now just checks equals of getFieldName.

@MMcM
Copy link
Contributor Author

MMcM commented Oct 28, 2018

Earlier note from @alecgrieser:

Protobuf supports, as a field type, the "map" type, which, like the name suggests, allows for users to store (using a single field), a mapping of elements from one type to elements of another type:

message SampleMessage {
    ...
    map<type_1, type_2> field_name = n;
    ...
}

If it matters to anyone, they store this as a repeated list of messages when serialized to bytes:

message SampleMessage {
    ...
    repeated MapElem field_name = n;
    ...
}

message MapElem {
    optional type_1 key = 1;
    optional type_2 value = 2;
}

so there is already a way to support most of what anyone would want to do with this kind of thing, but the ergonomics could be better.

Presumably, we would need a new Key.Expression type. Probably something like:

Key.Expressions.field("field_name").key() (or maybe .keys())

And:

Key.Expressions.field("field_name").value() (or maybe .values())

These would then have the same semantics as key expressions on Key.Expressions.field("field_name").nest(Key.Expressions.field("key")) and Key.Expressions.field("field_name").nest(Key.Expressions.field("value")).

Then you would specify that you are interested in querying this field with something like:

Query.field("field_name").keys().oneOfThem().hasWhateverPropertyIWant()

Which would be equivalent to:

Query.field("field_name").oneOfThem().matches(Query.field("key").hasWhateverPropertyIWant())

(And the same kind of shenanigans for value types.)

FanType: IMO, most of the sensible indexes would use the map fields in a manner that is equivalent to using field-based indexes with the FanOut FanType. I'm struggling to see what the case for concatenated might be, but maybe there is one, I don't know.

alecgrieser added a commit that referenced this issue Dec 17, 2018
Resolves #89: Expressions for use with maps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant