Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Pull improvements #682

Merged
merged 8 commits into from
May 13, 2018
Merged

Pull improvements #682

merged 8 commits into from
May 13, 2018

Conversation

rnewman
Copy link
Collaborator

@rnewman rnewman commented May 8, 2018

This PR allows aliasing of pull expressions and the use of :db/id for the entity ID itself:

(pull ?person [
    [:db/id :as :person/id]
    [:person/name :as :person/fullName]])

I wanted to flatten NamespacedKeyword, but soon realized that #648 still hasn't been wrapped up and landed, so I'll do that tomorrow. I plan to merge NamespacedKeyword and Keyword, with the only difference being a non-zero division offset and a different result from a predicate; we can preserve the restriction that all attribute names are namespaced while normalizing the API. That will make aliasing more useful.

@rnewman rnewman added the A-query Issues or requests for query capabilities. label May 8, 2018
@rnewman rnewman self-assigned this May 8, 2018
@rnewman rnewman requested a review from ncalexan May 8, 2018 15:06
Copy link
Member

@ncalexan ncalexan left a comment

Choose a reason for hiding this comment

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

lgtm!

@@ -303,11 +305,28 @@ def_parser!(Query, aggregate, Aggregate, {
})
});

def_parser!(Query, pull_concrete_attribute_ident, PullConcreteAttribute, {
Copy link
Member

Choose a reason for hiding this comment

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

I would have expected to be expressed as an optional :as foo, but I guess this works as well. The multiple try blocks should be a little less efficient than the optional block, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep — Datomic's grammar is wrong. I will fix.

.map(|ref r| r.to_value_rc());
match attribute {
&PullConcreteAttribute::Ident(ref i) => {
if let Some(entid) = schema.get_entid(i) {
Copy link
Member

Choose a reason for hiding this comment

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

Again, I think this should fail if we can't look up the entid for an ident, since it's probably an error to pull a non-attribute.

query/src/lib.rs Outdated
// PullMapSpec(Vec<…>),
// AttributeWithOpts(PullConcreteAttribute, …),
// LimitedAttribute(PullConcreteAttribute, u64), // Limit nil => Attribute instead.
Copy link
Member

Choose a reason for hiding this comment

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

PullConcreteAttribute has been superceded, so update these comments to NamedPullAttribute.

@@ -67,6 +67,7 @@ use self::mentat_query::{
Order,
OrJoin,
OrWhereClause,
NamedPullAttribute,
Copy link
Member

Choose a reason for hiding this comment

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

I'd vaguely prefer Aliased to Named, since that's what we're using throughout, but I'm not hung up on it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agreed with you, but it turns out that these are not always aliases; this is simply a pull attribute and its name, which sometimes differs from the attribute keyword itself.

@@ -143,6 +145,7 @@ pub struct Puller {
// The range is the set of aliases to use in the output.
attributes: BTreeMap<Entid, ValueRc<NamespacedKeyword>>,
attribute_spec: cache::AttributeSpec,
db_id_alias: Option<ValueRc<NamespacedKeyword>>,
Copy link
Member

Choose a reason for hiding this comment

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

Definitely wants a comment here, since this is a) not Datomic-alike and b) subtle.

@@ -22,6 +22,11 @@ error_chain! {
description("unnamed attribute")
display("attribute {:?} has no name", id)
}

Copy link
Member

Choose a reason for hiding this comment

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

The commit message is missing a "be": "to BE mentioned as a pull attribute."

// TODO: limits.
// TODO: fts.
Copy link
Member

Choose a reason for hiding this comment

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

I didn't see any obvious FTS extractions in the tests. Are there some?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are now!

@rnewman
Copy link
Collaborator Author

rnewman commented May 11, 2018

Rebased on top of #689: rnewman/pull-keyword.

I'm about to add non-namespaced aliases, but it'll have to wait for Monday!

@rnewman rnewman merged commit 60cb5d2 into master May 13, 2018
@rnewman rnewman deleted the rnewman/pull-2 branch May 13, 2018 21:15
@rnewman rnewman mentioned this pull request May 15, 2018
6 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-query Issues or requests for query capabilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants