org.apache.accumulo.core.client.TableExistsException Java Examples

The following examples show how to use org.apache.accumulo.core.client.TableExistsException. 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: QueryJoinSelectOptimizerTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

  mock = new MockInstance("accumulo");
  PasswordToken pToken = new PasswordToken("pass".getBytes());
  conn = mock.getConnector("user", pToken);

  config = new BatchWriterConfig();
  config.setMaxMemory(1000);
  config.setMaxLatency(1000, TimeUnit.SECONDS);
  config.setMaxWriteThreads(10);

  if (conn.tableOperations().exists("rya_prospects")) {
    conn.tableOperations().delete("rya_prospects");
  }
  if (conn.tableOperations().exists("rya_selectivity")) {
    conn.tableOperations().delete("rya_selectivity");
  }

  arc = new AccumuloRdfConfiguration();
  arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
  arc.setMaxRangesForScanner(300);
  res = new ProspectorServiceEvalStatsDAO(conn, arc);

}
 
Example #2
Source File: IngestJob.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the tables that are needed to load data using this ingest job if they don't already exist. If a table is created, it is configured with the
 * appropriate iterators, aggregators, and locality groups that are required for ingest and query functionality to work correctly.
 *
 * @param tableNames
 *            the names of the table to create if they don't exist
 * @param tops
 *            accumulo table operations helper for checking/creating tables
 * @param conf
 *            the Hadoop {@link Configuration} for retrieving table configuration information
 * @param log
 *            a logger for diagnostic messages
 * @param enableBloomFilters
 *            an indication of whether bloom filters should be enabled in the configuration
 * @throws AccumuloSecurityException
 * @throws AccumuloException
 * @throws TableNotFoundException
 */
protected void createAndConfigureTablesIfNecessary(String[] tableNames, TableOperations tops, NamespaceOperations namespaceOperations, Configuration conf,
                Logger log, boolean enableBloomFilters) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
    for (String table : tableNames) {
        createNamespaceIfNecessary(namespaceOperations, table);
        // If the tables don't exist, then create them.
        try {
            if (!tops.exists(table)) {
                tops.create(table);
            }
        } catch (TableExistsException te) {
            // in this case, somebody else must have created the table after our existence check
            log.info("Tried to create " + table + " but somebody beat us to the punch");
        }
    }
    
    // Pass along the enabling of bloom filters using the configuration
    conf.setBoolean(ShardTableConfigHelper.ENABLE_BLOOM_FILTERS, enableBloomFilters);
    
    configureTablesIfNecessary(tableNames, tops, conf, log);
}
 
Example #3
Source File: AccumuloSelectivityEvalDAOTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialize() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setConnector(conn);
    accc.setRdfEvalDAO(res);
    accc.init();

    TableOperations tos = conn.tableOperations();
    Assert.assertTrue(tos.exists("rya_prospects") && tos.exists("rya_selectivity"));
    Assert.assertTrue(accc.isInitialized());
    Assert.assertTrue(accc.getConf().equals(arc));
    Assert.assertTrue(accc.getConnector().equals(conn));
    Assert.assertTrue(accc.getRdfEvalDAO().equals(res));

}
 
Example #4
Source File: ProspectorService.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance of {@link ProspectorService}.
 *
 * @param connector - The Accumulo connector used to communicate with the table. (not null)
 * @param tableName - The name of the Accumulo table that will be queried for Prospect results. (not null)
 * @throws AccumuloException A problem occurred while creating the table.
 * @throws AccumuloSecurityException A problem occurred while creating the table.
 */
public ProspectorService(Connector connector, String tableName) throws AccumuloException, AccumuloSecurityException {
    this.connector = requireNonNull(connector);
    this.tableName = requireNonNull(tableName);

    this.plans = ProspectorUtils.planMap(manager.getPlans());

    // Create the table if it doesn't already exist.
    try {
        final TableOperations tos = connector.tableOperations();
        if(!tos.exists(tableName)) {
            tos.create(tableName);
        }
    } catch(TableExistsException e) {
        // Do nothing. Something else must have made it while we were.
    }
}
 
