Skip to content

Commit e6d3c42

Browse files
Support madlib2 for lighting.
This commit, we support madlib2 for the version 3 of lightning.
1 parent 6555f60 commit e6d3c42

10 files changed

Lines changed: 539 additions & 0 deletions

File tree

src/ports/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(postgres)
22
add_subdirectory(greenplum)
3+
add_subdirectory(cloudberry)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
add_current_cloudberry_version()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
add_current_cloudberry_version()
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# ------------------------------------------------------------------------------
19+
# Cloudberry Port
20+
# ------------------------------------------------------------------------------
21+
22+
set(PORT "Cloudberry")
23+
string(TOUPPER ${PORT} PORT_UC)
24+
string(TOLOWER ${PORT} PORT_LC)
25+
set(PORT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
26+
get_filename_component(PORT_DIR_NAME "${PORT_SOURCE_DIR}" NAME)
27+
set(PORT_DEPLOY_SCRIPT "${CMAKE_BINARY_DIR}/deploy/Component_${PORT}.cmake")
28+
29+
if(APPLE)
30+
# FIXME: This should be handled in a better way.
31+
set(ADDITIONAL_GCC_FLAGS "-m64")
32+
else(APPLE)
33+
unset(ADDITIONAL_GCC_FLAGS)
34+
endif(APPLE)
35+
36+
list(APPEND CMAKE_MODULE_PATH
37+
${CMAKE_CURRENT_SOURCE_DIR}/cmake
38+
${CMAKE_CURRENT_SOURCE_DIR}/../postgres/cmake)
39+
include(PostgreSQLUtils)
40+
include(CloudberryUtils)
41+
42+
43+
# -- 1. Specify files that will be compiled into the shared library, for *all*
44+
# versions of this port --------------------------------------------------
45+
46+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
47+
48+
set(MAD_DBAL_SOURCES
49+
${MAD_SOURCES})
50+
list(APPEND MAD_DBAL_SOURCES
51+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/Allocator_impl.hpp"
52+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/Allocator_proto.hpp"
53+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/AnyType_impl.hpp"
54+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/AnyType_proto.hpp"
55+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/ArrayHandle_impl.hpp"
56+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/ArrayHandle_proto.hpp"
57+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/ArrayWithNullException_proto.hpp"
58+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/Backend.hpp"
59+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/ByteString_impl.hpp"
60+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/ByteString_proto.hpp"
61+
"${CMAKE_CURRENT_SOURCE_DIR}/dbconnector/Compatibility.hpp"
62+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/dbconnector.hpp"
63+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/EigenIntegration_impl.hpp"
64+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/EigenIntegration_proto.hpp"
65+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/FunctionHandle_impl.hpp"
66+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/FunctionHandle_proto.hpp"
67+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/main.cpp"
68+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/NewDelete.cpp"
69+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/NativeRandomNumberGenerator_impl.hpp"
70+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/NativeRandomNumberGenerator_proto.hpp"
71+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/OutputStreamBuffer_impl.hpp"
72+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/OutputStreamBuffer_proto.hpp"
73+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/PGException_proto.hpp"
74+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/SystemInformation_impl.hpp"
75+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/SystemInformation_proto.hpp"
76+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/TransparentHandle_impl.hpp"
77+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/TransparentHandle_proto.hpp"
78+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/TypeTraits_impl.hpp"
79+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/TypeTraits_proto.hpp"
80+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/UDF_impl.hpp"
81+
"${CMAKE_CURRENT_SOURCE_DIR}/../postgres/dbconnector/UDF_proto.hpp"
82+
)
83+
84+
# FIXME: Convert legacy source code written in C
85+
# BEGIN Legacy Code
86+
87+
file(GLOB_RECURSE LEGACY_C_FILES
88+
"${CMAKE_SOURCE_DIR}/methods/*.c")
89+
list(APPEND MAD_DBAL_SOURCES ${LEGACY_C_FILES})
90+
91+
# END Legacy Code
92+
93+
94+
# -- 2. Copy all SQL files. Since SQL files contain file names, they are only
95+
# preprocessed at installation time, i.e., by madpack. -------------------
96+
97+
add_sql_files(
98+
SQL_TARGET_FILES
99+
"../postgres/modules"
100+
"${CMAKE_CURRENT_BINARY_DIR}/modules"
101+
)
102+
# Add Greenplum-specific modules. Files will be appended to SQL_TARGET_FILES.
103+
add_sql_files(
104+
SQL_TARGET_FILES
105+
"modules"
106+
"${CMAKE_CURRENT_BINARY_DIR}/modules"
107+
)
108+
# FIXME: Check legacy code for compliance with new architecture
109+
# BEGIN Legacy Code
110+
111+
file(GLOB_RECURSE LEGACY_SQL_FILES RELATIVE
112+
"${CMAKE_SOURCE_DIR}/methods"
113+
"${CMAKE_SOURCE_DIR}/methods/*.sql_in")
114+
foreach(CURRENT_FILE ${LEGACY_SQL_FILES})
115+
get_filename_component(CURRENT_PATH "${CMAKE_SOURCE_DIR}/methods/${CURRENT_FILE}" ABSOLUTE)
116+
set(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/modules/${CURRENT_FILE}")
117+
string(REPLACE "/src/pg_gp" "" OUTFILE ${OUTFILE})
118+
string(REPLACE "/sql/" "/test/" OUTFILE ${OUTFILE})
119+
add_custom_command(OUTPUT "${OUTFILE}"
120+
COMMAND "${CMAKE_SOURCE_DIR}/cmake/TestIfNoUTF8BOM.py" "${CURRENT_PATH}"
121+
COMMAND ${CMAKE_COMMAND} -E copy "${CURRENT_PATH}" "${OUTFILE}"
122+
DEPENDS "${CURRENT_PATH}"
123+
COMMENT "Validating and copying ${CURRENT_FILE}"
124+
)
125+
list(APPEND SQL_TARGET_FILES ${OUTFILE})
126+
endforeach(CURRENT_FILE ${LEGACY_SQL_FILES})
127+
128+
# END Legacy Code
129+
add_custom_target(sqlFiles_${PORT_LC} ALL DEPENDS ${SQL_TARGET_FILES})
130+
131+
132+
# -- 3. Install all SQL files --------------------------------------------------
133+
134+
cpack_add_port_group_and_component_for_all_versions()
135+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules
136+
DESTINATION ports/${PORT_DIR_NAME}
137+
COMPONENT ${PORT_LC}_any
138+
REGEX "^(.*/)?\\.DS_Store\$" EXCLUDE
139+
)
140+
141+
142+
# -- 4. Building the shared library is specific for each version of
143+
# this port --------------------------------------------------------------
144+
145+
function(add_${PORT_LC}_library IN_PORT_VERSION)
146+
add_definitions("-DIS_CLOUDBERRY")
147+
string(REPLACE "." "_" PORT_VERSION_UNDERSCORE "${IN_PORT_VERSION}")
148+
set(DBMS "${PORT_LC}_${PORT_VERSION_UNDERSCORE}")
149+
set(DBMS_UC "${PORT_UC}_${PORT_VERSION_UNDERSCORE}")
150+
151+
# -- 4.1. Compile C/C++ files---------------------------------------------------
152+
153+
message(">> Adding ${PORT} "
154+
"${IN_PORT_VERSION} "
155+
"(${${DBMS_UC}_ARCHITECTURE}) "
156+
"to target list...")
157+
158+
add_executable(${DBMS} IMPORTED)
159+
set_target_properties(${DBMS} PROPERTIES
160+
IMPORTED_LOCATION "${${DBMS_UC}_EXECUTABLE}"
161+
)
162+
163+
include_directories(SYSTEM
164+
${${DBMS_UC}_SERVER_INCLUDE_DIR}
165+
${${DBMS_UC}_ADDITIONAL_INCLUDE_DIRS}
166+
)
167+
168+
add_madlib_connector_library(madlib_${DBMS}
169+
lib
170+
"${${DBMS_UC}_EXECUTABLE}"
171+
${MAD_DBAL_SOURCES}
172+
)
173+
174+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
175+
# The source code specifies that we are POSIX.1-2001 compliant:
176+
# On the Mac, this is done in $GP_HOME/include/pg_config_manual.h.
177+
# On Linux, gcc predefines _GNU_SOURCE, which leads to
178+
# _POSIX_C_SOURCE being defined in /usr/include/features.h
179+
# We therefore define HAVE_ERAND48, so that lrand48 is not redeclared
180+
# in $GP_HOME/include/postgresql/server/port.h.
181+
set_source_files_properties(${MAD_DBAL_SOURCES} PROPERTIES
182+
COMPILE_FLAGS "-DHAVE_ERAND48 ${ADDITIONAL_GCC_FLAGS}")
183+
get_property(_OLD_VALUE TARGET madlib_${DBMS} PROPERTY LINK_FLAGS)
184+
# If property has not been initialized, _OLD_VALUE is "_OLD_VALUE-NOTFOUND"
185+
set_target_properties(madlib_${DBMS} PROPERTIES
186+
LINK_FLAGS "${_OLD_VALUE} ${ADDITIONAL_GCC_FLAGS}")
187+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
188+
# In syncbitvector.h, an array has zero length. This is non-standard,
189+
# but most compilers allow it. SunPro needs an extra option.
190+
set_source_files_properties(${MAD_DBAL_SOURCES} PROPERTIES
191+
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -features=zla")
192+
endif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
193+
194+
# FIXME: Convert legacy source code written in C
195+
# BEGIN Legacy Code
196+
197+
# From the CMake documentation:
198+
# "Source file properties are visible only to targets added in the same
199+
# directory (CMakeLists.txt)." We therefore have to set them for each
200+
# version of this port!
201+
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
202+
# FIXME: Is there a portable (not just for gcc) way of including a header file?
203+
# Due to Greenplum bug MPP-13254, we need to include <sys/time.h>
204+
# before <postgres.h>
205+
# FIXME: In the C code, we have several places where strict aliasing
206+
# rules are violated. See this web page for some background:
207+
# http://dbp-consulting.com/tutorials/StrictAliasing.html
208+
# For now, we tell GCC that it cannot rely on strict aliasing rules.
209+
# Downside: We forgo some potential optimization.
210+
# The warning GCC would output without -fno-strict-aliasing is:
211+
# dereferencing type-punned pointer will break strict-aliasing rules
212+
set_source_files_properties(${LEGACY_C_FILES} PROPERTIES
213+
COMPILE_FLAGS "-fno-strict-aliasing -include sys/time.h ${ADDITIONAL_GCC_FLAGS}")
214+
endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
215+
216+
set_source_files_properties(${LEGACY_C_FILES} PROPERTIES
217+
COMPILE_DEFINITIONS "NO_PG_MODULE_MAGIC"
218+
)
219+
220+
# sparse_vector.c indirectly includes openssl/ssl.h (via libpq/libpq-be.h)
221+
# removed due to we take out libpq/libpq-be.h
222+
# include_directories(SYSTEM ${${DBMS_UC}_CLIENT_INCLUDE_DIR})
223+
224+
# END Legacy Code
225+
226+
227+
# -- 4.2. Preprocess all Python files ------------------------------------------
228+
229+
define_cloudberry_features(${IN_PORT_VERSION} DBMS_FEATURES)
230+
define_m4_macros(M4_DEFINES_CMD_LINE M4_DEFINES_CODE ${DBMS_FEATURES})
231+
232+
add_python_files(
233+
PYTHON_TARGET_FILES
234+
"${PORT_SOURCE_DIR}/../postgres/modules"
235+
"${CMAKE_CURRENT_BINARY_DIR}/modules"
236+
${M4_DEFINES_CMD_LINE}
237+
)
238+
# FIXME: Check legacy code for compliance with new architecture
239+
# BEGIN Legacy Code
240+
241+
file(GLOB_RECURSE LEGACY_PYTHON_FILES RELATIVE
242+
"${CMAKE_SOURCE_DIR}/methods"
243+
"${CMAKE_SOURCE_DIR}/methods/*.py_in")
244+
foreach(CURRENT_FILE ${LEGACY_PYTHON_FILES})
245+
get_filename_component(CURRENT_PATH "${CMAKE_SOURCE_DIR}/methods/${CURRENT_FILE}" ABSOLUTE)
246+
set(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/modules/${CURRENT_FILE}")
247+
string(REPLACE "/src/pg_gp" "" OUTFILE ${OUTFILE})
248+
string(REGEX REPLACE ".py_in\$" ".py" OUTFILE ${OUTFILE})
249+
get_dir_name(OUTDIR ${OUTFILE})
250+
add_custom_command(OUTPUT "${OUTFILE}"
251+
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTDIR}"
252+
COMMAND ${M4_BINARY} ${M4_ARGUMENTS} ${M4_DEFINES_CMD_LINE}
253+
"${CURRENT_PATH}" > "${OUTFILE}"
254+
DEPENDS "${CURRENT_PATH}"
255+
COMMENT "Preprocessing ${CURRENT_FILE} with m4."
256+
)
257+
list(APPEND PYTHON_TARGET_FILES ${OUTFILE})
258+
endforeach(CURRENT_FILE ${LEGACY_PYTHON_FILES})
259+
260+
# END Legacy Code
261+
262+
configure_file("${PORT_SOURCE_DIR}/../postgres/madpack/SQLCommon.m4_in"
263+
"${CMAKE_CURRENT_BINARY_DIR}/madpack/SQLCommon.m4"
264+
@ONLY
265+
)
266+
267+
add_custom_target(pythonFiles_${DBMS} ALL
268+
DEPENDS ${PYTHON_TARGET_FILES})
269+
270+
271+
# -- 4.3. Install shared library, Python files, and M4 header ------------------
272+
273+
cpack_add_version_component()
274+
install(TARGETS madlib_${DBMS}
275+
LIBRARY DESTINATION ports/${PORT_DIR_NAME}/${IN_PORT_VERSION}/lib
276+
COMPONENT ${DBMS}
277+
)
278+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules
279+
DESTINATION ports/${PORT_DIR_NAME}/${IN_PORT_VERSION}
280+
COMPONENT ${DBMS}
281+
REGEX "^(.*/)?\\.DS_Store\$" EXCLUDE
282+
)
283+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/madpack/SQLCommon.m4"
284+
DESTINATION ports/${PORT_DIR_NAME}/${IN_PORT_VERSION}/madpack
285+
COMPONENT ${DBMS}
286+
)
287+
288+
# -- 4.4. Generate gppkg deployment scripts. Note: These are generated CMake
289+
# scripts! ---------------------------------------------------------------
290+
add_gppkg(${IN_PORT_VERSION} Cloudberry cbdb 1.0)
291+
292+
endfunction(add_${PORT_LC}_library)
293+
294+
295+
# -- 5. Provide a macro to be called from CMakeLists.txt in the version
296+
# directory. We want these files to be one-liners. -----------------------
297+
298+
# Add the current version as a target. This is a macro because it calls
299+
# find_package, and we want the side effects (the defined variables) to be
300+
# visible after the invocation
301+
macro(add_current_${PORT_LC}_version)
302+
get_filename_component(_VERSION "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
303+
string(REPLACE "." "_" _VERSION_UNDERSCORES ${_VERSION})
304+
305+
find_package(${PORT}_${_VERSION_UNDERSCORES})
306+
if(${PORT_UC}_${_VERSION_UNDERSCORES}_FOUND)
307+
add_cloudberry_library(${_VERSION})
308+
endif(${PORT_UC}_${_VERSION_UNDERSCORES}_FOUND)
309+
endmacro(add_current_${PORT_LC}_version)
310+
311+
312+
# -- 6. Build shared library and copy version-specific file for all
313+
# ${PORT_UC}_X_Y_PG_CONFIG macros defined by the user. If none has been
314+
# defined, try to find any version this port. ----------------------------
315+
316+
determine_target_versions(VERSIONS)
317+
foreach(VERSION ${VERSIONS})
318+
add_subdirectory(${VERSION})
319+
endforeach(VERSION)

0 commit comments

Comments
 (0)