Java Code Examples for org.apache.accumulo.core.iterators.SortedKeyValueIterator#deepCopy()

The following examples show how to use org.apache.accumulo.core.iterators.SortedKeyValueIterator#deepCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChunkCombinerTest.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private void runTest(boolean reseek, TreeMap<Key,Value> source, TreeMap<Key,Value> result,
    Collection<ByteSequence> cols) throws IOException {
  MapIterator src = new MapIterator(source);
  SortedKeyValueIterator<Key,Value> iter = new ChunkCombiner();
  iter.init(src, null, null);
  iter = iter.deepCopy(null);
  iter.seek(new Range(), cols, true);

  TreeMap<Key,Value> seen = new TreeMap<>();

  while (iter.hasTop()) {
    assertFalse("already contains " + iter.getTopKey(), seen.containsKey(iter.getTopKey()));
    seen.put(new Key(iter.getTopKey()), new Value(iter.getTopValue()));

    if (reseek)
      iter.seek(new Range(iter.getTopKey().followingKey(PartialKey.ROW_COLFAM_COLQUAL), true,
          null, true), cols, true);
    else
      iter.next();
  }

  assertEquals(result, seen);
}
 
Example 2
Source File: DocumentIndexIntersectingIterator.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {
  TextColumn[] terms = decodeColumns(options.get(columnOptionName));
  boolean[] prefixes = decodeBooleans(options.get(columnPrefix));
  ctxt = decodeContext(options.get(context));
  
  if(ctxt != null) {
      hasContext = true;
  }

 
  
  if (terms.length < 2) {
    throw new IllegalArgumentException("IntersectionIterator requires two or more columns families");
  }
  
  sources = new TermSource[terms.length];
  sources[0] = new TermSource(source, terms[0]);
  for (int i = 1; i < terms.length; i++) {
      //log.info("For decoded column " + i + " column family is " + terms[i].getColumnFamily() + " and qualifier is " + terms[i].getColumnQualifier());
    sources[i] = new TermSource(source.deepCopy(env), terms[i]);
    sources[i].isPrefix = prefixes[i];
  }
  sourcesCount = terms.length;
}
 
Example 3
Source File: DocumentIndexIntersectingIterator.java    From rya with Apache License 2.0 6 votes vote down vote up
public void addSource(SortedKeyValueIterator<Key,Value> source, IteratorEnvironment env, TextColumn column) {
  // Check if we have space for the added Source
  if (sources == null) {
    sources = new TermSource[1];
  } else {
    // allocate space for node, and copy current tree.
    // TODO: Should we change this to an ArrayList so that we can just add() ? - ACCUMULO-1309
    TermSource[] localSources = new TermSource[sources.length + 1];
    int currSource = 0;
    for (TermSource myTerm : sources) {
      // TODO: Do I need to call new here? or can I just re-use the term? - ACCUMULO-1309
      localSources[currSource] = new TermSource(myTerm);
      currSource++;
    }
    sources = localSources;
  }
  sources[sourcesCount] = new TermSource(source.deepCopy(env), column);
  sourcesCount++;
}
 
Example 4
Source File: AndingIterator.java    From rya with Apache License 2.0 6 votes vote down vote up
public void addSource(final SortedKeyValueIterator<Key, Value> source, final IteratorEnvironment env, final Text term, final boolean notFlag) {
	// Check if we have space for the added Source
	if (sources == null) {
		sources = new TermSource[1];
	} else {
		// allocate space for node, and copy current tree.
		// TODO: Should we change this to an ArrayList so that we can just add() ?
		final TermSource[] localSources = new TermSource[sources.length + 1];
		int currSource = 0;
		for (final TermSource myTerm : sources) {
			// TODO: Do I need to call new here? or can I just re-use the term?
			localSources[currSource] = new TermSource(myTerm);
			currSource++;
		}
		sources = localSources;
	}
	sources[sourcesCount] = new TermSource(source.deepCopy(env), term, notFlag);
	sourcesCount++;
}
 
Example 5
Source File: AndIterator.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
public void addSource(SortedKeyValueIterator<Key, Value> source, IteratorEnvironment env, Text dataLocation, Text term, boolean notFlag) {
    // Check if we have space for the added Source
    if (sources == null) {
        sources = new TermSource[1];
    } else {
        // allocate space for node, and copy current tree.
        // TODO: Should we change this to an ArrayList so that we can just add() ?
        TermSource[] localSources = new TermSource[sources.length + 1];
        int currSource = 0;
        for (TermSource myTerm : sources) {
            // TODO: Do I need to call new here? or can I just re-use the term?
            localSources[currSource] = new TermSource(myTerm);
            currSource++;
        }
        sources = localSources;
    }

    sources[sourcesCount] = new TermSource(source.deepCopy(env), dataLocation, term, notFlag);
    sourcesCount++;
}
 
Example 6
Source File: PropogatingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {
    if (null != source)
        this.iterator = source.deepCopy(env);
    else
        this.iterator = null;
    this.env = env;
    this.options.putAll(options);
    validateOptions(options);
    
}
 
