lidavidm commented on code in PR #4878:
URL: https://github.com/apache/arrow-adbc/pull/4878#discussion_r4266745458


##########
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:
   Why do we need to do this vs being able to put the expected values directly?



-- 
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]

Reply via email to