efegokdemir commented on code in PR #4878:
URL: https://github.com/apache/arrow-adbc/pull/4878#discussion_r4266532284
##########
c/driver/sqlite/sqlite_test.cc:
##########
@@ -1013,9 +1015,116 @@ TEST_F(SqliteReaderTest, IntsFloatsStrs) {
ASSERT_EQ(NANOARROW_TYPE_STRING, reader.fields[0].type);
ASSERT_NO_FATAL_FAILURE(reader.Next());
+
ASSERT_NO_FATAL_FAILURE(CompareArray<std::string>(reader.array_view->children[0],
+ {"1.0", "1.0", "", "Inf",
"-Inf"}));
+}
+
+TEST_F(SqliteReaderTest, InferFloatToStringPreservesRoundTripPrecision) {
+ ASSERT_NO_FATAL_FAILURE(Exec("CREATE TABLE foo (upcast_col, append_col)"));
+ ASSERT_NO_FATAL_FAILURE(
+ Exec("INSERT INTO foo VALUES "
+ "(123456789.123, 'start'), "
+ "(3.141592653589793, 123456789.123), "
+ "(0.1, 3.141592653589793), "
+ "('end', 0.1)"));
+
+ struct ExpectedValue {
+ std::optional<double> number;
+ std::string text;
+ };
+ std::vector<ExpectedValue> expected_upcast;
+ std::vector<ExpectedValue> expected_append;
+ sqlite3_stmt* expected_stmt = nullptr;
+ ASSERT_EQ(SQLITE_OK, sqlite3_prepare_v2(db, "SELECT upcast_col, append_col
FROM foo",
+ -1, &expected_stmt, nullptr));
+ int rc = SQLITE_OK;
+ while ((rc = sqlite3_step(expected_stmt)) == SQLITE_ROW) {
+ auto read_expected = [expected_stmt](int column) {
+ ExpectedValue value;
+ const int type = sqlite3_column_type(expected_stmt, column);
+ if (type == SQLITE_INTEGER || type == SQLITE_FLOAT) {
+ value.number = sqlite3_column_double(expected_stmt, column);
+ } else {
+ value.text = std::string(
+ reinterpret_cast<const char*>(sqlite3_column_text(expected_stmt,
column)),
+ sqlite3_column_bytes(expected_stmt, column));
+ }
+ return value;
+ };
+ expected_upcast.emplace_back(read_expected(0));
+ expected_append.emplace_back(read_expected(1));
+ }
+ EXPECT_EQ(SQLITE_DONE, rc);
+ sqlite3_finalize(expected_stmt);
Review Comment:
Changed the test to compare Arrow’s output with SQLite’s sqlite3_column_text
result directly, rather than parsing both values as doubles. The focused
precision and decimal-comma tests pass.
##########
c/driver/sqlite/sqlite_test.cc:
##########
@@ -1013,9 +1015,116 @@ TEST_F(SqliteReaderTest, IntsFloatsStrs) {
ASSERT_EQ(NANOARROW_TYPE_STRING, reader.fields[0].type);
ASSERT_NO_FATAL_FAILURE(reader.Next());
+
ASSERT_NO_FATAL_FAILURE(CompareArray<std::string>(reader.array_view->children[0],
+ {"1.0", "1.0", "", "Inf",
"-Inf"}));
+}
+
+TEST_F(SqliteReaderTest, InferFloatToStringPreservesRoundTripPrecision) {
+ ASSERT_NO_FATAL_FAILURE(Exec("CREATE TABLE foo (upcast_col, append_col)"));
+ ASSERT_NO_FATAL_FAILURE(
+ Exec("INSERT INTO foo VALUES "
+ "(123456789.123, 'start'), "
+ "(3.141592653589793, 123456789.123), "
+ "(0.1, 3.141592653589793), "
+ "('end', 0.1)"));
+
+ struct ExpectedValue {
+ std::optional<double> number;
+ std::string text;
+ };
+ std::vector<ExpectedValue> expected_upcast;
+ std::vector<ExpectedValue> expected_append;
+ sqlite3_stmt* expected_stmt = nullptr;
+ ASSERT_EQ(SQLITE_OK, sqlite3_prepare_v2(db, "SELECT upcast_col, append_col
FROM foo",
+ -1, &expected_stmt, nullptr));
+ int rc = SQLITE_OK;
+ while ((rc = sqlite3_step(expected_stmt)) == SQLITE_ROW) {
+ auto read_expected = [expected_stmt](int column) {
+ ExpectedValue value;
+ const int type = sqlite3_column_type(expected_stmt, column);
+ if (type == SQLITE_INTEGER || type == SQLITE_FLOAT) {
+ value.number = sqlite3_column_double(expected_stmt, column);
+ } else {
+ value.text = std::string(
+ reinterpret_cast<const char*>(sqlite3_column_text(expected_stmt,
column)),
+ sqlite3_column_bytes(expected_stmt, column));
+ }
+ return value;
+ };
+ expected_upcast.emplace_back(read_expected(0));
+ expected_append.emplace_back(read_expected(1));
+ }
+ EXPECT_EQ(SQLITE_DONE, rc);
+ sqlite3_finalize(expected_stmt);
+
+ adbc_validation::StreamReader reader;
+ ASSERT_NO_FATAL_FAILURE(Exec("SELECT * FROM foo", kInferRows, &reader));
+ ASSERT_EQ(NANOARROW_TYPE_STRING, reader.fields[0].type);
+ ASSERT_EQ(NANOARROW_TYPE_STRING, reader.fields[1].type);
+ ASSERT_NO_FATAL_FAILURE(reader.Next());
+ auto expect_round_trip = [](ArrowArrayView* actual,
+ const std::vector<ExpectedValue>& expected) {
+ ASSERT_EQ(actual->length, static_cast<int64_t>(expected.size()));
+ for (int64_t i = 0; i < actual->length; i++) {
+ const ArrowStringView actual_view =
ArrowArrayViewGetStringUnsafe(actual, i);
+ const std::string actual_value(actual_view.data, actual_view.size_bytes);
+
+ if (expected[i].number.has_value()) {
+ char* actual_end = nullptr;
+ const double actual_number = std::strtod(actual_value.c_str(),
&actual_end);
Review Comment:
Changed the test to compare Arrow’s output with SQLite’s sqlite3_column_text
result directly, rather than parsing both values as doubles. The focused
precision and decimal-comma tests pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]