Skip to content

Commit

Permalink
refactor(c/driver/postgresql): Split postgres_copy_reader.h into read…
Browse files Browse the repository at this point in the history
…er/writer headers (#1432)

Co-authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
  • Loading branch information
WillAyd and paleolimbot authored Jan 10, 2024
1 parent 5a73aa3 commit 6b73e52
Show file tree
Hide file tree
Showing 13 changed files with 2,229 additions and 2,051 deletions.
23 changes: 22 additions & 1 deletion c/driver/postgresql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ if(ADBC_BUILD_TESTS)
driver-postgresql
SOURCES
postgres_type_test.cc
postgres_copy_reader_test.cc
postgresql_test.cc
EXTRA_LINK_LIBS
adbc_driver_common
Expand All @@ -91,6 +90,28 @@ if(ADBC_BUILD_TESTS)
${REPOSITORY_ROOT}/c/vendor
${REPOSITORY_ROOT}/c/driver)
adbc_configure_target(adbc-driver-postgresql-test)

add_test_case(driver_postgresql_copy_test
PREFIX
adbc
EXTRA_LABELS
driver-postgresql
SOURCES
copy/postgres_copy_reader_test.cc
copy/postgres_copy_writer_test.cc
EXTRA_LINK_LIBS
adbc_driver_common
adbc_validation
nanoarrow
${TEST_LINK_LIBS})
target_compile_features(adbc-driver-postgresql-copy-test PRIVATE cxx_std_17)
target_include_directories(adbc-driver-postgresql-copy-test SYSTEM
PRIVATE ${REPOSITORY_ROOT}
${REPOSITORY_ROOT}/c/
${LIBPQ_INCLUDE_DIRS}
${REPOSITORY_ROOT}/c/vendor
${REPOSITORY_ROOT}/c/driver)
adbc_configure_target(adbc-driver-postgresql-copy-test)
endif()

if(ADBC_BUILD_BENCHMARKS)
Expand Down
45 changes: 45 additions & 0 deletions c/driver/postgresql/copy/copy_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

// Windows
#define NOMINMAX

#include <cstdint>

// R 3.6 / Windows builds on a very old toolchain that does not define ENODATA
#if defined(_WIN32) && !defined(MSVC) && !defined(ENODATA)
#define ENODATA 120
#endif

namespace adbcpq {

// "PGCOPY\n\377\r\n\0"
static int8_t kPgCopyBinarySignature[] = {0x50, 0x47, 0x43, 0x4F,
0x50, 0x59, 0x0A, static_cast<int8_t>(0xFF),
0x0D, 0x0A, 0x00};

// The maximum value in microseconds that can be converted into nanoseconds
// without overflow
constexpr int64_t kMaxSafeMicrosToNanos = 9223372036854775L;

// The minimum value in microseconds that can be converted into nanoseconds
// without overflow
constexpr int64_t kMinSafeMicrosToNanos = -9223372036854775L;

} // namespace adbcpq
Loading

0 comments on commit 6b73e52

Please sign in to comment.