@malloydata/malloy 0.0.179-dev240904162124 → 0.0.179-dev240904175913
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -92,8 +92,8 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
|
|
|
92
92
|
if (this.exprSrc) {
|
|
93
93
|
template.code = this.exprSrc;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if ((0, granular_result_1.isGranularResult)(exprValue) &&
|
|
96
|
+
(template.type === 'timestamp' || template.type === 'date')) {
|
|
97
97
|
template.timeframe = exprValue.timeframe;
|
|
98
98
|
}
|
|
99
99
|
if (this.note) {
|
|
@@ -62,24 +62,31 @@ function exprToString(e, symbols = {}) {
|
|
|
62
62
|
describe('expressions', () => {
|
|
63
63
|
describe('timeframes', () => {
|
|
64
64
|
const timeframes = [
|
|
65
|
-
'second',
|
|
66
|
-
'minute',
|
|
67
|
-
'hour',
|
|
68
|
-
'day',
|
|
69
|
-
'week',
|
|
70
|
-
'month',
|
|
71
|
-
'quarter',
|
|
72
|
-
'year',
|
|
65
|
+
['second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'],
|
|
73
66
|
];
|
|
74
|
-
test.each(timeframes
|
|
75
|
-
|
|
67
|
+
test.each(timeframes)('timestamp truncate %s', unit => {
|
|
68
|
+
const truncSrc = (0, test_translator_1.model) `run: a->{select: tts is ats.${unit}}`;
|
|
69
|
+
expect(truncSrc).toTranslate();
|
|
70
|
+
const tQuery = truncSrc.translator.getQuery(0);
|
|
71
|
+
expect(tQuery).toBeDefined();
|
|
72
|
+
const tField = (0, test_translator_1.getQueryFieldDef)(tQuery.pipeline[0], 'tts');
|
|
73
|
+
expect(tField['timeframe']).toEqual(unit);
|
|
74
|
+
});
|
|
75
|
+
const dateTF = [['week', 'month', 'quarter', 'year']];
|
|
76
|
+
test.each(dateTF)('date truncate %s', unit => {
|
|
77
|
+
const truncSrc = (0, test_translator_1.model) `run: a->{select: td is ad.${unit}}`;
|
|
78
|
+
expect(truncSrc).toTranslate();
|
|
79
|
+
const tQuery = truncSrc.translator.getQuery(0);
|
|
80
|
+
expect(tQuery).toBeDefined();
|
|
81
|
+
const tField = (0, test_translator_1.getQueryFieldDef)(tQuery.pipeline[0], 'td');
|
|
82
|
+
expect(tField['timeframe']).toEqual(unit);
|
|
76
83
|
});
|
|
77
84
|
// mtoy todo units missing: implement, or document
|
|
78
|
-
const diffable = ['second', 'minute', 'hour', 'day'];
|
|
79
|
-
test.each(diffable
|
|
85
|
+
const diffable = [['second', 'minute', 'hour', 'day']];
|
|
86
|
+
test.each(diffable)('timestamp difference - %s', unit => {
|
|
80
87
|
expect(new test_translator_1.BetaExpression(`${unit}(@2021 to ats)`)).toParse();
|
|
81
88
|
});
|
|
82
|
-
test.each(diffable
|
|
89
|
+
test.each(diffable)('timestamp difference - %s', unit => {
|
|
83
90
|
expect(new test_translator_1.BetaExpression(`${unit}(ats to @2030)`)).toParse();
|
|
84
91
|
});
|
|
85
92
|
});
|