Skip to content

Commit

Permalink
working test / protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Jul 28, 2023
1 parent bbf2b0e commit 503a0ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 8 additions & 6 deletions c/driver/postgresql/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,14 @@ struct BindStream {
break;
}
case ArrowType::NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: {
const uint32_t days = ToNetworkInt32(
array_view->children[col]->buffer_views[1].data.as_int32[row]);
const uint32_t months = ToNetworkInt32(
array_view->children[col]->buffer_views[1].data.as_int32[row] + 1);
const int64_t raw_ns =
array_view->children[col]->buffer_views[1].data.as_int64[row] + 1;
const auto buf =
array_view->children[col]->buffer_views[1].data.as_uint8 + row * 16;
const int32_t raw_months = *(int32_t*)buf;
const int32_t raw_days = *(int32_t*)(buf + 4);
const int64_t raw_ns = *(int64_t*)(buf + 8);

const uint32_t months = ToNetworkInt32(raw_months);
const uint32_t days = ToNetworkInt32(raw_days);
const uint64_t ms = ToNetworkInt64(raw_ns / 1000);

std::memcpy(param_values[col], &ms, sizeof(uint64_t));
Expand Down
6 changes: 2 additions & 4 deletions c/validation/adbc_validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1266,10 +1266,8 @@ void StatementTest::TestSqlIngestInterval() {
ASSERT_EQ(1, reader.array->n_children);

if (round_trip_type == type) {
// XXX: for now we can't compare values; we would need casting
// need to extend CompareArray to support intervals
// ASSERT_NO_FATAL_FAILURE(
// CompareArray<CType>(reader.array_view->children[0], values));
ASSERT_NO_FATAL_FAILURE(
CompareArray<ArrowInterval*>(reader.array_view->children[0], values));
}

ASSERT_NO_FATAL_FAILURE(reader.Next());
Expand Down
7 changes: 7 additions & 0 deletions c/validation/adbc_validation_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ void CompareArray(struct ArrowArrayView* array,
struct ArrowStringView view = ArrowArrayViewGetStringUnsafe(array, i);
std::string str(view.data, view.size_bytes);
ASSERT_EQ(*v, str);
} else if constexpr (std::is_same<T, ArrowInterval*>::value) {
ASSERT_NE(array->buffer_views[1].data.data, nullptr);
const auto buf = array->buffer_views[1].data.as_uint8;
const auto record = buf + i * 16;
ASSERT_EQ(memcmp(record, &(*v)->months, 4), 0);
ASSERT_EQ(memcmp(record + 4, &(*v)->days, 4), 0);
ASSERT_EQ(memcmp(record + 8, &(*v)->ns, 8), 0);
} else {
static_assert(!sizeof(T), "Not yet implemented");
}
Expand Down

0 comments on commit 503a0ad

Please sign in to comment.