NJ_315
NJ_315

Reputation: 1883

How to Filter using Regular Expression in Pig latin

I have to find a name given the first letter is 'P' and the last letter is 'l'. In sql, we would give it as 'P%%l'. In pig latin commands, how can this be given.

Upvotes: 1

Views: 910

Answers (3)

Kannappan Sirchabesan
Kannappan Sirchabesan

Reputation: 1382

The Pig equivalent of SQL's '%' is '.*'

So you can use

X = FILTER A BY (name matches 'P.*I');

Reference: http://pig.apache.org/docs/r0.10.0/basic.html#comparison

Upvotes: 0

Konstantin Kudryavtsev
Konstantin Kudryavtsev

Reputation: 592

The format of regular expressions in Pig is that supported by Java So, use matches in FILTER: result = FILTER input BY name matches '^P.*I$'

Upvotes: 1

Arnon Rotem-Gal-Oz
Arnon Rotem-Gal-Oz

Reputation: 25909

You'd use the FILTER command with a regex e.g.

X = FILTER A BY (name matches '\AP\w*l\b');

Upvotes: 2

Related Questions