Method R
Welcome, Guest
Please Login or Register.    Lost Password?
Re:substitution in a --group expression (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:substitution in a --group expression
#320
cmillsap (Admin)
Admin
Posts: 14
graphgraph
User Offline Click here to see the profile of this user
Re:substitution in a --group expression 1 Year ago  
Brian,

Don't feel bad; it's a complicated thing you're trying to do.

We can suggest two solutions.

Here's the first one. It uses --init to define a subroutine (Perl syntax) that then can be called by the --group expression:

mrskew *.trc --init='sub f($) { my $x = $_[0]; for ($x) { s:/\*\+.*?\*/::g; }; return $x; }' --group='substr(f($sql), 0, 50)'

One subtlety to notice is in the regular expression /\*\+.*?\*/. The .*? construct calls for a non-greedy match. It makes the RE work correctly for a string like "select /*+ hint1 */ stuff /*+ hint2 */". Without the ?, the RE processor would have eaten the string " stuff " as well as both hints, which would give an incorrect result.

The second one is simpler:

mrskew *.trc --group='substr(($sql =~ s:/\*\+.*?\*/::g, $sql)[1], 0, 50)'

This one constructs a list of two elements. The first element executes the =~ operator, which returns a count of matches, but changes its lvalue. The second element references the changed value of $sql. The [1] appended to the list means to select only the 1th element of the list as the --group expression's ultimate value.

Note that it's important in either case to do the substr() operator after the regular expression processing. Otherwise, you risk not having the closing */ delimiter in the string in which you're searching for hints.
 
Report to moderator   Logged Logged  
 
Last Edit: 2012/04/30 09:54 By cmillsap.
  The administrator has disabled public write access.
      Topics Author Date
    thread link
substitution in a --group expression
b_winter 2012/04/30 08:48
    thread link
thread linkthread link Re:substitution in a --group expression
cmillsap 2012/04/30 09:50
    thread link
thread linkthread linkthread link Re:substitution in a --group expression
b_winter 2012/04/30 10:11
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop