Java Code Examples for org.apache.accumulo.core.data.Mutation#put()

The following examples show how to use org.apache.accumulo.core.data.Mutation#put() . 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: CountPlan.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(final IntermediateProspect prospect, final Iterable<LongWritable> counts, final Date timestamp, final Reducer.Context context) throws IOException, InterruptedException {
    long sum = 0;
    for(final LongWritable count : counts) {
        sum += count.get();
    }

    final String indexType = prospect.getTripleValueType().getIndexType();

    // not sure if this is the best idea..
    if ((sum >= 0) || indexType.equals(TripleValueType.PREDICATE.getIndexType())) {
        final Mutation m = new Mutation(indexType + DELIM + prospect.getData() + DELIM + ProspectorUtils.getReverseIndexDateTime(timestamp));

        final String dataType = prospect.getDataType();
        final ColumnVisibility visibility = new ColumnVisibility(prospect.getVisibility());
        final Value sumValue = new Value(("" + sum).getBytes(StandardCharsets.UTF_8));
        m.put(COUNT, prospect.getDataType(), visibility, timestamp.getTime(), sumValue);

        context.write(null, m);
    }
}
 
Example 2
Source File: AccumuloGraphTestBase.java    From vertexium with Apache License 2.0 6 votes vote down vote up
private void addLegacySPVData(
    String vertexId,
    long timestamp,
    String propertyKey,
    String propertyName,
    String propertyValue
) throws MutationsRejectedException {
    String dataRowKey = new DataTableRowKey(vertexId, propertyKey, propertyName).getRowKey() + VALUE_SEPARATOR + timestamp;

    Mutation addPropertyMutation = new Mutation(vertexId);
    byte[] data = propertyValue.getBytes();
    StreamingPropertyValue spv = StreamingPropertyValue.create(propertyValue);
    StreamingPropertyValueTableRef spvValue = new StreamingPropertyValueTableRef(dataRowKey, spv, data);
    Metadata metadata = Metadata.create();
    Property property = new MutablePropertyImpl(propertyKey, propertyName, spvValue, metadata, timestamp, new HashSet<>(), new Visibility(""), FetchHints.ALL);
    Text columnQualifier = getColumnQualifierFromPropertyColumnQualifier(property, getGraph().getNameSubstitutionStrategy());
    addPropertyMutation.put(AccumuloElement.CF_PROPERTY, columnQualifier, new Value(getGraph().getVertexiumSerializer().objectToBytes(spvValue)));
    getGraph().getVerticesWriter().addMutation(addPropertyMutation);

    Mutation addDataMutation = new Mutation(dataRowKey);
    addDataMutation.put(EMPTY_TEXT, EMPTY_TEXT, timestamp - 1000, new Value(data));
    getGraph().getDataWriter().addMutation(addDataMutation);

    getGraph().flush();
}
 
Example 3
Source File: ElementMutationBuilder.java    From vertexium with Apache License 2.0 6 votes vote down vote up
public boolean alterElementVisibility(Mutation m, AccumuloElement element, Visibility newVisibility, Object data) {
    ColumnVisibility currentColumnVisibility = visibilityToAccumuloVisibility(element.getVisibility());
    ColumnVisibility newColumnVisibility = visibilityToAccumuloVisibility(newVisibility);
    if (currentColumnVisibility.equals(newColumnVisibility)) {
        return false;
    }

    if (element instanceof AccumuloEdge) {
        AccumuloEdge edge = (AccumuloEdge) element;
        m.put(AccumuloEdge.CF_SIGNAL, new Text(edge.getLabel()), currentColumnVisibility, currentTimeMillis(), toSignalDeletedValue(data));
        m.put(AccumuloEdge.CF_SIGNAL, new Text(edge.getLabel()), newColumnVisibility, currentTimeMillis(), toSignalValue(data));

        m.putDelete(AccumuloEdge.CF_OUT_VERTEX, new Text(edge.getVertexId(Direction.OUT)), currentColumnVisibility, currentTimeMillis());
        m.put(AccumuloEdge.CF_OUT_VERTEX, new Text(edge.getVertexId(Direction.OUT)), newColumnVisibility, currentTimeMillis(), ElementMutationBuilder.EMPTY_VALUE);

        m.putDelete(AccumuloEdge.CF_IN_VERTEX, new Text(edge.getVertexId(Direction.IN)), currentColumnVisibility, currentTimeMillis());
        m.put(AccumuloEdge.CF_IN_VERTEX, new Text(edge.getVertexId(Direction.IN)), newColumnVisibility, currentTimeMillis(), ElementMutationBuilder.EMPTY_VALUE);
    } else if (element instanceof AccumuloVertex) {
        m.put(AccumuloVertex.CF_SIGNAL, EMPTY_TEXT, currentColumnVisibility, currentTimeMillis(), toSignalDeletedValue(data));
        m.put(AccumuloVertex.CF_SIGNAL, EMPTY_TEXT, newColumnVisibility, currentTimeMillis(), toSignalValue(data));
    } else {
        throw new IllegalArgumentException("Invalid element type: " + element);
    }
    return true;
}
 
