adrift on a cosmic ocean

Writings on various topics (mostly technical) from Oliver Hookins and Angela Collins. We have lived in Berlin since 2009, have two kids, and have far too little time to really justify having a blog.

Broken environment variables and broken dreams

Posted by Oliver on the 12th of September, 2012 in category Tech
Tagged with: antenvironmentjavalocalepigpiggybank

OK, the content of this post is not nearly as melodramatic as the title - I'm attempting to do some log analysis with Hadoop and Pig (yes, I'm several years in the past, just barely catching up to all of you folk who have been using Hadoop for a long time). As the logs are coming from a webserver and are not that far from standard "combined" format, it is most logical to use the time-saving UDFs in Pig's Piggybank. This is just a set of user-contributed code, but very useful.

Unfortunately there doesn't seem to be a Debian package for it, at least not in the set of repositories I have available to me on this machine so I thought I'd just compile it - it is dynamically loadable from an arbitrary path in a Pig script so this is not a big issue. The process is two-fold:

  1. Compile Pig itself (or locate the pig-withouthadoop.jar pre-compiled on your system)
  2. Compile Piggybank against that version of Pig

Pig uses the Ant build system, and it really is as trivial as running ant from the top-level directory. I checked out the tagged release of 0.10.0 and successfully built Pig. Building Piggybank against it, however, errored out with something I wasn't immediately able to find on the interwebs:

$ ant
Buildfile: /home/oliver/release-0.10.0/contrib/piggybank/java/build.xml

    [mkdir] Created dir: /home/oliver/release-0.10.0/contrib/piggybank/java/build
    [mkdir] Created dir: /home/oliver/release-0.10.0/contrib/piggybank/java/build/classes
    [mkdir] Created dir: /home/oliver/release-0.10.0/contrib/piggybank/java/build/test
    [mkdir] Created dir: /home/oliver/release-0.10.0/contrib/piggybank/java/build/test/classes
    [mkdir] Created dir: /home/oliver/release-0.10.0/contrib/piggybank/java/build/docs/api

     [echo]  *** Compiling Pig UDFs ***
    [javac] /home/oliver/release-0.10.0/contrib/piggybank/java/build.xml:92: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 154 source files to /home/oliver/release-0.10.0/contrib/piggybank/java/build/classes
    [javac] error: error reading /home/oliver/release-0.10.0/pig-withouthadoop.jar; invalid header field
    [javac] 1 error

/home/oliver/release-0.10.0/contrib/piggybank/java/build.xml:92: Compile failed; see the compiler error output for details.

Total time: 0 seconds

Now, I'm not a Java guy so this means very little to me. However I do at least know that a Jar file is simply a zip archive so I went digging. Assuming that the 'invalid header field' is in the metadata of the Jar file, I looked in the contained META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.0
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Main-Class: org.apache.pig.Main

Name: org/apache/pig
Implementation-Vendor: Apache
Implementation-Title: Pig
Implementation-Version: 0.10.0-SNAPSHOT
Build-TimeStamp: Sep 12 2012, 08:14:45
Svn-Revision: svnversion: warning: cannot set LC_CTYPE locale
 on: warning: environment variable LC_CTYPE is UTF-8
svnversion: warni
 ng: please check that your locale name is correct

It seems that some locale settings in the environment are causing issues with the svnversion program, and indeed when running it separately I can confirm the same issue:

~/release-0.10.0$ svnversion
svnversion: warning: cannot set LC_CTYPE locale
svnversion: warning: environment variable LC_CTYPE is UTF-8
svnversion: warning: please check that your locale name is correct

I've been seeing this on a bunch of machines I've been using recently but frankly I haven't had the time to diagnose it. It is easily worked around with unset LC_CTYPE:

~/release-0.10.0$ unset LC_CTYPE
~/release-0.10.0$ svnversion

There is some contention around adding superfluous metadata fields in Ant builds, but again, this is something I don't particularly care to dive into at the moment. An acceptable alternative workaround in this case would have been to remove the additional metadata generation in the Ant build.xml.

Rebuilding Pig now and Piggybank against it works. Huzzah! On to the next problem 😆

© 2010-2018 Oliver Hookins and Angela Collins