Skip to content
Permalink
Browse files
ACCUMULO-142
formatted the code using the Eclipse Accumulo Codestyle



git-svn-id: https://svn.apache.org/repos/asf/accumulo/contrib/pig/trunk@1339307 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Jason Trost committed May 16, 2012
1 parent 7938b1b commit 8c13867ceb826a583ff9470efbe58e35ccbd9682
Showing 8 changed files with 649 additions and 739 deletions.

Large diffs are not rendered by default.

@@ -34,59 +34,50 @@

/**
* A LoadStoreFunc for retrieving data from and storing data to Accumulo
*
* A Key/Val pair will be returned as tuples: (key, colfam, colqual, colvis, timestamp, value). All fields except timestamp are DataByteArray, timestamp is a long.
*
* Tuples can be written in 2 forms:
* (key, colfam, colqual, colvis, value)
* OR
* (key, colfam, colqual, value)
* A Key/Val pair will be returned as tuples: (key, colfam, colqual, colvis, timestamp, value). All fields except timestamp are DataByteArray, timestamp is a
* long.
*
* Tuples can be written in 2 forms: (key, colfam, colqual, colvis, value) OR (key, colfam, colqual, value)
*
*/
public class AccumuloStorage extends AbstractAccumuloStorage
{
private static final Log LOG = LogFactory.getLog(AccumuloStorage.class);

public AccumuloStorage(){}

@Override
protected Tuple getTuple(Key key, Value value) throws IOException {
// and wrap it in a tuple
Tuple tuple = TupleFactory.getInstance().newTuple(6);
tuple.set(0, new DataByteArray(key.getRow().getBytes()));
tuple.set(1, new DataByteArray(key.getColumnFamily().getBytes()));
tuple.set(2, new DataByteArray(key.getColumnQualifier().getBytes()));
tuple.set(3, new DataByteArray(key.getColumnVisibility().getBytes()));
tuple.set(4, new Long(key.getTimestamp()));
tuple.set(5, new DataByteArray(value.get()));
return tuple;
}

@Override
public Collection<Mutation> getMutations(Tuple tuple) throws ExecException, IOException {
Mutation mut = new Mutation(Utils.objToText(tuple.get(0)));
Text cf = Utils.objToText(tuple.get(1));
Text cq = Utils.objToText(tuple.get(2));

if(tuple.size() > 4)
{
Text cv = Utils.objToText(tuple.get(3));
Value val = new Value(Utils.objToBytes(tuple.get(4)));
if(cv.getLength() == 0)
{
mut.put(cf, cq, val);
}
else
{
mut.put(cf, cq, new ColumnVisibility(cv), val);
}
}
else
{
Value val = new Value(Utils.objToBytes(tuple.get(3)));
mut.put(cf, cq, val);
}

return Collections.singleton(mut);
}
public class AccumuloStorage extends AbstractAccumuloStorage {
private static final Log LOG = LogFactory.getLog(AccumuloStorage.class);

public AccumuloStorage() {}

@Override
protected Tuple getTuple(Key key, Value value) throws IOException {
// and wrap it in a tuple
Tuple tuple = TupleFactory.getInstance().newTuple(6);
tuple.set(0, new DataByteArray(key.getRow().getBytes()));
tuple.set(1, new DataByteArray(key.getColumnFamily().getBytes()));
tuple.set(2, new DataByteArray(key.getColumnQualifier().getBytes()));
tuple.set(3, new DataByteArray(key.getColumnVisibility().getBytes()));
tuple.set(4, new Long(key.getTimestamp()));
tuple.set(5, new DataByteArray(value.get()));
return tuple;
}

@Override
public Collection<Mutation> getMutations(Tuple tuple) throws ExecException, IOException {
Mutation mut = new Mutation(Utils.objToText(tuple.get(0)));
Text cf = Utils.objToText(tuple.get(1));
Text cq = Utils.objToText(tuple.get(2));

if (tuple.size() > 4) {
Text cv = Utils.objToText(tuple.get(3));
Value val = new Value(Utils.objToBytes(tuple.get(4)));
if (cv.getLength() == 0) {
mut.put(cf, cq, val);
} else {
mut.put(cf, cq, new ColumnVisibility(cv), val);
}
} else {
Value val = new Value(Utils.objToBytes(tuple.get(3)));
mut.put(cf, cq, val);
}

return Collections.singleton(mut);
}
}
@@ -43,77 +43,65 @@

/**
* A LoadStoreFunc for retrieving data from and storing data to Accumulo
*
* A Key/Val pair will be returned as tuples: (key, colfam, colqual, colvis, timestamp, value). All fields except timestamp are DataByteArray, timestamp is a long.
*
* Tuples can be written in 2 forms:
* (key, colfam, colqual, colvis, value)
* OR
* (key, colfam, colqual, value)
* A Key/Val pair will be returned as tuples: (key, colfam, colqual, colvis, timestamp, value). All fields except timestamp are DataByteArray, timestamp is a
* long.
*
* Tuples can be written in 2 forms: (key, colfam, colqual, colvis, value) OR (key, colfam, colqual, value)
*
*/
public class AccumuloWholeRowStorage extends AbstractAccumuloStorage
{
private static final Log LOG = LogFactory.getLog(AccumuloWholeRowStorage.class);

public AccumuloWholeRowStorage(){}

@Override
protected Tuple getTuple(Key key, Value value) throws IOException {

SortedMap<Key, Value> rowKVs = WholeRowIterator.decodeRow(key, value);
List<Tuple> columns = new ArrayList<Tuple>(rowKVs.size());
for(Entry<Key, Value> e : rowKVs.entrySet())
{
columns.add(columnToTuple(
e.getKey().getColumnFamily(),
e.getKey().getColumnQualifier(),
e.getKey().getColumnVisibility(),
e.getKey().getTimestamp(),
e.getValue())
);
}

// and wrap it in a tuple
Tuple tuple = TupleFactory.getInstance().newTuple(2);
tuple.set(0, new DataByteArray(key.getRow().getBytes()));
tuple.set(1, new DefaultDataBag(columns));

return tuple;
}

private Tuple columnToTuple(Text colfam, Text colqual, Text colvis, long ts, Value val) throws IOException
{
Tuple tuple = TupleFactory.getInstance().newTuple(5);
tuple.set(0, new DataByteArray(colfam.getBytes()));
tuple.set(1, new DataByteArray(colqual.getBytes()));
tuple.set(2, new DataByteArray(colvis.getBytes()));
tuple.set(3, new Long(ts));
tuple.set(4, new DataByteArray(val.get()));
return tuple;
}

protected void configureInputFormat(Configuration conf)
{
AccumuloInputFormat.addIterator(conf, new IteratorSetting(10, WholeRowIterator.class));
public class AccumuloWholeRowStorage extends AbstractAccumuloStorage {
private static final Log LOG = LogFactory.getLog(AccumuloWholeRowStorage.class);

public AccumuloWholeRowStorage() {}

@Override
protected Tuple getTuple(Key key, Value value) throws IOException {

SortedMap<Key,Value> rowKVs = WholeRowIterator.decodeRow(key, value);
List<Tuple> columns = new ArrayList<Tuple>(rowKVs.size());
for (Entry<Key,Value> e : rowKVs.entrySet()) {
columns.add(columnToTuple(e.getKey().getColumnFamily(), e.getKey().getColumnQualifier(), e.getKey().getColumnVisibility(), e.getKey().getTimestamp(),
e.getValue()));
}

@Override
public Collection<Mutation> getMutations(Tuple tuple) throws ExecException, IOException {

Mutation mut = new Mutation(Utils.objToText(tuple.get(0)));
DefaultDataBag columns = (DefaultDataBag)tuple.get(1);
for(Tuple column : columns)
{
Text cf = Utils.objToText(column.get(0));
Text cq = Utils.objToText(column.get(1));
Text cv = Utils.objToText(column.get(2));
Long ts = (Long)column.get(3);
Value val = new Value(Utils.objToBytes(column.get(4)));

mut.put(cf, cq, new ColumnVisibility(cv), ts, val);
}

return Collections.singleton(mut);
// and wrap it in a tuple
Tuple tuple = TupleFactory.getInstance().newTuple(2);
tuple.set(0, new DataByteArray(key.getRow().getBytes()));
tuple.set(1, new DefaultDataBag(columns));

return tuple;
}

private Tuple columnToTuple(Text colfam, Text colqual, Text colvis, long ts, Value val) throws IOException {
Tuple tuple = TupleFactory.getInstance().newTuple(5);
tuple.set(0, new DataByteArray(colfam.getBytes()));
tuple.set(1, new DataByteArray(colqual.getBytes()));
tuple.set(2, new DataByteArray(colvis.getBytes()));
tuple.set(3, new Long(ts));
tuple.set(4, new DataByteArray(val.get()));
return tuple;
}

protected void configureInputFormat(Configuration conf) {
AccumuloInputFormat.addIterator(conf, new IteratorSetting(10, WholeRowIterator.class));
}

@Override
public Collection<Mutation> getMutations(Tuple tuple) throws ExecException, IOException {

Mutation mut = new Mutation(Utils.objToText(tuple.get(0)));
DefaultDataBag columns = (DefaultDataBag) tuple.get(1);
for (Tuple column : columns) {
Text cf = Utils.objToText(column.get(0));
Text cq = Utils.objToText(column.get(1));
Text cv = Utils.objToText(column.get(2));
Long ts = (Long) column.get(3);
Value val = new Value(Utils.objToBytes(column.get(4)));

mut.put(cf, cq, new ColumnVisibility(cv), ts, val);
}

return Collections.singleton(mut);
}
}
@@ -20,40 +20,33 @@
import org.apache.pig.data.DataByteArray;

public class Utils {
public static Text objToText(Object o)
{
return new Text(objToBytes(o));
public static Text objToText(Object o) {
return new Text(objToBytes(o));
}

public static byte[] objToBytes(Object o) {
if (o instanceof String) {
String str = (String) o;
return str.getBytes();
} else if (o instanceof Long) {
Long l = (Long) o;
return l.toString().getBytes();
} else if (o instanceof Integer) {
Integer l = (Integer) o;
return l.toString().getBytes();
} else if (o instanceof Boolean) {
Boolean l = (Boolean) o;
return l.toString().getBytes();
} else if (o instanceof Float) {
Float l = (Float) o;
return l.toString().getBytes();
} else if (o instanceof Double) {
Double l = (Double) o;
return l.toString().getBytes();
}

public static byte[] objToBytes(Object o)
{
if (o instanceof String) {
String str = (String) o;
return str.getBytes();
}
else if (o instanceof Long) {
Long l = (Long) o;
return l.toString().getBytes();
}
else if (o instanceof Integer) {
Integer l = (Integer) o;
return l.toString().getBytes();
}
else if (o instanceof Boolean) {
Boolean l = (Boolean) o;
return l.toString().getBytes();
}
else if (o instanceof Float) {
Float l = (Float) o;
return l.toString().getBytes();
}
else if (o instanceof Double) {
Double l = (Double) o;
return l.toString().getBytes();
}

// TODO: handle DataBag, Map<Object, Object>, and Tuple

return ((DataByteArray)o).get();
}
// TODO: handle DataBag, Map<Object, Object>, and Tuple

return ((DataByteArray) o).get();
}
}

0 comments on commit 8c13867

Please sign in to comment.