Skip to content

Commit 39ec6e6

Browse files
authored
feat: int/uint/float/string scalars (#59)
Closes #53 Closes #54 Closes #58 Closes #60
1 parent b7a2a6e commit 39ec6e6

32 files changed

+1923
-447
lines changed

Diff for: lib/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
api 'org.apache.commons:commons-math3:3.6.1'
2626

2727
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
28+
implementation 'org.jooq:joou:0.9.4'
2829
implementation 'com.google.guava:guava:32.1.2-jre'
2930
implementation 'info.picocli:picocli:4.7.4'
3031
implementation 'com.google.guava:guava:32.1.2-jre'

Diff for: lib/src/main/java/io/cloudquery/scalar/Binary.java

+22-32
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,30 @@
55

66
import java.util.Arrays;
77

8-
public class Binary implements Scalar<byte[]> {
9-
protected byte[] value;
10-
8+
public class Binary extends Scalar<byte[]> {
119
public Binary() {
10+
super();
1211
}
1312

1413
public Binary(Object value) throws ValidationException {
15-
this.set(value);
14+
super(value);
1615
}
1716

1817
@Override
19-
public String toString() {
18+
public java.lang.String toString() {
2019
if (this.value != null) {
2120
return Base64.encodeBase64String(this.value);
2221
}
2322
return NULL_VALUE_STRING;
2423
}
2524

26-
@Override
27-
public boolean isValid() {
28-
return this.value != null;
29-
}
30-
3125
@Override
3226
public ArrowType dataType() {
3327
return ArrowType.Binary.INSTANCE;
3428
}
3529

3630
@Override
37-
public void set(Object value) throws ValidationException {
38-
if (value == null) {
39-
this.value = null;
40-
return;
41-
}
42-
43-
if (value instanceof Scalar<?> scalar) {
44-
if (!scalar.isValid()) {
45-
this.value = null;
46-
return;
47-
}
48-
49-
this.set(scalar.get());
50-
return;
51-
}
52-
31+
public void setValue(Object value) throws ValidationException {
5332
if (value instanceof byte[] bytes) {
5433
this.value = bytes;
5534
return;
@@ -61,18 +40,13 @@ public void set(Object value) throws ValidationException {
6140
}
6241

6342
if (value instanceof char[] chars) {
64-
this.value = Base64.decodeBase64(new String(chars));
43+
this.value = Base64.decodeBase64(new java.lang.String(chars));
6544
return;
6645
}
6746

6847
throw new ValidationException(ValidationException.NO_CONVERSION_AVAILABLE, this.dataType(), value);
6948
}
7049

71-
@Override
72-
public byte[] get() {
73-
return this.value;
74-
}
75-
7650
@Override
7751
public boolean equals(Object other) {
7852
if (other instanceof Binary o) {
@@ -83,4 +57,20 @@ public boolean equals(Object other) {
8357
}
8458
return false;
8559
}
60+
61+
public static class LargeBinary extends Binary {
62+
63+
public LargeBinary() {
64+
super();
65+
}
66+
67+
public LargeBinary(Object value) throws ValidationException {
68+
super(value);
69+
}
70+
71+
@Override
72+
public ArrowType dataType() {
73+
return ArrowType.LargeBinary.INSTANCE;
74+
}
75+
}
8676
}

Diff for: lib/src/main/java/io/cloudquery/scalar/Bool.java

+4-49
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,13 @@
22

33
import org.apache.arrow.vector.types.pojo.ArrowType;
44

5-
public class Bool implements Scalar<Boolean> {
6-
protected Boolean value;
7-
5+
public class Bool extends Scalar<Boolean> {
86
public Bool() {
7+
super();
98
}
109

1110
public Bool(Object value) throws ValidationException {
12-
this.set(value);
13-
}
14-
15-
@Override
16-
public String toString() {
17-
if (this.value != null) {
18-
return this.value.toString();
19-
}
20-
return NULL_VALUE_STRING;
21-
}
22-
23-
@Override
24-
public boolean isValid() {
25-
return this.value != null;
11+
super(value);
2612
}
2713

2814
@Override
@@ -31,22 +17,7 @@ public ArrowType dataType() {
3117
}
3218

3319
@Override
34-
public void set(Object value) throws ValidationException {
35-
if (value == null) {
36-
this.value = null;
37-
return;
38-
}
39-
40-
if (value instanceof Scalar<?> scalar) {
41-
if (!scalar.isValid()) {
42-
this.value = null;
43-
return;
44-
}
45-
46-
this.set(scalar.get());
47-
return;
48-
}
49-
20+
public void setValue(Object value) throws ValidationException {
5021
if (value instanceof Boolean b) {
5122
this.value = b;
5223
return;
@@ -59,20 +30,4 @@ public void set(Object value) throws ValidationException {
5930

6031
throw new ValidationException(ValidationException.NO_CONVERSION_AVAILABLE, this.dataType(), value);
6132
}
62-
63-
@Override
64-
public Boolean get() {
65-
return this.value;
66-
}
67-
68-
@Override
69-
public boolean equals(Object other) {
70-
if (other instanceof Bool o) {
71-
if (this.value == null) {
72-
return o.value == null;
73-
}
74-
return this.value.equals(o.value);
75-
}
76-
return false;
77-
}
7833
}

Diff for: lib/src/main/java/io/cloudquery/scalar/DateDay.java

+4-54
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
import org.apache.arrow.vector.types.DateUnit;
44
import org.apache.arrow.vector.types.pojo.ArrowType;
55

6-
public class DateDay implements Scalar<Integer> {
7-
protected Integer value;
8-
6+
public class DateDay extends Scalar<Integer> {
97
public DateDay() {
8+
super();
109
}
1110

1211
public DateDay(Object value) throws ValidationException {
13-
this.set(value);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
if (this.value != null) {
19-
return this.value.toString();
20-
}
21-
return NULL_VALUE_STRING;
22-
}
23-
24-
@Override
25-
public boolean isValid() {
26-
return this.value != null;
12+
super(value);
2713
}
2814

2915
@Override
@@ -32,27 +18,7 @@ public ArrowType dataType() {
3218
}
3319

3420
@Override
35-
public void set(Object value) throws ValidationException {
36-
if (value == null) {
37-
this.value = 0;
38-
return;
39-
}
40-
41-
if (value instanceof Scalar<?> scalar) {
42-
if (!scalar.isValid()) {
43-
this.value = 0;
44-
return;
45-
}
46-
47-
if (scalar instanceof DateDay date) {
48-
this.value = date.value;
49-
return;
50-
}
51-
52-
this.set(scalar.get());
53-
return;
54-
}
55-
21+
public void setValue(Object value) throws ValidationException {
5622
if (value instanceof Integer b) {
5723
this.value = b;
5824
return;
@@ -65,20 +31,4 @@ public void set(Object value) throws ValidationException {
6531

6632
throw new ValidationException(ValidationException.NO_CONVERSION_AVAILABLE, this.dataType(), value);
6733
}
68-
69-
@Override
70-
public Integer get() {
71-
return this.value;
72-
}
73-
74-
@Override
75-
public boolean equals(Object other) {
76-
if (other instanceof DateDay o) {
77-
if (this.value == null) {
78-
return o.value == null;
79-
}
80-
return this.value.equals(o.value);
81-
}
82-
return false;
83-
}
8434
}

Diff for: lib/src/main/java/io/cloudquery/scalar/DateMilli.java

+4-54
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
import org.apache.arrow.vector.types.DateUnit;
44
import org.apache.arrow.vector.types.pojo.ArrowType;
55

6-
public class DateMilli implements Scalar<Long> {
7-
protected Long value;
8-
6+
public class DateMilli extends Scalar<Long> {
97
public DateMilli() {
8+
super();
109
}
1110

1211
public DateMilli(Object value) throws ValidationException {
13-
this.set(value);
14-
}
15-
16-
@Override
17-
public String toString() {
18-
if (this.value != null) {
19-
return this.value.toString();
20-
}
21-
return NULL_VALUE_STRING;
22-
}
23-
24-
@Override
25-
public boolean isValid() {
26-
return this.value != null;
12+
super(value);
2713
}
2814

2915
@Override
@@ -32,27 +18,7 @@ public ArrowType dataType() {
3218
}
3319

3420
@Override
35-
public void set(Object value) throws ValidationException {
36-
if (value == null) {
37-
this.value = null;
38-
return;
39-
}
40-
41-
if (value instanceof Scalar<?> scalar) {
42-
if (!scalar.isValid()) {
43-
this.value = null;
44-
return;
45-
}
46-
47-
if (scalar instanceof DateMilli date) {
48-
this.value = date.value;
49-
return;
50-
}
51-
52-
this.set(scalar.get());
53-
return;
54-
}
55-
21+
public void setValue(Object value) throws ValidationException {
5622
if (value instanceof Long b) {
5723
this.value = b;
5824
return;
@@ -70,20 +36,4 @@ public void set(Object value) throws ValidationException {
7036

7137
throw new ValidationException(ValidationException.NO_CONVERSION_AVAILABLE, this.dataType(), value);
7238
}
73-
74-
@Override
75-
public Long get() {
76-
return this.value;
77-
}
78-
79-
@Override
80-
public boolean equals(Object other) {
81-
if (other instanceof DateMilli o) {
82-
if (this.value == null) {
83-
return o.value == null;
84-
}
85-
return this.value.equals(o.value);
86-
}
87-
return false;
88-
}
8939
}

0 commit comments

Comments
 (0)