athena-query-result-value-converter 0.1.3 → 0.2.1
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.
- package/README.md +92 -16
- package/lib/converter.d.ts +23 -7
- package/lib/converter.js +28 -10
- package/lib/core/datetime.d.ts +148 -0
- package/lib/core/datetime.js +560 -0
- package/lib/core/errors.d.ts +32 -0
- package/lib/core/errors.js +44 -2
- package/lib/core/result-set.d.ts +73 -0
- package/lib/core/result-set.js +64 -0
- package/lib/core/typed-value.d.ts +19 -16
- package/lib/core/typed-value.js +61 -50
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -2
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/athena-query-result-value-converter)
|
|
6
6
|
[](https://github.com/gammarers-aws-sdk-extensions/athena-query-result-value-converter/actions/workflows/build.yml)
|
|
7
7
|
|
|
8
|
-
A TypeScript library that converts Amazon Athena query result
|
|
8
|
+
A TypeScript library that converts Amazon Athena query result cells and result-set rows using `ColumnInfo` types from `@aws-sdk/client-athena`. It keeps `bigint`, `decimal`, `time`, and timestamps finer than milliseconds as strings.
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
* **Type-aware conversion**: `AthenaQueryResultValueConverter.convert` maps cells from `ColumnInfo.Type` (and `Precision` / `Scale` for decimals).
|
|
13
|
-
* **
|
|
12
|
+
* **Type-aware conversion**: `AthenaQueryResultValueConverter.convert` maps cells from `ColumnInfo.Type` (and `Precision` / `Scale` for decimals and temporal types).
|
|
13
|
+
* **Result pages**: `convertResultSet` turns one `GetQueryResults` page into rows. `headerRow` says whether that page still starts with column names.
|
|
14
|
+
* **Safe helpers**: `toNumber`, `toBoolean`, and `toDate` for `string | null` values. `toDate` accepts Athena timestamp and `YYYY-MM-DD` literals.
|
|
14
15
|
* **Unparseable value handling**: `keep` (default), `null`, or `throw` with a typed error.
|
|
15
|
-
* **Type predicates**: `isStringLikeType` and `isParseableAsType`
|
|
16
|
+
* **Type predicates**: `isStringLikeType` and `isParseableAsType` use the same literals as `convert`.
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -44,9 +45,9 @@ import type { ColumnInfo } from '@aws-sdk/client-athena';
|
|
|
44
45
|
|
|
45
46
|
const { convert, toNumber, toBoolean, toDate } = AthenaQueryResultValueConverter;
|
|
46
47
|
|
|
47
|
-
const n = toNumber(
|
|
48
|
-
const b = toBoolean(
|
|
49
|
-
const d = toDate(
|
|
48
|
+
const n = toNumber('1.25'); // number | null
|
|
49
|
+
const b = toBoolean('true'); // boolean | null
|
|
50
|
+
const d = toDate('2026-01-01 00:00:00.000'); // Date → 2026-01-01T00:00:00.000Z
|
|
50
51
|
|
|
51
52
|
const column: ColumnInfo = { Name: 'user_id', Type: 'bigint' };
|
|
52
53
|
const typed = convert('9223372036854775807', 'user_id', column);
|
|
@@ -59,6 +60,18 @@ const amount = convert('1.50', 'amount', {
|
|
|
59
60
|
Scale: 2,
|
|
60
61
|
});
|
|
61
62
|
// decimal → string (trailing scale kept)
|
|
63
|
+
|
|
64
|
+
const createdAt = convert('2026-01-01 00:00:00.000', 'created_at', {
|
|
65
|
+
Name: 'created_at',
|
|
66
|
+
Type: 'timestamp',
|
|
67
|
+
}, { timeZone: 'Asia/Tokyo' });
|
|
68
|
+
// Date → 2025-12-31T15:00:00.000Z
|
|
69
|
+
|
|
70
|
+
const birthDate = convert('2026-01-01', 'birth_date', {
|
|
71
|
+
Name: 'birth_date',
|
|
72
|
+
Type: 'date',
|
|
73
|
+
}, { dateValue: 'string' });
|
|
74
|
+
// '2026-01-01'
|
|
62
75
|
```
|
|
63
76
|
|
|
64
77
|
### Unparseable values
|
|
@@ -77,32 +90,95 @@ convert('not-a-number', 'n', { Name: 'n', Type: 'integer' }, {
|
|
|
77
90
|
unparseableValueBehavior: 'null',
|
|
78
91
|
}); // null
|
|
79
92
|
|
|
93
|
+
const reportConvertError = (error: unknown): void => {
|
|
94
|
+
if (error instanceof AthenaQueryResultValueConverterUnparseableValueError) {
|
|
95
|
+
console.error(error.code, error.columnName, error.value);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (error instanceof AthenaQueryResultValueConverterError) {
|
|
99
|
+
console.error(error.code, error.message);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
80
103
|
try {
|
|
81
104
|
convert('not-a-number', 'n', { Name: 'n', Type: 'integer' }, {
|
|
82
105
|
unparseableValueBehavior: 'throw',
|
|
83
106
|
});
|
|
84
107
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
console.error(error.code, error.columnName, error.value);
|
|
87
|
-
} else if (error instanceof AthenaQueryResultValueConverterError) {
|
|
88
|
-
console.error(error.code, error.message);
|
|
89
|
-
}
|
|
108
|
+
reportConvertError(error);
|
|
90
109
|
}
|
|
91
110
|
```
|
|
92
111
|
|
|
112
|
+
### Result pages
|
|
113
|
+
|
|
114
|
+
`GetQueryResults` returns every cell as `Datum.VarCharValue`. NULL is a missing property. The first page starts with the column names. A page fetched with `NextToken` does not.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { AthenaQueryResultValueConverter } from 'athena-query-result-value-converter';
|
|
118
|
+
import type { ColumnInfo, Row } from '@aws-sdk/client-athena';
|
|
119
|
+
|
|
120
|
+
const { convertResultSet } = AthenaQueryResultValueConverter;
|
|
121
|
+
|
|
122
|
+
const columns: ColumnInfo[] = [
|
|
123
|
+
{ Name: 'user_id', Type: 'bigint' },
|
|
124
|
+
{ Name: 'created_at', Type: 'timestamp' },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const firstPage: Row[] = [
|
|
128
|
+
{ Data: [{ VarCharValue: 'user_id' }, { VarCharValue: 'created_at' }] },
|
|
129
|
+
{ Data: [{ VarCharValue: '9223372036854775807' }, { VarCharValue: '2026-01-01 00:00:00.000' }] },
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
const firstRows = convertResultSet(columns, firstPage, { headerRow: 'present' });
|
|
133
|
+
const nextPage: Row[] = [
|
|
134
|
+
{ Data: [{ VarCharValue: '1' }, {}] },
|
|
135
|
+
];
|
|
136
|
+
const nextRows = convertResultSet(columns, nextPage, { headerRow: 'absent' });
|
|
137
|
+
// nextRows[0].cells[1].value === null
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`cells` follows `ColumnInfo` order. Two columns with the same name stay as two cells.
|
|
141
|
+
|
|
93
142
|
## Options
|
|
94
143
|
|
|
95
144
|
### `ConvertOptions`
|
|
96
145
|
|
|
97
146
|
Accepted by `AthenaQueryResultValueConverter.convert`.
|
|
98
147
|
|
|
99
|
-
| Option | Default
|
|
100
|
-
| ------------------------ |
|
|
101
|
-
| unparseableValueBehavior | `'keep'`
|
|
102
|
-
| rowIndex | omitted
|
|
148
|
+
| Option | Default | Description |
|
|
149
|
+
| ------------------------ | ----------- | ---------------------------------------------------------------------------------------------------- |
|
|
150
|
+
| unparseableValueBehavior | `'keep'` | `UnparseableValueBehavior`. `'keep'` returns the original string. `'null'` returns `null`. `'throw'` throws a typed error. |
|
|
151
|
+
| rowIndex | omitted | Zero-based row index included in throw messages. |
|
|
152
|
+
| timeZone | `'UTC'` | IANA time zone for `timestamp` without a zone suffix. `timestamp with time zone` uses the suffix. |
|
|
153
|
+
| dateValue | `'instant'` | `DateValueKind`. `'instant'` returns `date` as a UTC-midnight `Date`. `'string'` returns the `YYYY-MM-DD` text. |
|
|
154
|
+
|
|
155
|
+
An unusable `timeZone` or `dateValue` throws `AthenaQueryResultValueConverterArgumentError`.
|
|
103
156
|
|
|
104
157
|
`tinyint`, `smallint`, `int`, and `integer` become `number` when the cell is a base-10 integer inside that type's range. `bigint` stays a string when it fits in signed 64 bits. `decimal` stays a string, including trailing fractional zeros. Digit limits for `decimal` use `ColumnInfo.Precision` and `ColumnInfo.Scale`, or `decimal(p,s)` on `Type` when those fields are absent. `real`, `float`, and `double` become `number`.
|
|
105
158
|
|
|
159
|
+
`timestamp`, `timestamp(p)`, and the `with time zone` forms accept Athena literals such as `2026-01-01 00:00:00.000` and `2026-01-01 00:00:00.000 Asia/Tokyo`. Precision comes from `ColumnInfo.Precision`, then `(p)`, then 3. Precision above 3 stays the original text, including when `unparseableValueBehavior` is `'throw'`. A repeated local time becomes the earlier instant. A skipped local time is unparseable. `time` and `time(p)` stay text. `date` accepts `YYYY-MM-DD` only.
|
|
160
|
+
|
|
161
|
+
### `ToDateOptions`
|
|
162
|
+
|
|
163
|
+
Accepted by `AthenaQueryResultValueConverter.toDate`.
|
|
164
|
+
|
|
165
|
+
| Option | Default | Description |
|
|
166
|
+
| -------- | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
167
|
+
| timeZone | `'UTC'` | IANA time zone when the text has no zone suffix. A suffix on the value wins. `YYYY-MM-DD` stays UTC midnight. An unusable name throws `AthenaQueryResultValueConverterArgumentError`. |
|
|
168
|
+
|
|
169
|
+
### `ConvertResultSetOptions`
|
|
170
|
+
|
|
171
|
+
Accepted by `AthenaQueryResultValueConverter.convertResultSet`.
|
|
172
|
+
|
|
173
|
+
| Option | Default | Description |
|
|
174
|
+
| ------------------------ | ----------- | ----------------------------------------------------------------------------------------------- |
|
|
175
|
+
| headerRow | required | `HeaderRowPresence`. `'present'` skips the first row. `'absent'` converts every row. Set this per page. |
|
|
176
|
+
| unparseableValueBehavior | `'keep'` | Same as `ConvertOptions`. |
|
|
177
|
+
| timeZone | `'UTC'` | Same as `ConvertOptions`. |
|
|
178
|
+
| dateValue | `'instant'` | Same as `ConvertOptions`. |
|
|
179
|
+
|
|
180
|
+
A row whose cell count differs from `columns` throws `AthenaQueryResultValueConverterColumnCountError`, including the header row. `rowIndex` on that error, and on an unparseable cell, is the index in the `rows` argument.
|
|
181
|
+
|
|
106
182
|
## Requirements
|
|
107
183
|
|
|
108
184
|
* Node.js >= 20
|
package/lib/converter.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { ColumnInfo } from '@aws-sdk/client-athena';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
1
|
+
import type { ColumnInfo, Row } from '@aws-sdk/client-athena';
|
|
2
|
+
import { type AthenaConvertedCell, type AthenaConvertedRow, type ConvertResultSetOptions, type HeaderRowPresence } from './core/result-set';
|
|
3
|
+
import { type AthenaTypedValue, type DateValueKind, type UnparseableValueBehavior } from './core/typed-value';
|
|
4
|
+
export type { AthenaTypedValue, DateValueKind, ToDateOptions, UnparseableValueBehavior } from './core/typed-value';
|
|
5
|
+
export type { AthenaConvertedCell, AthenaConvertedRow, ConvertResultSetOptions, HeaderRowPresence };
|
|
4
6
|
/**
|
|
5
7
|
* Options for {@link AthenaQueryResultValueConverter.convert}.
|
|
6
8
|
*/
|
|
@@ -17,18 +19,32 @@ export type ConvertOptions = {
|
|
|
17
19
|
* Zero-based row index included in throw messages when available.
|
|
18
20
|
*/
|
|
19
21
|
rowIndex?: number;
|
|
22
|
+
/**
|
|
23
|
+
* IANA time zone for a `timestamp` that has no zone suffix.
|
|
24
|
+
*
|
|
25
|
+
* Default: `'UTC'`. `timestamp with time zone` uses the suffix on the cell.
|
|
26
|
+
* `YYYY-MM-DD HH:mm:ss.SSS` is that zone's wall clock, not the host zone.
|
|
27
|
+
*/
|
|
28
|
+
timeZone?: string;
|
|
29
|
+
/**
|
|
30
|
+
* How to return a `date` column.
|
|
31
|
+
*
|
|
32
|
+
* - `'instant'` (default): UTC midnight {@link Date}
|
|
33
|
+
* - `'string'`: the `YYYY-MM-DD` text
|
|
34
|
+
*/
|
|
35
|
+
dateValue?: DateValueKind;
|
|
20
36
|
};
|
|
21
37
|
/**
|
|
22
|
-
* Converts Amazon Athena query result
|
|
38
|
+
* Converts Amazon Athena query result cells and result pages using column metadata.
|
|
23
39
|
*
|
|
24
|
-
* `bigint
|
|
25
|
-
* preserved.
|
|
40
|
+
* `bigint`, `decimal`, `time`, and timestamps finer than milliseconds stay strings.
|
|
26
41
|
*/
|
|
27
42
|
export declare const AthenaQueryResultValueConverter: {
|
|
28
43
|
readonly convert: (value: string | null, columnName: string, column: ColumnInfo | undefined, options?: ConvertOptions) => AthenaTypedValue;
|
|
44
|
+
readonly convertResultSet: (columns: readonly ColumnInfo[], rows: readonly Row[], options: ConvertResultSetOptions) => AthenaConvertedRow[];
|
|
29
45
|
readonly toNumber: (value: string | null) => number | null;
|
|
30
46
|
readonly toBoolean: (value: string | null) => boolean | null;
|
|
31
|
-
readonly toDate: (value: string | null) => Date | null;
|
|
47
|
+
readonly toDate: (value: string | null, options?: import("./converter").ToDateOptions) => Date | null;
|
|
32
48
|
readonly isStringLikeType: (type: string | undefined) => boolean;
|
|
33
49
|
readonly isParseableAsType: (value: string, type: string | undefined) => boolean;
|
|
34
50
|
};
|
package/lib/converter.js
CHANGED
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AthenaQueryResultValueConverter = void 0;
|
|
4
|
+
const result_set_1 = require("./core/result-set");
|
|
4
5
|
const typed_value_1 = require("./core/typed-value");
|
|
5
|
-
/**
|
|
6
|
-
* Default behavior when a cell cannot be converted for its column type.
|
|
7
|
-
*/
|
|
8
|
-
const DEFAULT_UNPARSEABLE_VALUE_BEHAVIOR = 'keep';
|
|
9
6
|
/**
|
|
10
7
|
* Converts a raw Athena cell using column metadata.
|
|
11
8
|
*
|
|
12
9
|
* `bigint` and `decimal` stay strings. `Number()` cannot represent every
|
|
13
|
-
* signed 64-bit integer, and it drops trailing decimal scale.
|
|
10
|
+
* signed 64-bit integer, and it drops trailing decimal scale. A `timestamp` with
|
|
11
|
+
* precision above milliseconds stays a string for the same reason. `time` stays a string.
|
|
14
12
|
*
|
|
15
13
|
* @param value - Raw `VarCharValue` (or `null` when missing).
|
|
16
14
|
* @param columnName - Header name used when conversion fails.
|
|
17
15
|
* @param column - Column metadata for this cell.
|
|
18
16
|
* @param options - Conversion options (for example unparseable-value behavior).
|
|
19
17
|
* @returns A typed value, or the original string / `null` when unparseable.
|
|
18
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When `timeZone` or `dateValue` is unusable.
|
|
20
19
|
* @throws {@link AthenaQueryResultValueConverterUnparseableValueError} When
|
|
21
20
|
* `unparseableValueBehavior` is `'throw'` and the cell does not match its column type.
|
|
22
21
|
*/
|
|
23
22
|
const convert = (value, columnName, column, options = {}) => {
|
|
24
|
-
|
|
23
|
+
const temporal = (0, typed_value_1.resolveTemporalOptions)(options);
|
|
24
|
+
return (0, typed_value_1.convert)(value, columnName, column, options.unparseableValueBehavior ?? typed_value_1.DEFAULT_UNPARSEABLE_VALUE_BEHAVIOR, options.rowIndex, temporal);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Converts one `GetQueryResults` page into data rows.
|
|
28
|
+
*
|
|
29
|
+
* Pass `headerRow: 'present'` for the first page and `headerRow: 'absent'` for a page
|
|
30
|
+
* fetched with `NextToken`. NULL is a missing `VarCharValue`.
|
|
31
|
+
*
|
|
32
|
+
* @param columns - `ResultSetMetadata.ColumnInfo` for the query.
|
|
33
|
+
* @param rows - `ResultSet.Rows` for this page.
|
|
34
|
+
* @param options - Required `headerRow`, plus the cell conversion options.
|
|
35
|
+
* @returns Data rows in column order. Duplicate column names stay as separate cells.
|
|
36
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When `headerRow`, `timeZone`, or `dateValue` is unusable.
|
|
37
|
+
* @throws {@link AthenaQueryResultValueConverterColumnCountError} When a row's cell count differs from `columns`.
|
|
38
|
+
* @throws {@link AthenaQueryResultValueConverterUnparseableValueError} When a cell does not match its type and
|
|
39
|
+
* `unparseableValueBehavior` is `'throw'`.
|
|
40
|
+
*/
|
|
41
|
+
const convertResultSet = (columns, rows, options) => {
|
|
42
|
+
return (0, result_set_1.convertResultSet)(columns, rows, options);
|
|
25
43
|
};
|
|
26
44
|
/**
|
|
27
|
-
* Converts Amazon Athena query result
|
|
45
|
+
* Converts Amazon Athena query result cells and result pages using column metadata.
|
|
28
46
|
*
|
|
29
|
-
* `bigint
|
|
30
|
-
* preserved.
|
|
47
|
+
* `bigint`, `decimal`, `time`, and timestamps finer than milliseconds stay strings.
|
|
31
48
|
*/
|
|
32
49
|
exports.AthenaQueryResultValueConverter = {
|
|
33
50
|
convert,
|
|
51
|
+
convertResultSet,
|
|
34
52
|
toNumber: typed_value_1.toNumber,
|
|
35
53
|
toBoolean: typed_value_1.toBoolean,
|
|
36
54
|
toDate: typed_value_1.toDate,
|
|
37
55
|
isStringLikeType: typed_value_1.isStringLikeType,
|
|
38
56
|
isParseableAsType: typed_value_1.isParseableAsType,
|
|
39
57
|
};
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
58
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udmVydGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2NvbnZlcnRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSxrREFNMkI7QUFDM0Isb0RBWTRCO0FBcUM1Qjs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7QUFDSCxNQUFNLE9BQU8sR0FBRyxDQUNkLEtBQW9CLEVBQ3BCLFVBQWtCLEVBQ2xCLE1BQThCLEVBQzlCLFVBQTBCLEVBQUUsRUFDVixFQUFFO0lBQ3BCLE1BQU0sUUFBUSxHQUFHLElBQUEsb0NBQXNCLEVBQUMsT0FBTyxDQUFDLENBQUM7SUFDakQsT0FBTyxJQUFBLHFCQUFXLEVBQ2hCLEtBQUssRUFDTCxVQUFVLEVBQ1YsTUFBTSxFQUNOLE9BQU8sQ0FBQyx3QkFBd0IsSUFBSSxnREFBa0MsRUFDdEUsT0FBTyxDQUFDLFFBQVEsRUFDaEIsUUFBUSxDQUNULENBQUM7QUFDSixDQUFDLENBQUM7QUFFRjs7Ozs7Ozs7Ozs7Ozs7R0FjR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VtYmVyLFxuICB0b0Jvb2xlYW4sXG4gIHRvRGF0ZSxcbiAgaXNTdHJpbmdMaWtlVHlwZSxcbiAgaXNQYXJzZWFibGVBc1R5cGUsXG59IGFzIGNvbnN0O1xuIl19
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session time zone used when a timestamp has no zone of its own.
|
|
3
|
+
* Athena's default session time zone is UTC.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_TIME_ZONE = "UTC";
|
|
6
|
+
/**
|
|
7
|
+
* Athena / Trino timestamp and time precision when the type omits `(p)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_TEMPORAL_PRECISION = 3;
|
|
10
|
+
declare const DATE_VALUE_INSTANT = "instant";
|
|
11
|
+
declare const DATE_VALUE_STRING = "string";
|
|
12
|
+
declare const TIMESTAMP_ZONE_ZONED = "zoned";
|
|
13
|
+
declare const TIMESTAMP_ZONE_SESSION = "session";
|
|
14
|
+
/**
|
|
15
|
+
* How a `date` column is returned.
|
|
16
|
+
*
|
|
17
|
+
* - `'instant'`: UTC midnight {@link Date}
|
|
18
|
+
* - `'string'`: the `YYYY-MM-DD` text
|
|
19
|
+
*/
|
|
20
|
+
export type DateValueKind = typeof DATE_VALUE_INSTANT | typeof DATE_VALUE_STRING;
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link toDate}.
|
|
23
|
+
*/
|
|
24
|
+
export type ToDateOptions = {
|
|
25
|
+
/**
|
|
26
|
+
* IANA time zone for a timestamp that has no zone suffix.
|
|
27
|
+
*
|
|
28
|
+
* Default: `'UTC'`. A suffix on the value wins. `YYYY-MM-DD` stays UTC midnight.
|
|
29
|
+
*/
|
|
30
|
+
timeZone?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Where a timestamp takes its time zone from.
|
|
34
|
+
*
|
|
35
|
+
* - `'zoned'`: the cell is `timestamp with time zone` and carries its own suffix
|
|
36
|
+
* - `'session'`: the cell is a zone-less timestamp and uses the session zone
|
|
37
|
+
*/
|
|
38
|
+
export type TimestampZoneSource = typeof TIMESTAMP_ZONE_ZONED | typeof TIMESTAMP_ZONE_SESSION;
|
|
39
|
+
/**
|
|
40
|
+
* Timestamp type after the Athena type string has been normalized.
|
|
41
|
+
*/
|
|
42
|
+
export type AthenaTimestampType = {
|
|
43
|
+
readonly zoneSource: TimestampZoneSource;
|
|
44
|
+
readonly typePrecision: number | undefined;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Time type after the Athena type string has been normalized.
|
|
48
|
+
*/
|
|
49
|
+
export type AthenaTimeType = {
|
|
50
|
+
readonly typePrecision: number | undefined;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Returns whether `Intl` accepts the time zone.
|
|
54
|
+
*
|
|
55
|
+
* @param timeZone - Caller-supplied IANA name, such as `UTC` or `Asia/Tokyo`.
|
|
56
|
+
* @returns `true` when the name can be used as a session time zone.
|
|
57
|
+
*/
|
|
58
|
+
export declare const isValidIanaTimeZone: (timeZone: string) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Rejects a session time zone `Intl` does not accept.
|
|
61
|
+
*
|
|
62
|
+
* @param timeZone - Caller-supplied IANA name.
|
|
63
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When the name is not a time zone.
|
|
64
|
+
*/
|
|
65
|
+
export declare const requireTimeZone: (timeZone: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Rejects a `dateValue` other than `'instant'` or `'string'`.
|
|
68
|
+
*
|
|
69
|
+
* @param dateValue - Caller-supplied date representation.
|
|
70
|
+
* @returns The same representation when it is `'instant'` or `'string'`.
|
|
71
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When the value is not one of those two.
|
|
72
|
+
*/
|
|
73
|
+
export declare const requireDateValue: (dateValue: string) => DateValueKind;
|
|
74
|
+
/**
|
|
75
|
+
* Resolved session zone and date representation for one conversion call.
|
|
76
|
+
*/
|
|
77
|
+
export type TemporalOptions = {
|
|
78
|
+
readonly timeZone: string;
|
|
79
|
+
readonly dateValue: DateValueKind;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Applies defaults and rejects an unusable session zone or date representation.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Partial caller options. Omitted fields use UTC and `'instant'`.
|
|
85
|
+
* @returns The options cell conversion should use.
|
|
86
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When `timeZone` or `dateValue` is unusable.
|
|
87
|
+
*/
|
|
88
|
+
export declare const resolveTemporalOptions: (options: {
|
|
89
|
+
readonly timeZone?: string;
|
|
90
|
+
readonly dateValue?: string;
|
|
91
|
+
}) => TemporalOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Converts an Athena timestamp literal.
|
|
94
|
+
*
|
|
95
|
+
* `Date.parse` is not used. It would treat `YYYY-MM-DD HH:mm:ss.SSS` as the host zone and would also accept `2026` or `January 1, 2026`.
|
|
96
|
+
*
|
|
97
|
+
* @param value - Raw cell text.
|
|
98
|
+
* @param precision - Declared precision. Above 3, a valid literal stays text.
|
|
99
|
+
* @param sessionTimeZone - IANA zone for a timestamp without a zone suffix.
|
|
100
|
+
* @param zoneSource - `'zoned'` reads the suffix on the value. `'session'` uses `sessionTimeZone`.
|
|
101
|
+
* @returns A {@link Date}, preserved text, or `null` when the cell does not match the column.
|
|
102
|
+
*/
|
|
103
|
+
export declare const toAthenaTimestamp: (value: string, precision: number, sessionTimeZone: string, zoneSource: TimestampZoneSource) => Date | string | null;
|
|
104
|
+
/**
|
|
105
|
+
* Converts an Athena `date` literal.
|
|
106
|
+
*
|
|
107
|
+
* @param value - Raw cell text.
|
|
108
|
+
* @param dateValue - `'instant'` for UTC midnight, `'string'` for `YYYY-MM-DD`.
|
|
109
|
+
* @returns A {@link Date}, the date text, or `null` when the cell is not `YYYY-MM-DD`.
|
|
110
|
+
*/
|
|
111
|
+
export declare const toAthenaDate: (value: string, dateValue: DateValueKind) => Date | string | null;
|
|
112
|
+
/**
|
|
113
|
+
* Keeps an Athena `time` / `time(p)` literal as text.
|
|
114
|
+
*
|
|
115
|
+
* A time has no date, so it is not a {@link Date}.
|
|
116
|
+
*
|
|
117
|
+
* @param value - Raw cell text.
|
|
118
|
+
* @param precision - Declared precision. Extra fractional digits do not match.
|
|
119
|
+
* @returns Trimmed time text, or `null` when the cell is not an Athena time.
|
|
120
|
+
*/
|
|
121
|
+
export declare const toAthenaTime: (value: string, precision: number) => string | null;
|
|
122
|
+
/**
|
|
123
|
+
* Reads `timestamp` or `timestamp(p)`, with or without `with time zone`.
|
|
124
|
+
*
|
|
125
|
+
* @param normalizedType - Lowercased Athena type string.
|
|
126
|
+
* @returns The zone source and the precision written on the type, if any.
|
|
127
|
+
*/
|
|
128
|
+
export declare const matchTimestampType: (normalizedType: string) => AthenaTimestampType | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Reads `time` or `time(p)`. `time with time zone` is not this type.
|
|
131
|
+
*
|
|
132
|
+
* @param normalizedType - Lowercased Athena type string.
|
|
133
|
+
* @returns The precision written on the type, if any.
|
|
134
|
+
*/
|
|
135
|
+
export declare const matchTimeType: (normalizedType: string) => AthenaTimeType | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Converts an Athena timestamp or `YYYY-MM-DD` date to a {@link Date}.
|
|
138
|
+
*
|
|
139
|
+
* Accepts `YYYY-MM-DD HH:mm:ss[.SSS]` and the same form with a `UTC`, numeric-offset, or IANA suffix.
|
|
140
|
+
* `YYYY-MM-DD` is UTC midnight. Other text, including ISO `T`/`Z` forms, returns `null`.
|
|
141
|
+
*
|
|
142
|
+
* @param value - Raw text, or `null`.
|
|
143
|
+
* @param options - Session time zone for a timestamp that has no suffix.
|
|
144
|
+
* @returns A {@link Date}, or `null` when the text is not a representable Athena literal.
|
|
145
|
+
* @throws {@link AthenaQueryResultValueConverterArgumentError} When `options.timeZone` is not an IANA time zone.
|
|
146
|
+
*/
|
|
147
|
+
export declare const toDate: (value: string | null, options?: ToDateOptions) => Date | null;
|
|
148
|
+
export {};
|