Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support current_utctimestamp #865

Merged
merged 16 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this function definition into the other databases?
Then the test can be move here:

describe('CURRENT_UTCTIME', () => {
test.skip('missing', () => {
throw new Error('not supported')
})
})
describe('CURRENT_UTCTIMESTAMP', () => {
test.skip('missing', () => {
throw new Error('not supported')
})
})

Copy link
Contributor Author

@johannes-vogel johannes-vogel Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially started there but the other databases don't support the argument, I could also split: noargs in compliance and args in hana native section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#909 but I don't like the different behavior on the dbs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good finding that the databases have different response formats. The purpose of the cal-functions is to define them in a way that they response in the correct format. Most likely adding a cast or element to the original func can apply the correct output converter for each database.


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
})
})
})
Loading