Example 4
Source File: MixedGeoAndGeoWaveTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
private static void writeKeyValues(Connector connector, Multimap<BulkIngestKey,Value> keyValues) throws Exception {
    final TableOperations tops = connector.tableOperations();
    final Set<BulkIngestKey> biKeys = keyValues.keySet();
    for (final BulkIngestKey biKey : biKeys) {
        final String tableName = biKey.getTableName().toString();
        if (!tops.exists(tableName))
            tops.create(tableName);
        
        final BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
        for (final Value val : keyValues.get(biKey)) {
            final Mutation mutation = new Mutation(biKey.getKey().getRow());
            mutation.put(biKey.getKey().getColumnFamily(), biKey.getKey().getColumnQualifier(), biKey.getKey().getColumnVisibilityParsed(), biKey.getKey()
                            .getTimestamp(), val);
            writer.addMutation(mutation);
        }
        writer.close();
    }
}
 
Example 5
Source File: MetricAdapter.java    From timely with Apache License 2.0 6 votes vote down vote up
public static Mutation toMutation(Metric metric) {

        final Mutation mutation = new Mutation(encodeRowKey(metric));
        List<Tag> tags = metric.getTags();
        tags = escapeDelimiters(tags);
        Collections.sort(tags);

        for (final Tag entry : tags) {
            if (entry.getKey().equals(VISIBILITY_TAG))
                continue;

            final String cf = entry.join();
            // @formatter:off
            String cq = tags.stream().filter(inner -> !inner.equals(entry))
                    .filter(inner -> !inner.getKey().equals(VISIBILITY_TAG))
                    .map(Tag::join)
                    .collect(Collectors.joining(","));
            // @formatter:on
            byte[] cqBytes = encodeColQual(metric.getValue().getTimestamp(), cq);
            mutation.put(new Text(cf.getBytes(Charset.forName("UTF-8"))), new Text(cqBytes), extractVisibility(tags),
                    metric.getValue().getTimestamp(), extractValue(metric));
        }
        return mutation;
    }
 
Example 6
Source File: TermIndexSink.java    From OSTMap with Apache License 2.0 6 votes vote down vote up
@Override
/**
 * this is called for each token in tweet
 */
public void invoke(Tuple2<TermIndexKey, Integer> value) throws Exception {
    // if the writer isnt already instantiated, do it now
    if (writerForTerms == null) {
        writerForTerms = createBatchWriter(tableTerms);
    }

    //Write termData once per token/user
    Mutation mutationTerms = new Mutation(value._1.getTermBytes());
    if(value._2()<=1)
    {
        //put without value
        // column family, column qualifier without value
        mutationTerms.put(value._1.getSourceBytes(), value._1.rawTwitterDataKey.keyBytes, EMPTY_BYTES);
    }
    else
    {
        //put with number of occurrences
        // column family, column qualifier and value to write
        mutationTerms.put(value._1.getSourceBytes(), value._1.rawTwitterDataKey.keyBytes, (""+value._2()).getBytes());
    }
    writerForTerms.addMutation(mutationTerms);
}
 
