Skip to content

Instantly share code, notes, and snippets.

@eutkin
Created August 7, 2023 05:46
Show Gist options
  • Save eutkin/89034d56ad84961bfb44465a5c9b862c to your computer and use it in GitHub Desktop.
Save eutkin/89034d56ad84961bfb44465a5c9b862c to your computer and use it in GitHub Desktop.
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