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

SPARKC-701 #1359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ class TableWriter[T] private (
val deleteColumnsClause = deleteColumnNames.map(quote).mkString(", ")
val whereClause = quotedColumnNames(primaryKey).map(c => s"$c = :$c").mkString(" AND ")

s"DELETE ${deleteColumnsClause} FROM ${quote(keyspaceName)}.${quote(tableName)} WHERE $whereClause"
val timestampSpec = writeConf.timestamp match {
case TimestampOption(PerRowWriteOptionValue(placeholder)) => s""" USING TIMESTAMP :$placeholder"""
case TimestampOption(StaticWriteOptionValue(value)) => s" USING TIMESTAMP $value"
case _ => ""
}

s"DELETE ${deleteColumnsClause} FROM ${quote(keyspaceName)}.${quote(tableName)}$timestampSpec WHERE $whereClause"
}
private lazy val queryTemplateUsingUpdate: String = {
val (primaryKey, regularColumns) = columns.partition(_.isPrimaryKeyColumn)
Expand All @@ -100,7 +106,22 @@ class TableWriter[T] private (
val setClause = (setNonCounterColumnsClause ++ setCounterColumnsClause).mkString(", ")
val whereClause = quotedColumnNames(primaryKey).map(c => s"$c = :$c").mkString(" AND ")

s"UPDATE ${quote(keyspaceName)}.${quote(tableName)} SET $setClause WHERE $whereClause"
val ttlSpec = writeConf.ttl match {
case TTLOption(PerRowWriteOptionValue(placeholder)) => Some(s"""TTL :$placeholder""")
case TTLOption(StaticWriteOptionValue(value)) => Some(s"TTL $value")
case _ => None
}

val timestampSpec = writeConf.timestamp match {
case TimestampOption(PerRowWriteOptionValue(placeholder)) => Some(s"""TIMESTAMP :$placeholder""")
case TimestampOption(StaticWriteOptionValue(value)) => Some(s"TIMESTAMP $value")
case _ => None
}

val options = List(ttlSpec, timestampSpec).flatten
val optionsSpec = if (options.nonEmpty) s" USING ${options.mkString(" AND ")}" else ""

s"UPDATE ${quote(keyspaceName)}.${quote(tableName)}$optionsSpec SET $setClause WHERE $whereClause"
}

private val isCounterUpdate =
Expand Down