Package mil.nga.giat.geowave.accumulo

Examples of mil.nga.giat.geowave.accumulo.Writer


      final T object) {
    final ByteArrayId id = getPrimaryId(object);
    addObjectToCache(object);
    try {

      final Writer writer = accumuloOperations.createWriter(
          getAccumuloTablename(),
          true);
      synchronized (this) {
        if (!iteratorsAttached) {
          iteratorsAttached = true;
          final IteratorConfig[] configs = getIteratorConfig();
          if ((configs != null) && (configs.length > 0)) {
            accumuloOperations.attachIterators(
                getAccumuloTablename(),
                true,
                configs);
          }
        }
      }

      final Mutation mutation = new Mutation(
          new Text(
              id.getBytes()));
      final Text cf = getSafeText(getAccumuloColumnFamily());
      final Text cq = getSafeText(getAccumuloColumnQualifier(object));
      final byte[] visibility = getAccumuloVisibility(object);
      if (visibility != null) {
        mutation.put(
            cf,
            cq,
            new ColumnVisibility(
                visibility),
            new Value(
                PersistenceUtils.toBinary(object)));
      }
      else {
        mutation.put(
            cf,
            cq,
            new Value(
                PersistenceUtils.toBinary(object)));
      }
      writer.write(mutation);
      writer.close();
    }
    catch (final TableNotFoundException e) {
      LOGGER.error(
          "Unable add object",
          e);
View Full Code Here


  }

  public void transform() {
    try {
      final Iterator<Entry<Key, Value>> rawIt = scanner.iterator();
      Writer writer = accumuloOperations.createWriter(tableName);
      writer.write(new Iterable<Mutation>() {
        @Override
        public Iterator<Mutation> iterator() {
          return new Iterator<Mutation>() {

            LinkedList<Mutation> pendingOutput = new LinkedList<Mutation>();

            @Override
            public boolean hasNext() {
              return !pendingOutput.isEmpty() || rawIt.hasNext();
            }

            @Override
            public Mutation next() {

              if (!pendingOutput.isEmpty()) {
                return pendingOutput.removeFirst();
              }
              else if (rawIt.hasNext()) {
                Entry<Key, Value> entry = rawIt.next();
                Entry<Key, Value> newEntry = transformer.transform(Pair.of(entry.getKey(),entry.getValue()));

                Mutation mutation = new Mutation(
                    entry.getKey().getRow());
                mutation.putDelete(
                    entry.getKey().getColumnFamily(),
                    entry.getKey().getColumnQualifier(),
                    entry.getKey().getColumnVisibilityParsed(),
                    entry.getKey().getTimestamp());
               
                pendingOutput.add(mutation);
               
                mutation = new Mutation(
                    newEntry.getKey().getRow());
               
                mutation.put(
                    newEntry.getKey().getColumnFamily(),
                    newEntry.getKey().getColumnQualifier(),
                    newEntry.getKey().getColumnVisibilityParsed(),
                    newEntry.getValue());
                pendingOutput.add(mutation);
              }

              return pendingOutput.removeFirst();
            }

            @Override
            public void remove() {

            }
          };
        }
      });
      writer.close();
    }
    catch (Exception ex) {
      LOGGER.error(
          "Cannot perform transformation",
          ex);
View Full Code Here

TOP

Related Classes of mil.nga.giat.geowave.accumulo.Writer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.