Skip to content

Instantly share code, notes, and snippets.

@msukmanowsky
Last active December 15, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msukmanowsky/198c878e1deaf4e470a9 to your computer and use it in GitHub Desktop.
Save msukmanowsky/198c878e1deaf4e470a9 to your computer and use it in GitHub Desktop.
Excerpt of the MetadataLookup EvalFunc.
package com.parsely.pig.cache;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.pig.EvalFunc;
import org.apache.pig.PigWarning;
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import org.apache.pig.impl.logicalLayer.schema.Schema;
import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
import com.parsely.util.cache.Metadata;
import com.parsely.util.cache.ParselyMetadataService;
public class MetadataLookup extends EvalFunc<Tuple> {
private ParselyMetadataService meta;
private TupleFactory mTupleFactory = TupleFactory.getInstance();
private DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
private Log logger;
public MetadataLookup(int lruSize) throws UnknownHostException {
// This service opens up a connection to both mongo and redis
this.meta = new ParselyMetadataService(lruSize);
this.logger = getLogger();
}
public MetadataLookup() throws UnknownHostException {
this(500);
}
@Override
public Tuple exec(Tuple input) throws IOException {
// Returns a 5 element tuple by using calls to meta.fetch()
// which queries Redis/Mongo depending on the parameters
}
@Override
public void finish() {
// Closes the private mongo and redis connections within meta
meta.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment