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

Add "json" support #88

Open
wants to merge 33 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ compile_commands.json
.clangd
.cache
/bu
build
96 changes: 96 additions & 0 deletions .idea/workspace.xml

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

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(clickhouse_fdw VERSION 1.4.0 LANGUAGES C)
project(clickhouse_fdw VERSION 1.4.1 LANGUAGES C)

set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
Expand Down
26 changes: 21 additions & 5 deletions src/clickhouse-cpp/clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,37 @@ SET ( clickhouse-cpp-lib-src

ADD_LIBRARY (clickhouse-cpp-lib SHARED ${clickhouse-cpp-lib-src})
SET_TARGET_PROPERTIES(clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib PRIVATE
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
cityhash-lib
lz4-lib
)

ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src})
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static PRIVATE
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
cityhash-lib
lz4-lib
)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt")
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib gcc_s)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static gcc_s)
INCLUDE (CheckCXXSourceCompiles)

CHECK_CXX_SOURCE_COMPILES("#include <bits/c++config.h>\nint main() { return __GLIBCXX__ != 0; }"
BUILDING_WITH_LIB_STDCXX)

IF (BUILDING_WITH_LIB_STDCXX)
# there is a problem with __builtin_mul_overflow call at link time
# the error looks like: ... undefined reference to `__muloti4' ...
# caused by clang bug https://bugs.llvm.org/show_bug.cgi?id=16404
# explicit linking to compiler-rt allows to workaround the problem
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt")

# some workaround for linking issues on linux:
# /usr/bin/ld: CMakeFiles/simple-test.dir/main.cpp.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
# /usr/bin/ld: /lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
# FIXME: that workaround breaks clang build on mingw
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib gcc_s)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static gcc_s)
ENDIF ()
ENDIF ()

if (CLICKHOUSE_CPP_ENABLE_INSTALL)
Expand Down
2 changes: 1 addition & 1 deletion src/clickhouse_fdw.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
comment = 'foreign-data wrapper for remote ClickHouse servers'
default_version = '1.4'
default_version = '1.4.1'
module_pathname = '$libdir/clickhouse_fdw'
relocatable = true
10 changes: 7 additions & 3 deletions src/pglink.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ parse_type(char *colname, char *typepart, bool *is_nullable, List **options)
i++;
}

ereport(ERROR, (errmsg("clickhouse_fdw: could not map type <%s>", typepart)));
ereport(ERROR, (errmsg("clickhouse_fdw: could not map type <|%s|>", typepart)));
}

List *
Expand All @@ -873,7 +873,11 @@ chfdw_construct_create_tables(ImportForeignSchemaStmt *stmt, ForeignServer *serv
"FROM system.tables WHERE database='%s' and name not like '.inner%%'", stmt->remote_schema);
cursor = conn.methods->simple_query(conn.conn, query);

datts = list_make2_int(1,2);
datts = list_make4_int(1, 2, 3, 4);
lcons_int(5, datts);
lcons_int(6, datts);
lcons_int(7, datts);
lcons_int(8, datts);

while ((row_values = (char **) conn.methods->fetch_row(cursor,
list_make3_int(1,2,3), NULL, NULL, NULL)) != NULL)
Expand Down Expand Up @@ -910,7 +914,7 @@ chfdw_construct_create_tables(ImportForeignSchemaStmt *stmt, ForeignServer *serv
initStringInfo(&buf);
appendStringInfo(&buf, "CREATE FOREIGN TABLE IF NOT EXISTS \"%s\".\"%s\" (\n",
stmt->local_schema, table_name);
query = psprintf("select name, type from system.columns where database='%s' and table='%s'",
query = psprintf("DESCRIBE %s.%s SETTINGS describe_extend_object_types=1, describe_include_subcolumns=1;",
stmt->remote_schema, table_name);
table_def = conn.methods->simple_query(conn.conn, query);

Expand Down