diff --git a/lib/src/main/java/io/cloudquery/scalar/Binary.java b/lib/src/main/java/io/cloudquery/scalar/Binary.java index 76844ae..b70f5d0 100644 --- a/lib/src/main/java/io/cloudquery/scalar/Binary.java +++ b/lib/src/main/java/io/cloudquery/scalar/Binary.java @@ -5,9 +5,8 @@ import java.util.Arrays; -public class Binary implements Scalar { +public class Binary implements Scalar { protected byte[] value; - protected boolean valid; public Binary() { } @@ -18,7 +17,7 @@ public Binary(Object value) throws ValidationException { @Override public String toString() { - if (this.valid) { + if (this.value != null) { return Base64.encodeBase64String(this.value); } return NULL_VALUE_STRING; @@ -26,7 +25,7 @@ public String toString() { @Override public boolean isValid() { - return this.valid; + return this.value != null; } @Override @@ -37,14 +36,12 @@ public ArrowType dataType() { @Override public void set(Object value) throws ValidationException { if (value == null) { - this.valid = false; this.value = null; return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { - this.valid = false; this.value = null; return; } @@ -54,19 +51,16 @@ public void set(Object value) throws ValidationException { } if (value instanceof byte[] bytes) { - this.valid = true; this.value = bytes; return; } if (value instanceof CharSequence sequence) { - this.valid = true; this.value = Base64.decodeBase64(sequence.toString()); return; } if (value instanceof char[] chars) { - this.valid = true; this.value = Base64.decodeBase64(new String(chars)); return; } @@ -75,23 +69,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - if (this.valid) { - return this.value; - } - return null; + public byte[] get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof Binary o)) { - return false; + if (other instanceof Binary o) { + if (this.value == null) { + return o.value == null; + } + return Arrays.equals(this.value, o.value); } - - return (this.valid == o.valid) && Arrays.equals(this.value, o.value); + return false; } } \ No newline at end of file diff --git a/lib/src/main/java/io/cloudquery/scalar/Bool.java b/lib/src/main/java/io/cloudquery/scalar/Bool.java index 27b2955..97698be 100644 --- a/lib/src/main/java/io/cloudquery/scalar/Bool.java +++ b/lib/src/main/java/io/cloudquery/scalar/Bool.java @@ -2,9 +2,8 @@ import org.apache.arrow.vector.types.pojo.ArrowType; -public class Bool implements Scalar { - protected boolean value; - protected boolean valid; +public class Bool implements Scalar { + protected Boolean value; public Bool() { } @@ -15,15 +14,15 @@ public Bool(Object value) throws ValidationException { @Override public String toString() { - if (this.valid) { - return Boolean.toString(this.value); + if (this.value != null) { + return this.value.toString(); } return NULL_VALUE_STRING; } @Override public boolean isValid() { - return this.valid; + return this.value != null; } @Override @@ -34,15 +33,13 @@ public ArrowType dataType() { @Override public void set(Object value) throws ValidationException { if (value == null) { - this.valid = false; - this.value = false; + this.value = null; return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { - this.valid = false; - this.value = false; + this.value = null; return; } @@ -51,13 +48,11 @@ public void set(Object value) throws ValidationException { } if (value instanceof Boolean b) { - this.valid = true; this.value = b; return; } if (value instanceof CharSequence sequence) { - this.valid = true; this.value = Boolean.parseBoolean(sequence.toString()); return; } @@ -66,23 +61,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - if (this.valid) { - return this.value; - } - return null; + public Boolean get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof Bool o)) { - return false; + if (other instanceof Bool o) { + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } - - return (this.valid == o.valid) && (this.value == o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/DateDay.java b/lib/src/main/java/io/cloudquery/scalar/DateDay.java index cfd3d7f..cc756c0 100644 --- a/lib/src/main/java/io/cloudquery/scalar/DateDay.java +++ b/lib/src/main/java/io/cloudquery/scalar/DateDay.java @@ -3,9 +3,8 @@ import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.pojo.ArrowType; -public class DateDay implements Scalar { - protected int value; - protected boolean valid; +public class DateDay implements Scalar { + protected Integer value; public DateDay() { } @@ -16,15 +15,15 @@ public DateDay(Object value) throws ValidationException { @Override public String toString() { - if (this.valid) { - return Integer.toString(this.value); + if (this.value != null) { + return this.value.toString(); } return NULL_VALUE_STRING; } @Override public boolean isValid() { - return this.valid; + return this.value != null; } @Override @@ -35,20 +34,17 @@ public ArrowType dataType() { @Override public void set(Object value) throws ValidationException { if (value == null) { - this.valid = false; this.value = 0; return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { - this.valid = false; this.value = 0; return; } if (scalar instanceof DateDay date) { - this.valid = date.valid; this.value = date.value; return; } @@ -58,13 +54,11 @@ public void set(Object value) throws ValidationException { } if (value instanceof Integer b) { - this.valid = true; this.value = b; return; } if (value instanceof CharSequence sequence) { - this.valid = true; this.value = Integer.parseInt(sequence.toString()); return; } @@ -73,23 +67,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - if (this.valid) { - return this.value; - } - return null; + public Integer get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof DateDay o)) { - return false; + if (other instanceof DateDay o) { + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } - - return (this.valid == o.valid) && (this.value == o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/DateMilli.java b/lib/src/main/java/io/cloudquery/scalar/DateMilli.java index eb6c9fa..15a699f 100644 --- a/lib/src/main/java/io/cloudquery/scalar/DateMilli.java +++ b/lib/src/main/java/io/cloudquery/scalar/DateMilli.java @@ -3,9 +3,8 @@ import org.apache.arrow.vector.types.DateUnit; import org.apache.arrow.vector.types.pojo.ArrowType; -public class DateMilli implements Scalar { - protected long value; - protected boolean valid; +public class DateMilli implements Scalar { + protected Long value; public DateMilli() { } @@ -16,15 +15,15 @@ public DateMilli(Object value) throws ValidationException { @Override public String toString() { - if (this.valid) { - return Long.toString(this.value); + if (this.value != null) { + return this.value.toString(); } return NULL_VALUE_STRING; } @Override public boolean isValid() { - return this.valid; + return this.value != null; } @Override @@ -35,20 +34,17 @@ public ArrowType dataType() { @Override public void set(Object value) throws ValidationException { if (value == null) { - this.valid = false; - this.value = 0; + this.value = null; return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { - this.valid = false; - this.value = 0; + this.value = null; return; } if (scalar instanceof DateMilli date) { - this.valid = date.valid; this.value = date.value; return; } @@ -58,19 +54,16 @@ public void set(Object value) throws ValidationException { } if (value instanceof Long b) { - this.valid = true; this.value = b; return; } if (value instanceof Integer b) { - this.valid = true; - this.value = b; + this.value = Long.valueOf(b); return; } if (value instanceof CharSequence sequence) { - this.valid = true; this.value = Long.parseLong(sequence.toString()); return; } @@ -79,23 +72,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - if (this.valid) { - return this.value; - } - return null; + public Long get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof DateMilli o)) { - return false; + if (other instanceof DateMilli o) { + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } - - return (this.valid == o.valid) && (this.value == o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/Duration.java b/lib/src/main/java/io/cloudquery/scalar/Duration.java index 3691428..64b3fb0 100644 --- a/lib/src/main/java/io/cloudquery/scalar/Duration.java +++ b/lib/src/main/java/io/cloudquery/scalar/Duration.java @@ -3,7 +3,7 @@ import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; -public class Duration implements Scalar { +public class Duration implements Scalar { protected java.time.Duration value; // TODO: add more units support later @@ -41,7 +41,7 @@ public void set(Object value) throws ValidationException { return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { this.value = null; return; @@ -80,20 +80,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - return this.value; // null or proper value + public java.time.Duration get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof Duration o)) { - return false; + if (other instanceof Duration o) { + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } - - return this.value == o.value || this.value.equals(o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/LargeBinary.java b/lib/src/main/java/io/cloudquery/scalar/LargeBinary.java index ade2dea..9e4f5bf 100644 --- a/lib/src/main/java/io/cloudquery/scalar/LargeBinary.java +++ b/lib/src/main/java/io/cloudquery/scalar/LargeBinary.java @@ -21,14 +21,12 @@ public ArrowType dataType() { @Override public boolean equals(Object other) { - if (other == null) { - return false; + if (other instanceof LargeBinary o) { + if (this.value == null) { + return o.value == null; + } + return Arrays.equals(this.value, o.value); } - - if (!(other instanceof LargeBinary o)) { - return false; - } - - return (this.valid == o.valid) && Arrays.equals(this.value, o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/Scalar.java b/lib/src/main/java/io/cloudquery/scalar/Scalar.java index b6857fd..f18934a 100644 --- a/lib/src/main/java/io/cloudquery/scalar/Scalar.java +++ b/lib/src/main/java/io/cloudquery/scalar/Scalar.java @@ -2,7 +2,7 @@ import org.apache.arrow.vector.types.pojo.ArrowType; -public interface Scalar { +public interface Scalar { String toString(); boolean isValid(); @@ -11,7 +11,7 @@ public interface Scalar { void set(Object value) throws ValidationException; - Object get(); + T get(); boolean equals(Object other); diff --git a/lib/src/main/java/io/cloudquery/scalar/Timestamp.java b/lib/src/main/java/io/cloudquery/scalar/Timestamp.java index 3377bae..04c6743 100644 --- a/lib/src/main/java/io/cloudquery/scalar/Timestamp.java +++ b/lib/src/main/java/io/cloudquery/scalar/Timestamp.java @@ -5,7 +5,7 @@ import java.time.*; -public class Timestamp implements Scalar { +public class Timestamp implements Scalar { public static final ZoneId zoneID = ZoneOffset.UTC; // TODO: add more units support later @@ -45,7 +45,7 @@ public void set(Object value) throws ValidationException { return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { this.value = null; return; @@ -94,20 +94,18 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { - return this.value; // null or proper value + public ZonedDateTime get() { + return this.value; } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (!(other instanceof Timestamp o)) { - return false; + if (other instanceof Timestamp o) { + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } - - return this.value == o.value || this.value.equals(o.value); + return false; } } diff --git a/lib/src/main/java/io/cloudquery/scalar/UUID.java b/lib/src/main/java/io/cloudquery/scalar/UUID.java index 8ea8ce8..53d17b9 100644 --- a/lib/src/main/java/io/cloudquery/scalar/UUID.java +++ b/lib/src/main/java/io/cloudquery/scalar/UUID.java @@ -6,7 +6,7 @@ import java.nio.ByteBuffer; import java.util.Objects; -public class UUID implements Scalar { +public class UUID implements Scalar { private static final int BYTE_WIDTH = 16; private static final FixedSizeBinary dt = new FixedSizeBinary(BYTE_WIDTH); @@ -19,6 +19,14 @@ public UUID(Object value) throws ValidationException { this.set(value); } + @Override + public String toString() { + if (this.value != null) { + return this.value.toString(); + } + return NULL_VALUE_STRING; + } + @Override public boolean isValid() { return this.value != null; @@ -36,7 +44,7 @@ public void set(Object value) throws ValidationException { return; } - if (value instanceof Scalar scalar) { + if (value instanceof Scalar scalar) { if (!scalar.isValid()) { this.value = null; return; @@ -76,14 +84,17 @@ public void set(Object value) throws ValidationException { } @Override - public Object get() { + public java.util.UUID get() { return this.value; } @Override public final boolean equals(Object other) { if (other instanceof UUID o) { - return this.value == o.value || Objects.equals(this.value, o.value); + if (this.value == null) { + return o.value == null; + } + return this.value.equals(o.value); } return false; } @@ -92,12 +103,4 @@ public final boolean equals(Object other) { public final int hashCode() { return Objects.hash(value); } - - @Override - public String toString() { - if (this.value != null) { - return this.value.toString(); - } - return NULL_VALUE_STRING; - } }