Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1 2 
Send Topic Print
Where clause? (Read 14592 times)
Loryn
Full Member
*
Offline



Posts: 97

Where clause?
Mar 06th, 2009, 4:31pm
 
I'm trying to find the intersection of two sets of data by value. Each set exists as children of different containers.

How do I do the equivalent of:

Select from Set_A a and Set_B b
where a.Name = b.Name
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Where clause?
Reply #1 - Mar 6th, 2009, 6:26pm
 
I assume you have, for given note(s) populated user set-type attributes $SetA and $SetB (underscore is not supported for attribute names), where each holds the Name of relevant  notes.  In which case, you should be able to use a query for common value 'a':

AgentQuery: Set_A(a) & Set_B(a)

N.B. do not use a $ prefix for attribute names the above usage.

The above will return all notes where 'a' is a value within both SetA and SetB.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Johnnie Wilcox - mistersquid
Full Member
*
Offline



Posts: 84
San Francisco, CA
Re: Where clause?
Reply #2 - Mar 6th, 2009, 8:07pm
 
You might give this a whirl if A and B are different containers.

(descendedFrom(A) & $Name="value") | (descendedFrom(B) & $Name="value")
Back to top
 
« Last Edit: Mar 6th, 2009, 8:08pm by Johnnie Wilcox - mistersquid »  
  IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: Where clause?
Reply #3 - Mar 7th, 2009, 2:58am
 
Thanks to both Mark and Johnnie.

Yes, Johnnie, I do have two containers. (SetA / SetB were just placeholders for my two containers.)

Your suggestion is close to what I want. Now the thing I need to add to it is the fact that the value comes from the Names of the notes themselves.

Is there a way I can have the agent search through each of the notes in the current folder, and compare it to the names of the notes in the other folder, to determine whether or not there is a match.

For example, can I do this something like this?

for_all(child,A) {
(descendedFrom(A) & Name(^.*$)) | (descendedFrom(B) & Name($1))
}

i.e. Loop through all the notes in container A, and see if the Name matches a note in container B. The $1 is intended to match whatever the regex matched in the first folder.

Back to top
 
 
  IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: Where clause?
Reply #4 - Mar 7th, 2009, 5:07pm
 
Johnnie or Mark

Is what I'm trying to do possible?

I'm trying to examine all children of one container, and see if there are children of another container that have matching names, returning an alias of any notes that do have matching names.

