This is an automated email from the ASF dual-hosted git repository.

khannaekta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/madlib.git


The following commit(s) were added to refs/heads/master by this push:
     new 687473e  Build: Add support for pg 12
687473e is described below

commit 687473ea1153b2e7649fd3223933f46ff0e818f8
Author: Orhan Kislal <[email protected]>
AuthorDate: Tue Nov 26 03:58:09 2019 -0800

    Build: Add support for pg 12
    
    JIRA: MADLIB-1391
    
    This commit adds the necessary files for PG12 support and makes a few 
changes
    in the backend.
    
    The FunctionCallInfoData struct from postgres has been changed to
    FunctionCallInfoBaseData. This new structure replaces the "value" variable 
with
    "value" and "isNull". We made changes in the backend to handle this new
    struct.
    Also, `get_float8_infinity()` was replaced with using FLT_MAX to
    accommodate the changes for the PG12 commit postgres/postgres@6bf0bc8.
    
    Co-authored-by: Nikhil Kak <[email protected]>
---
 methods/array_ops/src/pg_gp/array_ops.c            |  9 +++++----
 methods/utils/src/pg_gp/exec_sql_using.c           | 20 ++++++++++++++++++--
 src/ports/postgres/12/CMakeLists.txt               | 22 ++++++++++++++++++++++
 src/ports/postgres/cmake/FindPostgreSQL_12.cmake   | 21 +++++++++++++++++++++
 src/ports/postgres/dbconnector/Backend.hpp         | 12 ++++++++++--
 .../postgres/dbconnector/FunctionHandle_impl.hpp   | 19 ++++++++++++++++++-
 6 files changed, 94 insertions(+), 9 deletions(-)

diff --git a/methods/array_ops/src/pg_gp/array_ops.c 
b/methods/array_ops/src/pg_gp/array_ops.c
index b39d2cd..48880a6 100644
--- a/methods/array_ops/src/pg_gp/array_ops.c
+++ b/methods/array_ops/src/pg_gp/array_ops.c
@@ -14,6 +14,7 @@
 #include "utils/typcache.h"
 #include "access/hash.h"
 #include <math.h>
+#include <float.h>
 
 #ifndef NO_PG_MODULE_MAGIC
     PG_MODULE_MAGIC;
