Philip (flip) Kromer created PIG-3962:
-----------------------------------------
Summary: Unclear error messages for map type
Key: PIG-3962
URL: https://issues.apache.org/jira/browse/PIG-3962
Project: Pig
Issue Type: Bug
Reporter: Philip (flip) Kromer
Priority: Minor
Here is a correct script:
{code}
user_hashes = LOAD 'users.tsv' AS (info:map[]);
-- [userid#123,username#jerry,followers#192] name username
-- [userid#987,username#george,followers#31] id userid
-- [userid#568,username#elaine,followers#40] name followers
users = FOREACH user_hashes GENERATE
info#'userid' AS userid:chararray,
info#'username' AS username:chararray;
DUMP users;
-- (123,jerry)
-- (987,george)
-- (568,elaine)
{code}
If I omit the quotes on the key dereference,
{code}
users = FOREACH user_hashes GENERATE info#userid AS userid:chararray;
-- 400 ERROR: ERROR 1200: <file ./foo.pig, line 8, column 42> [...]
mismatched input 'userid' expecting set null
{code}
It may be that the user forgot the quotes, or may instead be assuming that Pig
allows dereferencing a map by the value of an alias or expression:
{code}
users = FOREACH user_hashes GENERATE
info#'username', -- works
info#username, -- need quotes around literal
info#fullref, -- no, can't use an alias' value to deref
info#(CONCAT('user',shortref)) -- and can't use an expression to deref
;
{code}
The error would be better off reading
{quote}
Values may only be retrieved from a map by using a literal chararray key. Did
you mean << info#'userid' >>? See
http://pig.apache.org/docs/r0.12.0/basic.html#map
{quote}
----------------------
Forgetting to attach the dummy square brackets on a map schema gives another
confusing error message:
{code}
user_hashes = LOAD 'users.tsv' AS (id:chararray, profile:map);
-- 390 ERROR: ERROR 1200: <file ./foo.pig, line 1, column 60> [...]
mismatched input ')' expecting LEFT_BRACKET
{code}
This message should read something like
{quote}
"You must specify a type for the values of a map, or empty square brackets for
a map with generic values. Did you mean << id:chararray, profile:map[]) >>? See
http://pig.apache.org/docs/r0.12.0/basic.html#map-schema"
{quote}
--
This message was sent by Atlassian JIRA
(v6.2#6252)