Example #5
Source File: AccumuloSelectivityEvalDAOTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

    mock = new MockInstance("accumulo");
    PasswordToken pToken = new PasswordToken("pass".getBytes());
    conn = mock.getConnector("user", pToken);

    config = new BatchWriterConfig();
    config.setMaxMemory(1000);
    config.setMaxLatency(1000, TimeUnit.SECONDS);
    config.setMaxWriteThreads(10);

    if (conn.tableOperations().exists("rya_prospects")) {
        conn.tableOperations().delete("rya_prospects");
    }
    if (conn.tableOperations().exists("rya_selectivity")) {
        conn.tableOperations().delete("rya_selectivity");
    }

    arc = new AccumuloRdfConfiguration();
    res = new ProspectorServiceEvalStatsDAO(conn, arc);
    arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
    arc.setMaxRangesForScanner(300);

}
 
Example #6
Source File: AccumuloGetInstanceDetailsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void getDetails_instanceDoesNotHaveDetails() throws AccumuloException, AccumuloSecurityException, InstanceDoesNotExistException, RyaClientException, TableExistsException {
    // Mimic a pre-details rya install.
    final TableOperations tableOps = getConnector().tableOperations();

    final String spoTableName = getRyaInstanceName() + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX;
    final String ospTableName = getRyaInstanceName() + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX;
    final String poTableName = getRyaInstanceName() + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX;
    tableOps.create(spoTableName);
    tableOps.create(ospTableName);
    tableOps.create(poTableName);

    // Verify that the operation returns empty.
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(
            getUsername(),
            getPassword().toCharArray(),
            getInstanceName(),
            getZookeepers());

    final GetInstanceDetails getInstanceDetails = new AccumuloGetInstanceDetails(connectionDetails, getConnector());
    final Optional<RyaDetails> details = getInstanceDetails.getDetails(getRyaInstanceName());
    assertFalse( details.isPresent() );
}
 
Example #7
Source File: AccumuloInstanceExistsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void exists_dataTables() throws AccumuloException, AccumuloSecurityException, RyaClientException, TableExistsException {
    final Connector connector = getConnector();
    final TableOperations tableOps = connector.tableOperations();

    // Create the Rya instance's Rya details table.
    final String instanceName = "test_instance_";

    final String spoTableName = instanceName + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX;
    final String ospTableName = instanceName + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX;
    final String poTableName = instanceName + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX;
    tableOps.create(spoTableName);
    tableOps.create(ospTableName);
    tableOps.create(poTableName);

    // Verify the command reports the instance exists.
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(
            getUsername(),
            getPassword().toCharArray(),
            getInstanceName(),
            getZookeepers());

    final AccumuloInstanceExists instanceExists = new AccumuloInstanceExists(connectionDetails, getConnector());
    assertTrue( instanceExists.exists(instanceName) );
}
 
Example #8
Source File: TracingExample.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private void execute(Opts opts) throws TableNotFoundException, AccumuloException,
    AccumuloSecurityException, TableExistsException {

  if (opts.createtable) {
    client.tableOperations().create(opts.getTableName());
  }

  if (opts.createEntries) {
    createEntries(opts);
  }

  if (opts.readEntries) {
    readEntries(opts);
  }

  if (opts.deletetable) {
    client.tableOperations().delete(opts.getTableName());
  }
}
 
Example #9
Source File: BloomFiltersNotFound.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize for writable use.  
 * This is called from the DAO, perhaps others.
 */
