Skip to content

Commit

Permalink
Initial commit for Babelfish v3.10 (#3453)
Browse files Browse the repository at this point in the history
This commit contains the following changes:
- Add version info and upgrade test for 14.16.
- Add upgrade schedule files for 14.16.
- Bump babelfish_version from 2.12.0 to 2.13.0

Signed-off-by: manisha-deshpande <[email protected]>
Co-authored-by: Rishabh Tanwar <[email protected]>
  • Loading branch information
manisha-deshpande and ritanwar authored Feb 7, 2025
1 parent ffbbfbd commit 1b6999f
Show file tree
Hide file tree
Showing 19 changed files with 1,230 additions and 15 deletions.
32 changes: 28 additions & 4 deletions .github/configuration/upgrade-test-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ upgrade-version: [{
}
],
},
{
upgrade-path: [
{
version: '14.16',
upgrade-type: null
},
{
version: target.latest,
upgrade-type: major
}
],
},
{
upgrade-path: [
{
version: '14.17',
upgrade-type: null
},
{
version: target.latest,
upgrade-type: major
}
],
},
{
upgrade-path: [
{
Expand Down Expand Up @@ -149,7 +173,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: '15.10',
version: '15.11',
upgrade-type: null
},
{
Expand Down Expand Up @@ -187,7 +211,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: '14.15',
version: '14.16',
upgrade-type: null
},
{
Expand All @@ -204,7 +228,7 @@ upgrade-version: [{
upgrade-type: null,
},
{
version: '14.15',
version: '14.16',
upgrade-type: major,
},
{
Expand All @@ -221,7 +245,7 @@ upgrade-version: [{
upgrade-type: null,
},
{
version: '14.15',
version: '14.16',
upgrade-type: minor,
},
{
Expand Down
6 changes: 6 additions & 0 deletions .github/template/version-branch-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
engine_branch: BABEL_2_11_STABLE__PG_14_15
extension_branch: BABEL_2_11_STABLE
'14.16':
engine_branch: BABEL_2_12_STABLE__PG_14_16
extension_branch: BABEL_2_12_STABLE
'14.17':
engine_branch: BABEL_2_X_DEV__PG_14_X
extension_branch: BABEL_2_X_DEV
'15.2':
Expand All @@ -76,6 +79,9 @@
'15.10':
engine_branch: BABEL_3_8_STABLE__PG_15_10
extension_branch: BABEL_3_8_STABLE
'15.11':
engine_branch: BABEL_3_9_STABLE__PG_15_11
extension_branch: BABEL_3_9_STABLE
'source.latest':
engine_branch: latest
extension_branch: latest
Expand Down
9 changes: 8 additions & 1 deletion contrib/babelfishpg_common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ GENERATED_UPGRADES = \
sql/$(EXTENSION)--3.4.0--3.5.0.sql \
sql/$(EXTENSION)--3.5.0--3.6.0.sql \
sql/$(EXTENSION)--3.6.0--3.7.0.sql \
sql/$(EXTENSION)--3.7.0--3.8.0.sql
sql/$(EXTENSION)--3.7.0--3.8.0.sql \
sql/$(EXTENSION)--3.8.0--3.9.0.sql

ifdef PREV_EXTVERSION
DATA = sql/$(EXTENSION)--$(PREV_EXTVERSION).sql
Expand Down Expand Up @@ -123,6 +124,9 @@ ifeq (,$(filter $(FLAG_TO_CHECK),$(PG_CPPFLAGS)))
sql/$(EXTENSION)--3.7.0--3.8.0.sql: sql/upgrades/babelfishpg_upgrades.in
cpp -D PREV_VERSION=3.7.0 -D CUR_VERSION=3.8.0 $< | sed 's/^# /-- /g' > $@

sql/$(EXTENSION)--3.8.0--3.9.0.sql: sql/upgrades/babelfishpg_upgrades.in
cpp -D PREV_VERSION=3.8.0 -D CUR_VERSION=3.9.0 $< | sed 's/^# /-- /g' > $@

else
# The flag is present build the .in file including the spatial type files
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).in
Expand All @@ -146,6 +150,9 @@ else
sql/$(EXTENSION)--3.7.0--3.8.0.sql: sql/upgrades/babelfishpg_upgrades.in
cpp -D ENABLE_SPATIAL_TYPES=1 -D PREV_VERSION=3.7.0 -D CUR_VERSION=3.8.0 $< | sed 's/^# /-- /g' > $@

sql/$(EXTENSION)--3.8.0--3.9.0.sql: sql/upgrades/babelfishpg_upgrades.in
cpp -D ENABLE_SPATIAL_TYPES=1 -D PREV_VERSION=3.8.0 -D CUR_VERSION=3.9.0 $< | sed 's/^# /-- /g' > $@

endif

sql/babelfishpg_common--%.sql: sql/upgrades/babelfishpg_common--%.sql
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_common/Version.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BBFPGCMN_MAJOR_VERSION=3
BBFPGCMN_MINOR_VERSION=8
BBFPGCMN_MINOR_VERSION=9
BBFPGCMN_MICRO_VERSION=0

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
------------------------------------------------------------------------------
---- Include changes related to other datatypes except spatial types here ----
------------------------------------------------------------------------------

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_common"" UPDATE TO "3.9.0"" to load this file. \quit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-------------------------------------------------------
---- Include changes related to spatial types here ----
-------------------------------------------------------
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/Version.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# places during the build process

PGTSQL_MAJOR_VERSION=3
PGTSQL_MINOR_VERSION=9
PGTSQL_MINOR_VERSION=10
PGTSQL_MICRO_VERSION=0

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '3.0.0'" to load this file. \quit

-- add 'sys' to search path for the convenience
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false);

-- please add your SQL here

CREATE OR REPLACE FUNCTION sys.babelfish_update_server_collation_name() RETURNS VOID
LANGUAGE C
AS 'babelfishpg_common', 'babelfish_update_server_collation_name';

SELECT sys.babelfish_update_server_collation_name();

DROP FUNCTION sys.babelfish_update_server_collation_name();

-- reset babelfishpg_tsql.restored_server_collation_name GUC
do
language plpgsql
$$
declare
query text;
begin
query := pg_catalog.format('alter database %s reset babelfishpg_tsql.restored_server_collation_name', CURRENT_DATABASE());
execute query;
end;
$$;

CREATE OR REPLACE FUNCTION sys.datepart_internal(IN datepart PG_CATALOG.TEXT, IN arg anyelement,IN df_tz INTEGER DEFAULT 0) RETURNS INTEGER AS $$
DECLARE
result INTEGER;
first_day DATE;
first_week_end INTEGER;
day INTEGER;
BEGIN
CASE datepart
WHEN 'dow' THEN
result = (date_part(datepart, arg)::INTEGER - current_setting('babelfishpg_tsql.datefirst')::INTEGER + 7) % 7 + 1;
WHEN 'tsql_week' THEN
first_day = make_date(date_part('year', arg)::INTEGER, 1, 1);
first_week_end = 8 - sys.datepart_internal('dow', first_day)::INTEGER;
day = date_part('doy', arg)::INTEGER;
IF day <= first_week_end THEN
result = 1;
ELSE
result = 2 + (day - first_week_end - 1) / 7;
END IF;
WHEN 'second' THEN
result = TRUNC(date_part(datepart, arg))::INTEGER;
WHEN 'millisecond' THEN
result = right(date_part(datepart, arg)::TEXT, 3)::INTEGER;
WHEN 'microsecond' THEN
result = right(date_part(datepart, arg)::TEXT, 6)::INTEGER;
WHEN 'nanosecond' THEN
-- Best we can do - Postgres does not support nanosecond precision
result = right(date_part('microsecond', arg)::TEXT, 6)::INTEGER * 1000;
WHEN 'tzoffset' THEN
-- timezone for datetimeoffset
result = df_tz;
ELSE
result = date_part(datepart, arg)::INTEGER;
END CASE;
RETURN result;
EXCEPTION WHEN invalid_parameter_value or feature_not_supported THEN
-- date_part() throws an exception when trying to get day/month/year etc. from
-- TIME, so we just need to catch the exception in this case
-- date_part() returns 0 when trying to get hour/minute/second etc. from
-- DATE, which is the desirable behavior for datepart() as well.
-- If the date argument data type does not have the specified datepart,
-- date_part() will return the default value for that datepart.
CASE datepart
-- Case for datepart is year, yy and yyyy, all mappings are defined in gram.y.
WHEN 'year' THEN RETURN 1900;
-- Case for datepart is quater, qq and q
WHEN 'quarter' THEN RETURN 1;
-- Case for datepart is month, mm and m
WHEN 'month' THEN RETURN 1;
-- Case for datepart is day, dd and d
WHEN 'day' THEN RETURN 1;
-- Case for datepart is dayofyear, dy
WHEN 'doy' THEN RETURN 1;
-- Case for datepart is y(also refers to dayofyear)
WHEN 'y' THEN RETURN 1;
-- Case for datepart is week, wk and ww
WHEN 'tsql_week' THEN RETURN 1;
-- Case for datepart is iso_week, isowk and isoww
WHEN 'week' THEN RETURN 1;
-- Case for datepart is tzoffset and tz
WHEN 'tzoffset' THEN RETURN 0;
-- Case for datepart is weekday and dw, return dow according to datefirst
WHEN 'dow' THEN
RETURN (1 - current_setting('babelfishpg_tsql.datefirst')::INTEGER + 7) % 7 + 1 ;
ELSE
RAISE EXCEPTION '''%'' is not a recognized datepart option', datepart;
RETURN -1;
END CASE;
END;
$$
STRICT
LANGUAGE plpgsql IMMUTABLE;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '3.10.0'" to load this file. \quit

-- add 'sys' to search path for the convenience
SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false);

-- Please add your SQLs here
/*
* Note: These SQL statements may get executed multiple times specially when some features get backpatched.
* So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting
* final behaviour.
*/


-- After upgrade, always run analyze for all babelfish catalogs.
CALL sys.analyze_babelfish_catalogs();

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/babelfish_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*-------------------------------------------------------------------------
*/

#define BABELFISH_VERSION_STR "3.9.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 15.11.0.0"
#define BABELFISH_VERSION_STR "3.10.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 15.12.0.0"
#define BABEL_COMPATIBILITY_VERSION "12.0.2000.8"
#define BABEL_COMPATIBILITY_MAJOR_VERSION "12"
2 changes: 1 addition & 1 deletion test/JDBC/expected/BABEL-3514.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- psql
select
cast(case when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
cast(case when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid babelfish version'
else 'invalid babelfish version' end as text);
GO
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/babel_collection.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GO
-- check the babelfish version
select cast(
case
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid'
else 'invalid'
end as sys.varchar(20));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GO
-- check the babelfish version
select cast(
case
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid'
else 'invalid'
end as sys.varchar(20));
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/parallel_query/babel_collection.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GO
-- check the babelfish version
select cast(
case
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid'
else 'invalid'
end as sys.varchar(20));
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/input/BABEL-3514.mix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- psql
select
cast(case when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
cast(case when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid babelfish version'
else 'invalid babelfish version' end as text);
GO
2 changes: 1 addition & 1 deletion test/JDBC/input/babel_collection.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GO
-- check the babelfish version
select cast(
case
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._._'
when cast(sys.SERVERPROPERTY('BabelfishVersion') as varchar(20)) LIKE '_._%._'
THEN 'valid'
else 'invalid'
end as sys.varchar(20));
Expand Down
Loading

0 comments on commit 1b6999f

Please sign in to comment.