Skip to content

Commit a2368b2

Browse files
authored
Fix C++ client reading FLOAT inference columns declared as DOUBLE (#17759)
* Fix C++ client reading FLOAT inference columns declared as DOUBLE CALL INFERENCE returns FLOAT data in TsBlock while the result schema declares DOUBLE. Coerce by actual column type in getDouble/getFloat to avoid Unsupported operation: getDouble when iterating RowRecord. * Move column type coercion test into sessionIT.cpp Avoid a separate test source file; keep the same coverage in session_tests. * Implement numeric widening getters on C++ Column classes Align with Java TsFile: IntColumn/FloatColumn/LongColumn support cross-type getters (e.g. FloatColumn::getDouble). IoTDBRpcDataSet delegates directly to column getters like the Java client. Fixes CALL INFERENCE crash when schema declares DOUBLE but TsBlock stores FLOAT (including RLE-encoded columns).
1 parent b616502 commit a2368b2

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

iotdb-client/client-cpp/src/main/Column.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ int32_t IntColumn::getInt(int32_t position) const {
152152
return values_[position + arrayOffset_];
153153
}
154154

155+
int64_t IntColumn::getLong(int32_t position) const {
156+
return values_[position + arrayOffset_];
157+
}
158+
159+
float IntColumn::getFloat(int32_t position) const {
160+
return values_[position + arrayOffset_];
161+
}
162+
163+
double IntColumn::getDouble(int32_t position) const {
164+
return values_[position + arrayOffset_];
165+
}
166+
155167
std::vector<int32_t> IntColumn::getInts() const {
156168
return values_;
157169
}
@@ -204,6 +216,10 @@ float FloatColumn::getFloat(int32_t position) const {
204216
return values_[position + arrayOffset_];
205217
}
206218

219+
double FloatColumn::getDouble(int32_t position) const {
220+
return values_[position + arrayOffset_];
221+
}
222+
207223
std::vector<float> FloatColumn::getFloats() const {
208224
return values_;
209225
}
@@ -256,6 +272,10 @@ int64_t LongColumn::getLong(int32_t position) const {
256272
return values_[position + arrayOffset_];
257273
}
258274

275+
double LongColumn::getDouble(int32_t position) const {
276+
return values_[position + arrayOffset_];
277+
}
278+
259279
std::vector<int64_t> LongColumn::getLongs() const {
260280
return values_;
261281
}

iotdb-client/client-cpp/src/main/Column.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class IntColumn : public Column {
196196
ColumnEncoding getEncoding() const override;
197197

198198
int32_t getInt(int32_t position) const override;
199+
int64_t getLong(int32_t position) const override;
200+
float getFloat(int32_t position) const override;
201+
double getDouble(int32_t position) const override;
199202
std::vector<int32_t> getInts() const override;
200203

201204
bool mayHaveNull() const override;
@@ -220,6 +223,7 @@ class FloatColumn : public Column {
220223
ColumnEncoding getEncoding() const override;
221224

222225
float getFloat(int32_t position) const override;
226+
double getDouble(int32_t position) const override;
223227
std::vector<float> getFloats() const override;
224228

225229
bool mayHaveNull() const override;
@@ -244,6 +248,7 @@ class LongColumn : public Column {
244248
ColumnEncoding getEncoding() const override;
245249

246250
int64_t getLong(int32_t position) const override;
251+
double getDouble(int32_t position) const override;
247252
std::vector<int64_t> getLongs() const override;
248253

249254
bool mayHaveNull() const override;

iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "catch.hpp"
21+
#include "Column.h"
2122
#include "Session.h"
2223
#include "SessionBuilder.h"
2324
#include "TsBlock.h"
@@ -878,4 +879,23 @@ TEST_CASE("TsBlock deserialize rejects truncated malicious payload", "[TsBlockDe
878879
std::string data(18, '\0');
879880
data[3] = '\x10';
880881
REQUIRE_THROWS_AS(TsBlock::deserialize(data), IoTDBException);
882+
}
883+
884+
TEST_CASE("Numeric column widening getters align with Java TsFile", "[column]") {
885+
std::vector<bool> valueIsNull(1, false);
886+
887+
std::vector<float> floatValues = {120.00000762939453f};
888+
auto floatColumn = std::make_shared<FloatColumn>(0, 1, valueIsNull, floatValues);
889+
auto rleColumn = std::make_shared<RunLengthEncodedColumn>(floatColumn, 20);
890+
REQUIRE(floatColumn->getDouble(0) == Approx(120.0).margin(0.01));
891+
REQUIRE(rleColumn->getDouble(0) == Approx(120.0).margin(0.01));
892+
893+
std::vector<int32_t> intValues = {42};
894+
auto intColumn = std::make_shared<IntColumn>(0, 1, valueIsNull, intValues);
895+
REQUIRE(intColumn->getLong(0) == 42);
896+
REQUIRE(intColumn->getDouble(0) == Approx(42.0));
897+
898+
std::vector<int64_t> longValues = {1000};
899+
auto longColumn = std::make_shared<LongColumn>(0, 1, valueIsNull, longValues);
900+
REQUIRE(longColumn->getDouble(0) == Approx(1000.0));
881901
}

0 commit comments

Comments
 (0)