@@ -524,7 +525,7 @@ array_min(PG_FUNCTION_ARGS){
 
     ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
     Oid element_type = ARR_ELEMTYPE(v);
-    Datum res = General_Array_to_Element(v, Float8GetDatum(0), 
get_float8_infinity(),
+    Datum res = General_Array_to_Element(v, Float8GetDatum(0), FLT_MAX,
             element_min, noop_finalize);
 
     PG_FREE_IF_COPY(v, 0);
@@ -543,7 +544,7 @@ array_max(PG_FUNCTION_ARGS){
     ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
     Oid element_type = ARR_ELEMTYPE(v);
 
-    Datum res = General_Array_to_Element(v, Float8GetDatum(0), 
-get_float8_infinity(),
+    Datum res = General_Array_to_Element(v, Float8GetDatum(0), -FLT_MAX,
             element_max, noop_finalize);
 
     PG_FREE_IF_COPY(v, 0);
@@ -572,7 +573,7 @@ array_max_index(PG_FUNCTION_ARGS) {
     }
 
     value_index *result = (value_index *)palloc(sizeof(value_index));
-    result->value = -get_float8_infinity();
+    result->value = -FLT_MAX;
     result->index = 0;
 
     Datum res = General_Array_to_Struct(v, result, element_argmax, 
value_index_finalize);
@@ -597,7 +598,7 @@ array_min_index(PG_FUNCTION_ARGS) {
     }
 
     value_index *result = (value_index *)palloc(sizeof(value_index));
-    result->value = get_float8_infinity();
+    result->value = FLT_MAX;
     result->index = 0;
 
     Datum res = General_Array_to_Struct(v, result, element_argmin, 
value_index_finalize);
diff --git a/methods/utils/src/pg_gp/exec_sql_using.c 
b/methods/utils/src/pg_gp/exec_sql_using.c
index d0dabed..268a143 100644
--- a/methods/utils/src/pg_gp/exec_sql_using.c
+++ b/methods/utils/src/pg_gp/exec_sql_using.c
@@ -98,7 +98,11 @@ exec_sql_using(PG_FUNCTION_ARGS) {
             ));
 
     char* nulls = NULL;
-    for (int i = 1; i < nargs; i++)
+#if PG_VERSION_NUM >= 120000
+    Datum* args_copy = palloc0(sizeof(Datum) * (nargs - 1));
+#endif
+
+    for (int i = 1; i < nargs; i++){
         if (PG_ARGISNULL(i)) {
             if (nulls == NULL) {
                 nulls = palloc0(sizeof(char) * (nargs - 1));
@@ -106,7 +110,10 @@ exec_sql_using(PG_FUNCTION_ARGS) {
             }
             nulls[i - 1] = 'n';
         }
-
+#if PG_VERSION_NUM >= 120000
+        args_copy[i-1] = fcinfo->args[i].value;
+#endif
+    }
     SPI_connect();
     SPIPlanPtr plan = SPI_prepare(stmt, nargs - 1, &types[1]);
     if (plan == NULL)
@@ -116,8 +123,13 @@ exec_sql_using(PG_FUNCTION_ARGS) {
                 format_procedure(fcinfo->flinfo->fn_oid))
             ));
 
+#if PG_VERSION_NUM >= 120000
+    int result = SPI_execute_plan(plan, args_copy, nulls, false,
+        returnVoid ? 0 : 1);
+#else
     int result = SPI_execute_plan(plan, &fcinfo->arg[1], nulls, false,
         returnVoid ? 0 : 1);
+#endif
 
     Datum returnValue = 0;
     bool returnNull = false;
@@ -153,6 +165,10 @@ exec_sql_using(PG_FUNCTION_ARGS) {
     SPI_freeplan(plan);
     if (nulls)
         pfree(nulls);
+#if PG_VERSION_NUM >= 120000
+    if (args_copy)
+        pfree(args_copy);
+#endif
     SPI_finish();
 
     if (result < 0)
diff --git a/src/ports/postgres/12/CMakeLists.txt 
b/src/ports/postgres/12/CMakeLists.txt
new file mode 100644
index 0000000..2d44a6f
--- /dev/null
+++ b/src/ports/postgres/12/CMakeLists.txt
@@ -0,0 +1,22 @@
+# 
------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# 
------------------------------------------------------------------------------
+
+add_current_postgresql_version()
+add_extension_support()
+
diff --git a/src/ports/postgres/cmake/FindPostgreSQL_12.cmake 
b/src/ports/postgres/cmake/FindPostgreSQL_12.cmake
new file mode 100644
index 0000000..43ba0e4
--- /dev/null
+++ b/src/ports/postgres/cmake/FindPostgreSQL_12.cmake
@@ -0,0 +1,21 @@
+# 
------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# 
------------------------------------------------------------------------------
+
+set(_FIND_PACKAGE_FILE "${CMAKE_CURRENT_LIST_FILE}")
+include("${CMAKE_CURRENT_LIST_DIR}/FindPostgreSQL.cmake")
diff --git a/src/ports/postgres/dbconnector/Backend.hpp 
b/src/ports/postgres/dbconnector/Backend.hpp
index 8922cf8..138136c 100644
--- a/src/ports/postgres/dbconnector/Backend.hpp
+++ b/src/ports/postgres/dbconnector/Backend.hpp
@@ -104,8 +104,15 @@ MADLIB_WRAP_VOID_PG_FUNC(
 
 inline
 void
-madlib_InitFunctionCallInfoData(FunctionCallInfoData& fcinfo, FmgrInfo* flinfo,
-    short nargs, Oid fncollation, fmNodePtr context, fmNodePtr resultinfo) {
+
+#if PG_VERSION_NUM >= 120000
+madlib_InitFunctionCallInfoData(FunctionCallInfoBaseData& fcinfo,
+#else
+madlib_InitFunctionCallInfoData(FunctionCallInfoData& fcinfo,
+#endif
+
+    FmgrInfo* flinfo, short nargs, Oid fncollation, fmNodePtr context,
+    fmNodePtr resultinfo) {
 
 #if PG_VERSION_NUM >= 90100
     // Collation support has been added to PostgreSQL with commit
@@ -113,6 +120,7 @@ madlib_InitFunctionCallInfoData(FunctionCallInfoData& 
fcinfo, FmgrInfo* flinfo,
     // on Tue Apr 12 2011 23:19:24 UTC. First release: PG9.1.
     InitFunctionCallInfoData(fcinfo, flinfo, nargs, fncollation, context,
         resultinfo);
+
 #else
     (void) fncollation;
     InitFunctionCallInfoData(fcinfo, flinfo, nargs, context, resultinfo);
diff --git a/src/ports/postgres/dbconnector/FunctionHandle_impl.hpp 
b/src/ports/postgres/dbconnector/FunctionHandle_impl.hpp
index 220f949..5587b25 100644
--- a/src/ports/postgres/dbconnector/FunctionHandle_impl.hpp
+++ b/src/ports/postgres/dbconnector/FunctionHandle_impl.hpp
@@ -125,7 +125,13 @@ FunctionHandle::invoke(AnyType &args) {
         oldContext = MemoryContextSwitchTo(callContext);
     }
 
+#if PG_VERSION_NUM >= 120000
+    FunctionCallInfoBaseData funcPtrCallInfo;
+    int nargs = args.numFields();
+    MemSet(&funcPtrCallInfo, 0, SizeForFunctionCallInfo(nargs));
+#else
     FunctionCallInfoData funcPtrCallInfo;
+#endif
     // Initializes all the fields of a FunctionCallInfoData except for the 
arg[]
     // and argnull[] arrays
     madlib_InitFunctionCallInfoData(
@@ -147,11 +153,22 @@ FunctionHandle::invoke(AnyType &args) {
         NULL
     );
 
+#if PG_VERSION_NUM >= 120000
     for (uint16_t i = 0; i < funcPtrCallInfo.nargs; ++i) {
-        funcPtrCallInfo.arg[i] = args[i].getAsDatum(&funcPtrCallInfo,
+
+        funcPtrCallInfo.args[i].value = args[i].getAsDatum(&funcPtrCallInfo,
+            mFuncInfo->getArgumentType(i));
+        funcPtrCallInfo.args[i].isnull = args[i].isNull();
+        elog(WARNING, "funcPtrCallInfo.args[i].value %d 
funcPtrCallInfo.args[i].isnull %d", funcPtrCallInfo.args[i].value, 
funcPtrCallInfo.args[i].isnull);
+    }
+#else
+    for (uint16_t i = 0; i < funcPtrCallInfo.nargs; ++i) {
+        funcPtrCallInfo.arg[i]= args[i].getAsDatum(&funcPtrCallInfo,
             mFuncInfo->getArgumentType(i));
         funcPtrCallInfo.argnull[i] = args[i].isNull();
     }
+#endif
+
 
     Datum result = internalInvoke(&funcPtrCallInfo);
 

Reply via email to