Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the option to set ttl from a column. #274

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

SariNusier
Copy link

@SariNusier SariNusier commented Nov 26, 2020

  • If ttl.column is set, the connector will use the value in that column to set the ttl of the record.
  • The ttl column will not be included in the fields of the record.

Sari Nusier added 4 commits November 26, 2020 10:26
- If ttl.column is set, the connector will use the value in that column to set the ttl of the record.
- The ttl column will not be included in the fields of the record.
- The ability to use a constant ttl is still there, but ttl.column takes precedence when both are set.
Copy link
Contributor

@fe2s fe2s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SariNusier
Thank you for the PR! It looks good in general.
Could you please also update documentation and tests?

@@ -25,7 +25,7 @@ class BinaryRedisPersistence extends RedisPersistence[Array[Byte]] {
override def load(pipeline: Pipeline, key: String, requiredColumns: Seq[String]): Unit =
pipeline.get(key.getBytes(UTF_8))

override def encodeRow(keyName: String, value: Row): Array[Byte] = {
override def encodeRow(keyName: String, value: Row, ttlColumn: Option[String] = None): Array[Byte] = {
val fields = value.schema.fields.map(_.name)
val valuesArray = fields.map(f => value.getAs[Any](f))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we exclude TTL column here as well?

@@ -39,6 +39,13 @@ class HashRedisPersistence extends RedisPersistence[Any] {
// don't store key values
k != keyName
}
.filter { case (k, _) =>
// don't store TTLs
ttlColumn match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably more efficient in terms of the performance to check if ttlColumn is specified only once rather than for every field.

val encodedRow = persistence.encodeRow(keyName, row)
persistence.save(pipeline, key, encodedRow, ttl)
val encodedRow = persistence.encodeRow(keyName, row, ttlColumn)
val recordTTL = if (ttlColumn.isEmpty) ttl else row.getAs[Int](ttlColumn.get)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rewrite it with val recordTTL = ttlColumn.map(v => row.getAs[Int](v)).getOrElse(ttl). It looks to be more idiomatic approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants