Search in sources :

Example 1 with CottontailWrapper

use of org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper in project cineast by vitrivr.

the class LSC21TemporalUpdateCommand method run.

@Override
@SuppressWarnings("unchecked")
public void run() {
    if (Config.sharedConfig().getDatabase().getSelector() != DataSource.COTTONTAIL) {
        System.out.println("Other DB than Cottontail DB not supported (yet). Aborting");
        return;
    }
    /* Preparation. */
    final CottontailWrapper cottontail = new CottontailWrapper(Config.sharedConfig().getDatabase().getHost(), Config.sharedConfig().getDatabase().getPort());
    long txId = cottontail.client.begin();
    final Query query = new Query(ENTITY_NAME).select("*", null).txId(txId);
    final TupleIterator ti = cottontail.client.query(query);
    final LinkedList<Update> updates = new LinkedList<>();
    int counter = 0;
    int totalCounter = 0;
    /* Prepare updates. */
    while (ti.hasNext()) {
        final Tuple t = ti.next();
        final MediaSegmentDescriptor segment = convert(t);
        try {
            final Optional<LocalDateTime> oldt = extractTimeInformation(segment.getSegmentId());
            if (!oldt.isPresent()) {
                continue;
            }
            final LocalDateTime ldt = oldt.get();
            final long msOfTheDay = ldt.getHour() * 60 * 60 * 1000 + ldt.getMinute() * 60 * 1000 + ldt.getSecond() * 1000;
            final long sAbs = ldt.toInstant(ZoneOffset.UTC).toEpochMilli() / 1000L;
            final Update update = new Update(ENTITY_NAME).values(new Pair<>(MediaSegmentDescriptor.SEGMENT_START_COL_NAME, (double) msOfTheDay), new Pair<>(MediaSegmentDescriptor.SEGMENT_END_COL_NAME, (double) msOfTheDay + 1), new Pair<>(MediaSegmentDescriptor.SEGMENT_STARTABS_COL_NAME, resetAbsTime ? 0.0 : sAbs), new Pair<>(MediaSegmentDescriptor.SEGMENT_ENDABS_COL_NAME, resetAbsTime ? 0.0 : (sAbs + 1))).where(new org.vitrivr.cottontail.client.language.extensions.Literal(CineastConstants.SEGMENT_ID_COLUMN_QUALIFIER, "=", segment.getSegmentId())).txId(txId);
            updates.add(update);
        } catch (Exception e) {
            LOGGER.warn("Could not update " + segment.getSegmentId() + " due to exception: " + e.getMessage());
        }
    }
    /* Execute updates. */
    Update update;
    while ((update = updates.poll()) != null) {
        cottontail.client.update(update);
        totalCounter++;
        if (counter++ > 99) {
            if (progress) {
                System.out.println("Updated " + totalCounter + " rows.");
            }
            counter = 0;
        }
    }
    cottontail.client.commit(txId);
    System.out.println("Done.");
}
Also used : LocalDateTime(java.time.LocalDateTime) CottontailWrapper(org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper) Query(org.vitrivr.cottontail.client.language.dql.Query) Update(org.vitrivr.cottontail.client.language.dml.Update) LinkedList(java.util.LinkedList) Literal(org.vitrivr.cottontail.grpc.CottontailGrpc.Literal) TupleIterator(org.vitrivr.cottontail.client.iterators.TupleIterator) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) Tuple(org.vitrivr.cottontail.client.iterators.Tuple)

Example 2 with CottontailWrapper

use of org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper in project cineast by vitrivr.

the class OptimizeEntitiesCommand method optimizeAllCottontailEntities.

