Skip to content

Commit

Permalink
Fixed RD-15252: date vs. timestamp comparisons not supported in SOQL
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz committed Dec 31, 2024
1 parent 5675372 commit e486335
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/main/scala/com/rawlabs/das/salesforce/DASSalesforceTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,27 @@ abstract class DASSalesforceTable(
"SELECT " + salesforceColumns.mkString(", ") + " FROM " + salesforceObjectName
}
}
val (supportedQuals, unsupportedQuals) = quals.partition(_.hasSimpleQual) // Only simple quals are supported

def isSupportedQual(q: Qual): Boolean = {
if (!q.hasSimpleQual) {
logger.warn("Unsupported qual (not SimpleQual)")
return false
}
val colType = columnTypes(q.getFieldName)
val dateColVsTimestampValue = colType.hasDate && q.getSimpleQual.getValue.hasTimestamp
if (dateColVsTimestampValue) {
// This isn't supported in SOQL
logger.warn("Unsupported qual (date column vs timestamp value)")
return false
}
true
}

val (supportedQuals, unsupportedQuals) = quals.partition(isSupportedQual)
if (supportedQuals.nonEmpty) {
soql += " WHERE " + supportedQuals
.map { q =>
assert(q.hasSimpleQual, "Only simple quals are supported")
val value = q.getSimpleQual.getValue // at this point we know it's a SimpleQual
val op = q.getSimpleQual.getOperator
val soqlOp =
if (op.hasEquals) "="
Expand All @@ -222,7 +238,23 @@ abstract class DASSalesforceTable(
assert(op.hasNotEquals)
"<>"
}
renameToSalesforce(q.getFieldName) + " " + soqlOp + " " + rawValueToSOQLValue(q.getSimpleQual.getValue)
val colType = columnTypes(q.getFieldName)
val colName = renameToSalesforce(q.getFieldName)
if (colType.hasTimestamp && value.hasDate) {
// Turn the date value into a timestamp value (00:00:00)
val timestampValue = {
val date = value.getDate
Value
.newBuilder()
.setTimestamp(
ValueTimestamp.newBuilder().setYear(date.getYear).setMonth(date.getMonth).setDay(date.getDay)
)
.build()
}
renameToSalesforce(q.getFieldName) + " " + soqlOp + " " + rawValueToSOQLValue(timestampValue)
} else {
colName + " " + soqlOp + " " + rawValueToSOQLValue(value)
}
}
.mkString(" AND ")
}
Expand Down

0 comments on commit e486335

Please sign in to comment.