private void initReadWrite() throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
                TableExistsException, RyaClientException {
    if (mtbw == null)
        throw new RyaClientException("Failed to initialize temporal index, setMultiTableBatchWriter() was not set.");
    if (conf == null)
        throw new RyaClientException("Failed to initialize temporal index, setConf() was not set.");
    if (temporalIndexTableName==null)
        throw new RyaClientException("Failed to set temporalIndexTableName==null.");

    // Now do all the writable setup, read should already be complete.
    // Create one index table on first run.
    Boolean isCreated = ConfigUtils.createTableIfNotExists(conf, temporalIndexTableName);
    if (isCreated) {
        logger.info("First run, created temporal index table: " + temporalIndexTableName);
    }
    temporalIndexBatchWriter = mtbw.getBatchWriter(temporalIndexTableName);
}
 
Example #11
Source File: CopyTool.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the child table if it doesn't already exist.
 * @param childTableName the name of the child table.
 * @throws IOException
 */
public void createTableIfNeeded(final String childTableName) throws IOException {
    try {
        final Configuration childConfig = MergeToolMapper.getChildConfig(conf);
        final AccumuloRdfConfiguration childAccumuloRdfConfiguration = new AccumuloRdfConfiguration(childConfig);
        childAccumuloRdfConfiguration.setTablePrefix(childTablePrefix);
        final Connector childConnector = AccumuloRyaUtils.setupConnector(childAccumuloRdfConfiguration);
        if (!childConnector.tableOperations().exists(childTableName)) {
            log.info("Creating table: " + childTableName);
            childConnector.tableOperations().create(childTableName);
            log.info("Created table: " + childTableName);
            log.info("Granting authorizations to table: " + childTableName);
            childConnector.securityOperations().grantTablePermission(childUserName, childTableName, TablePermission.WRITE);
            log.info("Granted authorizations to table: " + childTableName);
        }
    } catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
        throw new IOException(e);
    }
}
 
Example #12
Source File: ListQueryIdsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * This test ensures that when there are PCJ tables in Accumulo as well as
 * the Fluo table's export destinations column, the command for fetching the
 * list of queries only includes queries that appear in both places.
 */
@Test
public void getQueryIds() throws AccumuloException, AccumuloSecurityException, TableExistsException {
    try(FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
        // Store a few SPARQL/Query ID pairs in the Fluo table.
        try(Transaction tx = fluoClient.newTransaction()) {
            tx.set("SPARQL_3", QUERY_NODE_ID, "ID_3");
            tx.set("SPARQL_1", QUERY_NODE_ID, "ID_1");
            tx.set("SPARQL_4", QUERY_NODE_ID, "ID_4");
            tx.set("SPARQL_2", QUERY_NODE_ID, "ID_2");
            tx.commit();
        }

        // Ensure the correct list of Query IDs is retured.
        final List<String> expected = Lists.newArrayList("ID_1", "ID_2", "ID_3", "ID_4");
        final List<String> queryIds = new ListQueryIds().listQueryIds(fluoClient);
        assertEquals(expected, queryIds);
    }
}
 
Example #13
Source File: AccumuloInstanceExistsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void exists_ryaDetailsTable() throws AccumuloException, AccumuloSecurityException, RyaClientException, TableExistsException {
    final Connector connector = getConnector();
    final TableOperations tableOps = connector.tableOperations();

    // Create the Rya instance's Rya details table.
    final String instanceName = "test_instance_";
    final String ryaDetailsTable = instanceName + AccumuloRyaInstanceDetailsRepository.INSTANCE_DETAILS_TABLE_NAME;
    tableOps.create(ryaDetailsTable);

    // Verify the command reports the instance exists.
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(
            getUsername(),
            getPassword().toCharArray(),
            getInstanceName(),
            getZookeepers());

    final AccumuloInstanceExists instanceExists = new AccumuloInstanceExists(connectionDetails, getConnector());
    assertTrue( instanceExists.exists(instanceName) );
}
 
Example #14
Source File: MongoInstanceExistsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void exists_dataTables() throws MongoException, TableExistsException {
    final MongoClient client = getMongoClient();

    // Create the Rya instance's Rya triples collection.
    final String instanceName = "test_instance_";
    client.getDatabase(instanceName).createCollection("rya_triples");

    // Verify the command reports the instance exists.
    final MongoInstanceExists instanceExists = new MongoInstanceExists(getMongoClient());
    assertTrue( instanceExists.exists(instanceName) );
}
 
