Search in sources :

Example 1 with Tuple2

use of org.jooq.lambda.tuple.Tuple2 in project torodb by torodb.

the class ExclusiveWriteBackendTransactionImpl method copyMetaIndexColumns.

private List<Tuple2<String, Boolean>> copyMetaIndexColumns(MetaIdentifiedDocPartIndex fromMetaDocPartIndex, MutableMetaDocPartIndex toMetaDocPartIndex) {
    List<Tuple2<String, Boolean>> identifiers = new ArrayList<>();
    Iterator<? extends MetaDocPartIndexColumn> fromMetaDocPartIndexColumnIterator = fromMetaDocPartIndex.iteratorColumns();
    while (fromMetaDocPartIndexColumnIterator.hasNext()) {
        MetaDocPartIndexColumn fromMetaDocPartIndexColumn = fromMetaDocPartIndexColumnIterator.next();
        toMetaDocPartIndex.addMetaDocPartIndexColumn(fromMetaDocPartIndexColumn.getIdentifier(), fromMetaDocPartIndexColumn.getOrdering());
        identifiers.add(new Tuple2<>(fromMetaDocPartIndexColumn.getIdentifier(), fromMetaDocPartIndexColumn.getOrdering().isAscending()));
    }
    return identifiers;
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 2 with Tuple2

use of org.jooq.lambda.tuple.Tuple2 in project torodb by torodb.

the class SharedWriteBackendTransactionImpl method addField.

@Override
public void addField(MetaDatabase db, MetaCollection col, MutableMetaDocPart docPart, MetaField newField) throws UserException {
    Preconditions.checkState(!isClosed(), "This transaction is closed");
    getSqlInterface().getMetaDataWriteInterface().addMetaField(getDsl(), db, col, docPart, newField);
    getSqlInterface().getStructureInterface().addColumnToDocPartTable(getDsl(), db.getIdentifier(), docPart.getIdentifier(), newField.getIdentifier(), getSqlInterface().getDataTypeProvider().getDataType(newField.getType()));
    List<Tuple2<MetaIndex, List<String>>> missingIndexes = col.getMissingIndexesForNewField(docPart, newField);
    for (Tuple2<MetaIndex, List<String>> missingIndexEntry : missingIndexes) {
        MetaIndex missingIndex = missingIndexEntry.v1();
        List<String> identifiers = missingIndexEntry.v2();
        MutableMetaDocPartIndex docPartIndex = docPart.getOrCreatePartialMutableDocPartIndexForMissingIndexAndNewField(missingIndex, identifiers, newField);
        if (missingIndex.isMatch(docPart, identifiers, docPartIndex)) {
            List<Tuple2<String, Boolean>> columnList = new ArrayList<>(docPartIndex.size());
            for (String identifier : identifiers) {
                MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
                columnList.add(new Tuple2<>(docPartIndexColumn.getIdentifier(), docPartIndexColumn.getOrdering().isAscending()));
            }
            MetaIdentifiedDocPartIndex identifiedDocPartIndex = docPartIndex.immutableCopy(identifierFactory.toIndexIdentifier(db, docPart.getIdentifier(), columnList));
            getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndex(getDsl(), db, col, docPart, identifiedDocPartIndex);
            for (String identifier : identifiers) {
                MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
                getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndexColumn(getDsl(), db, col, docPart, identifiedDocPartIndex, docPartIndexColumn);
            }
            getSqlInterface().getStructureInterface().createIndex(getDsl(), identifiedDocPartIndex.getIdentifier(), db.getIdentifier(), docPart.getIdentifier(), columnList, docPartIndex.isUnique());
            LOGGER.info("Created index {} for table {} associated to logical index {}.{}.{}", identifiedDocPartIndex.getIdentifier(), docPart.getIdentifier(), db.getName(), col.getName(), missingIndex.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) List(java.util.List) MutableMetaDocPartIndex(com.torodb.core.transaction.metainf.MutableMetaDocPartIndex) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 3 with Tuple2

use of org.jooq.lambda.tuple.Tuple2 in project waltz by khartec.

the class AssetCostHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    AssetCostService service = ctx.getBean(AssetCostService.class);
    AssetCostStatsDao statsDao = ctx.getBean(AssetCostStatsDao.class);
    AssetCostDao costDao = ctx.getBean(AssetCostDao.class);
    ApplicationIdSelectorFactory selectorFactory = ctx.getBean(ApplicationIdSelectorFactory.class);
    long st = System.currentTimeMillis();
    System.out.println("-- start");
    IdSelectionOptions appIdSelectionOptions = ImmutableIdSelectionOptions.builder().scope(HierarchyQueryScope.CHILDREN).entityReference(ImmutableEntityReference.builder().id(5600).kind(EntityKind.ORG_UNIT).build()).build();
    List<Tuple2<Long, BigDecimal>> costs = service.calculateCombinedAmountsForSelector(appIdSelectionOptions);
    System.out.println("-- end, dur: " + (System.currentTimeMillis() - st));
    System.out.println(costs);
    System.out.println(costs.size());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AssetCostStatsDao(com.khartec.waltz.data.asset_cost.AssetCostStatsDao) ApplicationIdSelectorFactory(com.khartec.waltz.data.application.ApplicationIdSelectorFactory) Tuple2(org.jooq.lambda.tuple.Tuple2) AssetCostDao(com.khartec.waltz.data.asset_cost.AssetCostDao) DSLContext(org.jooq.DSLContext) AssetCostService(com.khartec.waltz.service.asset_cost.AssetCostService)

Example 4 with Tuple2

use of org.jooq.lambda.tuple.Tuple2 in project georocket by georocket.

the class GeoJsonSplitterTest method split.

private List<Tuple2<GeoJsonChunkMeta, JsonObject>> split(String file) throws IOException {
    byte[] json = IOUtils.toByteArray(GeoJsonSplitterTest.class.getResource(file));
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = new ArrayList<>();
    StringWindow window = new StringWindow();
    GeoJsonSplitter splitter = new GeoJsonSplitter(window);
    Observable.just(json).map(Buffer::buffer).doOnNext(window::append).lift(new JsonParserOperator()).flatMap(splitter::onEventObservable).toBlocking().forEach(result -> {
        JsonObject o = new JsonObject(result.getChunk());
        chunks.add(Tuple.tuple((GeoJsonChunkMeta) result.getMeta(), o));
    });
    return chunks;
}
Also used : StringWindow(io.georocket.util.StringWindow) Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) JsonParserOperator(io.georocket.util.JsonParserOperator)

Example 5 with Tuple2

use of org.jooq.lambda.tuple.Tuple2 in project georocket by georocket.

the class GeoJsonSplitterTest method multiPolygon.

/**
 * Test if a MultiPolygon can be split correctly
 * @throws IOException if the test file could not be read
 */
@Test
public void multiPolygon() throws IOException {
    String filename = "multipolygon.json";
    long size = getFileSize(filename);
    List<Tuple2<GeoJsonChunkMeta, JsonObject>> chunks = split(filename);
    assertEquals(1, chunks.size());
    Tuple2<GeoJsonChunkMeta, JsonObject> t1 = chunks.get(0);
    GeoJsonChunkMeta m1 = t1.v1;
    assertNull(m1.getParentFieldName());
    assertEquals(0, m1.getStart());
    assertEquals(size, m1.getEnd());
    assertEquals("MultiPolygon", m1.getType());
    JsonObject o1 = t1.v2;
    assertEquals("MultiPolygon", o1.getString("type"));
    assertEquals(1, o1.getJsonArray("coordinates").size());
    assertEquals(1, o1.getJsonArray("coordinates").getJsonArray(0).size());
    assertEquals(13, o1.getJsonArray("coordinates").getJsonArray(0).getJsonArray(0).size());
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

Tuple2 (org.jooq.lambda.tuple.Tuple2)28 JsonObject (io.vertx.core.json.JsonObject)13 Test (org.junit.Test)13 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)12 ArrayList (java.util.ArrayList)7 ResultSet (java.sql.ResultSet)4 List (java.util.List)4 Map (java.util.Map)4 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)3 MutableMetaDocPartIndex (com.torodb.core.transaction.metainf.MutableMetaDocPartIndex)3 Collectors (java.util.stream.Collectors)3 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)2 EntityReference (com.khartec.waltz.model.EntityReference)2 MetaDocPartIndexColumn (com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)2 KvValue (com.torodb.kvdocument.values.KvValue)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Stream (java.util.stream.Stream)2 DSLContext (org.jooq.DSLContext)2