Skip to content

Commit a7ad24b

Browse files
committed
add string
1 parent 859a517 commit a7ad24b

File tree

6 files changed

+156
-15
lines changed

6 files changed

+156
-15
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Binary(Object value) throws ValidationException {
1515
}
1616

1717
@Override
18-
public String toString() {
18+
public java.lang.String toString() {
1919
if (this.value != null) {
2020
return Base64.encodeBase64String(this.value);
2121
}
@@ -40,7 +40,7 @@ public void setValue(Object value) throws ValidationException {
4040
}
4141

4242
if (value instanceof char[] chars) {
43-
this.value = Base64.decodeBase64(new String(chars));
43+
this.value = Base64.decodeBase64(new java.lang.String(chars));
4444
return;
4545
}
4646

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Scalar(Object value) throws ValidationException {
1818

1919
public abstract ArrowType dataType();
2020

21-
public String toString() {
21+
public java.lang.String toString() {
2222
if (this.value != null) {
2323
return this.value.toString();
2424
}
@@ -72,5 +72,5 @@ public final int hashCode() {
7272
return Objects.hash(value);
7373
}
7474

75-
public static final String NULL_VALUE_STRING = "(null)";
75+
public static final java.lang.String NULL_VALUE_STRING = "(null)";
7676
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.cloudquery.scalar;
2+
3+
import org.apache.arrow.vector.types.pojo.ArrowType;
4+
5+
public class String extends Scalar<java.lang.String> {
6+
7+
public String() {
8+
super();
9+
}
10+
11+
public String(Object value) throws ValidationException {
12+
super(value);
13+
}
14+
15+
@Override
16+
public ArrowType dataType() {
17+
return ArrowType.Utf8.INSTANCE;
18+
}
19+
20+
@Override
21+
public void setValue(Object value) throws ValidationException {
22+
this.value = value.toString();
23+
}
24+
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44

55
public class ValidationException extends Exception {
66
public Throwable cause;
7-
public String message;
7+
public java.lang.String message;
88
public ArrowType type;
99
private final Object value;
1010

11-
static final String NO_CONVERSION_AVAILABLE = "no conversion available";
11+
static final java.lang.String NO_CONVERSION_AVAILABLE = "no conversion available";
1212

1313

14-
ValidationException(Throwable cause, String message, ArrowType type, Object value) {
14+
ValidationException(Throwable cause, java.lang.String message, ArrowType type, Object value) {
1515
super(message, cause);
1616
this.cause = cause;
1717
this.message = message;
1818
this.type = type;
1919
this.value = value;
2020
}
2121

22-
ValidationException(String message, ArrowType type, Object value) {
22+
ValidationException(java.lang.String message, ArrowType type, Object value) {
2323
super(message);
2424
this.message = message;
2525
this.type = type;
2626
this.value = value;
2727
}
2828

29-
public String Error() {
29+
public java.lang.String Error() {
3030
if (this.cause == null) {
31-
return String.format("cannot set `%s` with value `%s`: %s", this.type, this.value, this.message);
31+
return java.lang.String.format("cannot set `%s` with value `%s`: %s", this.type, this.value, this.message);
3232
}
33-
return String.format("cannot set `%s` with value `%s`: %s (%s)", this.type, this.value, this.message, this.cause);
33+
return java.lang.String.format("cannot set `%s` with value `%s`: %s (%s)", this.type, this.value, this.message, this.cause);
3434
}
3535

36-
public String Masked() {
36+
public java.lang.String Masked() {
3737
if (this.cause == null) {
38-
return String.format("cannot set `%s`: %s", this.type.toString(), this.message);
38+
return java.lang.String.format("cannot set `%s`: %s", this.type.toString(), this.message);
3939
}
40-
return String.format("cannot set `%s`: %s (%s)", this.type.toString(), this.message, this.cause);
40+
return java.lang.String.format("cannot set `%s`: %s (%s)", this.type.toString(), this.message, this.cause);
4141
}
4242
}
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package io.cloudquery.scalar;
2+
3+
import org.apache.arrow.vector.types.pojo.ArrowType;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
9+
public class StringTest {
10+
@Test
11+
public void testNew() {
12+
assertDoesNotThrow(() -> {
13+
new String();
14+
});
15+
}
16+
17+
@Test
18+
public void testNewWithValidParam() {
19+
assertDoesNotThrow(() -> {
20+
new String(1);
21+
new String("PT8H6M12.345S");
22+
new String("");
23+
24+
Scalar<?> s = new String(null);
25+
new String(s);
26+
});
27+
}
28+
29+
@Test
30+
public void testToString() {
31+
String string = new String();
32+
assertEquals(Scalar.NULL_VALUE_STRING, string.toString());
33+
34+
assertDoesNotThrow(() -> {
35+
string.set(1);
36+
});
37+
assertEquals("1", string.toString());
38+
39+
assertDoesNotThrow(() -> {
40+
string.set(-1L);
41+
});
42+
assertEquals("-1", string.toString());
43+
}
44+
45+
@Test
46+
public void testDataType() {
47+
String string = new String();
48+
assertEquals(ArrowType.Utf8.INSTANCE, string.dataType());
49+
assertEquals(new ArrowType.Utf8(), string.dataType());
50+
}
51+
52+
@Test
53+
public void testIsValid() {
54+
String string = new String();
55+
assertFalse(string.isValid());
56+
57+
assertDoesNotThrow(() -> {
58+
string.set(1L);
59+
});
60+
assertTrue(string.isValid());
61+
}
62+
63+
@Test
64+
public void testSet() {
65+
String string = new String();
66+
assertDoesNotThrow(() -> {
67+
string.set(1);
68+
string.set(1L);
69+
string.set("PT8H6M12.345S");
70+
string.set(null);
71+
72+
Scalar<?> s = new String("");
73+
string.set(s);
74+
});
75+
}
76+
77+
@Test
78+
public void testGet() {
79+
String string = new String();
80+
assertFalse(string.isValid());
81+
assertNull(string.get());
82+
83+
assertDoesNotThrow(() -> {
84+
string.set(-1L);
85+
});
86+
assertTrue(string.isValid());
87+
assertEquals("-1", string.get());
88+
89+
assertDoesNotThrow(() -> {
90+
string.set("");
91+
});
92+
assertTrue(string.isValid());
93+
assertEquals("", string.get());
94+
}
95+
96+
@Test
97+
public void testEquals() {
98+
String a = new String();
99+
String b = new String();
100+
assertEquals(a, b);
101+
assertNotEquals(a, null);
102+
assertNotEquals(a, new Bool()); // we can't cast Bool to String
103+
assertNotEquals(null, a);
104+
105+
assertDoesNotThrow(() -> {
106+
a.set(-1L);
107+
});
108+
assertNotEquals(a, b);
109+
110+
assertDoesNotThrow(() -> {
111+
for (Object obj : new Object[]{null, 0, 0L, -1, -1L, 1, 1L, "PT8H6M12.345S", ""}) {
112+
a.set(obj);
113+
assertEquals(a, new String(obj));
114+
}
115+
});
116+
}
117+
}

Diff for: lib/src/test/java/io/cloudquery/scalar/UUIDTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void testEquals() {
145145

146146
@Test
147147
public void testCorrectEndianBehaviour() {
148-
String expectUUID = "00010203-0405-0607-0809-0a0b0c0d0e0f";
148+
java.lang.String expectUUID = "00010203-0405-0607-0809-0a0b0c0d0e0f";
149149

150150
UUID uuid = new UUID();
151151
assertDoesNotThrow(() -> {

0 commit comments

Comments
 (0)