Created
August 7, 2023 05:46
-
-
Save eutkin/89034d56ad84961bfb44465a5c9b862c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package root | |
import org.apache.ignite.Ignition | |
import org.apache.ignite.cache.affinity.AffinityKeyMapped | |
import org.apache.ignite.cache.query.IndexQuery | |
import org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.lt | |
import org.apache.ignite.cache.query.annotations.QuerySqlField | |
import org.apache.ignite.configuration.CacheConfiguration | |
import org.apache.ignite.configuration.IgniteConfiguration | |
import java.util.UUID | |
fun main(args: Array<String>) { | |
Ignition.start(run { | |
val cfg = IgniteConfiguration() | |
cfg | |
}).use { ignite -> | |
val cfg = CacheConfiguration<EventKey, Value>("test") | |
cfg.setIndexedTypes(EventKey::class.java, Value::class.java) | |
ignite.getOrCreateCache(cfg).use { cache -> | |
val profileValue = UUID.randomUUID() | |
for (i in 0 until 10) { | |
val timestamp = i.toLong() | |
cache.put(EventKey(UUID.randomUUID(), profileValue), Value(timestamp = timestamp, i)) | |
} | |
val query = IndexQuery<EventKey, Value>(Value::class.java).setCriteria(lt("timestamp", 100.toLong())) | |
val events = cache.query(query).all.map { it.value.payload } | |
println(events) | |
} | |
} | |
} | |
// починить по аналогии с ListKey | |
data class EventKey( | |
val id: UUID, | |
@AffinityKeyMapped | |
val profileValue: UUID, // hashed | |
) | |
class Value( | |
@QuerySqlField( | |
index = true, | |
notNull = true, | |
descending = true, | |
name = "timestamp" | |
) | |
val timestamp: Long, | |
val payload: Int, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment