Skip to content

fix(test): Register extensions in tests #144

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

Merged
merged 1 commit into from
Nov 27, 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
23 changes: 1 addition & 22 deletions lib/src/main/java/io/cloudquery/helper/ArrowHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import io.cloudquery.schema.Resource;
import io.cloudquery.schema.Table;
import io.cloudquery.schema.Table.TableBuilder;
import io.cloudquery.types.JSONType;
import io.cloudquery.types.JSONType.JSONVector;
import io.cloudquery.types.UUIDType;
import io.cloudquery.types.UUIDType.UUIDVector;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -23,7 +21,6 @@
import org.apache.arrow.vector.ipc.ArrowReader;
import org.apache.arrow.vector.ipc.ArrowStreamReader;
import org.apache.arrow.vector.ipc.ArrowStreamWriter;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.types.pojo.Schema;
Expand Down Expand Up @@ -264,30 +261,12 @@ private static Column getColumn(Field field) {
boolean isIncrementalKey =
Objects.equals(field.getMetadata().get(CQ_EXTENSION_INCREMENTAL), "true");

ArrowType fieldType = field.getType();
String extensionName =
field.getMetadata().get(ArrowType.ExtensionType.EXTENSION_METADATA_KEY_NAME);
String extensionMetadata =
field.getMetadata().get(ArrowType.ExtensionType.EXTENSION_METADATA_KEY_METADATA);

// We need to scan our extension types manually because of
// https://github.com/apache/arrow/issues/38891
if (JSONType.EXTENSION_NAME.equals(extensionName)
&& JSONType.INSTANCE.serialize().equals(extensionMetadata)
&& JSONType.INSTANCE.storageType().equals(fieldType)) {
fieldType = JSONType.INSTANCE;
} else if (UUIDType.EXTENSION_NAME.equals(extensionName)
&& UUIDType.INSTANCE.serialize().equals(extensionMetadata)
&& UUIDType.INSTANCE.storageType().equals(fieldType)) {
fieldType = UUIDType.INSTANCE;
}

return Column.builder()
.name(field.getName())
.unique(isUnique)
.primaryKey(isPrimaryKey)
.incrementalKey(isIncrementalKey)
.type(fieldType)
.type(field.getType())
.build();
}

Expand Down
9 changes: 9 additions & 0 deletions lib/src/test/java/io/cloudquery/helper/ArrowHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.cloudquery.schema.Column;
import io.cloudquery.schema.Resource;
import io.cloudquery.schema.Table;
import io.cloudquery.types.Extensions;
import io.cloudquery.types.JSONType;
import io.cloudquery.types.UUIDType;
import java.io.IOException;
Expand Down Expand Up @@ -128,6 +129,8 @@ public class ArrowHelperTest {

@Test
public void testToArrowSchema() {
Extensions.registerExtensions();

Schema arrowSchema = ArrowHelper.toArrowSchema(TEST_TABLE);

for (Column col : TEST_TABLE.getColumns()) {
Expand Down Expand Up @@ -197,6 +200,8 @@ public void testToArrowSchema() {

@Test
public void testFromArrowSchema() {
Extensions.registerExtensions();

List<Field> fields =
List.of(
Field.nullable("string_column1", ArrowType.Utf8.INSTANCE),
Expand All @@ -218,6 +223,8 @@ public void testFromArrowSchema() {

@Test
public void testRoundTripTableEncoding() throws IOException {
Extensions.registerExtensions();

ByteString byteString = ArrowHelper.encode(TEST_TABLE);
Table table = ArrowHelper.decode(byteString);

Expand All @@ -237,6 +244,8 @@ public void testRoundTripTableEncoding() throws IOException {

@Test
public void testRoundTripResourceEncoding() throws Exception {
Extensions.registerExtensions();

Resource resource = Resource.builder().table(TEST_TABLE).build();
resource.set("pk", "test_pk");
resource.set("big_int", -1024L);
Expand Down