diff --git a/Makefile b/Makefile index 45243bf05..6008093b0 100755 --- a/Makefile +++ b/Makefile @@ -132,6 +132,6 @@ ifeq (${SUPPORTS_IMPORT}, 1) endif REGRESS = $(patsubst test-$(PYTHON_TEST_VERSION)/sql/%.sql,%,$(TESTS)) -REGRESS_OPTS = --inputdir=test-$(PYTHON_TEST_VERSION) --load-language=plpgsql +REGRESS_OPTS = --inputdir=test-$(PYTHON_TEST_VERSION) $(info Python version is $(python_version)) diff --git a/src/errors.c b/src/errors.c index ae1d877fd..22435bbdd 100644 --- a/src/errors.c +++ b/src/errors.c @@ -68,9 +68,17 @@ reportException(PyObject *pErrType, PyObject *pErrValue, PyObject *pErrTraceback { severity = ERROR; } +#if PG_VERSION_NUM >= 130000 + if (errstart(severity, TEXTDOMAIN)) +#else if (errstart(severity, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN)) +#endif { +#if PG_VERSION_NUM >= 130000 + if (errstart(severity, TEXTDOMAIN)) +#else if (errstart(severity, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN)) +#endif errmsg("Error in python: %s", errName); errdetail("%s", errValue); errdetail_log("%s", errTraceback); @@ -81,5 +89,9 @@ reportException(PyObject *pErrType, PyObject *pErrValue, PyObject *pErrTraceback Py_DECREF(tracebackModule); Py_DECREF(newline); Py_DECREF(pTemp); - errfinish(0); +#if PG_VERSION_NUM >= 130000 + errfinish(__FILE__, __LINE__, PG_FUNCNAME_MACRO); +#else + errfinish(0); +#endif } diff --git a/src/multicorn.c b/src/multicorn.c index c02d23a76..03b46de92 100644 --- a/src/multicorn.c +++ b/src/multicorn.c @@ -27,6 +27,9 @@ #include "utils/rel.h" #include "parser/parsetree.h" #include "fmgr.h" +#if PG_VERSION_NUM >= 130000 +#include "common/hashfn.h" /* oid_hash */ +#endif PG_MODULE_MAGIC; @@ -70,7 +73,13 @@ static void multicornReScanForeignScan(ForeignScanState *node); static void multicornEndForeignScan(ForeignScanState *node); #if PG_VERSION_NUM >= 90300 -static void multicornAddForeignUpdateTargets(Query *parsetree, +static void multicornAddForeignUpdateTargets( +#if PG_VERSION_NUM >= 140000 + PlannerInfo *root, + Index rtindex, +#else + Query *parsetree, +#endif RangeTblEntry *target_rte, Relation target_relation); @@ -311,7 +320,7 @@ multicornGetForeignRelSize(PlannerInfo *root, /* Extract the restrictions from the plan. */ foreach(lc, baserel->baserestrictinfo) { - extractRestrictions(baserel->relids, ((RestrictInfo *) lfirst(lc))->clause, + extractRestrictions(root, baserel->relids, ((RestrictInfo *) lfirst(lc))->clause, &planstate->qual_list); } @@ -444,7 +453,7 @@ multicornGetForeignPlan(PlannerInfo *root, foreach(lc, scan_clauses) { - extractRestrictions(baserel->relids, (Expr *) lfirst(lc), + extractRestrictions(root, baserel->relids, (Expr *) lfirst(lc), &planstate->qual_list); } } @@ -503,12 +512,15 @@ multicornBeginForeignScan(ForeignScanState *node, int eflags) execstate->values = palloc(sizeof(Datum) * tupdesc->natts); execstate->nulls = palloc(sizeof(bool) * tupdesc->natts); execstate->qual_list = NULL; +#if PG_VERSION_NUM < 140000 foreach(lc, fscan->fdw_exprs) { - extractRestrictions(bms_make_singleton(fscan->scan.scanrelid), + extractRestrictions(NULL, /* FIXME: set this properly. Parameter is used on PG14+ only, we can use NULL on older versions */ + bms_make_singleton(fscan->scan.scanrelid), ((Expr *) lfirst(lc)), &execstate->qual_list); } +#endif initConversioninfo(execstate->cinfos, TupleDescGetAttInMetadata(tupdesc)); node->fdw_state = execstate; } @@ -598,7 +610,13 @@ multicornEndForeignScan(ForeignScanState *node) * Add resjunk columns needed for update/delete. */ static void -multicornAddForeignUpdateTargets(Query *parsetree, +multicornAddForeignUpdateTargets( +#if PG_VERSION_NUM >= 140000 + PlannerInfo *root, + Index rtindex, +#else + Query *parsetree, +#endif RangeTblEntry *target_rte, Relation target_relation) { @@ -610,6 +628,9 @@ multicornAddForeignUpdateTargets(Query *parsetree, TupleDesc desc = target_relation->rd_att; int i; ListCell *cell; +#if PG_VERSION_NUM >= 140000 + Query *parsetree = root->parse; +#endif foreach(cell, parsetree->returningList) { @@ -681,7 +702,12 @@ multicornBeginForeignModify(ModifyTableState *mtstate, MulticornModifyState *modstate = palloc0(sizeof(MulticornModifyState)); Relation rel = resultRelInfo->ri_RelationDesc; TupleDesc desc = RelationGetDescr(rel); - PlanState *ps = mtstate->mt_plans[subplan_index]; + PlanState *ps = +#if PG_VERSION_NUM >= 140000 + outerPlanState(mtstate); +#else + mtstate->mt_plans[subplan_index]; +#endif Plan *subplan = ps->plan; MemoryContext oldcontext; int i; diff --git a/src/multicorn.h b/src/multicorn.h index 8022cf30b..e30dfe0e0 100644 --- a/src/multicorn.h +++ b/src/multicorn.h @@ -187,7 +187,8 @@ extern PGDLLIMPORT HTAB *InstancesHash; /* query.c */ -void extractRestrictions(Relids base_relids, +void extractRestrictions(PlannerInfo *root, + Relids base_relids, Expr *node, List **quals); List *extractColumns(List *reltargetlist, List *restrictinfolist); diff --git a/src/python.c b/src/python.c index 394236f91..55cb5ee0f 100644 --- a/src/python.c +++ b/src/python.c @@ -524,22 +524,37 @@ compareColumns(List *columns1, List *columns2) { return false; } +#if PG_VERSION_NUM >= 130000 + cell1 = lnext(coldef1, cell1); + cell2 = lnext(coldef2, cell2); +#else cell1 = lnext(cell1); cell2 = lnext(cell2); +#endif /* Compare typoid */ if (((Const *) (lfirst(cell1)))->constvalue != ((Const *) lfirst(cell2))->constvalue) { return false; } +#if PG_VERSION_NUM >= 130000 + cell1 = lnext(coldef1, cell1); + cell2 = lnext(coldef2, cell2); +#else cell1 = lnext(cell1); cell2 = lnext(cell2); +#endif /* Compare typmod */ if (((Const *) (lfirst(cell1)))->constvalue != ((Const *) lfirst(cell2))->constvalue) { return false; } +#if PG_VERSION_NUM >= 130000 + cell1 = lnext(coldef1, cell1); + cell2 = lnext(coldef2, cell2); +#else cell1 = lnext(cell1); cell2 = lnext(cell2); +#endif /* Compare column options */ if (!compareOptions(lfirst(cell1), lfirst(cell2))) { diff --git a/src/query.c b/src/query.c index dd8997e41..517c74291 100644 --- a/src/query.c +++ b/src/query.c @@ -21,7 +21,8 @@ #define get_attname(x, y) get_attname(x, y, true) #endif -void extractClauseFromOpExpr(Relids base_relids, +void extractClauseFromOpExpr(PlannerInfo *root, + Relids base_relids, OpExpr *node, List **quals); @@ -29,7 +30,8 @@ void extractClauseFromNullTest(Relids base_relids, NullTest *node, List **quals); -void extractClauseFromScalarArrayOpExpr(Relids base_relids, +void extractClauseFromScalarArrayOpExpr(PlannerInfo *root, + Relids base_relids, ScalarArrayOpExpr *node, List **quals); @@ -305,14 +307,15 @@ canonicalScalarArrayOpExpr(ScalarArrayOpExpr *opExpr, * */ void -extractRestrictions(Relids base_relids, +extractRestrictions(PlannerInfo *root, + Relids base_relids, Expr *node, List **quals) { switch (nodeTag(node)) { case T_OpExpr: - extractClauseFromOpExpr(base_relids, + extractClauseFromOpExpr(root, base_relids, (OpExpr *) node, quals); break; case T_NullTest: @@ -320,7 +323,7 @@ extractRestrictions(Relids base_relids, (NullTest *) node, quals); break; case T_ScalarArrayOpExpr: - extractClauseFromScalarArrayOpExpr(base_relids, + extractClauseFromScalarArrayOpExpr(root, base_relids, (ScalarArrayOpExpr *) node, quals); break; @@ -346,7 +349,8 @@ extractRestrictions(Relids base_relids, * - Var or Const value: the value. */ void -extractClauseFromOpExpr(Relids base_relids, +extractClauseFromOpExpr(PlannerInfo *root, + Relids base_relids, OpExpr *op, List **quals) { @@ -363,7 +367,11 @@ extractClauseFromOpExpr(Relids base_relids, /* Do not add it if it either contains a mutable function, or makes */ /* self references in the right hand side. */ if (!(contain_volatile_functions((Node *) right) || - bms_is_subset(base_relids, pull_varnos((Node *) right)))) + bms_is_subset(base_relids, pull_varnos( +#if PG_VERSION_NUM >= 140000 + root, +#endif + (Node *) right)))) { *quals = lappend(*quals, makeQual(left->varattno, getOperatorString(op->opno), @@ -373,7 +381,8 @@ extractClauseFromOpExpr(Relids base_relids, } void -extractClauseFromScalarArrayOpExpr(Relids base_relids, +extractClauseFromScalarArrayOpExpr(PlannerInfo *root, + Relids base_relids, ScalarArrayOpExpr *op, List **quals) { @@ -386,7 +395,11 @@ extractClauseFromScalarArrayOpExpr(Relids base_relids, left = list_nth(op->args, 0); right = list_nth(op->args, 1); if (!(contain_volatile_functions((Node *) right) || - bms_is_subset(base_relids, pull_varnos((Node *) right)))) + bms_is_subset(base_relids, pull_varnos( +#if PG_VERSION_NUM >= 140000 + root, +#endif + (Node *) right)))) { *quals = lappend(*quals, makeQual(left->varattno, getOperatorString(op->opno), @@ -837,26 +850,49 @@ deserializeDeparsedSortGroup(List *items) ListCell *lc; MulticornDeparsedSortGroup *key = palloc0(sizeof(MulticornDeparsedSortGroup)); +#if PG_VERSION_NUM >= 130000 + List *list = lfirst(k); +#endif lc = list_head(lfirst(k)); key->attname = (Name) strdup(strVal(lfirst(lc))); +#if PG_VERSION_NUM >= 130000 + lc = lnext(list, lc); +#else lc = lnext(lc); +#endif key->attnum = (int) intVal(lfirst(lc)); +#if PG_VERSION_NUM >= 130000 + lc = lnext(list, lc); +#else lc = lnext(lc); +#endif key->reversed = (bool) intVal(lfirst(lc)); +#if PG_VERSION_NUM >= 130000 + lc = lnext(list, lc); +#else lc = lnext(lc); +#endif key->nulls_first = (bool) intVal(lfirst(lc)); +#if PG_VERSION_NUM >= 130000 + lc = lnext(list, lc); +#else lc = lnext(lc); +#endif if(lfirst(lc) != NULL) key->collate = (Name) strdup(strVal(lfirst(lc))); else key->collate = NULL; +#if PG_VERSION_NUM >= 130000 + lc = lnext(list, lc); +#else lc = lnext(lc); +#endif key->key = (PathKey *) lfirst(lc); result = lappend(result, key); diff --git a/src/utils.c b/src/utils.c index 885dad720..f8c2f91f6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -89,7 +89,11 @@ log_to_postgres(PyObject *self, PyObject *args, PyObject *kwargs) } hint = PyDict_GetItemString(kwargs, "hint"); detail = PyDict_GetItemString(kwargs, "detail"); +#if PG_VERSION_NUM >= 130000 + if (errstart(severity, TEXTDOMAIN)) +#else if (errstart(severity, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN)) +#endif { errmsg("%s", message); if (hint != NULL && hint != Py_None) @@ -104,7 +108,11 @@ log_to_postgres(PyObject *self, PyObject *args, PyObject *kwargs) } Py_DECREF(args); Py_DECREF(kwargs); +#if PG_VERSION_NUM >= 130000 + errfinish(__FILE__, __LINE__, PG_FUNCNAME_MACRO); +#else errfinish(0); +#endif } else { diff --git a/test-2.7/expected/write_filesystem.out b/test-2.7/expected/write_filesystem.out index e3dd2083a..915a16107 100644 --- a/test-2.7/expected/write_filesystem.out +++ b/test-2.7/expected/write_filesystem.out @@ -3,7 +3,7 @@ CREATE EXTENSION multicorn; CREATE server multicorn_srv foreign data wrapper multicorn options ( wrapper 'multicorn.fsfdw.FilesystemFdw' ); -CREATE language plpythonu; +CREATE EXTENSION plpythonu; CREATE TABLE temp_dir (dirname varchar); -- Create a table with the filesystem fdw in a temporary directory, -- and store the dirname in the temp_dir table. @@ -598,4 +598,4 @@ DROP EXTENSION multicorn cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to server multicorn_srv drop cascades to foreign table testmulticorn -DROP LANGUAGE plpythonu; +DROP EXTENSION plpythonu; diff --git a/test-2.7/sql/write_filesystem.sql b/test-2.7/sql/write_filesystem.sql index 11baf6227..cca27679a 100644 --- a/test-2.7/sql/write_filesystem.sql +++ b/test-2.7/sql/write_filesystem.sql @@ -6,7 +6,7 @@ CREATE server multicorn_srv foreign data wrapper multicorn options ( ); -CREATE language plpythonu; +CREATE EXTENSION plpythonu; CREATE TABLE temp_dir (dirname varchar); -- Create a table with the filesystem fdw in a temporary directory, @@ -63,4 +63,4 @@ DROP FUNCTION cleanup_dir(); DROP TABLE temp_dir; DROP FUNCTION create_table(); DROP EXTENSION multicorn cascade; -DROP LANGUAGE plpythonu; +DROP EXTENSION plpythonu; diff --git a/test-3.3/expected/write_filesystem.out b/test-3.3/expected/write_filesystem.out index c8a750592..72b04fe41 100644 --- a/test-3.3/expected/write_filesystem.out +++ b/test-3.3/expected/write_filesystem.out @@ -1,6 +1,6 @@ -- Setup the test CREATE EXTENSION multicorn; -CREATE language plpython3u; +CREATE EXTENSION plpython3u; \i test-common/disable_jit.include DO $$ BEGIN @@ -606,4 +606,4 @@ DROP EXTENSION multicorn cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to server multicorn_srv drop cascades to foreign table testmulticorn -DROP LANGUAGE plpython3u; +DROP EXTENSION plpython3u; diff --git a/test-3.3/sql/write_filesystem.sql b/test-3.3/sql/write_filesystem.sql index 35ada0a6a..223bdb3db 100644 --- a/test-3.3/sql/write_filesystem.sql +++ b/test-3.3/sql/write_filesystem.sql @@ -1,6 +1,6 @@ -- Setup the test CREATE EXTENSION multicorn; -CREATE language plpython3u; +CREATE EXTENSION plpython3u; \i test-common/disable_jit.include CREATE OR REPLACE FUNCTION create_table() RETURNS VOID AS $$ @@ -65,4 +65,4 @@ DROP FUNCTION cleanup_dir(); DROP TABLE temp_dir; DROP FUNCTION create_table(); DROP EXTENSION multicorn cascade; -DROP LANGUAGE plpython3u; +DROP EXTENSION plpython3u;