diff --git a/.gitignore b/.gitignore index 9c74a3c..ae22b90 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ compile_commands.json .clangd .cache /bu +build diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..78eaca1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1655371181379 + + + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 68859cf..f9540bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/clickhouse-cpp/clickhouse/CMakeLists.txt b/src/clickhouse-cpp/clickhouse/CMakeLists.txt index 6577ca6..bc5971c 100644 --- a/src/clickhouse-cpp/clickhouse/CMakeLists.txt +++ b/src/clickhouse-cpp/clickhouse/CMakeLists.txt @@ -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 \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) diff --git a/src/clickhouse_fdw.control b/src/clickhouse_fdw.control index 8ee02d5..8deb1a3 100644 --- a/src/clickhouse_fdw.control +++ b/src/clickhouse_fdw.control @@ -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 diff --git a/src/pglink.c b/src/pglink.c index f8059c0..d4d0619 100644 --- a/src/pglink.c +++ b/src/pglink.c @@ -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 * @@ -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) @@ -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);