-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
859a517
commit 1fe0bb9
Showing
7 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.cloudquery.scalar; | ||
|
||
import org.apache.arrow.vector.types.pojo.ArrowType; | ||
|
||
public class String extends Scalar<java.lang.String> { | ||
|
||
public String() { | ||
super(); | ||
} | ||
|
||
public String(Object value) throws ValidationException { | ||
super(value); | ||
} | ||
|
||
@Override | ||
public ArrowType dataType() { | ||
return ArrowType.Utf8.INSTANCE; | ||
} | ||
|
||
@Override | ||
public void setValue(Object value) throws ValidationException { | ||
this.value = value.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package io.cloudquery.scalar; | ||
|
||
import org.apache.arrow.vector.types.pojo.ArrowType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
public class StringTest { | ||
@Test | ||
public void testNew() { | ||
assertDoesNotThrow(() -> { | ||
new String(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testNewWithValidParam() { | ||
assertDoesNotThrow(() -> { | ||
new String(1); | ||
new String("PT8H6M12.345S"); | ||
new String(""); | ||
|
||
Scalar<?> s = new String(null); | ||
new String(s); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testToString() { | ||
String string = new String(); | ||
assertEquals(Scalar.NULL_VALUE_STRING, string.toString()); | ||
|
||
assertDoesNotThrow(() -> { | ||
string.set(1); | ||
}); | ||
assertEquals("1", string.toString()); | ||
|
||
assertDoesNotThrow(() -> { | ||
string.set(-1L); | ||
}); | ||
assertEquals("-1", string.toString()); | ||
} | ||
|
||
@Test | ||
public void testDataType() { | ||
String string = new String(); | ||
assertEquals(ArrowType.Utf8.INSTANCE, string.dataType()); | ||
assertEquals(new ArrowType.Utf8(), string.dataType()); | ||
} | ||
|
||
@Test | ||
public void testIsValid() { | ||
String string = new String(); | ||
assertFalse(string.isValid()); | ||
|
||
assertDoesNotThrow(() -> { | ||
string.set(1L); | ||
}); | ||
assertTrue(string.isValid()); | ||
} | ||
|
||
@Test | ||
public void testSet() { | ||
String string = new String(); | ||
assertDoesNotThrow(() -> { | ||
string.set(1); | ||
string.set(1L); | ||
string.set("PT8H6M12.345S"); | ||
string.set(null); | ||
|
||
Scalar<?> s = new String(""); | ||
string.set(s); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
String string = new String(); | ||
assertFalse(string.isValid()); | ||
assertNull(string.get()); | ||
|
||
assertDoesNotThrow(() -> { | ||
string.set(-1L); | ||
}); | ||
assertTrue(string.isValid()); | ||
assertEquals("-1", string.get()); | ||
|
||
assertDoesNotThrow(() -> { | ||
string.set(""); | ||
}); | ||
assertTrue(string.isValid()); | ||
assertEquals("", string.get()); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
String a = new String(); | ||
String b = new String(); | ||
assertEquals(a, b); | ||
assertNotEquals(a, null); | ||
assertNotEquals(a, new Bool()); // we can't cast Bool to String | ||
assertNotEquals(null, a); | ||
|
||
assertDoesNotThrow(() -> { | ||
a.set(-1L); | ||
}); | ||
assertNotEquals(a, b); | ||
|
||
assertDoesNotThrow(() -> { | ||
for (Object obj : new Object[]{null, 0, 0L, -1, -1L, 1, 1L, "PT8H6M12.345S", ""}) { | ||
a.set(obj); | ||
assertEquals(a, new String(obj)); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters