Skip to content

Commit 9387022

Browse files
Nguyen Thi Van Anhaanhh
Nguyen Thi Van Anh
authored andcommitted
RELEASE v0.2.0
1 parent d20b583 commit 9387022

32 files changed

+1683
-705
lines changed

JDBCUtils.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,18 @@ public Object[] getResultSet(int resultSetID) throws SQLException {
285285
* has the value of the fields of the current
286286
* row as it values. */
287287
return tmpArrayOfResultRow;
288+
} else {
289+
/*
290+
* All of resultSet's rows have been returned to the C code.
291+
* Close tmpResultSet's statement
292+
*/
293+
tmpResultSet.getStatement().close();
294+
clearResultSetID(resultSetID);
295+
return null;
288296
}
289297
} catch (Throwable e) {
290298
throw e;
291299
}
292-
/* All of resultSet's rows have been returned to the C code. */
293-
return null;
294300
}
295301

296302
/*

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PG_CPPFLAGS = -I$(libpq_srcdir)
77
SHLIB_LINK = $(libpq)
88

99
EXTENSION = jdbc_fdw
10-
DATA = jdbc_fdw--1.0.sql
10+
DATA = jdbc_fdw--1.0.sql jdbc_fdw--1.0--1.1.sql
1111

1212
REGRESS = postgresql/jdbc_fdw postgresql/int4 postgresql/int8 postgresql/float4 postgresql/float8 postgresql/select postgresql/insert postgresql/update postgresql/aggregates
1313

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
JDBC Foreign Data Wrapper for PostgreSQL
22
=========================================
33
* This PostgreSQL extension is a Foreign Data Wrapper (FDW) for JDBC.
4-
* The current version can work with PostgreSQL 13, 14.
4+
* The current version can work with PostgreSQL 13.
55
* Java 5 or later is required (Confirmed version is Java OpenJDK 1.8.0).
66
* This jdbc_fdw is based on [JDBC\_FDW](http://github.com/atris/JDBC_FDW.git), [jdbc2\_fdw](https://github.com/heimir-sverrisson/jdbc2_fdw).
77

@@ -121,7 +121,7 @@ This is a performance feature.
121121
#### Aggregate function push-down
122122
List of aggregate functions push-down:
123123
```
124-
sum, avg, stddev, variance, max, min, count.
124+
sum, avg, stddev, stddev_pop, stddev_samp, var_pop, var_samp, variance, max, min, count.
125125
```
126126

127127
Usage
@@ -147,9 +147,6 @@ IMPORT FOREIGN SCHEMA public
147147

148148
Limitations
149149
-----------
150-
#### Multiple aggregate functions push-down
151-
Currently, jdbc_fdw can only push-down one aggregation function in single SQL.
152-
153150
#### Unsupported clause
154151
The following clasues are not support in jdbc_fdw:
155152
RETURNING, GROUPBY, ORDER BY clauses, casting type, transaction control

deparse.c

+55-50
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@ static void jdbc_append_function_name(Oid funcid, deparse_expr_cxt *context);
156156
static const char *jdbc_quote_identifier(const char *ident,
157157
char *q_char,
158158
bool quote_all_identifiers);
159+
static bool jdbc_func_exist_in_list(char *funcname, const char **funclist);
160+
161+
/*
162+
* JdbcSupportedBuiltinAggFunction
163+
* List of supported builtin aggregate functions for Jdbc
164+
*/
165+
static const char *JdbcSupportedBuiltinAggFunction[] = {
166+
"sum",
167+
"avg",
168+
"max",
169+
"min",
170+
"count",
171+
"stddev",
172+
"stddev_pop",
173+
"stddev_samp",
174+
"var_pop",
175+
"var_samp",
176+
"variance",
177+
NULL};
159178

