Database Reference
In-Depth Information
Table 16-5. Pig Latin expressions
Category
Expressions
Description
Examples
Constant
Literal
Constant value (see also the “Literal
example” column in Table 16-6 )
1.0 , 'a'
Field (by posi-
tion)
Field in position n (zero-based)
$ n
$0
Field (by
name)
Field named f
year
f
Field (disam-
biguate)
Field named f from relation r after
grouping or joining
r :: f
A::year
Projection
c .$ n , c . f
Field in container c (relation, bag, or
tuple) by position, by name
records.$0 , records.year
Map lookup
Value associated with key k in map m
m # k
items#'Coat'
Cast
Cast of field f to type t
( t ) f
(int) year
Arithmetic
x + y , x - y Addition, subtraction
$1 + $2 , $1 - $2
x * y , x / y Multiplication, division
$1 * $2 , $1 / $2
Modulo, the remainder of x divided by
y
x % y
$1 % $2
+ x , - x
Unary positive, negation
+1 , -1
Conditional
Bincond/ternary; y if x evaluates to
true, z otherwise
x ? y : z
quality == 0 ? 0 : 1
Multi-case conditional
CASE
CASE q WHEN 0 THEN
'good' ELSE 'bad' END
Comparison
x == y , x !=
y
Equals, does not equal
quality == 0 , temperat-
ure != 9999
x > y , x < y Greater than, less than
quality > 0 , quality <
10
x >= y , x <=
y
Greater than or equal to, less than or
equal to
quality >= 1 , quality <=
9
x matches y Pattern matching with regular expres-
sion
quality matches
'[01459]'
Is null
x is null
temperature is null
Is not null
x is not
null
temperature is not
null
Search WWH ::




Custom Search