Skip to content
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
4 changes: 4 additions & 0 deletions lib/src/main/java/io/cloudquery/memdb/MemDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import io.cloudquery.transformers.Tables;
import io.cloudquery.transformers.TransformWithClass;
import io.grpc.stub.StreamObserver;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class MemDB extends Plugin {
Expand All @@ -32,6 +34,8 @@ public void resolve(
Table1Data.builder()
.id(UUID.fromString("46b2b6e6-8f3e-4340-a721-4aa0786b1cc0"))
.name("name1")
.timestamp(LocalDateTime.now())
.json(Map.of("key1", "value1", "key2", "value2"))
.build());
stream.write(
Table1Data.builder()
Expand Down
4 changes: 4 additions & 0 deletions lib/src/main/java/io/cloudquery/memdb/Table1Data.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cloudquery.memdb;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.UUID;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -9,4 +11,6 @@
public class Table1Data {
private UUID id;
private String name;
private LocalDateTime timestamp;
private Map<String, String> json;
}
32 changes: 16 additions & 16 deletions lib/src/main/java/io/cloudquery/scalar/Scalar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.cloudquery.scalar;

import io.cloudquery.types.JSONType;
import io.cloudquery.types.UUIDType;
import java.util.Objects;
import org.apache.arrow.vector.types.pojo.ArrowType;
Expand Down Expand Up @@ -77,6 +78,21 @@ public final int hashCode() {
public static final java.lang.String NULL_VALUE_STRING = "(null)";

public static Scalar<?> fromArrowType(ArrowType arrowType) {
if (arrowType instanceof ArrowType.ExtensionType extensionType) {
switch (extensionType.extensionName()) {
case UUIDType.EXTENSION_NAME -> {
return new UUID();
}
case JSONType.EXTENSION_NAME -> {
return new JSON();
}
// TODO: Add support for these types when scalar available
// case INETType.EXTENSION_NAME -> {
// return new INET();
// }
}
}

switch (arrowType.getTypeID()) {
case Timestamp -> {
return new Timestamp();
Expand Down Expand Up @@ -110,22 +126,6 @@ public static Scalar<?> fromArrowType(ArrowType arrowType) {
}
}

if (arrowType instanceof ArrowType.ExtensionType extensionType) {
//noinspection SwitchStatementWithTooFewBranches
switch (extensionType.extensionName()) {
case UUIDType.EXTENSION_NAME -> {
return new UUID();
}
// TODO: Add support for these types when scalar available
// case JSONType.EXTENSION_NAME -> {
// return new JSON();
// }
// case INETType.EXTENSION_NAME -> {
// return new INET();
// }
}
}

throw new UnsupportedOperationException("Unsupported type: " + arrowType);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/test/java/io/cloudquery/scalar/ScalarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertInstanceOf;

import io.cloudquery.types.JSONType;
import io.cloudquery.types.UUIDType;
import java.time.ZoneOffset;
import java.util.stream.Stream;
Expand Down Expand Up @@ -64,6 +65,7 @@ public static Stream<Arguments> testDataSource() {

// Extension
Arguments.of(new UUIDType(), UUID.class),
Arguments.of(new JSONType(), JSON.class),

// Date
Arguments.of(new ArrowType.Date(DateUnit.DAY), DateDay.class),
Expand Down