Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions src/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -561,6 +563,21 @@ extern "C"
}
break;
}
case BOOLOID:
{
switch (col->Type()->GetCode())
{
case Type::Code::UInt8:
col->AsStrict<ColumnUInt8>()->Append((uint8_t)val);
break;
case Type::Code::Bool:
col->AsStrict<ColumnBool>()->Append((bool)val);
break;
default:
THROW_UNEXPECTED_COLUMN("BOOL", col);
}
break;
}
case INT4OID:
{
switch (col->Type()->GetCode())
Expand Down Expand Up @@ -967,6 +984,13 @@ extern "C"
*valtype = INT2OID;
}
break;
case Type::Code::Bool:
{
bool val = col->AsStrict<ColumnBool>()->At(row);
ret = (Datum)val;
*valtype = BOOLOID;
}
break;
case Type::Code::UInt16:
{
int16 val = col->AsStrict<ColumnUInt16>()->At(row);
Expand Down
14 changes: 0 additions & 14 deletions src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down
Loading