diff --git a/docker-compose.yml b/docker-compose.yml index 481f6a1..8e226d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,11 @@ version: '2' services: clickhouse: - image: yandex/clickhouse-server + image: clickhouse/clickhouse-server:latest + network_mode: "host" ports: - - "8123:8123" - - "9000:9000" + - 8123:8123 + - 9000:9000 volumes: - ./docker/clickhouse-config.xml:/etc/clickhouse-server/config.xml - - ./docker/clickhouse-users.xml:/etc/clickhouse-server/users.xml + - ./docker/clickhouse-users.xml:/etc/clickhouse-server/users.xml \ No newline at end of file diff --git a/src/http.c b/src/http.c index f930650..118f568 100644 --- a/src/http.c +++ b/src/http.c @@ -100,6 +100,9 @@ ch_http_connection_t *ch_http_connection(char *host, int port, char *username, c conn->base_url = connstring; conn->base_url_len = strlen(conn->base_url); + + if (database == NULL) + database = "default"; // Set default value conn->database = malloc(strlen(database)); strcpy(conn->database, database); diff --git a/tests/expected/binary_queries_1.out b/tests/expected/binary_queries_1.out index 89581f3..bcb36ef 100644 --- a/tests/expected/binary_queries_1.out +++ b/tests/expected/binary_queries_1.out @@ -143,10 +143,10 @@ SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work ALTER SERVER loopback OPTIONS (SET dbname 'no such database'); SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should fail -ERROR: clickhouse_fdw: DB::Exception: Database `no such database` doesn't exist +ERROR: clickhouse_fdw: DB::Exception: Database `no such database` does not exist ALTER USER MAPPING FOR CURRENT_USER SERVER loopback OPTIONS (ADD user 'no such user'); SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should fail -ERROR: clickhouse_fdw: connection error: DB::Exception: no such user: Authentication failed: password is incorrect or there is no user with such name +ERROR: clickhouse_fdw: connection error: DB::Exception: no such user: Authentication failed: password is incorrect, or there is no user with such name. ALTER SERVER loopback OPTIONS (SET dbname 'regression'); ALTER USER MAPPING FOR CURRENT_USER SERVER loopback OPTIONS (DROP user); SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again diff --git a/tests/expected/functions.out b/tests/expected/functions.out index 143b4b9..71cc28e 100644 --- a/tests/expected/functions.out +++ b/tests/expected/functions.out @@ -234,8 +234,8 @@ SELECT uniq_exact(a) FILTER(WHERE b>1) FROM t1; (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1; - QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ Foreign Scan Output: c Relations: Aggregate on (t1) @@ -243,8 +243,8 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('201 (4 rows) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1; - d1 ------------------------- + d1 +--------------------- 2019-01-01 10:00:00 2019-01-02 10:00:00 (2 rows) @@ -253,7 +253,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('dAy', c at time zone 'UTC') as d QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (date_trunc('dAy'::text, timezone('UTC'::text, c))) + Output: (date_trunc('dAy'::text, (c AT TIME ZONE 'UTC'::text))) Relations: Aggregate on (t1) Remote SQL: SELECT toStartOfDay(toTimeZone(c, 'UTC')) FROM regression.t1 GROUP BY (toStartOfDay(toTimeZone(c, 'UTC'))) ORDER BY toStartOfDay(toTimeZone(c, 'UTC')) ASC (4 rows) @@ -269,7 +269,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('day', c at time zone 'UTC') as d QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (date_trunc('day'::text, timezone('UTC'::text, c))) + Output: (date_trunc('day'::text, (c AT TIME ZONE 'UTC'::text))) Relations: Aggregate on (t2) Remote SQL: SELECT toStartOfDay(toTimeZone(c, 'UTC')) FROM regression.t1 GROUP BY (toStartOfDay(toTimeZone(c, 'UTC'))) ORDER BY toStartOfDay(toTimeZone(c, 'UTC')) ASC (4 rows) @@ -361,12 +361,12 @@ SELECT date_part('minuTe'::text, timezone('UTC'::text, c)) as d1 FROM t2 GROUP B (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('SeCond', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1; - QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (date_trunc('SeCond'::text, timezone('UTC'::text, c))) + Output: (date_trunc('SeCond'::text, (c AT TIME ZONE 'UTC'::text))) Relations: Aggregate on (t1) - Remote SQL: SELECT toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1)) FROM regression.t1 GROUP BY (toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1))) ORDER BY toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1)) ASC + Remote SQL: SELECT toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC')) FROM regression.t1 GROUP BY (toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC'))) ORDER BY toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC')) ASC (4 rows) SELECT date_trunc('SeCond', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1; diff --git a/tests/expected/functions_1.out b/tests/expected/functions_1.out index b895eac..71cc28e 100644 --- a/tests/expected/functions_1.out +++ b/tests/expected/functions_1.out @@ -233,6 +233,22 @@ SELECT uniq_exact(a) FILTER(WHERE b>1) FROM t1; 1 (1 row) +EXPLAIN (VERBOSE, COSTS OFF) SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------ + Foreign Scan + Output: c + Relations: Aggregate on (t1) + Remote SQL: SELECT c FROM regression.t1 WHERE ((c >= parseDateTimeBestEffortOrNull('2019-01-01 00:00:00.000000'))) GROUP BY c ORDER BY c ASC +(4 rows) + +SELECT c as d1 FROM t1 WHERE c >= to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') GROUP BY d1 ORDER BY d1; + d1 +--------------------- + 2019-01-01 10:00:00 + 2019-01-02 10:00:00 +(2 rows) + EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('dAy', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -345,12 +361,12 @@ SELECT date_part('minuTe'::text, timezone('UTC'::text, c)) as d1 FROM t2 GROUP B (1 row) EXPLAIN (VERBOSE, COSTS OFF) SELECT date_trunc('SeCond', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1; - QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan Output: (date_trunc('SeCond'::text, (c AT TIME ZONE 'UTC'::text))) Relations: Aggregate on (t1) - Remote SQL: SELECT toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1)) FROM regression.t1 GROUP BY (toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1))) ORDER BY toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1)) ASC + Remote SQL: SELECT toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC')) FROM regression.t1 GROUP BY (toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC'))) ORDER BY toStartOfSecond(toDateTime64(toTimeZone(c, 'UTC'), 1, 'UTC')) ASC (4 rows) SELECT date_trunc('SeCond', c at time zone 'UTC') as d1 FROM t1 GROUP BY d1 ORDER BY d1; diff --git a/tests/expected/http_1.out b/tests/expected/http_1.out index bdc6451..feaf425 100644 --- a/tests/expected/http_1.out +++ b/tests/expected/http_1.out @@ -166,12 +166,10 @@ SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work ALTER SERVER loopback OPTIONS (SET dbname 'no such database'); SELECT c3, c4 FROM ft1 ORDER BY c3, c1; -- should fail -ERROR: clickhouse_fdw:Code: 81. DB::Exception: Database `no such database` doesn't exist. (UNKNOWN_DATABASE) -QUERY:SELECT c1, c3, c4 FROM "no such database".t1 ORDER BY c3 ASC, c1 ASC +ERROR: clickhouse_fdw: communication error: URL rejected: Malformed input to a URL function ALTER USER MAPPING FOR CURRENT_USER SERVER loopback OPTIONS (ADD user 'no such user'); SELECT c3, c4 FROM ft1 ORDER BY c3, c1; -- should fail -ERROR: clickhouse_fdw:Code: 516. DB::Exception: no such user: Authentication failed: password is incorrect or there is no user with such name. (AUTHENTICATION_FAILED) -QUERY:SELECT c1, c3, c4 FROM "no such database".t1 ORDER BY c3 ASC, c1 ASC +ERROR: clickhouse_fdw: communication error: URL rejected: Malformed input to a URL function ALTER SERVER loopback OPTIONS (SET dbname 'regression'); ALTER USER MAPPING FOR CURRENT_USER SERVER loopback OPTIONS (DROP user); SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again