You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Alex Karasulu <ak...@gmail.com> on 2009/02/18 16:37:58 UTC

Re: [SHARED] Is there an easy way to compare filters, some with OID and some without?

On Wed, Feb 18, 2009 at 10:25 AM, Hammond, Steve
<st...@polycom.com>wrote:

>  I am trying to compare 2 filters (ExprNode), it happens to be an and
> clause, but that is irrelevant.
>
>
>
> So my code is *if* ( filter.equals(*groupUnimporte**d))   // special
> filter case.*
>
> * *
>
> The problem is that when it gets to this code filter =
> (&(2.5.4.0=group)(!(1.2.840.113556.1.4.26=-1)))
>
> And groupUnimported= (&(objectClass=group)(!(ugpid=-1)))
>
>
>
> I can look at those and know they are equal.  Is there some normalizer I
> can run the 2 ExprNodes thru before doing the equals?  I don't want to do 4
> separate equals tests, especially if we start to get bigger filters that end
> up as special cases.
>
You're in luck Steve. You can use the following visitor implementation to
perform normalized comparisons of filter expressions.  This was specifically
written to match for equivalent logical expressions that may have term order
variations.

Here take a look:

    http://ahkaek.notlong.com/

This BranchNormalizedVisitor will normalize the order of terms in a filter
branch (OR / AND nodes only) without effecting the logic of the filter.
After doing this the filter can be dumped to a string and compared.

In addition to this you'll want to normalize attributes to OID's which is
easy to do if you have access to the schema.  Just write another visitor to
change the attribute alias names in leaf nodes to their respective OID value
using the lookup method in AttriuteTypeRegistry.

HTH,
Alex

Re: [SHARED] Is there an easy way to compare filters, some with OID and some without?

Posted by Alex Karasulu <ak...@gmail.com>.
On Wed, Feb 18, 2009 at 11:03 AM, Hammond, Steve
<st...@polycom.com>wrote:

>  Great!
>
>
>
> I have one question.  Why do you suggest dumping to a string to compare
> when there is an equals function on ExprNode already?
>
>
Ahh yeah I forgot that I added the equals method.  Use that sure.

Regards,
Alex


>
>  ------------------------------
>
> *From:* Alex Karasulu [mailto:akarasulu@gmail.com]
> *Sent:* Wednesday, February 18, 2009 8:38 AM
> *To:* Apache Directory Developers List
> *Subject:* Re: [SHARED] Is there an easy way to compare filters, some with
> OID and some without?
>
>
>
>
>
> On Wed, Feb 18, 2009 at 10:25 AM, Hammond, Steve <
> steve.hammond@polycom.com> wrote:
>
> I am trying to compare 2 filters (ExprNode), it happens to be an and
> clause, but that is irrelevant.
>
>
>
> So my code is *if* ( filter.equals(*groupUnimporte**d))   // special
> filter case.*
>
> * *
>
> The problem is that when it gets to this code filter =
> (&(2.5.4.0=group)(!(1.2.840.113556.1.4.26=-1)))
>
> And groupUnimported= (&(objectClass=group)(!(ugpid=-1)))
>
>
>
> I can look at those and know they are equal.  Is there some normalizer I
> can run the 2 ExprNodes thru before doing the equals?  I don't want to do 4
> separate equals tests, especially if we start to get bigger filters that end
> up as special cases.
>
> You're in luck Steve. You can use the following visitor implementation to
> perform normalized comparisons of filter expressions.  This was specifically
> written to match for equivalent logical expressions that may have term order
> variations.
>
> Here take a look:
>
>     http://ahkaek.notlong.com/
>
> This BranchNormalizedVisitor will normalize the order of terms in a filter
> branch (OR / AND nodes only) without effecting the logic of the filter.
> After doing this the filter can be dumped to a string and compared.
>
> In addition to this you'll want to normalize attributes to OID's which is
> easy to do if you have access to the schema.  Just write another visitor to
> change the attribute alias names in leaf nodes to their respective OID value
> using the lookup method in AttriuteTypeRegistry.
>
> HTH,
> Alex
>

RE: [SHARED] Is there an easy way to compare filters, some with OID and some without?

Posted by "Hammond, Steve" <st...@Polycom.com>.
Great!

 

I have one question.  Why do you suggest dumping to a string to compare
when there is an equals function on ExprNode already?

 

________________________________

From: Alex Karasulu [mailto:akarasulu@gmail.com] 
Sent: Wednesday, February 18, 2009 8:38 AM
To: Apache Directory Developers List
Subject: Re: [SHARED] Is there an easy way to compare filters, some with
OID and some without?

 

 

On Wed, Feb 18, 2009 at 10:25 AM, Hammond, Steve
<st...@polycom.com> wrote:

I am trying to compare 2 filters (ExprNode), it happens to be an and
clause, but that is irrelevant.

 

So my code is if ( filter.equals(groupUnimported))   // special filter
case.

 

The problem is that when it gets to this code filter =
(&(2.5.4.0=group)(!(1.2.840.113556.1.4.26=-1)))

And groupUnimported= (&(objectClass=group)(!(ugpid=-1)))

 

I can look at those and know they are equal.  Is there some normalizer I
can run the 2 ExprNodes thru before doing the equals?  I don't want to
do 4 separate equals tests, especially if we start to get bigger filters
that end up as special cases.

You're in luck Steve. You can use the following visitor implementation
to perform normalized comparisons of filter expressions.  This was
specifically written to match for equivalent logical expressions that
may have term order variations.

Here take a look:

    http://ahkaek.notlong.com/

This BranchNormalizedVisitor will normalize the order of terms in a
filter branch (OR / AND nodes only) without effecting the logic of the
filter. After doing this the filter can be dumped to a string and
compared. 

In addition to this you'll want to normalize attributes to OID's which
is easy to do if you have access to the schema.  Just write another
visitor to change the attribute alias names in leaf nodes to their
respective OID value using the lookup method in AttriuteTypeRegistry.

HTH,
Alex