Example 7
Source File: ElementMutationBuilder.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private Mutation createMutationForVertexBuilder(AccumuloGraph graph, VertexBuilder vertexBuilder, long timestamp) {
    String vertexRowKey = vertexBuilder.getId();
    Mutation m = new Mutation(vertexRowKey);
    m.put(AccumuloVertex.CF_SIGNAL, EMPTY_TEXT, visibilityToAccumuloVisibility(vertexBuilder.getVisibility()), timestamp, EMPTY_VALUE);
    createMutationForElementBuilder(graph, vertexBuilder, vertexRowKey, m);
    return m;
}
 
Example 8
Source File: DiscoveryLogicTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected void insertReverseModel(String from, String to) throws Throwable {
    BatchWriterConfig config = new BatchWriterConfig().setMaxMemory(1024L).setMaxLatency(1, TimeUnit.SECONDS).setMaxWriteThreads(1);
    ColumnVisibility viz = new ColumnVisibility("FOO");
    
    try (BatchWriter writer = connector.createBatchWriter(QueryTestTableHelper.METADATA_TABLE_NAME, config)) {
        Mutation m = new Mutation(from.toUpperCase());
        m.put("DATAWAVE", to.toUpperCase() + "\u0000reverse", viz, blank);
        writer.addMutation(m);
    }
}
 
Example 9
Source File: OSMMapperBase.java    From geowave with Apache License 2.0 5 votes vote down vote up
protected void put(final Mutation m, final String cf, final String cq, final String val) {
  if (val != null) {
    m.put(
        StringUtils.stringToBinary(cf),
        StringUtils.stringToBinary(cq),
        _visibility,
        stringWriter.writeField(val));
  }
}
 
Example 10
Source File: ElementMutationBuilder.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private Mutation createMutationForEdgeBuilder(AccumuloGraph graph, EdgeBuilderBase edgeBuilder, ColumnVisibility edgeColumnVisibility, long timestamp) {
    String edgeRowKey = edgeBuilder.getId();
    Mutation m = new Mutation(edgeRowKey);
    String edgeLabel = edgeBuilder.getEdgeLabel();
    if (edgeBuilder.getNewEdgeLabel() != null) {
        edgeLabel = edgeBuilder.getNewEdgeLabel();
        m.putDelete(AccumuloEdge.CF_SIGNAL, new Text(edgeBuilder.getEdgeLabel()), edgeColumnVisibility, currentTimeMillis());
    }
    m.put(AccumuloEdge.CF_SIGNAL, new Text(edgeLabel), edgeColumnVisibility, timestamp, ElementMutationBuilder.EMPTY_VALUE);
    m.put(AccumuloEdge.CF_OUT_VERTEX, new Text(edgeBuilder.getVertexId(Direction.OUT)), edgeColumnVisibility, timestamp, ElementMutationBuilder.EMPTY_VALUE);
    m.put(AccumuloEdge.CF_IN_VERTEX, new Text(edgeBuilder.getVertexId(Direction.IN)), edgeColumnVisibility, timestamp, ElementMutationBuilder.EMPTY_VALUE);
    createMutationForElementBuilder(graph, edgeBuilder, edgeRowKey, m);
    return m;
}
 
Example 11
Source File: RyaTableMutationsFactory.java    From rya with Apache License 2.0 5 votes vote down vote up
protected Mutation createMutation(TripleRow tripleRow) {
    Mutation mutation = new Mutation(new Text(tripleRow.getRow()));
    byte[] columnVisibility = tripleRow.getColumnVisibility();
    ColumnVisibility cv = columnVisibility == null ? EMPTY_CV : new ColumnVisibility(columnVisibility);
    Long timestamp = tripleRow.getTimestamp();
    byte[] value = tripleRow.getValue();
    Value v = value == null ? EMPTY_VALUE : new Value(value);
    byte[] columnQualifier = tripleRow.getColumnQualifier();
    Text cqText = columnQualifier == null ? EMPTY_TEXT : new Text(columnQualifier);
    byte[] columnFamily = tripleRow.getColumnFamily();
    Text cfText = columnFamily == null ? EMPTY_TEXT : new Text(columnFamily);

    mutation.put(cfText, cqText, cv, timestamp, v);
    return mutation;
}
 
Example 12
Source File: MetricsDailySummaryReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a simple summation metric value. The key is written out as is and the values, assumed to be string longs, are aggregated and written out.
 */
