org.apache.accumulo.core.client.Accumulo Java Examples
The following examples show how to use
org.apache.accumulo.core.client.Accumulo.
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: CopyPlus5K.java From accumulo-examples with Apache License 2.0 | 6 votes |
private static void cleanupAndCreateTables(Properties props) throws Exception { FileSystem hdfs = FileSystem.get(new Configuration()); if (hdfs.exists(rootPath)) { hdfs.delete(rootPath, true); } try (AccumuloClient client = Accumulo.newClient().from(props).build()) { if (client.tableOperations().exists(inputTable)) { client.tableOperations().delete(inputTable); } if (client.tableOperations().exists(outputTable)) { client.tableOperations().delete(outputTable); } // Create tables client.tableOperations().create(inputTable); client.tableOperations().create(outputTable); // Write data to input table try (BatchWriter bw = client.createBatchWriter(inputTable)) { for (int i = 0; i < 100; i++) { Mutation m = new Mutation(String.format("%03d", i)); m.at().family("cf1").qualifier("cq1").put("" + i); bw.addMutation(m); } } } }
Example #2
Source File: ITBase.java From fluo with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpAccumulo() throws Exception { instanceName = System.getProperty(IT_INSTANCE_NAME_PROP, "it-instance-default"); File instanceDir = new File("target/accumulo2-maven-plugin/" + instanceName); boolean instanceClear = System.getProperty(IT_INSTANCE_CLEAR_PROP, "true").equalsIgnoreCase("true"); if (instanceDir.exists() && instanceClear) { FileUtils.deleteDirectory(instanceDir); } if (!instanceDir.exists()) { MiniAccumuloConfig cfg = new MiniAccumuloConfig(instanceDir, PASSWORD); cfg.setInstanceName(instanceName); cluster = new MiniAccumuloCluster(cfg); cluster.start(); startedCluster = true; } Properties props = MiniAccumuloCluster.getClientProperties(instanceDir); aClient = Accumulo.newClient().from(props).build(); }
Example #3
Source File: ExamplesIT.java From accumulo-examples with Apache License 2.0 | 6 votes |
@Before public void setupTest() throws Exception { c = Accumulo.newClient().from(getClientProps()).build(); String user = c.whoami(); String instance = getClientInfo().getInstanceName(); String keepers = getClientInfo().getZooKeepers(); AuthenticationToken token = getAdminToken(); if (token instanceof PasswordToken) { String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8); writeClientPropsFile(getClientPropsFile(), instance, keepers, user, passwd); } else { Assert.fail("Unknown token type: " + token); } fs = getCluster().getFileSystem(); dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString(); origAuths = c.securityOperations().getUserAuthorizations(user); c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(","))); }
Example #4
Source File: CountIT.java From accumulo-examples with Apache License 2.0 | 6 votes |
@Before public void setupInstance() throws Exception { tableName = getUniqueNames(1)[0]; client = Accumulo.newClient().from(getClientProperties()).build(); client.tableOperations().create(tableName); BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig()); ColumnVisibility cv = new ColumnVisibility(); // / has 1 dir // /local has 2 dirs 1 file // /local/user1 has 2 files bw.addMutation(Ingest.buildMutation(cv, "/local", true, false, true, 272, 12345, null)); bw.addMutation(Ingest.buildMutation(cv, "/local/user1", true, false, true, 272, 12345, null)); bw.addMutation(Ingest.buildMutation(cv, "/local/user2", true, false, true, 272, 12345, null)); bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 12345, null)); bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 23456, null)); bw.addMutation( Ingest.buildMutation(cv, "/local/user1/file1", false, false, false, 2024, 12345, null)); bw.addMutation( Ingest.buildMutation(cv, "/local/user1/file2", false, false, false, 1028, 23456, null)); bw.close(); }
Example #5
Source File: BloomFiltersNotFound.java From accumulo-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(BloomFiltersNotFound.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { try { client.tableOperations().create("bloom_test3"); client.tableOperations().create("bloom_test4"); client.tableOperations().setProperty("bloom_test4", "table.bloom.enabled", "true"); } catch (TableExistsException e) { // ignore } System.out.println("Writing data to bloom_test3 and bloom_test4 (bloom filters enabled)"); writeData(client, "bloom_test3", 7); client.tableOperations().flush("bloom_test3", null, null, true); writeData(client, "bloom_test4", 7); client.tableOperations().flush("bloom_test4", null, null, true); BloomBatchScanner.scan(client, "bloom_test3", 8); BloomBatchScanner.scan(client, "bloom_test4", 8); } }
Example #6
Source File: Query.java From accumulo-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { QueryOpts opts = new QueryOpts(); opts.parseArgs(Query.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 10)) { if (opts.useSample) { SamplerConfiguration samplerConfig = client.tableOperations() .getSamplerConfiguration(opts.tableName); CutoffIntersectingIterator.validateSamplerConfig( client.tableOperations().getSamplerConfiguration(opts.tableName)); bs.setSamplerConfiguration(samplerConfig); } for (String entry : query(bs, opts.terms, opts.sampleCutoff)) { System.out.println(" " + entry); } } }
Example #7
Source File: Read.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(Read.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); Scanner scan = client.createScanner("hellotable", Authorizations.EMPTY)) { scan.setRange(new Range(new Key("row_0"), new Key("row_1002"))); for (Entry<Key,Value> e : scan) { Key key = e.getKey(); log.trace(key.getRow() + " " + key.getColumnFamily() + " " + key.getColumnQualifier() + " " + e.getValue()); } } }
Example #8
Source File: SetupTable.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ClientOpts opts = new ClientOpts(); opts.parseArgs(SetupTable.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { try { client.tableOperations().create(tableName); } catch (TableExistsException e) { // ignore } // create a table with initial partitions TreeSet<Text> intialPartitions = new TreeSet<>(); for (String split : splits) { intialPartitions.add(new Text(split)); } client.tableOperations().addSplits(tableName, intialPartitions); FileSystem fs = FileSystem.get(new Configuration()); try (PrintStream out = new PrintStream( new BufferedOutputStream(fs.create(new Path(outputFile))))) { // create some data in outputFile for (int i = 0; i < numRows; i++) { out.println(String.format("row_%010d\tvalue_%010d", i, i)); } } } }
Example #9
Source File: Reverse.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(Reverse.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); Scanner scanner = client.createScanner(opts.shardTable, Authorizations.EMPTY); BatchWriter bw = client.createBatchWriter(opts.doc2TermTable)) { for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); Mutation m = new Mutation(key.getColumnQualifier()); m.put(key.getColumnFamily(), new Text(), new Value(new byte[0])); bw.addMutation(m); } } }
Example #10
Source File: Index.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { IndexOpts opts = new IndexOpts(); opts.parseArgs(Index.class.getName(), args); String splitRegex = "\\W+"; try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); BatchWriter bw = client.createBatchWriter(opts.tableName)) { for (String filename : opts.files) { index(opts.partitions, new File(filename), splitRegex, bw); } } }
Example #11
Source File: ContinuousQuery.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(ContinuousQuery.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { ArrayList<Text[]> randTerms = findRandomTerms( client.createScanner(opts.doc2Term, Authorizations.EMPTY), opts.numTerms); Random rand = new Random(); try (BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 5)) { for (long i = 0; i < opts.iterations; i += 1) { Text[] columns = randTerms.get(rand.nextInt(randTerms.size())); bs.clearScanIterators(); bs.clearColumns(); IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class); IntersectingIterator.setColumnFamilies(ii, columns); bs.addScanIterator(ii); bs.setRanges(Collections.singleton(new Range())); long t1 = System.currentTimeMillis(); int count = Iterators.size(bs.iterator()); long t2 = System.currentTimeMillis(); System.out.printf(" %s %,d %6.3f%n", Arrays.asList(columns), count, (t2 - t1) / 1000.0); } } } }
Example #12
Source File: BloomFilters.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(BloomFilters.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { try { System.out.println("Creating bloom_test1 and bloom_test2"); client.tableOperations().create("bloom_test1"); client.tableOperations().setProperty("bloom_test1", "table.compaction.major.ratio", "7"); client.tableOperations().create("bloom_test2"); client.tableOperations().setProperty("bloom_test2", "table.bloom.enabled", "true"); client.tableOperations().setProperty("bloom_test2", "table.compaction.major.ratio", "7"); } catch (TableExistsException e) { // ignore } // Write a million rows 3 times flushing files to disk separately System.out.println("Writing data to bloom_test1"); writeData(client, "bloom_test1", 7); client.tableOperations().flush("bloom_test1", null, null, true); writeData(client, "bloom_test1", 8); client.tableOperations().flush("bloom_test1", null, null, true); writeData(client, "bloom_test1", 9); client.tableOperations().flush("bloom_test1", null, null, true); System.out.println("Writing data to bloom_test2"); writeData(client, "bloom_test2", 7); client.tableOperations().flush("bloom_test2", null, null, true); writeData(client, "bloom_test2", 8); client.tableOperations().flush("bloom_test2", null, null, true); writeData(client, "bloom_test2", 9); client.tableOperations().flush("bloom_test2", null, null, true); } }
Example #13
Source File: BloomBatchScanner.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(BloomBatchScanner.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { scan(client, "bloom_test1", 7); scan(client, "bloom_test2", 7); } }
Example #14
Source File: Insert.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(Insert.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { try { client.tableOperations().create("hellotable"); } catch (TableExistsException e) { // ignore } try (BatchWriter bw = client.createBatchWriter("hellotable")) { log.trace("writing ..."); for (int i = 0; i < 10000; i++) { Mutation m = new Mutation(String.format("row_%d", i)); for (int j = 0; j < 5; j++) { m.put("colfam", String.format("colqual_%d", j), new Value((String.format("value_%d_%d", i, j)).getBytes())); } bw.addMutation(m); if (i % 100 == 0) { log.trace(String.valueOf(i)); } } } } }
Example #15
Source File: VerifyIngest.java From accumulo-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws TableNotFoundException { ClientOpts opts = new ClientOpts(); opts.parseArgs(VerifyIngest.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); Scanner scanner = client.createScanner(SetupTable.tableName, Authorizations.EMPTY)) { scanner.setRange(new Range(String.format("row_%010d", 0), null)); Iterator<Entry<Key,Value>> si = scanner.iterator(); boolean ok = true; for (int i = 0; i < SetupTable.numRows; i++) { if (si.hasNext()) { Entry<Key,Value> entry = si.next(); if (!entry.getKey().getRow().toString().equals(String.format("row_%010d", i))) { log.error("unexpected row key " + entry.getKey().getRow().toString() + " expected " + String.format("row_%010d", i)); ok = false; } if (!entry.getValue().toString().equals(String.format("value_%010d", i))) { log.error("unexpected value " + entry.getValue().toString() + " expected " + String.format("value_%010d", i)); ok = false; } } else { log.error("no more rows, expected " + String.format("row_%010d", i)); ok = false; break; } } if (ok) { System.out.println("OK"); System.exit(0); } else { System.exit(1); } } }
Example #16
Source File: ClientOpts.java From accumulo-examples with Apache License 2.0 | 4 votes |
public AccumuloClient createAccumuloClient() { return Accumulo.newClient().from(getClientPropsPath()).build(); }
Example #17
Source File: ClientOpts.java From accumulo-examples with Apache License 2.0 | 4 votes |
public Properties getClientProperties() { if (cachedProps == null) { cachedProps = Accumulo.newClientProperties().from(getClientPropsPath()).build(); } return cachedProps; }
Example #18
Source File: ChunkInputStreamIT.java From accumulo-examples with Apache License 2.0 | 4 votes |
@Before public void setupInstance() throws Exception { client = Accumulo.newClient().from(getClientProps()).build(); tableName = getUniqueNames(1)[0]; client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS); }
Example #19
Source File: ChunkInputFormatIT.java From accumulo-examples with Apache License 2.0 | 4 votes |
@Before public void setupInstance() throws Exception { client = Accumulo.newClient().from(getClientProps()).build(); tableName = getUniqueNames(1)[0]; client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS); }
Example #20
Source File: AccumuloService.java From nifi with Apache License 2.0 | 4 votes |
@OnEnabled public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException { if (!context.getProperty(INSTANCE_NAME).isSet() || !context.getProperty(ZOOKEEPER_QUORUM).isSet() || !context.getProperty(ACCUMULO_USER).isSet()){ throw new InitializationException("Instance name and Zookeeper Quorum must be specified"); } final String instanceName = context.getProperty(INSTANCE_NAME).evaluateAttributeExpressions().getValue(); final String zookeepers = context.getProperty(ZOOKEEPER_QUORUM).evaluateAttributeExpressions().getValue(); final String accumuloUser = context.getProperty(ACCUMULO_USER).evaluateAttributeExpressions().getValue(); final AuthenticationType type = AuthenticationType.valueOf( context.getProperty(AUTHENTICATION_TYPE).getValue() ); final AuthenticationToken token = getToken(type,context); this.client = Accumulo.newClient().to(instanceName,zookeepers).as(accumuloUser,token).build(); if (null == token){ throw new InitializationException("Feature not implemented"); } }
Example #21
Source File: AccumuloUtil.java From fluo with Apache License 2.0 | 4 votes |
/** * Creates Accumulo connector given FluoConfiguration */ public static AccumuloClient getClient(FluoConfiguration config) { return Accumulo.newClient().to(config.getAccumuloInstance(), config.getAccumuloZookeepers()) .as(config.getAccumuloUser(), config.getAccumuloPassword()).build(); }