alitrack / duckdb_fdw

DuckDB Foreign Data Wrapper for PostgreSQL
MIT License
332 stars 21 forks source link

Fail to build with new version of duckdb 0.8.0 #16

Closed elysabethpc closed 7 months ago

elysabethpc commented 1 year ago

Hello,

The build process failed with the new version of duckdb 0.8.0.

All errors seem similar to this one:

sqlite3_api_wrapper.cpp:91:9: error: reference to ‘unique_ptr’ is ambiguous
   91 |         unique_ptr<char[]> data;
      |         ^~~~~~~~~~
In file included from /usr/include/c++/11/memory:76,
                 from duckdb.hpp:55,
                 from sqlite3_api_wrapper.cpp:3:
/usr/include/c++/11/bits/unique_ptr.h:242:11: note: candidates are: ‘template<class _Tp, class _Dp> class std::unique_ptr’
  242 |     class unique_ptr
      |           ^~~~~~~~~~
In file included from sqlite3_api_wrapper.cpp:3:
duckdb.hpp:851:7: note:                 ‘template<class _Tp, class _Dp, bool SAFE> class duckdb::unique_ptr’
  851 | class unique_ptr : public std::unique_ptr<_Tp, _Dp> {

I tried to solve but my knowledge of C++ is bad.

Thanks for this software.

alitrack commented 1 year ago

sqlite3_api_wrapper.cpp of DuckDB changed too much in 0.8, will update to support 0.8 when I have time.

alitrack commented 1 year ago

fixed in https://github.com/alitrack/duckdb_fdw/pull/18

pashkatrick commented 1 year ago

hello @alitrack i have same errors in fresh release

sqlite3_api_wrapper.cpp:92:10: error: ‘unsafe_unique_array’ in namespace ‘duckdb’ does not name a template type
#31 23.87    92 |  duckdb::unsafe_unique_array<char> data;
#31 23.87       |          ^~~~~~~~~~~~~~~~~~~
#31 23.97 sqlite3_api_wrapper.cpp: In function ‘int sqlite3_open_v2(const char*, sqlite3**, int, const char*)’:
#31 23.97 sqlite3_api_wrapper.cpp:167:13: error: ‘make_uniq’ was not declared in this scope
#31 23.97   167 |   pDb->db = make_uniq<DuckDB>(filename, &config);
#31 23.97       |             ^~~~~~~~~
#31 23.97 sqlite3_api_wrapper.cpp:167:29: error: expected primary-expression before ‘>’ token
#31 23.97   167 |   pDb->db = make_uniq<DuckDB>(filename, &config);
#31 23.97       |                             ^
#31 23.97 sqlite3_api_wrapper.cpp:167:31: warning: left operand of comma operator has no effect [-Wunused-value]
#31 23.97   167 |   pDb->db = make_uniq<DuckDB>(filename, &config);
#31 23.97       |                               ^~~~~~~~
#31 23.97 sqlite3_api_wrapper.cpp:169:34: error: expected primary-expression before ‘>’ token
#31 23.97   169 |   pDb->con = make_uniq<Connection>(*pDb->db);
#31 23.97       |                                  ^
#31 24.13 sqlite3_api_wrapper.cpp: In function ‘int sqlite3_prepare_v2(sqlite3*, const char*, int, sqlite3_stmt**, const char**)’:
#31 24.13 sqlite3_api_wrapper.cpp:257:43: error: ‘make_uniq’ was not declared in this scope
#31 24.13   257 |   duckdb::unique_ptr<sqlite3_stmt> stmt = make_uniq<sqlite3_stmt>();
#31 24.13       |                                           ^~~~~~~~~
#31 24.13 sqlite3_api_wrapper.cpp:257:65: error: expected primary-expression before ‘>’ token
#31 24.13   257 |   duckdb::unique_ptr<sqlite3_stmt> stmt = make_uniq<sqlite3_stmt>();
#31 24.13       |                                                                 ^
#31 24.13 sqlite3_api_wrapper.cpp:257:67: error: expected primary-expression before ‘)’ token
#31 24.13   257 |   duckdb::unique_ptr<sqlite3_stmt> stmt = make_uniq<sqlite3_stmt>();
#31 24.13       |                                                                   ^
#31 24.17 sqlite3_api_wrapper.cpp: In function ‘const unsigned char* sqlite3_column_text(sqlite3_stmt*, int)’:
#31 24.17 sqlite3_api_wrapper.cpp:612:14: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.17   612 |   if (!entry.data) {
#31 24.17       |              ^~~~
#31 24.17 sqlite3_api_wrapper.cpp:615:10: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.17   615 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.17       |          ^~~~
#31 24.18 sqlite3_api_wrapper.cpp:615:25: error: ‘make_unsafe_uniq_array’ is not a member of ‘duckdb’
#31 24.18   615 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.18       |                         ^~~~~~~~~~~~~~~~~~~~~~
#31 24.18 sqlite3_api_wrapper.cpp:615:48: error: expected primary-expression before ‘char’
#31 24.18   615 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.18       |                                                ^~~~
#31 24.18 sqlite3_api_wrapper.cpp:616:17: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.18   616 |    memcpy(entry.data.get(), str_val.c_str(), str_val.size() + 1);
#31 24.18       |                 ^~~~
#31 24.18 sqlite3_api_wrapper.cpp:619:39: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.18   619 |   return (const unsigned char *)entry.data.get();
#31 24.18       |                                       ^~~~
#31 24.18 sqlite3_api_wrapper.cpp: In function ‘const void* sqlite3_column_blob(sqlite3_stmt*, int)’:
#31 24.18 sqlite3_api_wrapper.cpp:637:14: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.18   637 |   if (!entry.data) {
#31 24.18       |              ^~~~
#31 24.18 sqlite3_api_wrapper.cpp:640:10: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.18   640 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.18       |          ^~~~
#31 24.19 sqlite3_api_wrapper.cpp:640:25: error: ‘make_unsafe_uniq_array’ is not a member of ‘duckdb’
#31 24.19   640 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.19       |                         ^~~~~~~~~~~~~~~~~~~~~~
#31 24.19 sqlite3_api_wrapper.cpp:640:48: error: expected primary-expression before ‘char’
#31 24.19   640 |    entry.data = duckdb::make_unsafe_uniq_array<char>(str_val.size() + 1);
#31 24.19       |                                                ^~~~
#31 24.19 sqlite3_api_wrapper.cpp:641:17: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.19   641 |    memcpy(entry.data.get(), str_val.c_str(), str_val.size() + 1);
#31 24.19       |                 ^~~~
#31 24.19 sqlite3_api_wrapper.cpp:644:39: error: ‘struct sqlite3_string_buffer’ has no member named ‘data’
#31 24.19   644 |   return (const unsigned char *)entry.data.get();
elysabethpc commented 12 months ago

Thank you.

It works for version 0.8.1 but failed to load for the new version v0.9.0 of duckdb.

I get this error:

❯ psql -U dev -d logs
psql (15.4 (Ubuntu 15.4-2.pgdg22.04+1))
Type "help" for help.

logs=> select ....;
ERROR:  could not load library "/usr/lib/postgresql/15/lib/duckdb_fdw.so": /usr/lib/postgresql/15/lib/duckdb_fdw.so: undefined symbol: _ZN6duckdb13KeywordHelper9IsKeywordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
elysabethpc commented 12 months ago

Hello,

I tried harder and it seems that the issue has been resolved in version v0.9.0, as I am no longer encountering the "undefined symbol" error, which I suspect was related to using an outdated import of schema present in the database done with older version of duckdb_fdw.

However, a new issue has arisen with this version. I am unable to import foreign schema, as I receive an error stating that the relation already exists, even though it doesn't:

-- as postgres user
create server duckdb_srv foreign data wrapper duckdb_fdw options (database '/tmp/bd.duckdb', read_only 'true');
grant usage on foreign server duckdb_srv to dev;

-- as dev user
drop schema if exists duckdb cascade;
create schema duckdb;
import foreign schema public limit to (org) from server duckdb_srv into duckdb;

ERROR:  relation "org" already exists
CONTEXT:  importing foreign table "org"

db=> \dE duckdb.*
Did not find any relation named "duckdb.*".

However, when I manually create a foreign table, it works as expected:

drop schema if exists duckdb cascade;
create schema duckdb;
create foreign table duckdb.org(id_org integer, name text) server duckdb_srv options(table 'org');
select * from duckdb.org; --OK

db=> \dE duckdb.*
             List of relations
 Schema |   Name    |     Type      | Owner
--------+-----------+---------------+-------
 duckdb | org       | foreign table | dev
(1 row)

Has anyone else experienced this error? Or is there a change in the way we are supposed to use import foreign schema in this version?

Thank you.

VincentAntoine commented 10 months ago

Results of my duckdb_fdw installation tests in dockerized image starting from Postgres 15 :

DuckDB version duckdb_fdw install and usage experience
<= 0.7.1 duckdb_fdw install fails (same as @pashkatrick)
0.8.0, 0.8.1 duckdb_fdw install is successful and I could query parquet files using DuckDB through Postgres as a foreign table
>= 0.9.0 duckdb_fdw install is successful, but failure upon CREATE EXTENSION duckdb_fdw with ERROR: could not load library "/usr/lib/postgresql/15/lib/duckdb_fdw.so": /usr/lib/postgresql/15/lib/duckdb_fdw.so: undefined symbol: _ZN6duckdb13KeywordHelper9IsKeywordERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE same as @elysabethpc

Dockerfile used (change duckdb version in wget command to test various versions)

FROM postgres:15

RUN apt-get update && apt-get install -y \
    build-essential \
    wget \ 
    unzip \
    postgresql-server-dev-15 \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y git;

RUN git clone https://github.com/alitrack/duckdb_fdw
WORKDIR /duckdb_fdw
RUN wget -c https://github.com/duckdb/duckdb/releases/download/v0.7.1/libduckdb-linux-amd64.zip \
    && unzip -d . libduckdb-linux-amd64.zip \
    && cp libduckdb.so $(pg_config --libdir) \
    && rm libduckdb-linux-amd64.zip

RUN make USE_PGXS=1
RUN make install USE_PGXS=1
elysabethpc commented 10 months ago

@VincentAntoine

the error with the undefined symbol can be fix building duckdb from source. The binary version of the libduckdb.so is wrong in some way.

I can fixed with

git clone https://github.com/duckdb/duckdb.git
git clone https://github.com/alitrack/duckdb_fdw
cd duckdb
git checkout tags/v0.9.2
make
cd ../duckdb_fdw
cp ../duckdb/src/libduckdb* .
cp ../duckdb_fdw/duckdb.h* .
export PATH=$PATH:/usr/pgsql-15/bin #fedora pgdg
cp libduckdb.so $(pg_config --libdir) 
make clean USE_PGXS=1
make USE_PGXS=1
make install USE_PGXS=1
alitrack commented 7 months ago

already fixed