Skip to content

Commit

Permalink
Added Geometry and Geography datatype related metadata support to the… (
Browse files Browse the repository at this point in the history
#2293)

* Added Geometry and Geography datatype related metadata support to the… (#2277)

* Added Geometry and Geography datatype related metadata support to the system views

Signed-off-by: Anikait Agrawal <[email protected]>

* Fixed datatype MetaData and expected output file differences

Signed-off-by: Anikait Agrawal <[email protected]>

* Resolved Github action failures

Signed-off-by: Anikait Agrawal <[email protected]>

* Updated Expected output files

Signed-off-by: Anikait Agrawal <[email protected]>

* Reverted extra changes

Signed-off-by: Anikait Agrawal <[email protected]>

* Resolved Comments

Signed-off-by: Anikait Agrawal <[email protected]>

* Resolved Github Action Failures

Signed-off-by: Anikait Agrawal <[email protected]>

* Resolved Github Action Failures

Signed-off-by: Anikait Agrawal <[email protected]>

* Resolved Github Action Failures

Signed-off-by: Anikait Agrawal <[email protected]>

* Updated test files

---------

Signed-off-by: Anikait Agrawal <[email protected]>
Co-authored-by: Anikait Agrawal <[email protected]>

* Updated upgrade file

Signed-off-by: Anikait Agrawal <[email protected]>

---------

Signed-off-by: Anikait Agrawal <[email protected]>
Co-authored-by: Anikait Agrawal <[email protected]>
  • Loading branch information
Anikait143 and Anikait Agrawal authored Jan 25, 2024
1 parent 9f67648 commit 4e200d1
Show file tree
Hide file tree
Showing 64 changed files with 564 additions and 78 deletions.
7 changes: 6 additions & 1 deletion contrib/babelfishpg_common/src/typecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ type_info_t type_infos[TOTAL_TYPECODE_COUNT] =
{0, 1, "decimal", "decimal", 5, 30, 5},
{0, 1, "sysname", "sysname", 5, 31, 5},
{0, 1, "rowversion", "timestamp", 8, 32, 3},
{0, 1, "timestamp", "timestamp", 8, 33, 3}
{0, 1, "timestamp", "timestamp", 8, 33, 3},
/*
* Geospatial types cannot be stored in SQL variant so setting sqlvariant header size to 1
*/
{0, 1, "geometry", "geometry", 5, 34, 1},
{0, 1, "geography", "geography", 5, 35, 1}
};

/* Hash tables to help backward searching (from OID to Persist ID) */
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_common/src/typecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define FIXEDDECIMAL_MULTIPLIER 10000LL
#endif

#define TOTAL_TYPECODE_COUNT 33
#define TOTAL_TYPECODE_COUNT 35

struct Node;

Expand Down
5 changes: 5 additions & 0 deletions contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ GRANT SELECT ON sys.spt_datatype_info_table TO PUBLIC;
INSERT INTO sys.spt_datatype_info_table VALUES (N'datetimeoffset', -155, 34, N'''', N'''', N'scale ', 1, 0, 3, NULL, 0, NULL, N'datetimeoffset', 0, 7, -155, 0, NULL, NULL, 0, 68, 0, 'datetimeoffset');
INSERT INTO sys.spt_datatype_info_table VALUES (N'time', -154, 16, N'''', N'''', N'scale ', 1, 0, 3, NULL, 0, NULL, N'time', 0, 7, -154, 0, NULL, NULL, 0, 32, 0, 'time');
INSERT INTO sys.spt_datatype_info_table VALUES (N'xml', -152, 0, N'N''', N'''', NULL, 1, 1, 0, NULL, 0, NULL, N'xml', NULL, NULL, -152, NULL, NULL, NULL, 0, 2147483646, 0, N'xml');
INSERT INTO sys.spt_datatype_info_table VALUES (N'geometry', -151, 0, NULL, NULL, NULL, 1, 1, 0, NULL, 0, NULL, N'geometry', NULL, NULL, -151, NULL, NULL, NULL, 0, 2147483646, 23, NULL);
INSERT INTO sys.spt_datatype_info_table VALUES (N'geography', -151, 0, NULL, NULL, NULL, 1, 1, 0, NULL, 0, NULL, N'geography', NULL, NULL, -151, NULL, NULL, NULL, 0, 2147483646, 23, NULL);
INSERT INTO sys.spt_datatype_info_table VALUES (N'sql_variant', -150, 8000, NULL, NULL, NULL, 1, 0, 2, NULL, 0, NULL, N'sql_variant', 0, 0, -150, NULL, 10, NULL, 0, 8000, 39, 'sql_variant');
INSERT INTO sys.spt_datatype_info_table VALUES (N'uniqueidentifier', -11, 36, N'''', N'''', NULL, 1, 0, 2, NULL, 0, NULL, N'uniqueidentifier', NULL, NULL, -11, NULL, NULL, NULL, 0, 16, 37, 'uniqueidentifier');
INSERT INTO sys.spt_datatype_info_table VALUES (N'ntext', -10, 1073741823, N'N''', N'''', NULL, 1, 1, 1, NULL, 0, NULL, N'ntext', NULL, NULL, -10, NULL, NULL, NULL, 0, 2147483646, 35, NULL);
Expand Down Expand Up @@ -283,6 +285,7 @@ BEGIN
WHEN type in ('text', 'image') THEN length = 2147483647;
WHEN type = 'ntext' THEN length = 2147483646;
WHEN type = 'xml' THEN length = 0;
WHEN type IN ('geometry', 'geography') THEN length = -1;
WHEN type = 'sql_variant' THEN length = 8000;
WHEN type = 'money' THEN length = 21;
WHEN type = 'sysname' THEN length = (typemod - 4) * 2;
Expand Down Expand Up @@ -636,6 +639,8 @@ BEGIN
WHEN 'sql_variant' THEN tds_id = 98;
WHEN 'datetimeoffset' THEN tds_id = 43;
WHEN 'timestamp' THEN tds_id = 173;
WHEN 'geometry' THEN tds_id = 240;
WHEN 'geography' THEN tds_id = 240;
ELSE tds_id = 0;
END CASE;
RETURN tds_id;
Expand Down
6 changes: 3 additions & 3 deletions contrib/babelfishpg_tsql/sql/information_schema_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $$SELECT
THEN 1073741823
WHEN type = 'sysname'
THEN 128
WHEN type = 'xml'
WHEN type IN ('xml', 'geometry', 'geography')
THEN -1
WHEN type = 'sql_variant'
THEN 0
Expand Down Expand Up @@ -89,7 +89,7 @@ $$SELECT
THEN 256
WHEN type = 'sql_variant'
THEN 0
WHEN type = 'xml'
WHEN type IN ('xml', 'geometry', 'geography')
THEN -1
ELSE null
END$$;
Expand All @@ -112,7 +112,7 @@ $$SELECT
THEN 1073741823
WHEN type = 'sysname'
THEN 128
WHEN type = 'xml'
WHEN type IN ('xml', 'geometry', 'geography')
THEN -1
WHEN type = 'sql_variant'
THEN 0
Expand Down
15 changes: 13 additions & 2 deletions contrib/babelfishpg_tsql/sql/sys_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ BEGIN
END IF;
WHEN v_type in ('binary', 'char', 'bpchar', 'nchar') THEN max_length = 8000;
WHEN v_type in ('decimal', 'numeric') THEN max_length = 17;
WHEN v_type in ('geometry', 'geography') THEN max_length = -1;
ELSE max_length = typemod;
END CASE;
RETURN max_length;
Expand Down Expand Up @@ -1105,7 +1106,12 @@ select
END as collation_name
, case when typnotnull then cast(0 as sys.bit) else cast(1 as sys.bit) end as is_nullable
, CAST(0 as sys.bit) as is_user_defined
, CAST(0 as sys.bit) as is_assembly_type
, CASE tsql_type_name
-- CLR UDT have is_assembly_type = 1
WHEN 'geometry' THEN CAST(1 as sys.bit)
WHEN 'geography' THEN CAST(1 as sys.bit)
ELSE CAST(0 as sys.bit)
END as is_assembly_type
, CAST(0 as int) as default_object_id
, CAST(0 as int) as rule_object_id
, CAST(0 as sys.bit) as is_table_type
Expand Down Expand Up @@ -1138,7 +1144,12 @@ select cast(t.typname as sys.sysname) as name
as is_nullable
-- CREATE TYPE ... FROM is implemented as CREATE DOMAIN in babel
, CAST(1 as sys.bit) as is_user_defined
, CAST(0 as sys.bit) as is_assembly_type
, CASE tsql_type_name
-- CLR UDT have is_assembly_type = 1
WHEN 'geometry' THEN CAST(1 as sys.bit)
WHEN 'geography' THEN CAST(1 as sys.bit)
ELSE CAST(0 as sys.bit)
END as is_assembly_type
, CAST(0 as int) as default_object_id
, CAST(0 as int) as rule_object_id
, case when tt.typrelid is not null then CAST(1 as sys.bit) else CAST(0 as sys.bit) end as is_table_type
Expand Down
Loading

0 comments on commit 4e200d1

Please sign in to comment.