diff --git a/CHANGELOG.md b/CHANGELOG.md index 7add1799..355b0a0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ All notable changes to this project will be documented in this file. It uses the `re2extractallgroupshorizontal`, `re2extractallgroupsvertical`, `re2regexpquotemeta`, and `re2splitbyregexp`. Thanks to Philip Dubé for the PR ([#232]). +* Updated binary driver to properly support handling `Bool`s as boolean + values rather than `int16` values, avoiding the need for casting. [v0.3.1]: https://github.com/ClickHouse/pg_clickhouse/compare/v0.3.0...v0.3.1 [#232]: https://github.com/ClickHouse/pg_clickhouse/pull/232 diff --git a/Makefile b/Makefile index 2d348c8d..37572fe4 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ CH_CPP_BUILD_DIR = vendor/_build/$(OS)-$(ARCH)-$(CH_BUILD)-$(shell git submodule # List the clickhouse-cpp libraries we require. CH_CPP_LIB = $(CH_CPP_BUILD_DIR)/clickhouse/libclickhouse-cpp-lib$(DLSUFFIX) -CH_CPP_FLAGS = -D CMAKE_BUILD_TYPE=Release -D WITH_OPENSSL=ON +CH_CPP_FLAGS = -D CMAKE_BUILD_TYPE=Release -D WITH_OPENSSL=ON -DCH_MAP_BOOL_TO_UINT8=OFF # Are we statically compiling clickhouse-cpp into the extension or no? ifeq ($(CH_BUILD), static) diff --git a/src/binary.cpp b/src/binary.cpp index 61567c00..9f962193 100644 --- a/src/binary.cpp +++ b/src/binary.cpp @@ -300,6 +300,8 @@ extern "C" case Type::Code::Int16: case Type::Code::UInt8: return INT2OID; + case Type::Code::Bool: + return BOOLOID; case Type::Code::Int32: case Type::Code::UInt16: return INT4OID; @@ -561,6 +563,21 @@ extern "C" } break; } + case BOOLOID: + { + switch (col->Type()->GetCode()) + { + case Type::Code::UInt8: + col->AsStrict()->Append((uint8_t)val); + break; + case Type::Code::Bool: + col->AsStrict()->Append((bool)val); + break; + default: + THROW_UNEXPECTED_COLUMN("BOOL", col); + } + break; + } case INT4OID: { switch (col->Type()->GetCode()) @@ -967,6 +984,13 @@ extern "C" *valtype = INT2OID; } break; + case Type::Code::Bool: + { + bool val = col->AsStrict()->At(row); + ret = (Datum)val; + *valtype = BOOLOID; + } + break; case Type::Code::UInt16: { int16 val = col->AsStrict()->At(row); diff --git a/src/convert.c b/src/convert.c index c056447b..8091fc58 100644 --- a/src/convert.c +++ b/src/convert.c @@ -319,12 +319,6 @@ convert_bool(ch_convert_state * state, Datum val) return BoolGetDatum(dat); } -inline static Datum -convert_bool_to_int16(ch_convert_output_state * state, Datum val) -{ - return Int16GetDatum(DatumGetBool(val) ? 1 : 0); -} - Datum ch_binary_convert_datum(void *state, Datum val) { @@ -521,14 +515,6 @@ init_output_convert_state(ch_convert_output_state * state) ) return; - /* Postgres has no cast from bool to INT16, so provide our own. */ - if (state->outtype == INT2OID && state->intype == BOOLOID) - { - state->func = convert_bool_to_int16; - state->ctype = COERCION_PATH_FUNC; - return; - } - state->func = convert_out_generic; state->ctype = find_coercion_pathway(state->outtype, state->intype, diff --git a/vendor/clickhouse-cpp b/vendor/clickhouse-cpp index f067937e..7ae2335b 160000 --- a/vendor/clickhouse-cpp +++ b/vendor/clickhouse-cpp @@ -1 +1 @@ -Subproject commit f067937e47ff75767709b7471821c6cefbea7666 +Subproject commit 7ae2335b1a9d9ebfe38be0098bbc659d7068cac3