private Mutation sumMutation(Key key, Iterable<Value> values) {
    LongValueSum sum = new LongValueSum();
    for (Value v : values)
        sum.addNextValue(v);
    
    ColumnVisibility columnVisibility = new ColumnVisibility(key.getColumnVisibility());
    Mutation m = new Mutation(key.getRow());
    m.put(key.getColumnFamily(), key.getColumnQualifier(), columnVisibility, new Value(sum.getReport().getBytes()));
    return m;
}
 
Example 13
Source File: AddVertexMutator.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Mutation> create() {
  Mutation m = new Mutation(id);
  m.put(Constants.LABEL.getBytes(),
      Constants.EXISTS.getBytes(), Constants.EMPTY);
  return Lists.newArrayList(m);
}
 
Example 14
Source File: AccumuloPageSink.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link Row} to an Accumulo mutation.
 *
 * @param row Row object
 * @param rowIdOrdinal Ordinal in the list of columns that is the row ID. This isn't checked at all, so I hope you're right. Also, it is expected that the list of column handles is sorted in ordinal order. This is a very demanding function.
 * @param columns All column handles for the Row, sorted by ordinal.
 * @param serializer Instance of {@link AccumuloRowSerializer} used to encode the values of the row to the Mutation
 * @return Mutation
 */
public static Mutation toMutation(Row row, int rowIdOrdinal, List<AccumuloColumnHandle> columns, AccumuloRowSerializer serializer)
{
    // Set our value to the row ID
    Text value = new Text();
    Field rowField = row.getField(rowIdOrdinal);
    if (rowField.isNull()) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Column mapped as the Accumulo row ID cannot be null");
    }

    setText(rowField, value, serializer);

    // Iterate through all the column handles, setting the Mutation's columns
    Mutation mutation = new Mutation(value);

    // Store row ID in a special column
    mutation.put(ROW_ID_COLUMN, ROW_ID_COLUMN, new Value(value.copyBytes()));
    for (AccumuloColumnHandle columnHandle : columns) {
        // Skip the row ID ordinal
        if (columnHandle.getOrdinal() == rowIdOrdinal) {
            continue;
        }

        // If the value of the field is not null
        if (!row.getField(columnHandle.getOrdinal()).isNull()) {
            // Serialize the value to the text
            setText(row.getField(columnHandle.getOrdinal()), value, serializer);

            // And add the bytes to the Mutation
            mutation.put(columnHandle.getFamily().get(), columnHandle.getQualifier().get(), new Value(value.copyBytes()));
        }
    }

    return mutation;
}
 
Example 15
Source File: ElementMutationBuilder.java    From vertexium with Apache License 2.0 4 votes vote down vote up
public Mutation getDeleteRowMutation(String rowKey) {
    Mutation m = new Mutation(rowKey);
    m.put(AccumuloElement.DELETE_ROW_COLUMN_FAMILY, AccumuloElement.DELETE_ROW_COLUMN_QUALIFIER, RowDeletingIterator.DELETE_ROW_VALUE);
    return m;
}
 
Example 16
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testFixedRangeColumnValidateSubjPrefix() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 1 ), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 2), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 1 ), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 2 ), new Value(new byte[0]));



        if(i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 3 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 4), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 4 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 5 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 5 ), new Value(new byte[0]));
        }

        bw.addMutation(m);

    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("subj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.setRange(Range.exact(new Text("" + 30)));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 13****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(3, results);




}
 