160179
/*
161180
* Deparse given targetlist and append it to context->buf.
@@ -495,6 +514,10 @@ jdbc_foreign_expr_walker(Node *node,
495514
{
496515
FuncExpr *fe = (FuncExpr *) node;
497516

517+
/* Does not support push down explicit cast function */
518+
if (fe->funcformat == COERCE_EXPLICIT_CAST)
519+
return false;
520+
498521
/*
499522
* If function used by the expression is not built-in, it
500523
* can't be sent to remote because it might have incompatible
@@ -722,9 +745,6 @@ jdbc_foreign_expr_walker(Node *node,
722745
Aggref *agg = (Aggref *) node;
723746
ListCell *lc;
724747
char *opername = NULL;
725-
bool is_math_func = false;
726-
bool is_selector_func = false;
727-
bool is_count_func = false;
728748
HeapTuple tuple;
729749

730750
/* get function name */
@@ -736,21 +756,8 @@ jdbc_foreign_expr_walker(Node *node,
736756
opername = pstrdup(((Form_pg_proc) GETSTRUCT(tuple))->proname.data);
737757
ReleaseSysCache(tuple);
738758

739-
/* these function can be passed to JDBC */
740-
if (strcmp(opername, "sum") == 0 ||
741-
strcmp(opername, "avg") == 0 ||
742-
strcmp(opername, "stddev") == 0 ||
743-
strcmp(opername, "variance") == 0)
744-
is_math_func = true;
745-
746-
if (strcmp(opername, "max") == 0 ||
747-
strcmp(opername, "min") == 0)
748-
is_selector_func = true;
749-
750-
if (strcmp(opername, "count") == 0)
751-
is_count_func = true;
752-
753-
if (!(is_math_func || is_selector_func || is_count_func))
759+
/* Only function exist in JdbcSupportedBuiltinAggFunction can be passed to JDBC */
760+
if (!jdbc_func_exist_in_list(opername, JdbcSupportedBuiltinAggFunction))
754761
return false;
755762

756763
/* Not safe to pushdown when not in grouping context */
@@ -761,6 +768,15 @@ jdbc_foreign_expr_walker(Node *node,
761768
if (agg->aggsplit != AGGSPLIT_SIMPLE)
762769
return false;
763770

771+
/*
772+
* Does not push down DISTINCT inside aggregate function
773+
* because of undefined behavior of the GridDB JDBC driver.
774+
* TODO: We may hanlde DISTINCT in future with new release
775+
* of GridDB JDBC driver.
776+
*/
777+
if (agg->aggdistinct != NIL)
778+
return false;
779+
764780
/*
765781
* Recurse to input args. aggdirectargs, aggorder and
766782
* aggdistinct are all present in args, so no need to check
@@ -776,41 +792,9 @@ jdbc_foreign_expr_walker(Node *node,
776792
if (IsA(n, TargetEntry))
777793
{
778794
TargetEntry *tle = (TargetEntry *) n;
779-
Var *tmp_var;
780795

781796
n = (Node *) tle->expr;
782-
tmp_var = (Var *) n;
783-
switch (tmp_var->vartype)
784-
{
785-
case INT2OID:
786-
case INT4OID:
787-
case INT8OID:
788-
case OIDOID:
789-
case FLOAT4OID:
790-
case FLOAT8OID:
791-
case NUMERICOID:
792-
{
793-
if (!(is_math_func || is_selector_func))
794-
{
795-
return false;
796-
}
797-
break;
798-
}
799-
case TIMESTAMPOID:
800-
case TIMESTAMPTZOID:
801-
{
802-
if (!is_selector_func)
803-
{
804-
return false;
805-
}
806-
break;
807-
}
808-
default:
809-
return false;
810-
}
811797
}
812-
else if (!(agg->aggstar == true && is_count_func))
813-
return false;
814798

815799
if (!jdbc_foreign_expr_walker(n, glob_cxt, &inner_cxt))
816800
return false;
@@ -2506,3 +2490,24 @@ jdbc_quote_identifier(const char *ident, char *q_char, bool quote_all_identifier
25062490

25072491
return result;
25082492
}
2493+
2494+
/*
2495+
* Return true if function name existed in list of function
2496+
*/
2497+
static bool
2498+
jdbc_func_exist_in_list(char *funcname, const char **funclist)
2499+
{
2500+
int i;
2501+
2502+
if (funclist == NULL || /* NULL list */
2503+
funclist[0] == NULL || /* List length = 0 */
2504+
funcname == NULL) /* Input function name = NULL */
2505+
return false;
2506+
2507+
for (i = 0; funclist[i]; i++)
2508+
{
2509+
if (strcmp(funcname, funclist[i]) == 0)
2510+
return true;
2511+
}
2512+
return false;
2513+
}

expected/13.4/griddb/aggregates.out

+52-58
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ drivername :DB_DRIVERNAME,
1515
url :DB_URL,
1616
querytimeout '10',
1717
jarfile :DB_DRIVERPATH,
18-
maxheapsize '6000'
18+
maxheapsize '600'
1919
);
2020
--Testcase 3:
2121
CREATE USER MAPPING FOR public SERVER :DB_SERVERNAME OPTIONS(username :DB_USER,password :DB_PASS);
@@ -105,16 +105,20 @@ SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
105105
-- Round the result to 3 digits to avoid platform-specific results.
106106
--Testcase 14:
107107
EXPLAIN VERBOSE SELECT avg(b)::numeric(10,3) AS avg_107_943 FROM aggtest;
108-
QUERY PLAN
109-
-------------------------------------------------------------
108+
QUERY PLAN
109+
-------------------------------------------------
110110
Foreign Scan (cost=1.00..1.00 rows=1 width=16)
111-
Output: ((avg(b))::numeric(10,3))
112-
Remote SQL: SELECT "numeric"(avg(b), 655367) FROM aggtest
111+
Output: ((avg(b)))::numeric(10,3)
112+
Remote SQL: SELECT avg(b) FROM aggtest
113113
(3 rows)
114114

115115
--Testcase 15:
116116
SELECT avg(b)::numeric(10,3) AS avg_107_943 FROM aggtest;
117-
psql:sql/13.4/aggregates.sql:80: ERROR: remote server returned an error
117+
avg_107_943
118+
-------------
119+
107.943
120+
(1 row)
121+
118122
--Testcase 16:
119123
EXPLAIN VERBOSE SELECT sum(four) AS sum_1500 FROM onek;
120124
QUERY PLAN
@@ -213,14 +217,12 @@ SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
213217

214218
--Testcase 28:
215219
EXPLAIN VERBOSE SELECT stddev_pop(b) FROM aggtest;
216-
QUERY PLAN
217-
-------------------------------------------------------------------------------
218-
Aggregate (cost=205.06..205.07 rows=1 width=8)
219-
Output: stddev_pop(b)
220-
-> Foreign Scan on public.aggtest (cost=100.00..197.75 rows=2925 width=4)
221-
Output: id, a, b
222-
Remote SQL: SELECT b FROM aggtest
223-
(5 rows)
220+
QUERY PLAN
221+
-------------------------------------------------
222+
Foreign Scan (cost=1.00..1.00 rows=1 width=8)
223+
Output: (stddev_pop(b))
224+
Remote SQL: SELECT stddev_pop(b) FROM aggtest
225+
(3 rows)
224226

225227
--Testcase 29:
226228
SELECT stddev_pop(b) FROM aggtest;
@@ -231,14 +233,12 @@ SELECT stddev_pop(b) FROM aggtest;
231233

232234
--Testcase 30:
233235
EXPLAIN VERBOSE SELECT stddev_samp(b) FROM aggtest;
234-
QUERY PLAN
235-
-------------------------------------------------------------------------------
236-
Aggregate (cost=205.06..205.07 rows=1 width=8)
237-
Output: stddev_samp(b)
238-
-> Foreign Scan on public.aggtest (cost=100.00..197.75 rows=2925 width=4)
239-
Output: id, a, b
240-
Remote SQL: SELECT b FROM aggtest
241-
(5 rows)
236+
QUERY PLAN
237+
--------------------------------------------------
238+
Foreign Scan (cost=1.00..1.00 rows=1 width=8)
239+
Output: (stddev_samp(b))
240+
Remote SQL: SELECT stddev_samp(b) FROM aggtest
241+
(3 rows)
242242

243243
--Testcase 31:
244244
SELECT stddev_samp(b) FROM aggtest;
@@ -249,14 +249,12 @@ SELECT stddev_samp(b) FROM aggtest;
249249

250250
--Testcase 32:
251251
EXPLAIN VERBOSE SELECT var_pop(b) FROM aggtest;
252-
QUERY PLAN
253-
-------------------------------------------------------------------------------
254-
Aggregate (cost=205.06..205.07 rows=1 width=8)
255-
Output: var_pop(b)
256-
-> Foreign Scan on public.aggtest (cost=100.00..197.75 rows=2925 width=4)
257-
Output: id, a, b
258-
Remote SQL: SELECT b FROM aggtest
259-
(5 rows)
252+
QUERY PLAN
253+
------------------------------------------------
254+
Foreign Scan (cost=1.00..1.00 rows=1 width=8)
255+
Output: (var_pop(b))
256+
Remote SQL: SELECT var_pop(b) FROM aggtest
257+
(3 rows)
260258

261259
--Testcase 33:
262260
SELECT var_pop(b) FROM aggtest;
@@ -267,14 +265,12 @@ SELECT var_pop(b) FROM aggtest;
267265

268266
--Testcase 34:
269267
EXPLAIN VERBOSE SELECT var_samp(b) FROM aggtest;
270-
QUERY PLAN
271-
-------------------------------------------------------------------------------
272-
Aggregate (cost=205.06..205.07 rows=1 width=8)
273-
Output: var_samp(b)
274-
-> Foreign Scan on public.aggtest (cost=100.00..197.75 rows=2925 width=4)
275-
Output: id, a, b
276-
Remote SQL: SELECT b FROM aggtest
277-
(5 rows)
268+
QUERY PLAN
269+
------------------------------------------------
270+
Foreign Scan (cost=1.00..1.00 rows=1 width=8)
271+
Output: (var_samp(b))
272+
Remote SQL: SELECT var_samp(b) FROM aggtest
273+
(3 rows)
278274

279275
--Testcase 35:
280276
SELECT var_samp(b) FROM aggtest;
@@ -593,14 +589,12 @@ DROP FOREIGN TABLE regr_test;
593589
-- test count, distinct
594590
--Testcase 72:
595591
EXPLAIN VERBOSE SELECT count(four) AS cnt_1000 FROM onek;
596-
QUERY PLAN
597-
-------------------------------------------------------------------------------------------------------------------------------------------------------
598-
Aggregate (cost=205.06..205.07 rows=1 width=8)
599-
Output: count(four)
600-
-> Foreign Scan on public.onek (cost=100.00..197.75 rows=2925 width=4)
601-
Output: unique1, unique2, two, four, ten, twenty, hundred, thousand, twothousand, fivethous, tenthous, odd, even, stringu1, stringu2, string4
602-
Remote SQL: SELECT four FROM onek
603-
(5 rows)
592+
QUERY PLAN
593+
------------------------------------------------
594+
Foreign Scan (cost=1.00..1.00 rows=1 width=8)
595+
Output: (count(four))
596+
Remote SQL: SELECT count(four) FROM onek
597+
(3 rows)
604598

605599
--Testcase 73:
606600
SELECT count(four) AS cnt_1000 FROM onek;
@@ -652,9 +646,14 @@ from tenk1 o;
652646
(13 rows)
653647

654648
--Testcase 77:
655-
-- select
656-
-- (select max((select i.unique2 from tenk1 i where i.unique1 = o.unique1)))
657-
-- from tenk1 o;
649+
select
650+
(select max((select i.unique2 from tenk1 i where i.unique1 = o.unique1)))
651+
from tenk1 o;
652+
max
653+
------
654+
9999
655+
(1 row)
656+
658657
--
659658
-- test boolean aggregates
660659
--
@@ -873,15 +872,10 @@ select distinct max(unique2) from tenk1;
873872
--Testcase 99:
874873
explain (costs off)
875874
select max(100) from tenk1;
876-
QUERY PLAN
877-
----------------------------------------------------
878-
Result
879-
InitPlan 1 (returns $0)
880-
-> Limit
881-
-> Result
882-
One-Time Filter: (100 IS NOT NULL)
883-
-> Foreign Scan on tenk1
884-
(6 rows)
875+
QUERY PLAN
876+
--------------
877+
Foreign Scan
878+
(1 row)
885879

886880
--Testcase 100:
887881
select max(100) from tenk1;

0 commit comments

Comments
 (0)