Показ дописів із міткою pig. Показати всі дописи
Показ дописів із міткою pig. Показати всі дописи
четвер, 24 жовтня 2013 р.
вівторок, 3 вересня 2013 р.
Several Apache Pig trips and ticks
1. Counters in Pig
2. Pick up latest version of JAR
Incredible simple way to use always the last version of jar file without code changes
3. Call Java code without UDF from Pig script
It's pity that you have to write UDF each time when java call is required, even for the one line of code. There is a way to call built-in java functions without writing UDF and it's called Dynamic Invokers. For example, java.net.URLDecoder#decode method is called in the next example:
4. Set timeout for long-running UDF
Sometimes UDF can require much more time than it is expected, there is a way to stop long-running UDF automatically by Pig with @MonitoredUDF annotation (more information available here)
PigStatusReporter reporter = PigStatusReporter.getInstance(); if (reporter != null) { reporter.getCounter(key).increment(incr); }
2. Pick up latest version of JAR
Incredible simple way to use always the last version of jar file without code changes
%default elephantBirdJar `hadoop fs -ls /tmp/libs/elephant-bird-core*jar | awk '{print $8;}' | sort -n | head -1` register 'hdfs://$elephantBirdJar'
3. Call Java code without UDF from Pig script
It's pity that you have to write UDF each time when java call is required, even for the one line of code. There is a way to call built-in java functions without writing UDF and it's called Dynamic Invokers. For example, java.net.URLDecoder#decode method is called in the next example:
DEFINE UrlDecode InvokeForString('java.net.URLDecoder.decode', 'String String'); encoded_strings = LOAD 'data.txt' as (encoded:chararray); decoded_strings = FOREACH encoded_strings GENERATE UrlDecode(encoded, 'UTF-8');
4. Set timeout for long-running UDF
Sometimes UDF can require much more time than it is expected, there is a way to stop long-running UDF automatically by Pig with @MonitoredUDF annotation (more information available here)
/* Timeout for UDF is 10 seconds, if no result. thna default will be returned; pay close attention, only several types are suported to be returned, i. e. there are not tuples or bags */ @MonitoredUDF(timeUnit = TimeUnit.MILLISECONDS, duration = 10000, intDefault = 10) public class MyUDF extends EvalFunc<Integer> { /* implementation goes here */ }
пʼятниця, 17 травня 2013 р.
Fix PigUnit issue on Windows
PigUnit is the nice and extremely easy way to test your Pig script. Read more here
However, it doesn't run on Windows at all. When you write your first PigUnit script, you will get the following exception:
Try to run again. The next possible error will be:
It means, your temporary directory is not set correctly (or doesn't set at all). Be honest, I tried to set up this temporary directory with the following code:
Unfortunately,it doesn't work.... The solution is to set up system property. There are a lot of way to do it, and one of them is to tune java run configuration when you run your test, just add:
that's because of error in the code.
There are several solutions to fix this bug (it is present in Hadoop for a years... :(). One of them, is to use this patch or fix code and recompile. But for me it was the best way (special, it will be fix only for specefic version, also it is difficult to maintain on several clusters on dev machines and so on).
So, I've decided to change code at runtime with Javassist
So, the solution is a very simple and self-describing:
To apply it, just call from you test before run in. I'd recommend to do it just after PigTest instance creation.
However, it doesn't run on Windows at all. When you write your first PigUnit script, you will get the following exception:
Exception in thread "main" java.io.IOException: Cannot run program "chmod": CreateProcess error=2, The system cannot find the file specified :In fact, it means Cygwin is not correctly installed. To fix it, you have to download and install Cygwin, after that edit PATH variable and enter the path name to cygwin directory.
Try to run again. The next possible error will be:
ERROR mapReduceLayer.Launcher: Backend error message during job submission java.io.IOException: Failed to set permissions of path: \tmp\hadoop-MyUsername\mapred\staging\MyUsername1049214732.staging to 0700
It means, your temporary directory is not set correctly (or doesn't set at all). Be honest, I tried to set up this temporary directory with the following code:
pigServer.getPigContext().getProperties().setProperty("pig.temp.dir", "D:/TMP");
pigServer.getPigContext().getProperties().setProperty("hadoop.tmp.dir", "D:/TMP");
Unfortunately,it doesn't work.... The solution is to set up system property. There are a lot of way to do it, and one of them is to tune java run configuration when you run your test, just add:
-Djava.io.tmpdir=D:\TMP\Ok, that's much better, but it's not the finish yet, there is error
java.io.IOException: Failed to set permissions of path: file:/tmp/hadoop-iwonabb/mapred/staging/iwonabb-1931875024/.staging to 0700
at org.apache.hadoop.fs.RawLocalFileSystem.checkReturnValue(RawLocalFileSystem.java:526)
that's because of error in the code.
There are several solutions to fix this bug (it is present in Hadoop for a years... :(). One of them, is to use this patch or fix code and recompile. But for me it was the best way (special, it will be fix only for specefic version, also it is difficult to maintain on several clusters on dev machines and so on).
So, I've decided to change code at runtime with Javassist
So, the solution is a very simple and self-describing:
Підписатися на:
Дописи (Atom)