Skip to content
Draft
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: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "clickhouse-cpp"]
path = vendor/clickhouse-cpp
url = https://github.com/ClickHouse/clickhouse-cpp.git
url = https://github.com/theory/clickhouse-cpp.git
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ CH_CPP_FLAGS = -D CMAKE_BUILD_TYPE=Release -D WITH_OPENSSL=ON

# Build static on Darwin by default.
ifndef ($(CH_BUILD))
# ifeq ($(OS),Darwin)
ifeq ($(OS),Darwin)
CH_BUILD = static
# endif
endif
endif

# Are we statically compiling clickhouse-cpp into the extension or no?
Expand Down
45 changes: 2 additions & 43 deletions src/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,50 +778,9 @@ static Datum make_datum(clickhouse::ColumnRef col, size_t row, Oid * valtype, bo
case Type::Code::Decimal32:
case Type::Code::Decimal:
{
auto decCol = col->As<ColumnDecimal>();
auto val = decCol->At(row);

/* Convert the Int128 to a string. */
std::stringstream ss;
ss << val;
std::string str = ss.str();

/* Start a destination string. */
std::stringstream res;
auto scale = decCol->GetScale();

/* Output a dash for negative values */
if (val < 0)
{
res << '-';
str.erase(0, 1);
}

if (scale == 0)
{
/* No decimal point, just output the entire value. */
res << str;
}
else if (str.length() <= scale)
{
/* Append the entire value prepended with zeros after the decimal. */
res << "0." << std::string(scale-str.length(), '0') << str;
}
else
{
/* There are digits before the decimal. */
auto decAt = str.length() - scale;
res << str.substr(0, decAt);

/* Append any digits after the decimal. */
if (decAt < str.length())
{
res << '.' << str.substr(decAt);
}
}

auto val = col->As<ColumnDecimal>()->GetString(row);
ret = DirectFunctionCall3(numeric_in,
CStringGetDatum(res.str().c_str()),
CStringGetDatum(val.c_str()),
ObjectIdGetDatum(0),
Int32GetDatum(-1));
*valtype = NUMERICOID;
Expand Down
2 changes: 1 addition & 1 deletion vendor/clickhouse-cpp
Loading