Skip to content

Commit

Permalink
feat: support current_utctimestamp (#865)
Browse files Browse the repository at this point in the history
works locally with SAP HANA Cloud but does not work with HXE

---------

Co-authored-by: Samuel Brucksch <SamuelBrucksch@users.noreply.github.com>
  • Loading branch information
johannes-vogel and SamuelBrucksch authored Nov 22, 2024
1 parent f6593e6 commit aaf39ad
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions hana/lib/cql-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const StandardFunctions = {
current_date: () => 'current_utcdate',
current_time: () => 'current_utctime',
current_timestamp: () => 'current_utctimestamp',
current_utctimestamp: x => x ? `current_utctimestamp(${x})` : 'current_utctimestamp',
fractionalseconds: x => `(TO_DECIMAL(SECOND(${x}),5,3) - TO_INTEGER(SECOND(${x})))`,
}

Expand Down
50 changes: 50 additions & 0 deletions hana/test/hana-functions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const cds = require('../../test/cds')

describe('HANA native functions', () => {
const { expect } = cds.test(__dirname, 'fuzzy.cds')

describe('current_timestamp', () => {
test('no arguments', async () => {
const cqn = { SELECT: {
one: true,
from: {ref: ['DUMMY']},
columns: [{func: 'current_utctimestamp', as: 'NO'}]
}}

const res = await cds.run(cqn)

expect(res.NO.match(/\.(\d\d\d)0000/)).not.to.be.null // default 3
})

// HXE does not allow args
test.skip('0 skips ms precision', async () => {
const cqn = { SELECT: {
one: true,
from: {ref: ['DUMMY']},
columns: [
{func: 'current_utctimestamp', as: 'NO'},
{func: 'current_utctimestamp', args: [{val: 0}], as: 'P0'}]
}}

const res = await cds.run(cqn)

expect(res.P0.match(/\.0000000/)).not.to.be.null
})

// HXE does not allow args
test.skip('arbitrary values', async () => {
const cqn = { SELECT: {
one: true,
from: {ref: ['DUMMY']},
columns: [
{func: 'current_utctimestamp', args: [{val: 3}], as: 'P3'},
{func: 'current_utctimestamp', args: [{val: 7}], as: 'P7'}]
}}

const res = await cds.run(cqn)

expect(res.P3.match(/\.(\d\d\d)0000/)).not.to.be.null
expect(res.P7.match(/\.(\d\d\d\d\d\d\d)/)).not.to.be.null
})
})
})

0 comments on commit aaf39ad

Please sign in to comment.