Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clickhouse cpp to 2.5.1 #109

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^LICENSE$
^tests/testthat/test-dbplyr-ch.R$
.ipynb_checkpoints
^src/vendor/clickhouse-cpp/build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/vendor/clickhouse-cpp"]
path = src/vendor/clickhouse-cpp
url = [email protected]:ClickHouse/clickhouse-cpp.git
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ Authors@R: c(
Description: 'Yandex Clickhouse' (<https://clickhouse.com/>) is a high-performance relational column-store database to enable
big data exploration and 'analytics' scaling to petabytes of data. Methods are
provided that enable working with 'Yandex Clickhouse' databases via
'DBI' methods and using 'dplyr'/'dbplyr' idioms.
'DBI' methods and using 'dplyr'/'dbplyr' idioms.
NOTE(mmitkevich): https://github.com/ClickHouse/clickhouse-cpp/commit/87fc1186063b82b8ddf37b1c70c485bdd7504f8d
https://github.com/mmitkevich/RClickhouse
License: GPL-2
SystemRequirements: C++17
Imports:
dplyr (>= 1.1.0),
dbplyr (>= 2.0.0),
Expand All @@ -33,7 +36,7 @@ Imports:
Rcpp (>= 0.11.0),
bit64,
cli
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
NeedsCompilation: yes
Depends:
R (>= 3.6.2)
Expand Down
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Makefile for generating R packages.
# 2011 Andrew Redd
#
# Assumes Makefile is in a folder where package contents are in a subfolder pkg.
# Roxygen uses the roxygen2 package, and will run automatically on check and all.

PKG_VERSION=$(shell grep -i ^version DESCRIPTION | cut -d : -d \ -f 2)
PKG_NAME=$(shell grep -i ^package DESCRIPTION | cut -d : -d \ -f 2)

R_FILES := $(wildcard R/*.R)
SRC_FILES := $(wildcard R/*.R)
PKG_FILES := DESCRIPTION NAMESPACE $(R_FILES) $(SRC_FILES)

.PHONY: tarball install check clean roxygen

tarball: $(PKG_NAME)_$(PKG_VERSION).tar.gz
$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES)
R CMD build .

all: clean check install

check: $(PKG_NAME)_$(PKG_VERSION).tar.gz roxygen
R CMD check $(PKG_NAME)_$(PKG_VERSION).tar.gz

install: $(PKG_NAME)_$(PKG_VERSION).tar.gz
R CMD INSTALL $(PKG_NAME)_$(PKG_VERSION).tar.gz

roxygen:
Rscript -e "library(roxygen2);roxygenize('.')"

clean:
-rm -f $(PKG_NAME)_*.tar.gz
-rm -r -f $(PKG_NAME).Rcheck
34 changes: 34 additions & 0 deletions man/RClickhouse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Makevars.common
include Makevars.common
55 changes: 31 additions & 24 deletions src/Makevars.common
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
PKG_CPPFLAGS = $(SYS_FLAGS) -I. -I../inst/include -I./vendor/clickhouse-cpp -I./vendor/clickhouse-cpp/contrib -I./vendor/clickhouse-cpp/contrib/bigerint

CXX_STD = CXX11
CXX_STD = CXX17
PKG_CPPFLAGS = $(SYS_FLAGS) -I. -I../inst/include -I./vendor/clickhouse-cpp -I./vendor/clickhouse-cpp/contrib -I./vendor/clickhouse-cpp/contrib/absl -I./vendor/clickhouse-cpp/contrib/cityhash/cityhash -I./vendor/clickhouse-cpp/contrib/lz4/lz4 -DWITH_OPENSSL=1
# -I./vendor/clickhouse-cpp/contrib/bigerint

OBJ_FILES = \
vendor/clickhouse-cpp/clickhouse/columns/string.o \
vendor/clickhouse-cpp/clickhouse/columns/date.o \
vendor/clickhouse-cpp/clickhouse/columns/numeric.o \
vendor/clickhouse-cpp/clickhouse/columns/decimal.o \
vendor/clickhouse-cpp/clickhouse/columns/tuple.o \
vendor/clickhouse-cpp/clickhouse/columns/array.o \
vendor/clickhouse-cpp/clickhouse/columns/factory.o \
vendor/clickhouse-cpp/clickhouse/columns/nullable.o \
vendor/clickhouse-cpp/clickhouse/columns/enum.o \
vendor/clickhouse-cpp/clickhouse/columns/uuid.o \
vendor/clickhouse-cpp/clickhouse/columns/ip4.o \
vendor/clickhouse-cpp/clickhouse/columns/ip6.o \
vendor/clickhouse-cpp/clickhouse/query.o \
vendor/clickhouse-cpp/clickhouse/base/platform.o \
vendor/clickhouse-cpp/clickhouse/base/socket.o \
vendor/clickhouse-cpp/clickhouse/base/platform.o \
vendor/clickhouse-cpp/clickhouse/base/sslsocket.o \
vendor/clickhouse-cpp/clickhouse/base/input.o \
vendor/clickhouse-cpp/clickhouse/base/output.o \
vendor/clickhouse-cpp/clickhouse/base/coded.o \
vendor/clickhouse-cpp/clickhouse/base/compressed.o \
vendor/clickhouse-cpp/clickhouse/client.o \
vendor/clickhouse-cpp/clickhouse/base/wire_format.o \
vendor/clickhouse-cpp/clickhouse/base/endpoints_iterator.o \
vendor/clickhouse-cpp/clickhouse/block.o \
vendor/clickhouse-cpp/clickhouse/query.o \
vendor/clickhouse-cpp/clickhouse/types/types.o \
vendor/clickhouse-cpp/clickhouse/types/type_parser.o \
vendor/clickhouse-cpp/clickhouse/block.o \
vendor/clickhouse-cpp/contrib/cityhash/city.o \
vendor/clickhouse-cpp/contrib/lz4/lz4.o \
vendor/clickhouse-cpp/contrib/lz4/lz4hc.o
vendor/clickhouse-cpp/clickhouse/client.o \
vendor/clickhouse-cpp/clickhouse/columns/ip6.o \
vendor/clickhouse-cpp/clickhouse/columns/ip4.o \
vendor/clickhouse-cpp/clickhouse/columns/lowcardinality.o \
vendor/clickhouse-cpp/clickhouse/columns/numeric.o \
vendor/clickhouse-cpp/clickhouse/columns/decimal.o \
vendor/clickhouse-cpp/clickhouse/columns/array.o \
vendor/clickhouse-cpp/clickhouse/columns/factory.o \
vendor/clickhouse-cpp/clickhouse/columns/date.o \
vendor/clickhouse-cpp/clickhouse/columns/enum.o \
vendor/clickhouse-cpp/clickhouse/columns/tuple.o \
vendor/clickhouse-cpp/clickhouse/columns/itemview.o \
vendor/clickhouse-cpp/clickhouse/columns/string.o \
vendor/clickhouse-cpp/clickhouse/columns/nullable.o \
vendor/clickhouse-cpp/clickhouse/columns/uuid.o \
vendor/clickhouse-cpp/clickhouse/columns/column.o \
vendor/clickhouse-cpp/clickhouse/columns/geo.o \
vendor/clickhouse-cpp/clickhouse/columns/map.o \
vendor/clickhouse-cpp/contrib/lz4/lz4/lz4hc.o \
vendor/clickhouse-cpp/contrib/lz4/lz4/lz4.o \
vendor/clickhouse-cpp/contrib/cityhash/cityhash/city.o

PKG_LIBS = $(OBJ_FILES) -lpthread $(SYS_LIBS)
PKG_LIBS = $(OBJ_FILES) -lpthread -lssl $(SYS_LIBS)

$(SHLIB): $(OBJ_FILES)
52 changes: 49 additions & 3 deletions src/result.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdexcept>
#include <type_traits>
#include "clickhouse/columns/string.h"
#include "result.h"



// helper function which emits an R warning without causing a longjmp
// see https://stackoverflow.com/questions/24557711/how-to-generate-an-r-warning-safely-in-rcpp
void warn(std::string text) {
Expand Down Expand Up @@ -62,6 +63,37 @@ void convertEntries(std::shared_ptr<const CT> in, NullCol nullCol, RT &out,
}


// workaround lack of Rcpp::StringVector x; x[i] = std::string_view();
template<>
void convertEntries<ch::ColumnString, Rcpp::StringVector>(std::shared_ptr<const ch::ColumnString> in, NullCol nullCol, Rcpp::StringVector &out,
size_t offset, size_t start, size_t end)
{
for(size_t j = start; j < end; j++) {
// can't use the ternary operator here, since that would require explicit
// conversion from the Clickhouse storage type (which is far messier)
if(nullCol && nullCol->IsNull(j)) {
out[offset+j-start] = Rcpp::StringVector::get_na();
} else {
out[offset+j-start] = std::string(in->At(j));
}
}
}

template<>
void convertEntries<ch::ColumnFixedString, Rcpp::StringVector>(std::shared_ptr<const ch::ColumnFixedString> in, NullCol nullCol, Rcpp::StringVector &out,
size_t offset, size_t start, size_t end)
{
for(size_t j = start; j < end; j++) {
// can't use the ternary operator here, since that would require explicit
// conversion from the Clickhouse storage type (which is far messier)
if(nullCol && nullCol->IsNull(j)) {
out[offset+j-start] = Rcpp::StringVector::get_na();
} else {
out[offset+j-start] = std::string(in->At(j));
}
}
}

template<>
void convertEntries<ch::ColumnInt64, Rcpp::StringVector>(std::shared_ptr<const ch::ColumnInt64> in, NullCol nullCol, Rcpp::StringVector &out,
size_t offset, size_t start, size_t end) {
Expand Down Expand Up @@ -104,7 +136,18 @@ void convertEntries<ch::ColumnDate, Rcpp::DateVector>(std::shared_ptr<const ch::
}
}
}

template<>
void convertEntries<ch::ColumnDateTime64, Rcpp::DatetimeVector>(std::shared_ptr<const ch::ColumnDateTime64> in,
NullCol nullCol, Rcpp::DatetimeVector &out, size_t offset, size_t start, size_t end) {
double factor = std::pow(10.,in->GetPrecision());
for(size_t j = start; j < end; j++) {
if(nullCol && nullCol->IsNull(j)) {
out[offset+j-start] = Rcpp::DateVector::get_na();
} else {
out[offset+j-start] = static_cast<double>(in->At(j)/factor);
}
}
}
std::string formatUUID(const ch::UInt128 &v) {
const size_t bufsize = 128/4 + 4 + 1; // 128 bit in hexadecimal + 4 dashes + null terminator
char buf[bufsize];
Expand Down Expand Up @@ -292,6 +335,9 @@ std::unique_ptr<Converter> Result::buildConverter(std::string name, ch::TypeRef
return std::unique_ptr<ScalarConverter<ch::ColumnDateTime, Rcpp::DatetimeVector>>(new ScalarConverter<ch::ColumnDateTime, Rcpp::DatetimeVector>);
case TC::Date:
return std::unique_ptr<ScalarConverter<ch::ColumnDate, Rcpp::DateVector>>(new ScalarConverter<ch::ColumnDate, Rcpp::DateVector>);
case TC::DateTime64:
return std::unique_ptr<ScalarConverter<ch::ColumnDateTime64, Rcpp::DatetimeVector>>(new ScalarConverter<ch::ColumnDateTime64, Rcpp::DatetimeVector>);

case TC::Nullable:
{
// downcast to NullableType to access GetNestedType member
Expand Down
1 change: 1 addition & 0 deletions src/vendor/clickhouse-cpp
Submodule clickhouse-cpp added at 68e592
2 changes: 0 additions & 2 deletions src/vendor/clickhouse-cpp/.buckconfig

This file was deleted.

11 changes: 0 additions & 11 deletions src/vendor/clickhouse-cpp/.clang-format

This file was deleted.

63 changes: 0 additions & 63 deletions src/vendor/clickhouse-cpp/.gitattributes

This file was deleted.

Loading