-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDateMilli.java
47 lines (38 loc) · 1.08 KB
/
DateMilli.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package io.cloudquery.scalar;
import java.time.LocalDateTime;
import org.apache.arrow.vector.types.DateUnit;
import org.apache.arrow.vector.types.pojo.ArrowType;
public class DateMilli extends Scalar<Long> {
public DateMilli() {
super();
}
public DateMilli(Object value) throws ValidationException {
super(value);
}
@Override
public ArrowType dataType() {
return new ArrowType.Date(DateUnit.MILLISECOND);
}
@Override
public void setValue(Object value) throws ValidationException {
if (value instanceof Long b) {
this.value = b;
return;
}
if (value instanceof Integer b) {
this.value = Long.valueOf(b);
return;
}
if (value instanceof CharSequence sequence) {
this.value = Long.parseLong(sequence.toString());
return;
}
if (value instanceof LocalDateTime localDateTime) {
// we actually store only date
this.value = localDateTime.toLocalDate().toEpochDay();
return;
}
throw new ValidationException(
ValidationException.NO_CONVERSION_AVAILABLE, this.dataType(), value);
}
}