Example #15
Source File: AccumuloTemporalIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testStoreStatementsSameTime() throws IOException, NoSuchAlgorithmException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
    ValueFactory vf = SimpleValueFactory.getInstance();
    IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME);
    IRI pred2_circa = vf.createIRI(URI_PROPERTY_CIRCA);

    // These are the same datetime instant but from different time
    // zones.
    // This is an arbitrary zone, BRST=Brazil, better if not local.
    final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00";
    final String ZONETestDateInZulu = "2015-01-01T01:59:59Z";
    final String ZONETestDateInET = "2014-12-31T20:59:59-05:00";

    // These all should be stored because they are in the predicate list.
    // BUT they will get converted to the same exact datetime in UTC.
    // So we have to make the key distinct! Good luck indexer!
    Statement s1 = vf.createStatement(vf.createIRI("foo:subj1"), pred2_circa, vf.createLiteral(ZONETestDateInET));
    Statement s2 = vf.createStatement(vf.createIRI("foo:subj2"), pred1_atTime, vf.createLiteral(ZONETestDateInZulu));
    Statement s3 = vf.createStatement(vf.createIRI("foo:subj3"), pred1_atTime, vf.createLiteral(ZONETestDateInBRST));
    int rowsStoredExpected = 0;
    tIndexer.storeStatement(convertStatement(s1));
    rowsStoredExpected++;
    tIndexer.storeStatement(convertStatement(s2));
    rowsStoredExpected++;
    tIndexer.storeStatement(convertStatement(s3));
    rowsStoredExpected++;
    int rowsStoredActual = printTables("junit testing: Duplicate times stored", null /*System.out*/, null);
    Assert.assertEquals("Number of Duplicate times stored, 1 means duplicates not handled correctly.", rowsStoredExpected*4, rowsStoredActual);
}
 
Example #16
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException,
        MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException {

    accCon = new MockInstance().getConnector("root", "".getBytes());
    accCon.tableOperations().create(tablename);

}
 
Example #17
Source File: MockTableTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
    InMemoryInstance i = new InMemoryInstance(this.getClass().toString());
    connector = i.getConnector("root", new PasswordToken(""));
    if (connector.tableOperations().exists(TABLE_NAME))
        connector.tableOperations().delete(TABLE_NAME);
    connector.tableOperations().create(TABLE_NAME);
    writer = createBatchWriter();
    tableOperations = connector.tableOperations();
}
 
Example #18
Source File: MongoGetInstanceDetailsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void getDetails_instanceDoesNotHaveDetails() throws MongoException, TableExistsException, RyaClientException {
    // Mimic a pre-details rya install.
    final String instanceName = "instance_name";

    getMongoClient().getDatabase(instanceName).createCollection("rya_triples");

    // Verify that the operation returns empty.
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    final GetInstanceDetails getInstanceDetails = ryaClient.getGetInstanceDetails();
    final Optional<RyaDetails> details = getInstanceDetails.getDetails(instanceName);
    assertFalse( details.isPresent() );
}
 
Example #19
Source File: AccumuloFreeTextIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
private static void destroyTable(Configuration conf, String tablename) throws AccumuloException, AccumuloSecurityException,
        TableNotFoundException, TableExistsException {
    TableOperations tableOps = ConfigUtils.getConnector(conf).tableOperations();
    if (tableOps.exists(tablename)) {
        tableOps.delete(tablename);
    }
}
 
