Skip to content
Permalink
Browse files
some minor code cleanup (#83)
  • Loading branch information
Manno15 committed Dec 9, 2021
1 parent d1cc653 commit 6c00d0cc9e717190205ea4252788bca9224dd75a
Showing 22 changed files with 50 additions and 56 deletions.
@@ -46,7 +46,7 @@ public void receive(Key key, Value value) {
String row = key.getRow().toString();
long rowid = Integer.parseInt(row.split("_")[1]);

byte expectedValue[] = RandomBatchWriter.createValue(rowid, expectedValueSize);
byte[] expectedValue = RandomBatchWriter.createValue(rowid, expectedValueSize);

if (!Arrays.equals(expectedValue, value.get())) {
log.error("Got unexpected value for " + key + " expected : "
@@ -58,7 +58,7 @@ public class RandomBatchWriter {
*/
public static byte[] createValue(long rowid, int dataSize) {
Random r = new Random(rowid);
byte value[] = new byte[dataSize];
byte[] value = new byte[dataSize];

r.nextBytes(value);

@@ -89,7 +89,7 @@ public static Mutation createMutation(long rowid, int dataSize, ColumnVisibility

// create a random value that is a function of the
// row id for verification purposes
byte value[] = createValue(rowid, dataSize);
byte[] value = createValue(rowid, dataSize);

m.put(new Text("foo"), new Text("1"), visibility, new Value(value));

@@ -159,7 +159,7 @@ public static void main(String[] args) throws AccumuloException, TableNotFoundEx
if (e.getSecurityErrorCodes().size() > 0) {
HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
for (Entry<TabletId,Set<SecurityErrorCode>> ke : e.getSecurityErrorCodes().entrySet()) {
String tableId = ke.getKey().getTableId().toString();
String tableId = ke.getKey().getTable().toString();
Set<SecurityErrorCode> secCodes = tables.get(tableId);
if (secCodes == null) {
secCodes = new HashSet<>();
@@ -52,7 +52,7 @@ public class TracingExample {
private static final Logger log = LoggerFactory.getLogger(TracingExample.class);
private static final String DEFAULT_TABLE_NAME = "test";

private AccumuloClient client;
private final AccumuloClient client;

static class Opts extends ClientOnDefaultTable {
@Parameter(names = {"--createtable"}, description = "create table before doing anything")
@@ -44,12 +44,12 @@ public class FileCount {
private int entriesScanned;
private int inserts;

private ScannerOpts scanOpts;
private BatchWriterOpts bwOpts;
private AccumuloClient client;
private String tableName;
private Authorizations auths;
private ColumnVisibility visibility;
private final ScannerOpts scanOpts;
private final BatchWriterOpts bwOpts;
private final AccumuloClient client;
private final String tableName;
private final Authorizations auths;
private final ColumnVisibility visibility;

private static class CountValue {
int dirCount = 0;
@@ -100,7 +100,7 @@ private int findMaxDepth(Scanner scanner, int min, int max) {
}

private int findMaxDepth(Scanner scanner, int min, int mid, int max) {
// check to see if the mid point exist
// check to see if the mid-point exist
if (max < min)
return -1;

@@ -68,7 +68,7 @@ public static Mutation buildMutation(ColumnVisibility cv, String path, boolean i
if (path.equals("/"))
path = "";
Mutation m = new Mutation(QueryUtil.getRow(path));
Text colf = null;
Text colf;
if (isDir)
colf = QueryUtil.DIR_COLF;
else
@@ -39,9 +39,9 @@
* and performing single wild card searches on file or directory names.
*/
public class QueryUtil {
private AccumuloClient client;
private String tableName;
private Authorizations auths;
private final AccumuloClient client;
private final String tableName;
private final Authorizations auths;
public static final Text DIR_COLF = new Text("dir");
public static final Text FORWARD_PREFIX = new Text("f");
public static final Text REVERSE_PREFIX = new Text("r");
@@ -171,7 +171,7 @@ public Map<String,Map<String,String>> getDirList(String path) throws TableNotFou
name = name.substring(name.lastIndexOf("/") + 1);
String type = getType(e.getKey().getColumnFamily());
if (!fim.containsKey(name)) {
fim.put(name, new TreeMap<String,String>());
fim.put(name, new TreeMap<>());
fim.get(name).put("fullname", e.getKey().getRow().toString().substring(3));
}
fim.get(name).put(type + e.getKey().getColumnQualifier().toString() + ":"
@@ -202,7 +202,7 @@ public Iterable<Entry<Key,Value>> exactTermSearch(String term) throws Exception
* beginning or end
*/
public Iterable<Entry<Key,Value>> singleRestrictedWildCardSearch(String exp) throws Exception {
if (exp.indexOf("/") >= 0)
if (exp.contains("/"))
throw new Exception("this method only works with unqualified names");

Scanner scanner = client.createScanner(tableName, auths);
@@ -214,7 +214,7 @@ public Iterable<Entry<Key,Value>> singleRestrictedWildCardSearch(String exp) thr
System.out.println("executing ending wildcard search for " + exp);
exp = exp.substring(0, exp.length() - 1);
scanner.setRange(Range.prefix(getForwardIndex(exp)));
} else if (exp.indexOf("*") >= 0) {
} else if (exp.contains("*")) {
throw new Exception("this method only works for beginning or ending wild cards");
} else {
return exactTermSearch(exp);
@@ -62,8 +62,8 @@ public class Viewer extends JFrame implements TreeSelectionListener, TreeExpansi
JScrollPane dataPane;

public static class NodeInfo {
private String name;
private Map<String,String> data;
private final String name;
private final Map<String,String> data;

public NodeInfo(String name, Map<String,String> data) {
this.name = name;
@@ -53,8 +53,7 @@ public static class HistMapper extends Mapper<List<Entry<Key,Value>>,InputStream
public void map(List<Entry<Key,Value>> k, InputStream v, Context context)
throws IOException, InterruptedException {
Long[] hist = new Long[256];
for (int i = 0; i < hist.length; i++)
hist[i] = 0L;
Arrays.fill(hist, 0L);
int b = v.read();
while (b >= 0) {
hist[b] += 1L;
@@ -41,7 +41,7 @@ public class ChunkInputFormat extends InputFormatBase<List<Entry<Key,Value>>,Inp
@Override
public RecordReader<List<Entry<Key,Value>>,InputStream> createRecordReader(InputSplit split,
TaskAttemptContext context) {
return new RecordReaderBase<List<Entry<Key,Value>>,InputStream>() {
return new RecordReaderBase<>() {
private PeekingIterator<Entry<Key,Value>> peekingScannerIterator;

@Override
@@ -45,7 +45,7 @@ public class ChunkInputStream extends InputStream {
protected int currentChunkSize;
protected boolean gotEndMarker;

protected byte buf[];
protected byte[] buf;
protected int count;
protected int pos;

@@ -86,9 +86,7 @@ public void setSource(PeekingIterator<Entry<Key,Value>> in) throws IOException {
currentVis.add(currentKey.getColumnVisibility());
currentChunk = FileDataIngest.bytesToInt(currentKey.getColumnQualifier().getBytes(), 4);
currentChunkSize = FileDataIngest.bytesToInt(currentKey.getColumnQualifier().getBytes(), 0);
gotEndMarker = false;
if (buf.length == 0)
gotEndMarker = true;
gotEndMarker = buf.length == 0;
if (currentChunk != 0) {
source = null;
throw new IOException("starting chunk number isn't 0 for " + currentKey.getRow());
@@ -136,8 +134,7 @@ private int fill() throws IOException {
}

// add the visibility to the list if it's not there
if (!currentVis.contains(thisKey.getColumnVisibility()))
currentVis.add(thisKey.getColumnVisibility());
currentVis.add(thisKey.getColumnVisibility());

// check to see if it is an identical chunk with a different visibility
if (thisKey.getColumnQualifier().equals(currentKey.getColumnQualifier())) {
@@ -40,7 +40,7 @@
*/
public class FileDataQuery {
List<Entry<Key,Value>> lastRefs;
private ChunkInputStream cis;
private final ChunkInputStream cis;
Scanner scanner;

public FileDataQuery(AccumuloClient client, String tableName, Authorizations auths)
@@ -26,7 +26,7 @@
*/
public class VisibilityCombiner {

private TreeSet<String> visibilities = new TreeSet<>();
private final TreeSet<String> visibilities = new TreeSet<>();

void add(ByteSequence cv) {
if (cv.length() == 0)
@@ -57,7 +57,7 @@ static class NGramMapper extends Mapper<LongWritable,Text,Text,Mutation> {
@Override
protected void map(LongWritable location, Text value, Context context)
throws IOException, InterruptedException {
String parts[] = value.toString().split("\\t");
String[] parts = value.toString().split("\\t");
if (parts.length >= 4) {
Mutation m = new Mutation(parts[0]);
m.put(parts[1], String.format("%010d", Long.parseLong(parts[2])),
@@ -92,9 +92,9 @@ public static void main(String[] args) throws Exception {
log.info("Creating table " + opts.tableName);
Common.createTableWithNamespace(client, opts.tableName);
SortedSet<Text> splits = new TreeSet<>();
String numbers[] = "1 2 3 4 5 6 7 8 9".split("\\s");
String lower[] = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split("\\s");
String upper[] = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split("\\s");
String[] numbers = "1 2 3 4 5 6 7 8 9".split("\\s");
String[] lower = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split("\\s");
String[] upper = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split("\\s");
for (String[] array : new String[][] {numbers, lower, upper}) {
for (String s : array) {
splits.add(new Text(s));
@@ -183,8 +183,8 @@ public List<InputSplit> getSplits(JobContext job) {
}
}

private static String NUMSPLITS = "terasort.overridesplits";
private static String NUMROWS = "terasort.numrows";
private static final String NUMSPLITS = "terasort.overridesplits";
private static final String NUMROWS = "terasort.numrows";

static class RandomGenerator {
private long seed = 0;
@@ -237,12 +237,12 @@ public static class SortGenMapper extends Mapper<LongWritable,NullWritable,Text,
private int minvaluelength = 0;
private int maxvaluelength = 0;

private Text key = new Text();
private Text value = new Text();
private final Text key = new Text();
private final Text value = new Text();
private RandomGenerator rand;
private byte[] keyBytes; // = new byte[12];
private byte[] spaces = " ".getBytes();
private byte[][] filler = new byte[26][];
private final byte[] spaces = " ".getBytes();
private final byte[][] filler = new byte[26][];
{
for (int i = 0; i < 26; ++i) {
filler[i] = new byte[10];
@@ -255,7 +255,7 @@ public static class SortGenMapper extends Mapper<LongWritable,NullWritable,Text,
/**
* Add a random key to the text
*/
private Random random = new Random();
private final Random random = new Random();

private void addKey() {
int range = random.nextInt(maxkeylength - minkeylength + 1);
@@ -44,7 +44,7 @@ public class UniqueColumns {
private static final Text EMPTY = new Text();

public static class UMapper extends Mapper<Key,Value,Text,Text> {
private Text temp = new Text();
private final Text temp = new Text();
private static final Text CF = new Text("cf:");
private static final Text CQ = new Text("cq:");

@@ -126,7 +126,7 @@ private static void selectRandomWords(ArrayList<Text> words, ArrayList<Text[]> r
int numTerms) {
if (words.size() >= numTerms) {
Collections.shuffle(words, rand);
Text docWords[] = new Text[numTerms];
Text[] docWords = new Text[numTerms];
for (int i = 0; i < docWords.length; i++) {
docWords[i] = words.get(i);
}
@@ -82,7 +82,7 @@ public static void index(int numPartitions, File src, String splitRegex, BatchWr

StringBuilder sb = new StringBuilder();

char data[] = new char[4096];
char[] data = new char[4096];
int len;
while ((len = fr.read(data)) != -1) {
sb.append(data, 0, len);
@@ -52,16 +52,16 @@ static class QueryOpts extends ClientOpts {

@Parameter(names = {"--sample"},
description = "Do queries against sample, useful when sample is built using column qualifier")
private boolean useSample = false;
private final boolean useSample = false;

@Parameter(names = {"--sampleCutoff"},
description = "Use sample data to determine if a query might return a number of documents over the cutoff. This check is per tablet.")
private Integer sampleCutoff = null;
private final Integer sampleCutoff = null;
}

public static List<String> query(BatchScanner bs, List<String> terms, Integer cutoff) {

Text columns[] = new Text[terms.size()];
Text[] columns = new Text[terms.size()];
int i = 0;
for (String term : terms) {
columns[i++] = new Text(term);
@@ -28,7 +28,7 @@

public class AlphaNumKeyConstraintTest {

private AlphaNumKeyConstraint ankc = new AlphaNumKeyConstraint();
private final AlphaNumKeyConstraint ankc = new AlphaNumKeyConstraint();

@Test
public void test() {
@@ -28,7 +28,7 @@

public class NumericValueConstraintTest {

private NumericValueConstraint nvc = new NumericValueConstraint();
private final NumericValueConstraint nvc = new NumericValueConstraint();

@Test
public void testCheck() {
@@ -42,7 +42,7 @@ public static class MapIterator implements SortedKeyValueIterator<Key,Value> {
private Iterator<Entry<Key,Value>> iter;
private Entry<Key,Value> entry;
Collection<ByteSequence> columnFamilies;
private SortedMap<Key,Value> map;
private final SortedMap<Key,Value> map;
private Range range;

@Override
@@ -65,7 +65,7 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo
// track errors in the map reduce job; jobs insert a dummy error for the map and cleanup tasks (to
// ensure test correctness), so error tests should check to see if there is at least one error
// (could be more depending on the test) rather than zero
private static Multimap<String,AssertionError> assertionErrors = ArrayListMultimap.create();
private static final Multimap<String,AssertionError> assertionErrors = ArrayListMultimap.create();

private static final Authorizations AUTHS = new Authorizations("A", "B", "C", "D");

@@ -126,7 +126,7 @@ protected void map(List<Entry<Key,Value>> key, InputStream value, Context contex

byte[] b = new byte[20];
int read;
try {
try (value) {
switch (count) {
case 0:
assertEquals(key.size(), 2);
@@ -149,8 +149,6 @@ protected void map(List<Entry<Key,Value>> key, InputStream value, Context contex
}
} catch (AssertionError e) {
assertionErrors.put(table, e);
} finally {
value.close();
}
count++;
}

0 comments on commit 6c00d0c

Please sign in to comment.