Skip to content

Commit 22daff1

Browse files
pravinbhatmsmygit
authored andcommitted
CDM-92: Fix NPE issue with target counter tables with null fields
1 parent ffe7bc0 commit 22daff1

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

RELEASE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release Notes
2-
## [4.1.3] - 2023-07-06
2+
## [4.1.4] - 2023-08-16
3+
- In rare edge situations, counter tables with existing data in Target can have null values on target. This release will handle null values in Target counter table transparently.
4+
5+
## [4.1.3] - 2023-08-14
36
- Counter table columns will usually have zeros to begin with, but in rare edge situations, they can have null values. This release will handle null values in counter table transparently.
47

58
## [4.1.2] - 2023-07-06

SIT/smoke/04_counters/setup.cql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ UPDATE origin.smoke_counters set col1=col1+500 where key='record6';
1111
DROP TABLE IF EXISTS target.smoke_counters;
1212
CREATE TABLE target.smoke_counters(key text,col1 counter,col2 counter, PRIMARY KEY (key));
1313

14+
UPDATE target.smoke_counters set col1=col1+1 where key='record1';
15+
1416
SELECT * FROM origin.smoke_counters;

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<connection>scm:git:[email protected]:datastax/cassandra-data-migrator.git</connection>
137137
<developerConnection>scm:git:[email protected]:datastax/cassandra-data-migrator.git</developerConnection>
138138
<url>https://github.com/datastax/cassandra-data-migrator</url>
139-
<tag>@{project.version}</tag>
139+
<tag>@{version}</tag>
140140
</scm>
141141

142142
<build>

src/main/java/com/datastax/cdm/cql/statement/TargetUpdateStatement.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,39 @@ protected BoundStatement bind(Row originRow, Row targetRow, Integer ttl, Long wr
4242
boundStatement = boundStatement.set(currentBindIndex++, writeTime, Long.class);
4343
}
4444

45-
Object bindValue = null;
45+
Object bindValueOrg = null;
46+
Object bindValueDest = null;
4647
for (int targetIndex : columnIndexesToBind) {
4748
int originIndex = cqlTable.getCorrespondingIndex(targetIndex);
4849

4950
try {
50-
if(usingCounter && counterIndexes.contains(targetIndex)) {
51-
bindValue = cqlTable.getOtherCqlTable().getData(originIndex, originRow);
52-
if (null == bindValue) {
51+
if (usingCounter && counterIndexes.contains(targetIndex)) {
52+
bindValueOrg = cqlTable.getOtherCqlTable().getData(originIndex, originRow);
53+
if (null == bindValueOrg) {
5354
currentBindIndex++;
5455
continue;
5556
}
56-
bindValue = ((Long) bindValue - (null==targetRow ? 0 : (Long) cqlTable.getData(targetIndex, targetRow)));
57+
bindValueDest = (null == targetRow ? 0L : cqlTable.getData(targetIndex, targetRow));
58+
bindValueDest = ((Long) bindValueOrg - (null == bindValueDest ? 0L : (Long) bindValueDest));
5759
}
5860
else if (targetIndex== explodeMapKeyIndex) {
59-
bindValue = explodeMapKey;
61+
bindValueDest = explodeMapKey;
6062
}
6163
else if (targetIndex== explodeMapValueIndex) {
62-
bindValue = explodeMapValue;
64+
bindValueDest = explodeMapValue;
6365
} else {
6466
if (originIndex < 0)
6567
// we don't have data to bind for this column; continue to the next targetIndex
6668
continue;
67-
bindValue = cqlTable.getOtherCqlTable().getAndConvertData(originIndex, originRow);
69+
bindValueDest = cqlTable.getOtherCqlTable().getAndConvertData(originIndex, originRow);
6870
}
6971

70-
boundStatement = boundStatement.set(currentBindIndex++, bindValue, cqlTable.getBindClass(targetIndex));
72+
boundStatement = boundStatement.set(currentBindIndex++, bindValueDest, cqlTable.getBindClass(targetIndex));
7173
}
7274
catch (Exception e) {
73-
logger.error("Error trying to bind value:" + bindValue + " to column:" + targetColumnNames.get(targetIndex) + " of targetDataType:" + targetColumnTypes.get(targetIndex)+ "/" + cqlTable.getBindClass(targetIndex).getName() + " at column index:" + targetIndex);
75+
logger.error("Error trying to bind value:" + bindValueDest + " to column:" +
76+
targetColumnNames.get(targetIndex) + " of targetDataType:" + targetColumnTypes.get(targetIndex) + "/"
77+
+ cqlTable.getBindClass(targetIndex).getName() + " at column index:" + targetIndex);
7478
throw e;
7579
}
7680
}

0 commit comments

Comments
 (0)