If it isn't possible, I'm going to need to export the data into a different program to resolve this. (I'd rather get it done in-place in Tinderbox, if possible.)
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Where clause?
Reply #5 - Mar 7th, 2009, 6:29pm
 
It's easy if you now a specific value of Name

     #inside(a) & inside(b) & $Name=this

What you wanted to do USED to be impossible, and might still be.  But it just might be possible through clever hackery.  

For example, you could build a set "BNames" of all the names found in container b

     bnames=collect(b,$Name)

And then (maybe) test whether bname contains the name in question

    #inside(a) & #inside(b) & eval(b,"bnames("+$Name(this)+")")

This is NOT tested, improvised, and might not work.  It's ugly as sin.  And it's inefficient. (But your query is also quadratic, which is why Tinderbox doesn't really like to do it)

Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Where clause?
Reply #6 - Mar 7th, 2009, 6:32pm
 
Let's assume the containers are 'box 1' and 'Box 2'. Intuitively, this query should do what you seek:

(inside(Box A))&(inside(Box B))

Except that finds nothing even if the children of the two containers have same named notes. This does find all children:

(inside(Box A))|(inside(Box B))

Huh? The explanation is note 'Green' might be a child in 'Box 1' and 'box 2' but it is not the same note just one with the same name.

One can easily make a set of a container's child notes names:

$MySet = collect(child(Box 1),$Name);$MySet2 = collect(child(Box 2),$Name);

How to get the subset of set values present in $MySet and $MySet2 , I'm not sure...
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Where clause?
Reply #7 - Mar 8th, 2009, 10:00am
 
Aha (I think).

Make a new agent, C:

    query: inside(a)|inside(b)
    sort: Name

Now. make yet another agent, D:

    query: inside(c) & (($Name=$Name(prevSibling) | (($Name=$Name(nextSibling))

Note that this isn't *quite* what you want, since it will also find notes two named "foo" that are both inside a.  If that matters, yet another agent can check that, for each note in D that is inside a, either its previous or next sibling is inside b.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Where clause?
Reply #8 - Mar 8th, 2009, 12:19pm
 
The missing (functional) link here seems to be that one can't use attribName(pattern) where pattern is actually an evaluated value. Agian, assume MySet = names from Box A and MySet2 = names from Box B. now, if AttributeName(this) or AttributeName(current) were allowed syntax whereby the currently evaluated note's name where used as the pattern search string then:

(MySet(current)) & (MySet2(current))

...ought to meet the OP's needs. I'm not 100% sure if the designator above should be this or current but as this is only an idea, it's moot for now. Another not-possible alternative syntax suggestion is if a syntax like AttributeName($AnotherAttribute) were allowed:

$Name=$MySet($Name)   (where MySet is the agent's user attribute set holding a list of note names, sert via a rule)

These musings point towards considering an extended attribute(search) syntax or a different but parallel action/query operator that uses an evaluated argument for an attribute value search. The limitation isn't that TB can't search for such a value, but rather there's no syntax to pass in such a value.

Clearly, the above is effectively a feature suggestion/request at this point.

Back to top
 
« Last Edit: Mar 8th, 2009, 3:30pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Johnnie Wilcox - mistersquid
Full Member
*
Offline



Posts: 84
San Francisco, CA
Re: Where clause?
Reply #9 - Mar 8th, 2009, 1:44pm
 
I love a good puzzle, especially if it's tantalizing like this one.

Mark A.'s last response makes some sense to me, but because my poor brain buckles when thinking about recursion/iteration even at two levels, I can't decide if I like the first or second proposal better. I'll say the first

Code:
(MySet(current)) & (MySet2(current))
 



only because I think I can understand it more easily.

As long as we're now in the realm of feature request, I can imagine a specialized function that queries the intersection of any number of agents based on an attribute. Something like

Code:
intersection(AgentName1,AgentName2, . . .,AgentNameN,$SomeAttribute)
 



Placed in series, this query method would provide an easy way for users to filter using multiple attributes. It could also be extended so that AgentName could be replaced by objects such as child(SomeNote), inside(SomeNote), etc.
Back to top
 
« Last Edit: Mar 8th, 2009, 1:45pm by Johnnie Wilcox - mistersquid »  
  IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: Where clause?
Reply #10 - Mar 8th, 2009, 3:27pm
 
MarkB's suggestion seems pretty inspired. And I can work with the limitation Mark pointed out, because my values are unique in each set.

ALAS!

It doesn't seem to work.

WORKS:      inside(c) & ($Name=$Name(this))
FAILS:         inside(c) & ($Name=$Name(nextSibling))
FAILS:         inside(c) & ($Name=$Name(nextSibling)|($Name=$Name(prevSibling))

By fails, I mean it returns no results when there is data available to be returned. I don't understand why this doesn't appear to be working.

@Johnnie

I like your suggestion for feature request. Explicitly:

intersect(container1, container2,...)  

would work by reference: aliases of the same note OR an alias and the note it refers to?

intersect(container1, container2,...,$AttributeName)

would work by value, as you suggested.

Other set operators may also prove useful.
Back to top
 
 
  IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: Where clause?
Reply #11 - Mar 8th, 2009, 6:05pm
 
SUCCESS:

Query:  inside(c)

Action:
WORKS:    $cnames(agent)=collect_if(child(agent),$Name=$Name(nextSibling),$Name)
WORKS:      $cnames(agent)=collect_if(child(agent),(($Name=$Name(nextSibling))|($Name=$Name
(prevSibling))),$Name)

Whereas: when used in a query:

FAIL:    inside(c) & $Name=$Name(nextSibling)
FAIL:    inside(c) & (($Name=$Name(nextSibling))|($Name=$Name(prevSibling)))

Again, where fail returns no results.

Is this a Tinderbox bug?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Where clause?
Reply #12 - Mar 8th, 2009, 6:20pm
 
My hunch is that the $AttributeName(path) syntax isn't working as intended in queries. Why, I don't know.

So, hard to say it's specifically a bug.  Track back to the stat of this thread and we've all been trying to figure a workaround for a try of query whose construct isn't supported in a direct sense.  At the same time changes to action/agent syntax handling  in v4.6.0 is throwing up some unexpected consequences - mainly , it seems, due to well-intentioned attempts to support old syntax.  IOW, do you break everyone's code, or just some code for some people. Folk are always going to shout if something breaks so the correct choice isn't easy. I've no inside track here, but on past performance I'd expect an update before long addressing some of the coercion/name collision issues in current post-v4.6 threads. Until then it's best to stop trying things that don't work.

At this point the most helpful thing we can do - if having 'new' syntax issues is to document them thoroughly - i.e. what works/doesn't - rather as you've done and then dwell a pause to let Mark and his team lake a look. I'm sure it will get resolved. Making such under-the-hood surgery as v4.6 has always risks some unexpected side effects.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Where clause?
Reply #13 - Mar 8th, 2009, 6:33pm
 
Not a bug, as far as I can tell.  Test Case: a container c that holds "1", "1", "2", and "3"

SUCCESS:  #inside(c) & $Name=$Name(prevSibling)
SUCCESS: #inside(c) & $Name=$Name(nextSibling)

Note: if one of the notes named "1" is colored bright red, you can check *which* of the identically-named notes you're looking at.


Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Where clause?
Reply #14 - Mar 8th, 2009, 6:45pm
 
I've a hunch that an confusion (on the user side of things) is to overlook that TB allows 2 notes to have the same name - even with the same path (i.e. same parent). This means TB must track a unique note ID behind the scenes. In other words, the note's name isn't the primary ID. I've fallen into this trap myself in assuming (user 'hat' on) that same name must equal a match - and that's before we consider aliases vs original. Viewed from the implementation side of the house, I can see that's not such a clear assumption. Of course, as users we 'just' want to do things and what we want to do is the 'obvious' working assumption (mea cupla!).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1 2 
Send Topic Print