diff --git a/db-service/lib/cqn2sql.js b/db-service/lib/cqn2sql.js index 72cd82d1a..0093786ee 100644 --- a/db-service/lib/cqn2sql.js +++ b/db-service/lib/cqn2sql.js @@ -197,6 +197,7 @@ class CQN2SQLRenderer { Association: () => false, Composition: () => false, array: () => 'NCLOB', + Map: () => 'NCLOB', // HANA types 'cds.hana.TINYINT': () => 'TINYINT', 'cds.hana.REAL': () => 'REAL', diff --git a/db-service/lib/cqn4sql.js b/db-service/lib/cqn4sql.js index 70a06737b..e75da05e1 100644 --- a/db-service/lib/cqn4sql.js +++ b/db-service/lib/cqn4sql.js @@ -1286,7 +1286,7 @@ function cqn4sql(originalQuery, model) { } } return flatColumns - } else if (element.elements) { + } else if (element.elements && element.type !== 'cds.Map') { const flatRefs = [] Object.values(element.elements).forEach(e => { const alias = columnAlias ? `${columnAlias}_${e.name}` : null diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index b4c8655ac..63001a6a8 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -1160,6 +1160,7 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction})) AS NEW LE LargeBinary: () => `NVARCHAR(2147483647)`, Binary: () => `NVARCHAR(2147483647)`, array: () => `NVARCHAR(2147483647) FORMAT JSON`, + Map: () => `NVARCHAR(2147483647) FORMAT JSON`, Vector: () => `NVARCHAR(2147483647)`, Decimal: () => `DECIMAL`, diff --git a/postgres/lib/PostgresService.js b/postgres/lib/PostgresService.js index 80f909f37..e5ba727ba 100644 --- a/postgres/lib/PostgresService.js +++ b/postgres/lib/PostgresService.js @@ -512,6 +512,7 @@ GROUP BY k Time: () => 'TIME', DateTime: () => 'TIMESTAMP', Timestamp: () => 'TIMESTAMP', + Map: () => 'JSONB', // HANA Types 'cds.hana.CLOB': () => 'BYTEA', @@ -542,6 +543,7 @@ GROUP BY k DecimalFloat: (e, t) => e[0] === '$' ? e : `CAST(${e} as decimal${t.precision && t.scale ? `(${t.precision},${t.scale})` : ''})`, Binary: e => e[0] === '$' ? e : `DECODE(${e},'base64')`, LargeBinary: e => e[0] === '$' ? e : `DECODE(${e},'base64')`, + Map: e => e[0] === '$' ? e : `CAST(${e} as jsonb)`, // HANA Types 'cds.hana.CLOB': e => e[0] === '$' ? e : `DECODE(${e},'base64')`, diff --git a/sqlite/lib/SQLiteService.js b/sqlite/lib/SQLiteService.js index a59e13995..71fd606d5 100644 --- a/sqlite/lib/SQLiteService.js +++ b/sqlite/lib/SQLiteService.js @@ -247,6 +247,7 @@ class SQLiteService extends SQLService { Time: () => 'TIME_TEXT', DateTime: () => 'DATETIME_TEXT', Timestamp: () => 'TIMESTAMP_TEXT', + Map: () => 'JSON_TEXT' } get is_distinct_from_() { diff --git a/test/bookshop/db/schema.cds b/test/bookshop/db/schema.cds index 61924d33f..88a22c00b 100644 --- a/test/bookshop/db/schema.cds +++ b/test/bookshop/db/schema.cds @@ -67,5 +67,6 @@ entity C : managed { B : Integer; toB : Composition of many B on toB.ID = $self.B; -}; +} + entity BooksAnnotated as projection on Books; diff --git a/test/compliance/literals.test.js b/test/compliance/literals.test.js index 68026f9e0..e8c65060c 100644 --- a/test/compliance/literals.test.js +++ b/test/compliance/literals.test.js @@ -56,4 +56,10 @@ describe('literals', () => { throw new Error('not supported') }) }) + + describe('maps', () => { + test.skip('missing', () => { + throw new Error('not supported') + }) + }) }) diff --git a/test/compliance/resources/db/basic/literals.cds b/test/compliance/resources/db/basic/literals.cds index fd6aa5ed6..1c54c9d4d 100644 --- a/test/compliance/resources/db/basic/literals.cds +++ b/test/compliance/resources/db/basic/literals.cds @@ -58,6 +58,10 @@ entity array { integer : array of Integer; } +entity map { + map : Map; +} + entity binaries { binary : Binary; largebinary : LargeBinary; diff --git a/test/compliance/resources/db/basic/literals/basic.literals.map.js b/test/compliance/resources/db/basic/literals/basic.literals.map.js new file mode 100644 index 000000000..0343f2602 --- /dev/null +++ b/test/compliance/resources/db/basic/literals/basic.literals.map.js @@ -0,0 +1,20 @@ +module.exports = [ + { + map: null, + }, + { + map: {}, + }, + { + map: { key: null }, + }, + { + map: { key: 'value' }, + }, + { + map: { a: { b: { c: 3 } } }, + }, + { + map: { a: [{ b: 1 }, { c: 2 }] }, + }, +]