Example #20
Source File: AccumuloTemporalIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link AccumuloTemporalIndexer#storeStatements(java.util.Collection)} .
 *
 * @throws TableExistsException
 * @throws TableNotFoundException
 * @throws AccumuloSecurityException
 * @throws AccumuloException
 * @throws IOException
 * @throws IllegalArgumentException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testStoreStatements()
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, IllegalArgumentException, IOException,
        NoSuchAlgorithmException {
    long valueHash = 0;
    Collection<Statement> statements = new ArrayList<Statement>(70);
    statements.addAll(Arrays.asList(seriesSpo));
    int rowsStoredExpected = statements.size()*4;  // instants store 4 each
    // hash the expected output:
    for (Statement statement : statements) {
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
    }
    statements.add(spo_B02_E30);
    rowsStoredExpected += 2; // intervals store two dates
    statements.add(spo_B30_E32);
    rowsStoredExpected += 2; // intervals store two dates
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B02_E30)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B02_E30)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B30_E32)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B30_E32)));
    // duplicates will overwrite old ones, no change in the output except timestamps
    statements.add(spo_B30_E32);
    statements.add(spo_B30_E32);

    List<RyaStatement> ryaStatements = Lists.newArrayList();
    for (Statement s : statements){ ryaStatements.add(convertStatement(s));}
    tIndexer.storeStatements(ryaStatements);

    Map<String, Long> statistics = new HashMap<String, Long>();
    int rowsStoredActual = printTables("junit testing: StoreStatements multiple statements", null, statistics);
    Assert.assertEquals("Number of rows stored.", rowsStoredExpected, rowsStoredActual); // 4 index entries per statement
    Assert.assertEquals("value hash.", valueHash, statistics.get(STAT_VALUEHASH).longValue());
}
 
Example #21
Source File: MongoTemporalIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() throws IOException, MongoException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException {
    try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
        tIndexer.setConf(conf);
        tIndexer.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();

        final IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME);
        final IRI pred2_circa = vf.createIRI(URI_PROPERTY_CIRCA);

        final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
        final String testDate2016InET = "2016-12-31T20:59:59-05:00";

        // These should be stored because they are in the predicate list.
        // BUT they will get converted to the same exact datetime in UTC.
        final Statement s1 = vf.createStatement(vf.createIRI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST));
        final Statement s2 = vf.createStatement(vf.createIRI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET));
        tIndexer.storeStatement(convertStatement(s1));
        tIndexer.storeStatement(convertStatement(s2));

        final String dbName = conf.getMongoDBName();
        final MongoDatabase db = super.getMongoClient().getDatabase(dbName);
        final MongoCollection<Document> collection = db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya") + tIndexer.getCollectionName());

        printTables(tIndexer, "junit testing: Temporal entities stored in testDelete before delete");
        assertEquals("Number of rows stored.", 2, collection.countDocuments()); // 4 index entries per statement

        tIndexer.deleteStatement(convertStatement(s1));
        tIndexer.deleteStatement(convertStatement(s2));

        printTables(tIndexer, "junit testing: Temporal entities stored in testDelete after delete");
        assertEquals("Number of rows stored after delete.", 0, collection.countDocuments());
    }
}
 
Example #22
Source File: AccumuloTemporalIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException {
    // count rows expected to store:
    int rowsStoredExpected = 0;

    ValueFactory vf = SimpleValueFactory.getInstance();

    IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME);
    IRI pred2_circa = vf.createIRI(URI_PROPERTY_CIRCA);

    final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
    final String testDate2016InET = "2016-12-31T20:59:59-05:00";

    // These should be stored because they are in the predicate list.
    // BUT they will get converted to the same exact datetime in UTC.
    Statement s1 = vf.createStatement(vf.createIRI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST));
    Statement s2 = vf.createStatement(vf.createIRI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET));
    tIndexer.storeStatement(convertStatement(s1));
    rowsStoredExpected++;
    tIndexer.storeStatement(convertStatement(s2));
    rowsStoredExpected++;

    tIndexer.flush();

    int rowsStoredActual = printTables("junit testing: Temporal entities stored in testDelete before delete", System.out, null);
    Assert.assertEquals("Number of rows stored.", rowsStoredExpected*4, rowsStoredActual); // 4 index entries per statement

    tIndexer.deleteStatement(convertStatement(s1));
    tIndexer.deleteStatement(convertStatement(s2));

    int afterDeleteRowsStoredActual = printTables("junit testing: Temporal entities stored in testDelete after delete", System.out, null);
    Assert.assertEquals("Number of rows stored after delete.", 0, afterDeleteRowsStoredActual);
}
 
