Skip to content

Commit 044c568

Browse files
authored
Merge pull request #190 from datastax/issue/CDM-92
CDM-92: Fix NPE issue with target counter tables with null fields
2 parents ffe7bc0 + 90c5b4c commit 044c568

File tree

9 files changed

+33
-23
lines changed

9 files changed

+33
-23
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
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Read Record Count: 6
1+
Read Record Count: 7
22
Mismatch Record Count: 2
33
Corrected Mismatch Record Count: 2
44
Missing Record Count: 1
55
Corrected Missing Record Count: 0
6-
Valid Record Count: 3
6+
Valid Record Count: 4
77
Skipped Record Count: 0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Read Record Count: 6
1+
Read Record Count: 7
22
Mismatch Record Count: 0
33
Corrected Mismatch Record Count: 0
44
Missing Record Count: 1
55
Corrected Missing Record Count: 1
6-
Valid Record Count: 5
6+
Valid Record Count: 6
77
Skipped Record Count: 0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Read Record Count: 6
1+
Read Record Count: 7
22
Skipped Record Count: 0
3-
Write Record Count: 6
3+
Write Record Count: 7
44
Error Record Count: 0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Read Record Count: 6
1+
Read Record Count: 7
22
Mismatch Record Count: 0
33
Corrected Mismatch Record Count: 0
44
Missing Record Count: 0
55
Corrected Missing Record Count: 0
6-
Valid Record Count: 6
6+
Valid Record Count: 7
77
Skipped Record Count: 0

SIT/smoke/04_counters/expected.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
record2 | 11 | 20
77
record6 | 500 | null
88
record1 | 1 | 2
9+
record7 | 1 | 2
910
record4 | 10000 | 20001
1011

11-
(6 rows)
12+
(7 rows)

SIT/smoke/04_counters/setup.cql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ UPDATE origin.smoke_counters set col1=col1+1000, col2=col2+2000 where key='recor
77
UPDATE origin.smoke_counters set col1=col1+10000, col2=col2+20000 where key='record4';
88
UPDATE origin.smoke_counters set col1=col1+500, col2=col2+500 where key='record5';
99
UPDATE origin.smoke_counters set col1=col1+500 where key='record6';
10+
UPDATE origin.smoke_counters set col1=col1+1, col2=col2+2 where key='record7';
1011

1112
DROP TABLE IF EXISTS target.smoke_counters;
1213
CREATE TABLE target.smoke_counters(key text,col1 counter,col2 counter, PRIMARY KEY (key));
1314

15+
UPDATE target.smoke_counters set col1=col1+1 where key='record7';
16+
1417
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: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,38 @@ 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 originValue, targetValue;
46+
Object bindValueTarget = 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+
originValue = cqlTable.getOtherCqlTable().getData(originIndex, originRow);
53+
if (null == originValue) {
5354
currentBindIndex++;
5455
continue;
5556
}
56-
bindValue = ((Long) bindValue - (null==targetRow ? 0 : (Long) cqlTable.getData(targetIndex, targetRow)));
57+
targetValue = (null == targetRow ? 0L : cqlTable.getData(targetIndex, targetRow));
58+
bindValueTarget = ((Long) originValue - (null == targetValue ? 0L : (Long) targetValue));
5759
}
5860
else if (targetIndex== explodeMapKeyIndex) {
59-
bindValue = explodeMapKey;
61+
bindValueTarget = explodeMapKey;
6062
}
6163
else if (targetIndex== explodeMapValueIndex) {
62-
bindValue = explodeMapValue;
64+
bindValueTarget = 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+
bindValueTarget = cqlTable.getOtherCqlTable().getAndConvertData(originIndex, originRow);
6870
}
6971

70-
boundStatement = boundStatement.set(currentBindIndex++, bindValue, cqlTable.getBindClass(targetIndex));
71-
}
72-
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);
72+
boundStatement = boundStatement.set(currentBindIndex++, bindValueTarget, cqlTable.getBindClass(targetIndex));
73+
} catch (Exception e) {
74+
logger.error("Error trying to bind value:" + bindValueTarget + " to column:" +
75+
targetColumnNames.get(targetIndex) + " of targetDataType:" + targetColumnTypes.get(targetIndex) + "/"
76+
+ cqlTable.getBindClass(targetIndex).getName() + " at column index:" + targetIndex);
7477
throw e;
7578
}
7679
}

0 commit comments

Comments
 (0)