Line data Source code
1 : import * as arrow from 'apache-arrow';
2 :
3 :
4 1 : export function isTemporalType(typeId: arrow.Type): boolean {
5 1 : switch (typeId) {
6 1 : case arrow.Type.Date:
7 1 : case arrow.Type.DateDay:
8 1 : case arrow.Type.DateMillisecond:
9 1 : case arrow.Type.Time:
10 1 : case arrow.Type.TimeSecond:
11 1 : case arrow.Type.TimeMillisecond:
12 1 : case arrow.Type.TimeMicrosecond:
13 1 : case arrow.Type.TimeNanosecond:
14 1 : case arrow.Type.Timestamp:
15 1 : case arrow.Type.TimestampSecond:
16 1 : case arrow.Type.TimestampMillisecond:
17 1 : case arrow.Type.TimestampMicrosecond:
18 1 : case arrow.Type.TimestampNanosecond:
19 1 : case arrow.Type.DurationSecond:
20 1 : case arrow.Type.DurationMillisecond:
21 1 : case arrow.Type.DurationMicrosecond:
22 1 : case arrow.Type.DurationNanosecond:
23 1 : return true;
24 1 : default:
25 1 : return false;
26 1 : }
27 1 : }
28 :
29 1 : export function getToNumericFn(typeId: arrow.Type): string | undefined {
30 1 : switch (typeId) {
31 : // Hyper extracts no epoch from a time of day, only from its interval since midnight
32 1 : case arrow.Type.Time:
33 1 : case arrow.Type.TimeSecond:
34 1 : case arrow.Type.TimeMillisecond:
35 1 : case arrow.Type.TimeMicrosecond:
36 1 : case arrow.Type.TimeNanosecond:
37 1 : return "TIME_EPOCH";
38 1 : }
39 1 : if (isTemporalType(typeId)) {
40 1 : return "EPOCH";
41 : }
42 1 : return typeId === arrow.Type.Bool ? "BOOLEAN" : undefined;
43 1 : }
44 :
45 1 : export function isIntegerType(typeId: arrow.Type): boolean {
46 1 : switch (typeId) {
47 1 : case arrow.Type.Int:
48 1 : case arrow.Type.Int8:
49 1 : case arrow.Type.Int16:
50 1 : case arrow.Type.Int32:
51 1 : case arrow.Type.Int64:
52 1 : case arrow.Type.Uint8:
53 1 : case arrow.Type.Uint16:
54 1 : case arrow.Type.Uint32:
55 1 : case arrow.Type.Uint64:
56 1 : return true;
57 1 : default:
58 1 : return false;
59 1 : }
60 1 : }
61 :
62 1 : export function getSmallIntegerDomainSize(minValue: unknown, maxValue: unknown, maxSize: number): number | null {
63 1 : if (typeof minValue === 'bigint' && typeof maxValue === 'bigint') {
64 1 : const size = maxValue - minValue + 1n;
65 1 : return size > 0n && size <= BigInt(maxSize) ? Number(size) : null;
66 1 : }
67 1 : if (typeof minValue === 'number' && typeof maxValue === 'number' && Number.isInteger(minValue) && Number.isInteger(maxValue)) {
68 1 : const size = maxValue - minValue + 1;
69 1 : return size > 0 && size <= maxSize ? size : null;
70 1 : }
71 0 : return null;
72 1 : }
73 :
74 1 : export function createUniqueColumnName(prefix: string, fieldNames: Set<string>) {
75 1 : let name = prefix;
76 1 : while (true) {
77 1 : if (fieldNames.has(name)) {
78 0 : name = `_${name}`;
79 1 : } else {
80 1 : fieldNames.add(name);
81 1 : return name;
82 1 : }
83 : }
84 1 : }
|