Nital
Nital

Reputation: 6084

How to use string functions in pig

I am trying to convert a string to upper case in pig using one of it's built-in functions. I am using pig in local mode.

emps.csv

1,John,35,M,101,50000.00,03/03/79
2,Jack,30,F,201,3540000.00,09/10/84

Commands for loading data (WORKS FINE)

empdata = load 'emps.csv'  using PigStorage(',') as (id:int,name:chararray,age:int,gender:chararray,deptId:int,sal:double);
dump empdata

Convert to upper case and print it (FAILS WITH ERROR)

empnameucase = foreach empdata generate id,upper(name);

But I am getting following exception after executing above command:

Error Log:

Caused by: org.apache.pig.backend.executionengine.ExecException: ERROR 1070: Could not resolve upper using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]
        at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:653)
        at org.apache.pig.impl.PigContext.getClassForAlias(PigContext.java:769)
        at org.apache.pig.parser.LogicalPlanBuilder.buildUDF(LogicalPlanBuilder.java:1491)
        ... 28 more

Please guide.

Upvotes: 0

Views: 1132

Answers (1)

Rengasamy
Rengasamy

Reputation: 1043

Try this, You should specify the function name in UPPER case like

UPPER(name)

Hopt,it should work.

Upvotes: 1

Related Questions