Skip to content

Commit

Permalink
Merge pull request #2696 from ALPSMAC/bugfix/2695-RepreparedStatement
Browse files Browse the repository at this point in the history
Prevent re-preparing already prepared statement in CassandraLayerReader
  • Loading branch information
pomadchin committed Jun 19, 2018
2 parents 4011222 + e7ad394 commit 7a8928d
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -43,15 +43,17 @@ class CassandraValueReader(
val writerSchema = attributeStore.readSchema(layerId)
val codec = KeyValueRecordCodec[K, V]

def read(key: K): V = instance.withSession { session =>
val statement = session.prepare(
private lazy val statement = instance.withSession{ session =>
session.prepare(
QueryBuilder.select("value")
.from(header.keyspace, header.tileTable)
.where(eqs("key", QueryBuilder.bindMarker()))
.and(eqs("name", layerId.name))
.and(eqs("zoom", layerId.zoom))
)
}

def read(key: K): V = instance.withSession { session =>
val row = session.execute(statement.bind(keyIndex.toIndex(key): BigInteger)).all()
val tiles = row.map { entry =>
AvroEncoder.fromBinary(writerSchema, entry.getBytes("value").array())(codec)
Expand Down

0 comments on commit 7a8928d

Please sign in to comment.