Example #23
Source File: AccumuloFreeTextIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * setConf sets the configuration and then initializes for query only.  
 * Use this alone if usage does not require writing.
 * For a writeable (store and delete) version of this, 
 * call this and then setMultiTableBatchWriter(), then call init()
 * that is what the DAO does.
 */
@Override
public void setConf(final Configuration conf) {
    this.conf = conf;
    if (!isInit) {
        try {
            initInternal();
            isInit = true;
        } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException | TableExistsException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        }
    }
}
 
Example #24
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * intilize the temporal index.
 * This is dependent on a few set method calls before init:
 * >  Connector = ConfigUtils.getConnector(conf);
 * >  MultiTableBatchWriter mtbw = connector.createMultiTableBatchWriter(new BatchWriterConfig());
 * >  // optional: temporal.setConnector(connector);
 * >  temporal.setMultiTableBatchWriter(mtbw);
 * >  temporal.init();
 */
@Override
public void init() {
    if (!isInit) {
        try {
            initReadWrite();
            isInit = true;
        } catch (final AccumuloException | AccumuloSecurityException | TableNotFoundException | TableExistsException | RyaClientException e) {
            logger.error("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        }
    }
}
 
Example #25
Source File: ConfigUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * @param conf
 * @param tablename
 * @return if the table was created
 * @throws AccumuloException
 * @throws AccumuloSecurityException
 * @throws TableExistsException
 */
public static boolean createTableIfNotExists(final Configuration conf, final String tablename)
        throws AccumuloException, AccumuloSecurityException, TableExistsException {
    final TableOperations tops = getConnector(conf).tableOperations();
    if (!tops.exists(tablename)) {
        logger.info("Creating table: " + tablename);
        tops.create(tablename);
        return true;
    }
    return false;
}
 
Example #26
Source File: PCJOptionalTestIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluateSingeIndexExactMatch()
        throws TupleQueryResultHandlerException, QueryEvaluationException,
        MalformedQueryException, RepositoryException, AccumuloException,
        AccumuloSecurityException, TableExistsException, RyaDAOException,
        SailException, TableNotFoundException, PcjException, InferenceEngineException {

    final String indexSparqlString = ""//
            + "SELECT ?e ?c ?l ?o" //
            + "{" //
            + "  ?e a ?c . "//
            + "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
            + "  OPTIONAL{?e <uri:talksTo> ?o } . "//
            + "}";//

    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablePrefix
            + "INDEX_1", indexSparqlString, new String[] { "e", "c", "l", "o" },
            Optional.absent());
    final String queryString = ""//
            + "SELECT ?e ?c ?l ?o " //
            + "{" //
            + "  ?e a ?c . "//
            + "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
            + "  OPTIONAL {?e <uri:talksTo> ?o } . "//
            + "}";//
    final CountingResultHandler crh = new CountingResultHandler();
    PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, tablePrefix);
    PcjIntegrationTestingUtil.closeAndShutdown(conn, repo);
    final TupleQuery tupQuery = pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupQuery.evaluate(crh);

    Assert.assertEquals(3, crh.getCount());

}
 