Example 7
Source File: DatawaveFieldIndexCachingIteratorJexl.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Get a source copy. This is only used when retrieving unsorted values.
 *
 * @return a source
 */
protected SortedKeyValueIterator<Key,Value> getSourceCopy() {
    SortedKeyValueIterator<Key,Value> source = getSource();
    synchronized (source) {
        source = source.deepCopy(initEnv);
    }
    return source;
}
 
Example 8
Source File: CutoffIntersectingIterator.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
    IteratorEnvironment env) throws IOException {
  super.init(source, options, env);

  IteratorEnvironment sampleEnv = env.cloneWithSamplingEnabled();

  setMax(sampleEnv, options);

  SortedKeyValueIterator<Key,Value> sampleDC = source.deepCopy(sampleEnv);
  sampleII = new IntersectingIterator();
  sampleII.init(sampleDC, options, env);

}
 
Example 9
Source File: EntryIterator.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
public void init(SortedKeyValueIterator<Key, Value> source, java.util.Map<String, String> options,
                 IteratorEnvironment env) throws IOException {

    super.init(source, options, env);
    sourceItr = source.deepCopy(env);
    this.typeRegistry = getTypeRegistry(options);
    this.writable = new EventWritable();
}
 
Example 10
Source File: ChunkCombiner.java    From accumulo-examples with Apache License 2.0 4 votes vote down vote up
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
    IteratorEnvironment env) throws IOException {
  this.source = source;
  this.refsSource = source.deepCopy(env);
}
 
Example 11
Source File: AndingIterator.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public void init(final SortedKeyValueIterator<Key, Value> source, final Map<String, String> options, final IteratorEnvironment env) throws IOException {
	final Text[] terms = decodeColumns(options.get(columnFamiliesOptionName));
	boolean[] notFlag = decodeBooleans(options.get(notFlagOptionName));

	if (terms.length < 2) {
		throw new IllegalArgumentException("IntersectionIterator requires two or more columns families");
	}

	// Scan the not flags.
	// There must be at least one term that isn't negated
	// And we are going to re-order such that the first term is not a ! term
	if (notFlag == null) {
		notFlag = new boolean[terms.length];
		for (int i = 0; i < terms.length; i++) {
               notFlag[i] = false;
           }
	}
	if (notFlag[0]) {
		for (int i = 1; i < notFlag.length; i++) {
			if (notFlag[i] == false) {
				final Text swapFamily = new Text(terms[0]);
				terms[0].set(terms[i]);
				terms[i].set(swapFamily);
				notFlag[0] = false;
				notFlag[i] = true;
				break;
			}
		}
		if (notFlag[0]) {
			throw new IllegalArgumentException("IntersectionIterator requires at lest one column family without not");
		}
	}

	sources = new TermSource[terms.length];
	sources[0] = new TermSource(source, terms[0]);
	for (int i = 1; i < terms.length; i++) {
		sources[i] = new TermSource(source.deepCopy(env), terms[i], notFlag[i]);
	}
	sourcesCount = terms.length;
}
 
Example 12
Source File: AndIterator.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
public void init(SortedKeyValueIterator<Key, Value> source, Map<String, String> options, IteratorEnvironment env) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("In AndIterator.init()");
    }

    Text[] dataLocations = decodeColumns(options.get(columnFamiliesOptionName));
    Text[] terms = decodeTermValues(options.get(termValuesOptionName));
    boolean[] notFlags = decodeBooleans(options.get(notFlagsOptionName));

    if (terms.length < 2) {
        throw new IllegalArgumentException("AndIterator requires two or more columns families");
    }

    // Scan the not flags.
    // There must be at least one term that isn't negated
    // And we are going to re-order such that the first term is not a ! term
    if (notFlags == null) {
        notFlags = new boolean[terms.length];
        for (int i = 0; i < terms.length; i++) {
            notFlags[i] = false;
        }
    }

    // Make sure that the first dataLocation/Term is not a NOT by swapping it with a later dataLocation/Term
    if (notFlags[0]) {
        for (int i = 1; i < notFlags.length; i++) {
            if (notFlags[i] == false) {
                // Swap the terms
                Text swap = new Text(terms[0]);
                terms[0].set(terms[i]);
                terms[i].set(swap);

                // Swap the dataLocations
                swap.set(dataLocations[0]);
                dataLocations[0].set(dataLocations[i]);
                dataLocations[i].set(swap);

                // Flip the notFlags
                notFlags[0] = false;
                notFlags[i] = true;
                break;
            }
        }

        if (notFlags[0]) {
            throw new IllegalArgumentException("AndIterator requires at least one column family without not");
        }
    }

    // Build up the array of sources that are to be intersected
    sources = new TermSource[dataLocations.length];
    for (int i = 0; i < dataLocations.length; i++) {
        sources[i] = new TermSource(source.deepCopy(env), dataLocations[i], terms[i], notFlags[i]);
    }

    sourcesCount = dataLocations.length;
}