public static void optimizeAllCottontailEntities() {
    if (Config.sharedConfig().getDatabase().getSelector() != DataSource.COTTONTAIL || Config.sharedConfig().getDatabase().getWriter() != DataSource.COTTONTAIL) {
        System.err.println("Cottontail DB is not both selector & writer in the config. exiting");
        return;
    }
    try (final CottontailWrapper wrapper = new CottontailWrapper(Config.sharedConfig().getDatabase().getHost(), Config.sharedConfig().getDatabase().getPort())) {
        System.out.println("Optimizing all entities for schema '" + CottontailWrapper.CINEAST_SCHEMA + "' in Cottontail");
        wrapper.client.list(new ListEntities(CottontailWrapper.CINEAST_SCHEMA)).forEachRemaining(entity -> {
            System.out.println("Optimizing entity " + entity);
            final String name = entity.asString("dbo").replace("warren.", "");
            wrapper.client.optimize(new OptimizeEntity(name));
        });
        System.out.println("Finished optimizing all entities");
    }
}
Also used : CottontailWrapper(org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper) ListEntities(org.vitrivr.cottontail.client.language.ddl.ListEntities) OptimizeEntity(org.vitrivr.cottontail.client.language.ddl.OptimizeEntity)

Example 3 with CottontailWrapper

use of org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper in project cineast by vitrivr.

the class DataImportHandler method cleanOnDemand.

/**
 * Drops the entity if called. This is in order to have clean imports.
 *
 * @param entityName The entity name to drop
 * @param taskName   The task name during which this dropping occurs. Only for logging purposes
 */
protected static void cleanOnDemand(String entityName, String taskName) {
    final EntityCreator ec = Config.sharedConfig().getDatabase().getEntityCreatorSupplier().get();
    /* Beware, this drops the table */
    CreateEntity createEntity = null;
    CottontailWrapper cottontail = null;
    if (Config.sharedConfig().getDatabase().getSelector() != DataSource.COTTONTAIL || Config.sharedConfig().getDatabase().getWriter() != DataSource.COTTONTAIL) {
        LOGGER.warn("Other database than Cottontail DB in use. Using inconvenient database restore");
    } else {
        LOGGER.info("Storing entity ({}) details for re-setup", entityName);
        cottontail = new CottontailWrapper(Config.sharedConfig().getDatabase().getHost(), Config.sharedConfig().getDatabase().getPort());
    // entityDefinition = cottontail.entityDetailsBlocking(CottontailMessageBuilder.entity(entityName));
    }
    LOGGER.info("{} - Dropping table for entity {}...", taskName, entityName);
    ec.dropEntity(entityName);
    LOGGER.info("{} - Finished dropping table for entity {}", taskName, entityName);
    if (createEntity == null) {
        LOGGER.warn("Calling command: setup -- This may take a while");
        DatabaseSetupCommand setupCmd = new DatabaseSetupCommand();
        setupCmd.doSetup();
    } else {
        cottontail.client.create(createEntity);
        LOGGER.info("Re-created entity: {}", createEntity.getBuilder().getDefinition().getEntity().getName());
    }
}
Also used : CreateEntity(org.vitrivr.cottontail.client.language.ddl.CreateEntity) EntityCreator(org.vitrivr.cineast.core.db.setup.EntityCreator) CottontailWrapper(org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper) DatabaseSetupCommand(org.vitrivr.cineast.standalone.cli.DatabaseSetupCommand)

Aggregations

CottontailWrapper (org.vitrivr.cineast.core.db.cottontaildb.CottontailWrapper)3 LocalDateTime (java.time.LocalDateTime)1 LinkedList (java.util.LinkedList)1 MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)1 EntityCreator (org.vitrivr.cineast.core.db.setup.EntityCreator)1 DatabaseSetupCommand (org.vitrivr.cineast.standalone.cli.DatabaseSetupCommand)1 Tuple (org.vitrivr.cottontail.client.iterators.Tuple)1 TupleIterator (org.vitrivr.cottontail.client.iterators.TupleIterator)1 CreateEntity (org.vitrivr.cottontail.client.language.ddl.CreateEntity)1 ListEntities (org.vitrivr.cottontail.client.language.ddl.ListEntities)1 OptimizeEntity (org.vitrivr.cottontail.client.language.ddl.OptimizeEntity)1 Update (org.vitrivr.cottontail.client.language.dml.Update)1 Query (org.vitrivr.cottontail.client.language.dql.Query)1 Literal (org.vitrivr.cottontail.grpc.CottontailGrpc.Literal)1