Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: int/uint/float/string scalars #59

Merged
merged 9 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
api 'org.apache.commons:commons-math3:3.6.1'

// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'org.jooq:joou:0.9.4'
implementation 'com.google.guava:guava:32.1.2-jre'
implementation 'info.picocli:picocli:4.7.4'
implementation 'com.google.guava:guava:32.1.2-jre'
Expand Down
54 changes: 22 additions & 32 deletions lib/src/main/java/io/cloudquery/scalar/Binary.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,30 @@

import java.util.Arrays;

public class Binary implements Scalar<byte[]> {
protected byte[] value;

public class Binary extends Scalar<byte[]> {
public Binary() {
super();
}

public Binary(Object value) throws ValidationException {
this.set(value);
super(value);
}

@Override
public String toString() {
public java.lang.String toString() {
if (this.value != null) {
return Base64.encodeBase64String(this.value);
}
return NULL_VALUE_STRING;
}

@Override
public boolean isValid() {
return this.value != null;
}

@Override
public ArrowType dataType() {
return ArrowType.Binary.INSTANCE;
}

@Override
public void set(Object value) throws ValidationException {
if (value == null) {
this.value = null;
return;
}

if (value instanceof Scalar<?> scalar) {
if (!scalar.isValid()) {
this.value = null;
return;
}

this.set(scalar.get());
return;
}

public void setValue(Object value) throws ValidationException {
if (value instanceof byte[] bytes) {
this.value = bytes;
return;
Expand All @@ -61,18 +40,13 @@ public void set(Object value) throws ValidationException {
}

if (value instanceof char[] chars) {
this.value = Base64.decodeBase64(new String(chars));
this.value = Base64.decodeBase64(new java.lang.String(chars));
return;
}

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

@Override
public byte[] get() {
return this.value;
}

@Override
public boolean equals(Object other) {
if (other instanceof Binary o) {
Expand All @@ -83,4 +57,20 @@ public boolean equals(Object other) {
}
return false;
}

public static class LargeBinary extends Binary {

public LargeBinary() {
super();
}

public LargeBinary(Object value) throws ValidationException {
super(value);
}

@Override
public ArrowType dataType() {
return ArrowType.LargeBinary.INSTANCE;
}
}
}
53 changes: 4 additions & 49 deletions lib/src/main/java/io/cloudquery/scalar/Bool.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

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

public class Bool implements Scalar<Boolean> {
protected Boolean value;

public class Bool extends Scalar<Boolean> {
public Bool() {
super();
}

public Bool(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;
super(value);
}

@Override
Expand All @@ -31,22 +17,7 @@ public ArrowType dataType() {
}

@Override
public void set(Object value) throws ValidationException {
if (value == null) {
this.value = null;
return;
}

if (value instanceof Scalar<?> scalar) {
if (!scalar.isValid()) {
this.value = null;
return;
}

this.set(scalar.get());
return;
}

public void setValue(Object value) throws ValidationException {
if (value instanceof Boolean b) {
this.value = b;
return;
Expand All @@ -59,20 +30,4 @@ public void set(Object value) throws ValidationException {

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

@Override
public Boolean get() {
return this.value;
}

@Override
public boolean equals(Object other) {
if (other instanceof Bool o) {
if (this.value == null) {
return o.value == null;
}
return this.value.equals(o.value);
}
return false;
}
}
58 changes: 4 additions & 54 deletions lib/src/main/java/io/cloudquery/scalar/DateDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@
import org.apache.arrow.vector.types.DateUnit;
import org.apache.arrow.vector.types.pojo.ArrowType;

public class DateDay implements Scalar<Integer> {
protected Integer value;

public class DateDay extends Scalar<Integer> {
public DateDay() {
super();
}

public DateDay(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;
super(value);
}

@Override
Expand All @@ -32,27 +18,7 @@ public ArrowType dataType() {
}

@Override
public void set(Object value) throws ValidationException {
if (value == null) {
this.value = 0;
return;
}

if (value instanceof Scalar<?> scalar) {
if (!scalar.isValid()) {
this.value = 0;
return;
}

if (scalar instanceof DateDay date) {
this.value = date.value;
return;
}

this.set(scalar.get());
return;
}

public void setValue(Object value) throws ValidationException {
if (value instanceof Integer b) {
this.value = b;
return;
Expand All @@ -65,20 +31,4 @@ public void set(Object value) throws ValidationException {

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

@Override
public Integer get() {
return this.value;
}

@Override
public boolean equals(Object other) {
if (other instanceof DateDay o) {
if (this.value == null) {
return o.value == null;
}
return this.value.equals(o.value);
}
return false;
}
}
58 changes: 4 additions & 54 deletions lib/src/main/java/io/cloudquery/scalar/DateMilli.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@
import org.apache.arrow.vector.types.DateUnit;
import org.apache.arrow.vector.types.pojo.ArrowType;

public class DateMilli implements Scalar<Long> {
protected Long value;

public class DateMilli extends Scalar<Long> {
public DateMilli() {
super();
}

public DateMilli(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;
super(value);
}

@Override
Expand All @@ -32,27 +18,7 @@ public ArrowType dataType() {
}

@Override
public void set(Object value) throws ValidationException {
if (value == null) {
this.value = null;
return;
}

if (value instanceof Scalar<?> scalar) {
if (!scalar.isValid()) {
this.value = null;
return;
}

if (scalar instanceof DateMilli date) {
this.value = date.value;
return;
}

this.set(scalar.get());
return;
}

public void setValue(Object value) throws ValidationException {
if (value instanceof Long b) {
this.value = b;
return;
Expand All @@ -70,20 +36,4 @@ public void set(Object value) throws ValidationException {

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

@Override
public Long get() {
return this.value;
}

@Override
public boolean equals(Object other) {
if (other instanceof DateMilli o) {
if (this.value == null) {
return o.value == null;
}
return this.value.equals(o.value);
}
return false;
}
}
Loading