Example 17
Source File: CBMutationOutputFormatterTest.java    From datawave with Apache License 2.0 2 votes vote down vote up
@Test
public void testRecordWriterWriteWithTableNameWithUpdates() throws IOException, InterruptedException {
    
    CBMutationOutputFormatterTest.logger.info("testRecordWriterWriteWithTableNameWithUpdates called...");
    
    try {
        
        CBMutationOutputFormatter uut = new CBMutationOutputFormatter();
        
        Assert.assertNotNull("CBMutationOutputFormatter constructor failed to generate an instance.", uut);
        
        Configuration conf = new Configuration();
        
        String simulationKey = String.format("%s.%s.%s", AccumuloOutputFormat.class.getSimpleName(), Features.SIMULATION_MODE.getDeclaringClass()
                        .getSimpleName(), StringUtils.camelize(Features.SIMULATION_MODE.name().toLowerCase()));
        
        conf.set(simulationKey, Boolean.TRUE.toString());
        conf.setInt("AccumuloOutputFormat.GeneralOpts.LogLevel", Level.ALL.toInt());
        conf.set(ShardedDataTypeHandler.SHARD_TNAME, "test-table");
        
        TaskAttemptContext attempt = new TaskAttemptContextImpl(conf, new TaskAttemptID());
        
        RecordWriter<Text,Mutation> rw = uut.getRecordWriter(attempt);
        
        Assert.assertNotNull("CBMutationOutputFormatter#getRecordWriter failed to create an instance of RecordWriter", rw);
        
        Text key = new Text("test-table");
        Mutation value = new Mutation("hello, world".getBytes());
        
        value.put("colf".getBytes(), "colq".getBytes(), "hello, world!!".getBytes());
        
        rw.write(key, value);
        
        List<String> entries = uutAppender.retrieveLogsEntries();
        
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to create simulation warning message.",
                        processOutputContains(entries, "Simulating output only. No writes to tables will occur"));
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to create Event Table name message.",
                        processOutputContains(entries, "Event Table Name property for "));
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to create simulation warning message.",
                        processOutputContains(entries, "Table test-table row key: "));
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to table column update message.",
                        processOutputContains(entries, "Table test-table column: colf:colq"));
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to table column security message.",
                        processOutputContains(entries, "Table test-table security: "));
        Assert.assertTrue("CBMutationOutputFormatter$getRecordWriter#write failed to table value message.",
                        processOutputContains(entries, "Table test-table value: "));
        
    } finally {
        
        CBMutationOutputFormatterTest.logger.info("testRecordWriterWriteWithTableNameWithUpdates completed.");
    }
    
}
 
Example 18
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testOneHundredColumnSubjObjPrefix() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        for(int j= 0; j < 100; j++) {
            m.put(new Text("cf" + j), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + j), new Value(new byte[0]));
        }

        if (i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 100), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + (100 + i)), new Value(new byte[0]));
            m.put(new Text("cf" + 100), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + (100 + i + 1)), new Value(new byte[0]));
        }






        bw.addMutation(m);

    }

    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf" + 20), new Text("obj" + "\u0000" + "cq" + 20));
    TextColumn tc2 = new TextColumn(new Text("cf" + 50), new Text("obj" + "\u0000" + "cq" + 50));
    TextColumn tc3 = new TextColumn(new Text("cf" + 100), new Text("subj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;

    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 7****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(4, results);




}
 
Example 19
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testContext6() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("row" + i));


        m.put(new Text("cf" + 1), new Text("context1" + "\u0000"  + "obj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context1" + "\u0000"  + "subj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text("context2" + "\u0000"  + "obj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context2" + "\u0000"  + "subj" + "\u0000" + "cq" + i), new Value(new byte[0]));


        bw.addMutation(m);


    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" ));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("subj" ));


    tc1.setIsPrefix(true);
    tc2.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[2];
    tc[0] = tc1;
    tc[1] = tc2;



    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);
    DocumentIndexIntersectingIterator.setContext(is, "context2");

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));

    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 19****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(100, results);




}
 
Example 20
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testBasicColumnObjPrefix()  throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));
        m.put(new Text("cf"), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" ), new Value(new byte[0]));
        m.put(new Text("cF"), new Text(null + "\u0000" +"obj" + "\u0000" + "cQ"), new Value(new byte[0]));

        if (i == 30 || i == 60) {
            m.put(new Text("CF"), new Text(null + "\u0000" +"obj" + "\u0000" + "CQ" ), new Value(new byte[0]));
        }



        bw.addMutation(m);

    }

    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf"), new Text("obj" + "\u0000" + "cq"));
    TextColumn tc2 = new TextColumn(new Text("cF"), new Text("obj" + "\u0000" + "cQ"));
    TextColumn tc3 = new TextColumn(new Text("CF"), new Text("obj"));

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;

    tc3.setIsPrefix(true);

    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 2****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(2, results);




}