use of org.jooq.lambda.tuple.Tuple3 in project torodb by torodb.
the class SqlWriteTorodTransaction method createIndex.
@Override
public boolean createIndex(String dbName, String colName, String indexName, List<IndexFieldInfo> fields, boolean unique) throws UserException {
if (fields.size() > 1) {
throw new UnsupportedCompoundIndexException(dbName, colName, indexName);
}
MutableMetaDatabase metaDb = getOrCreateMetaDatabase(dbName);
MutableMetaCollection metaColl = getOrCreateMetaCollection(metaDb, colName);
List<Tuple3<TableRef, String, FieldIndexOrdering>> indexFieldDefs = new ArrayList<>(fields.size());
for (IndexFieldInfo field : fields) {
AttributeReference attRef = field.getAttributeReference();
FieldIndexOrdering ordering = field.isAscending() ? FieldIndexOrdering.ASC : FieldIndexOrdering.DESC;
TableRef tableRef = extractTableRef(attRef);
String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
indexFieldDefs.add(new Tuple3<>(tableRef, lastKey, ordering));
}
if (unique) {
TableRef anyIndexTableRef = indexFieldDefs.stream().findAny().get().v1();
boolean isUniqueIndexWithMutlipleTableRefs = indexFieldDefs.stream().anyMatch(t -> !t.v1().equals(anyIndexTableRef));
if (isUniqueIndexWithMutlipleTableRefs) {
throw new UnsupportedUniqueIndexException(dbName, colName, indexName);
}
}
boolean indexExists = metaColl.streamContainedMetaIndexes().anyMatch(index -> index.getName().equals(indexName) || (index.isUnique() == unique && index.size() == indexFieldDefs.size() && Seq.seq(index.iteratorFields()).allMatch(indexField -> {
Tuple3<TableRef, String, FieldIndexOrdering> indexFieldDef = indexFieldDefs.get(indexField.getPosition());
return indexFieldDef != null && indexFieldDef.v1().equals(indexField.getTableRef()) && indexFieldDef.v2().equals(indexField.getName()) && indexFieldDef.v3() == indexField.getOrdering();
})));
if (!indexExists) {
MutableMetaIndex metaIndex = metaColl.addMetaIndex(indexName, unique);
for (Tuple3<TableRef, String, FieldIndexOrdering> indexFieldDef : indexFieldDefs) {
metaIndex.addMetaIndexField(indexFieldDef.v1(), indexFieldDef.v2(), indexFieldDef.v3());
}
getInternalTransaction().getBackendTransaction().createIndex(metaDb, metaColl, metaIndex);
}
return !indexExists;
}
use of org.jooq.lambda.tuple.Tuple3 in project SimpleFlatMapper by arnaudroger.
the class JoolTupleTest method testCsvParser.
@Test
public void testCsvParser() throws IOException {
final CsvParser.StaticMapToDSL<Tuple3<Long, Integer, Short>> mapToDSL = CsvParser.mapTo(new TypeReference<Tuple3<Long, Integer, Short>>() {
}).defaultHeaders();
final Iterator<Tuple3<Long, Integer, Short>> iterator = mapToDSL.iterator(new StringReader("6,7,3\n7,8,9"));
final Tuple3<Long, Integer, Short> tuple1 = iterator.next();
assertEquals(6l, tuple1.v1().longValue());
assertEquals(7, tuple1.v2().intValue());
assertEquals((short) 3, tuple1.v3().shortValue());
final Tuple3<Long, Integer, Short> tuple2 = iterator.next();
assertEquals(7l, tuple2.v1().longValue());
assertEquals(8, tuple2.v2().intValue());
assertEquals((short) 9, tuple2.v3().shortValue());
}
use of org.jooq.lambda.tuple.Tuple3 in project SimpleFlatMapper by arnaudroger.
the class JoolTupleTest method testMetaDataOnJoolTuple.
@Test
public void testMetaDataOnJoolTuple() throws Exception {
// creates a new tuple allocated on the JVM heap
System.out.println("super " + Tuple3.class.toString());
for (Class<?> clazz : Tuple3.class.getInterfaces()) {
System.out.println("I " + clazz.toString());
}
ClassMeta<Tuple3<Long, Integer, Short>> cm = ReflectionService.newInstance().getClassMeta(new TypeReference<Tuple3<Long, Integer, Short>>() {
}.getType());
final PropertyFinder<Tuple3<Long, Integer, Short>> propertyFinder = cm.newPropertyFinder(isValidPropertyMeta);
final PropertyMeta<Tuple3<Long, Integer, Short>, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0", 0, true, true), new Object[0]);
final PropertyMeta<Tuple3<Long, Integer, Short>, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1", 0, true, true), new Object[0]);
final PropertyMeta<Tuple3<Long, Integer, Short>, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt2", 0, true, true), new Object[0]);
final PropertyMeta<Tuple3<Long, Integer, Short>, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt3", 0, true, true), new Object[0]);
assertNotNull(fieldA);
assertNotNull(fieldB);
assertNotNull(fieldC);
assertNull(fieldD);
Tuple3<Long, Integer, Short> tuple = new Tuple3<Long, Integer, Short>(6l, 7, (short) 3);
assertTrue(fieldA instanceof ConstructorPropertyMeta);
assertTrue(fieldB instanceof ConstructorPropertyMeta);
assertTrue(fieldC instanceof ConstructorPropertyMeta);
Assert.assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
Assert.assertEquals(7, fieldB.getGetter().get(tuple).intValue());
Assert.assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
use of org.jooq.lambda.tuple.Tuple3 in project georocket by georocket.
the class IndexerVerticle method insertDocuments.
/**
* Insert multiple Elasticsearch documents into the index. Perform a
* bulk request. This method replies to all messages if the bulk request
* was successful.
* @param type Elasticsearch type for documents
* @param documents a list of tuples containing document IDs, documents to
* index, and the respective messages from which the documents were created
* @return an observable that completes when the operation has finished
*/
private Observable<Void> insertDocuments(String type, List<Tuple3<String, JsonObject, Message<JsonObject>>> documents) {
long startTimeStamp = System.currentTimeMillis();
List<String> chunkPaths = Seq.seq(documents).map(Tuple3::v1).toList();
onIndexingStarted(startTimeStamp, chunkPaths);
List<Tuple2<String, JsonObject>> docsToInsert = Seq.seq(documents).map(Tuple3::limit2).toList();
List<Message<JsonObject>> messages = Seq.seq(documents).map(Tuple3::v3).toList();
return client.bulkInsert(type, docsToInsert).flatMap(bres -> {
JsonArray items = bres.getJsonArray("items");
for (int i = 0; i < items.size(); ++i) {
JsonObject jo = items.getJsonObject(i);
JsonObject item = jo.getJsonObject("index");
Message<JsonObject> msg = messages.get(i);
if (client.bulkResponseItemHasErrors(item)) {
msg.fail(500, client.bulkResponseItemGetErrorMessage(item));
} else {
msg.reply(null);
}
}
long stopTimeStamp = System.currentTimeMillis();
List<String> correlationIds = Seq.seq(messages).map(Message::body).map(d -> d.getString("correlationId")).toList();
onIndexingFinished(stopTimeStamp - startTimeStamp, correlationIds, chunkPaths, client.bulkResponseGetErrorMessage(bres));
return Observable.empty();
});
}
Aggregations