lidavidm commented on code in PR #4878:
URL: https://github.com/apache/arrow-adbc/pull/4878#discussion_r4337068854
##########
c/driver/sqlite/sqlite_test.cc:
##########
@@ -1013,9 +1016,98 @@ 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(
- CompareArray<std::string>(reader.array_view->children[0],
- {"1.000000e+00", "1.000000e+00", "", "inf",
"-inf"}));
+ Exec("INSERT INTO foo VALUES "
+ "(123456789.123, 'start'), "
+ "(3.141592653589793, 123456789.123), "
+ "(0.1, 3.141592653589793), "
+ "('end', 0.1)"));
+
+ const std::vector<std::optional<double>> expected_upcast = {
+ 123456789.123, 3.141592653589793, 0.1, std::nullopt};
+ const std::vector<std::optional<double>> expected_append = {std::nullopt,
123456789.123,
+
3.141592653589793, 0.1};
+ const std::vector<std::string> expected_text_upcast = {"", "", "", "end"};
+ const std::vector<std::string> expected_text_append = {"start", "", "", ""};
+
+ 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<std::optional<double>>&
expected_values,
+ const std::vector<std::string>& expected_text) {
+ ASSERT_EQ(actual->length, static_cast<int64_t>(expected_values.size()));
+ ASSERT_EQ(expected_values.size(), expected_text.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_values[i].has_value()) {
+ double parsed = 0.0;
+ const char* begin = actual_value.data();
+ const char* end = begin + actual_value.size();
+ const auto result =
+ std::from_chars(begin, end, parsed, std::chars_format::general);
+ ASSERT_EQ(result.ec, std::errc{});
+ ASSERT_EQ(result.ptr, end);
+ EXPECT_EQ(parsed, expected_values[i].value());
+ } else {
+ EXPECT_EQ(actual_value, expected_text[i]);
+ }
+ }
Review Comment:
Another point: the PR description doesn't need to reflect this comment.
"Rather than parsing the output into doubles" is useless information once the
change has been made.
--
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]