Skip to content

Commit 5a91c62

Browse files
zakalibitAlex Revetchi
andauthored
Non null values wont be read after a row with null value for the column (#516)
* - is_null_ is not set to false by a non null value, it stays true after a row with a null value for the column * - fix formatting Co-authored-by: Alex Revetchi <[email protected]>
1 parent 3386668 commit 5a91c62

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/value.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,13 @@ Value::Value(const DataType::ConstPtr& data_type, Decoder decoder)
204204
} else if (data_type->is_user_type()) {
205205
const UserType& user_type = static_cast<const UserType&>(*data_type);
206206
count_ = user_type.fields().size();
207-
} else {
208-
count_ = 0;
209207
}
210208
}
211209

212210
bool Value::update(const Decoder& decoder) {
213211
decoder_ = decoder;
214-
if (!decoder_.is_null()) {
212+
is_null_ = decoder_.is_null();
213+
if (!is_null_) {
215214
if (data_type_->is_collection()) {
216215
return decoder_.decode_int32(count_);
217216
} else if (data_type_->is_tuple()) {
@@ -223,9 +222,7 @@ bool Value::update(const Decoder& decoder) {
223222
}
224223
} else {
225224
count_ = 0;
226-
is_null_ = true;
227225
}
228-
229226
return true;
230227
}
231228

tests/src/unit/tests/test_value.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ TEST(ValueUnitTest, BadDecimal) {
111111
CASS_ERROR_LIB_NOT_ENOUGH_DATA);
112112
}
113113

114+
TEST(ValueUnitTest, NullInNextRow) {
115+
DataType::ConstPtr data_type(new DataType(CASS_VALUE_TYPE_INT));
116+
117+
// Size (int32_t) and contents of element
118+
const signed char input[8] = { 0, 0, 0, 4, 0, 0, 0, 2 };
119+
Decoder decoder((const char*)input, 12);
120+
121+
// init with a non null column in a row
122+
Value value(data_type, 2, decoder);
123+
EXPECT_FALSE(value.is_null());
124+
125+
const signed char null_input[4] = { -1, 1, 1, 1 };
126+
Decoder null_decoder((const char*)null_input, 4);
127+
128+
// simulate next row null value in the column
129+
null_decoder.update_value(value);
130+
EXPECT_TRUE(value.is_null());
131+
132+
// next row non null value check is_null() returns correct value
133+
Decoder decoder2((const char*)input, 12);
134+
decoder2.update_value(value);
135+
EXPECT_FALSE(value.is_null());
136+
}
137+
114138
TEST(ValueUnitTest, NullElementInCollectionList) {
115139
const signed char input[12] = {
116140
-1, -1, -1, -1, // Element 1 is NULL

0 commit comments

Comments
 (0)