Example #27
Source File: AccumuloPcjIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws RepositoryException,
		TupleQueryResultHandlerException, QueryEvaluationException,
		MalformedQueryException, AccumuloException,
		AccumuloSecurityException, TableExistsException, RyaDAOException,
		TableNotFoundException, InferenceEngineException,
		NumberFormatException, UnknownHostException, SailException {

	repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(prefix, "instance");
	conn = repo.getConnection();

	pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(prefix, "instance");
	pcjConn = pcjRepo.getConnection();

	final IRI sub = VF.createIRI("uri:entity");
	subclass = VF.createIRI("uri:class");
	obj = VF.createIRI("uri:obj");
	talksTo = VF.createIRI("uri:talksTo");

	conn.add(sub, RDF.TYPE, subclass);
	conn.add(sub, RDFS.LABEL, VF.createLiteral("label"));
	conn.add(sub, talksTo, obj);

	final IRI sub2 = VF.createIRI("uri:entity2");
	subclass2 = VF.createIRI("uri:class2");
	obj2 = VF.createIRI("uri:obj2");

	conn.add(sub2, RDF.TYPE, subclass2);
	conn.add(sub2, RDFS.LABEL, VF.createLiteral("label2"));
	conn.add(sub2, talksTo, obj2);

	accCon = ConfigUtils.getConnector(conf);


}
 
Example #28
Source File: AccumuloRdfUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
public static void createTableIfNotExist(TableOperations tableOperations, String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
    boolean tableExists = tableOperations.exists(tableName);
    if (!tableExists) {
        logger.debug("Creating accumulo table: " + tableName);
        tableOperations.create(tableName);
    }
}
 
Example #29
Source File: AccumuloPcjIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluateOneIndex() throws PcjException,
		RepositoryException, AccumuloException, AccumuloSecurityException,
		TableExistsException, TableNotFoundException,
		MalformedQueryException, SailException, QueryEvaluationException,
		TupleQueryResultHandlerException {

	final IRI superclass = VF.createIRI("uri:superclass");
	final IRI superclass2 = VF.createIRI("uri:superclass2");

	conn.add(subclass, RDF.TYPE, superclass);
	conn.add(subclass2, RDF.TYPE, superclass2);
	conn.add(obj, RDFS.LABEL, VF.createLiteral("label"));
	conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2"));
	conn.add(obj, RDFS.LABEL, VF.createLiteral("label"));
	conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2"));

	final String indexSparqlString = ""//
			+ "SELECT ?dog ?pig ?duck  " //
			+ "{" //
			+ "  ?pig a ?dog . "//
			+ "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck "//
			+ "}";//

	final CountingResultHandler crh1 = new CountingResultHandler();
	final CountingResultHandler crh2 = new CountingResultHandler();

	PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1,
			indexSparqlString, new String[] { "dog", "pig", "duck" },
			Optional.absent());

	conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString)
			.evaluate(crh1);
	PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
	pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString)
			.evaluate(crh2);

	Assert.assertEquals(crh1.count, crh2.count);

}
 
Example #30
Source File: PrecompJoinOptimizerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws RepositoryException,
		TupleQueryResultHandlerException, QueryEvaluationException,
		MalformedQueryException, AccumuloException,
		AccumuloSecurityException, TableExistsException, RyaDAOException,
		TableNotFoundException, InferenceEngineException, NumberFormatException,
		UnknownHostException, SailException {

	repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(tablePrefix, "instance");
	conn = repo.getConnection();

	pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
	pcjConn = pcjRepo.getConnection();

	sub = VF.createIRI("uri:entity");
	subclass = VF.createIRI("uri:class");
	obj = VF.createIRI("uri:obj");
	talksTo = VF.createIRI("uri:talksTo");

	conn.add(sub, RDF.TYPE, subclass);
	conn.add(sub, RDFS.LABEL, VF.createLiteral("label"));
	conn.add(sub, talksTo, obj);

	sub2 = VF.createIRI("uri:entity2");
	subclass2 = VF.createIRI("uri:class2");
	obj2 = VF.createIRI("uri:obj2");

	conn.add(sub2, RDF.TYPE, subclass2);
	conn.add(sub2, RDFS.LABEL, VF.createLiteral("label2"));
	conn.add(sub2, talksTo, obj2);

	accCon = new MockInstance("instance").getConnector("root",
			new PasswordToken(""));

}