Java Code Examples for org.apache.accumulo.core.client.Scanner#addScanIterator()
The following examples show how to use
org.apache.accumulo.core.client.Scanner#addScanIterator() .
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: AccumuloGraph.java From vertexium with Apache License 2.0 | 6 votes |
private long getRowCountFromTable(String tableName, Text signalColumn, Authorizations authorizations) { try { LOGGER.debug("BEGIN getRowCountFromTable(%s)", tableName); Scanner scanner = createScanner(tableName, null, authorizations); try { scanner.fetchColumnFamily(signalColumn); IteratorSetting countingIterator = new IteratorSetting( 100, CountingIterator.class.getSimpleName(), CountingIterator.class ); scanner.addScanIterator(countingIterator); GRAPH_LOGGER.logStartIterator(tableName, scanner); long count = 0; for (Map.Entry<Key, Value> entry : scanner) { Long countForKey = LongCombiner.FIXED_LEN_ENCODER.decode(entry.getValue().get()); LOGGER.debug("getRowCountFromTable(%s): %s: %d", tableName, entry.getKey().getRow(), countForKey); count += countForKey; } LOGGER.debug("getRowCountFromTable(%s): TOTAL: %d", tableName, count); return count; } finally { scanner.close(); } } catch (TableNotFoundException ex) { throw new VertexiumException("Could not get count from table: " + tableName, ex); } }
Example 2
Source File: AccumuloRyaUtils.java From rya with Apache License 2.0 | 6 votes |
/** * Prints the table with pretty formatting using the specified config and additional settings. * @param tableName the name of the table to print. * @param config the {@link AccumuloRdfConfiguration}. * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner. * {@code false} otherwise. * @param settings the additional {@link IteratorSetting}s to add besides the common ones. * @throws IOException */ public static void printTablePretty(final String tableName, final Configuration config, final boolean shouldAddCommonIterators, final IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException { final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators); for (final IteratorSetting setting : settings) { scanner.addScanIterator(setting); } final String format = "| %-64s | %-24s | %-28s | %-20s | %-20s | %-10s |"; final int totalFormatLength = String.format(format, 1, 2, 3, 4, 5, 6).length(); final String instance = config.get(MRUtils.AC_INSTANCE_PROP); log.info(StringUtils.rightPad("==================", totalFormatLength, "=")); log.info(StringUtils.rightPad("| TABLE: " + tableName + " INSTANCE: " + instance, totalFormatLength - 1) + "|"); log.info(StringUtils.rightPad("------------------", totalFormatLength, "-")); log.info(String.format(format, "--Row--", "--ColumnVisibility--", "--Timestamp--", "--ColumnFamily--", "--ColumnQualifier--", "--Value--")); log.info(StringUtils.rightPad("|-----------------", totalFormatLength - 1, "-") + "|"); for (final Entry<Key, Value> entry : scanner) { final Key k = entry.getKey(); final String rowString = Key.appendPrintableString(k.getRow().getBytes(), 0, k.getRow().getLength(), Constants.MAX_DATA_TO_PRINT, new StringBuilder()).toString(); log.info(String.format(format, rowString, k.getColumnVisibility(), new Date(k.getTimestamp()), k.getColumnFamily(), k.getColumnQualifier(), entry.getValue())); } log.info(StringUtils.rightPad("==================", totalFormatLength, "=")); }
Example 3
Source File: GraphXInputFormat.java From rya with Apache License 2.0 | 6 votes |
@Override protected void setupIterators(TaskAttemptContext context, Scanner scanner, String tableName, org.apache.accumulo.core.client.mapreduce.RangeInputSplit split) { List<IteratorSetting> iterators = null; if (null == split) { iterators = contextIterators(context, tableName); } else { iterators = split.getIterators(); if (null == iterators) { iterators = contextIterators(context, tableName); } } for (IteratorSetting iterator : iterators) scanner.addScanIterator(iterator); }
Example 4
Source File: WholeColumnFamilyIteratorTest.java From accumulo-recipes with Apache License 2.0 | 5 votes |
private Scanner buildScanner(int n) throws TableNotFoundException { IteratorSetting setting = new IteratorSetting(5, WholeColumnFamilyIterator.class); Scanner scanner = connector.createScanner("test", new Authorizations()); scanner.addScanIterator(setting); return scanner; }
Example 5
Source File: ElementTableWrapper.java From AccumuloGraph with Apache License 2.0 | 5 votes |
/** * Add custom iterator to the given scanner so that * it will only return keys with value corresponding to an edge. * @param scan * @param labels */ protected void applyEdgeLabelValueFilter(Scanner scan, String... labels) { StringBuilder regex = new StringBuilder(); for (String lab : labels) { if (regex.length() != 0) regex.append("|"); regex.append(".*"+Constants.ID_DELIM+"\\Q").append(lab).append("\\E$"); } IteratorSetting is = new IteratorSetting(10, "edgeValueFilter", RegExFilter.class); RegExFilter.setRegexs(is, null, null, null, regex.toString(), false); scan.addScanIterator(is); }
Example 6
Source File: AccumuloFeatureStore.java From accumulo-recipes with Apache License 2.0 | 5 votes |
protected ScannerBase metricScanner(AccumuloFeatureConfig xform, Date start, Date end, String group, String type, String name, TimeUnit timeUnit, Auths auths) { checkNotNull(xform); try { group = defaultString(group); timeUnit = (timeUnit == null ? TimeUnit.MINUTES : timeUnit); Scanner scanner = connector.createScanner(tableName + REVERSE_SUFFIX, auths.getAuths()); scanner.setRange(buildRange(type, start, end, timeUnit)); if (group != null && name != null) { scanner.fetchColumn(new Text(combine(timeUnit.toString(), xform.featureName())), new Text(combine(group, name))); } else { scanner.fetchColumnFamily(new Text(combine(timeUnit.toString(), xform.featureName()))); String cqRegex = null; if (group != null) { cqRegex = combine(group, "(.*)"); } else if (name != null) cqRegex = combine("(.*)", name); if (cqRegex != null) { IteratorSetting regexIterator = new IteratorSetting(Constants.DEFAULT_ITERATOR_PRIORITY - 1, "regex", RegExFilter.class); scanner.addScanIterator(regexIterator); } } return scanner; } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example 7
Source File: TimeskippingIT.java From fluo with Apache License 2.0 | 5 votes |
@Test public void testTimestampSkippingIterPerformance() throws Exception { aClient.tableOperations().create("ttsi", new NewTableConfiguration().withoutDefaultIterators() .setProperties(Collections.singletonMap(AccumuloProps.TABLE_DELETE_BEHAVIOR, AccumuloProps.TABLE_DELETE_BEHAVIOR_VALUE))); BatchWriter bw = aClient.createBatchWriter("ttsi", new BatchWriterConfig()); Mutation m = new Mutation("r1"); for (int i = 0; i < 100000; i++) { m.put("f1", "q1", i, "v" + i); } bw.addMutation(m); bw.close(); long t2 = System.currentTimeMillis(); Scanner scanner = aClient.createScanner("ttsi", Authorizations.EMPTY); scanner.addScanIterator(new IteratorSetting(10, Skip100StampsIterator.class)); Assert.assertEquals("999", Iterables.getOnlyElement(scanner).getValue().toString()); long t3 = System.currentTimeMillis(); if (t3 - t2 > 3000) { log.error("Timestamp skipping iterator took longer than expected " + (t3 - t2)); } aClient.tableOperations().flush("ttsi", null, null, true); long t4 = System.currentTimeMillis(); Assert.assertEquals("999", Iterables.getOnlyElement(scanner).getValue().toString()); long t5 = System.currentTimeMillis(); if (t5 - t4 > 3000) { log.error("Timestamp skipping iterator took longer than expected " + (t5 - t4)); } }
Example 8
Source File: FirstNEntriesInRowIteratorIT.java From accumulo-recipes with Apache License 2.0 | 5 votes |
private Scanner buildScanner(int n) throws TableNotFoundException { IteratorSetting setting = new IteratorSetting(5, FirstNEntriesInRowIterator.class); FirstNEntriesInRowIterator.setNumKeysToReturn(setting, n); Scanner scanner = connector.createScanner("test", new Authorizations()); scanner.addScanIterator(setting); return scanner; }
Example 9
Source File: AccumuloRyaUtils.java From rya with Apache License 2.0 | 4 votes |
/** * Adds all the common regex filter {@link IteratorSetting}s to the provided {@link Scanner} so * certain metadata keys in a table are ignored. * @param scanner the {@link Scanner} to add the regex filter {@link IteratorSetting}s to. */ public static void addCommonScannerIteratorsTo(final Scanner scanner) { for (final IteratorSetting iteratorSetting : COMMON_REG_EX_FILTER_SETTINGS) { scanner.addScanIterator(iteratorSetting); } }
Example 10
Source File: Notification.java From fluo with Apache License 2.0 | 4 votes |
public static void configureScanner(Scanner scanner) { scanner.fetchColumnFamily(ByteUtil.toText(ColumnConstants.NOTIFY_CF)); scanner.addScanIterator(new IteratorSetting(11, NotificationIterator.class)); }
Example 11
Source File: DiscoveryIteratorTest.java From datawave with Apache License 2.0 | 4 votes |
@Test public void testReverseIndex() throws Throwable { Connector con = new InMemoryInstance("DiscoveryIteratorTest").getConnector("root", new PasswordToken("")); con.tableOperations().create("reverseIndex"); writeSample(con.createBatchWriter("reverseIndex", new BatchWriterConfig().setMaxLatency(0, TimeUnit.SECONDS).setMaxMemory(0).setMaxWriteThreads(1)), true); Scanner s = con.createScanner("reverseIndex", new Authorizations("FOO")); IteratorSetting setting = new IteratorSetting(50, DiscoveryIterator.class); setting.addOption(DiscoveryLogic.REVERSE_INDEX, "true"); s.addScanIterator(setting); s.setRange(new Range()); Iterator<Map.Entry<Key,Value>> itr = s.iterator(); assertTrue(itr.hasNext()); Map.Entry<Key,Value> e = itr.next(); assertFalse(itr.hasNext()); Key key = e.getKey(); assertEquals("mret", key.getRow().toString()); assertEquals("field", key.getColumnFamily().toString()); // see DiscoveryIterator for why this has a max unsigned char tacked on the end assertEquals("20130101\uffff", key.getColumnQualifier().toString()); Value value = e.getValue(); assertTrue(value.getSize() > 0); DataInputBuffer in = new DataInputBuffer(); in.reset(value.get(), value.getSize()); ArrayWritable valWrapper = new ArrayWritable(DiscoveredThing.class); valWrapper.readFields(in); Writable[] values = valWrapper.get(); assertEquals(3, values.length); Set<String> types = Sets.newHashSet("t1", "t2", "t3"); for (int i = 0; i < 3; ++i) { DiscoveredThing thing = (DiscoveredThing) values[i]; assertEquals("term", thing.getTerm()); assertEquals("field", thing.getField()); assertTrue(types.remove(thing.getType())); assertEquals("20130101", thing.getDate()); assertEquals("FOO", thing.getColumnVisibility()); assertEquals(240L, thing.getCount()); } }
Example 12
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@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 13
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testGeneralStarQueryMultipleSubjPrefix() 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.addScanIterator(is); int results = 0; System.out.println("************************Test 12****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(12, results); }
Example 14
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testContext7() throws Exception { BatchWriter bw = null; bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30); for (int i = 0; i < 10; 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" + "obj" + "\u0000" + "cq" + i), new Value(new byte[0])); m.put(new Text("cf" + 2), new Text("context1" + "\u0000" + "obj" + "\u0000" + "cq" + 100 + 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" + "obj" + "\u0000" + "cq" + i), new Value(new byte[0])); m.put(new Text("cf" + 2), new Text("context2" + "\u0000" + "obj" + "\u0000" + "cq" + 100+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("obj" )); 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); Scanner scan = accCon.createScanner(tablename, new Authorizations("auths")); scan.addScanIterator(is); int results = 0; System.out.println("************************Test 20****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(40, results); }
Example 15
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testLubmLikeTest() throws Exception { BatchWriter bw = null; bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30); for (int i = 0; i < 100; i++) { Mutation m1 = new Mutation(new Text("ProfessorA" + i)); Mutation m2= new Mutation(new Text("ProfessorB" + i)); m1.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom"), new Text(null + "\u0000" +"object" + "\u0000" + "http://www.University" + i + ".edu"), new Value(new byte[0])); m2.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom"), new Text(null + "\u0000" +"object" + "\u0000" + "http://www.University" + i + ".edu"), new Value(new byte[0])); m1.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"), new Text(null + "\u0000" +"object" + "\u0000" + "http://Course" + i), new Value(new byte[0])); m2.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"), new Text(null + "\u0000" +"object" + "\u0000" + "http://Course" + i), new Value(new byte[0])); bw.addMutation(m1); bw.addMutation(m2); } TextColumn tc1 = new TextColumn(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom" ), new Text("object" + "\u0000" + "http://www.University" + 30 + ".edu")); TextColumn tc2 = new TextColumn(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"), new Text("object" + "\u0000" + "http://Course" + 30)); TextColumn[] tc = new TextColumn[2]; tc[0] = tc1; tc[1] = tc2; IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class); DocumentIndexIntersectingIterator.setColumnFamilies(is, tc); Scanner scan = accCon.createScanner(tablename, new Authorizations("auths")); scan.addScanIterator(is); int results = 0; System.out.println("************************Test 15****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(2, results); }
Example 16
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testOneHundredColumnSubjObj() 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 ) { m.put(new Text("cf" + 100), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 100), new Value(new byte[0])); } if (i == 60) { m.put(new Text("cf" + 100), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 100), 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("obj" + "\u0000" + "cq" + 100)); 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 4****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(1, results); }
Example 17
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testOneHundredColumnObjPrefix() 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])); } 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("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 5****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(4, results); }
Example 18
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testContext1() 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("context1" + "\u0000" + "obj" + "\u0000" + "cq" + 1 ), new Value(new byte[0])); m.put(new Text("cf" + 2), new Text("context1" + "\u0000" +"obj" + "\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("context1" + "\u0000" +"obj" + "\u0000" + "cq" + 3 ), new Value(new byte[0])); m.put(new Text("cf" + 3), new Text("context2" + "\u0000" +"obj" + "\u0000" + "cq" + 4 ), new Value(new byte[0])); m.put(new Text("cf" + 3), new Text("context1" + "\u0000" +"obj" + "\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("obj")); 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); DocumentIndexIntersectingIterator.setContext(is, "context1"); Scanner scan = accCon.createScanner(tablename, new Authorizations("auths")); scan.addScanIterator(is); int results = 0; System.out.println("************************Test 14****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(8, results); }
Example 19
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@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 20
Source File: DocumentIndexIntersectingIteratorTest.java From rya with Apache License 2.0 | 2 votes |
@Test public void testOneHundredColumnSubjObjPrefixFourTerms() 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")); TextColumn tc4 = new TextColumn(new Text("cf" + 100), new Text("obj")); tc3.setIsPrefix(true); tc4.setIsPrefix(true); TextColumn[] tc = new TextColumn[4]; tc[0] = tc1; tc[1] = tc2; tc[2] = tc3; tc[3] = tc4; 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 8****************************"); for (Map.Entry<Key, Value> e : scan) { System.out.println(e); results++; } Assert.assertEquals(4, results); }