Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private Field getField(HoodieSchema fieldSchema, String name, boolean nullable)
standardSQLTypeName = StandardSQLTypeName.NUMERIC;
break;
case RECORD:
case BLOB:
return Field.newBuilder(name, StandardSQLTypeName.STRUCT,
FieldList.of(getFields(fieldSchema))).setMode(fieldMode).build();
case ARRAY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,62 @@ void getTableSchema_withoutPartitionFields() throws Exception {
Assertions.assertEquals(PRIMITIVE_TYPES_BQ_SCHEMA, resolver.getTableSchema(mockMetaClient, Collections.emptyList()));
}

@Test
void convertSchema_blobField() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: can we use camel case here

Copy link
Copy Markdown
Member Author

@voonhous voonhous Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other tests in this style using a mix of camel and snake case, so let's keep it as is.

HoodieSchema input = HoodieSchema.createRecord("testRecord", null, null, false, Arrays.asList(
HoodieSchemaField.of("id", HoodieSchema.create(HoodieSchemaType.INT)),
HoodieSchemaField.of("blob_data", HoodieSchema.createBlob())
));

Field expectedBlobField = Field.newBuilder("blob_data", StandardSQLTypeName.STRUCT,
Field.newBuilder("type", StandardSQLTypeName.STRING).setMode(Field.Mode.REQUIRED).build(),
Field.newBuilder("data", StandardSQLTypeName.BYTES).setMode(Field.Mode.NULLABLE).build(),
Field.newBuilder("reference", StandardSQLTypeName.STRUCT,
Field.newBuilder("external_path", StandardSQLTypeName.STRING).setMode(Field.Mode.REQUIRED).build(),
Field.newBuilder("offset", StandardSQLTypeName.INT64).setMode(Field.Mode.NULLABLE).build(),
Field.newBuilder("length", StandardSQLTypeName.INT64).setMode(Field.Mode.NULLABLE).build(),
Field.newBuilder("managed", StandardSQLTypeName.BOOL).setMode(Field.Mode.REQUIRED).build())
.setMode(Field.Mode.NULLABLE).build())
.setMode(Field.Mode.REQUIRED).build();

Schema result = SCHEMA_RESOLVER.convertSchema(input);
Assertions.assertEquals(2, result.getFields().size());
Assertions.assertEquals(expectedBlobField, result.getFields().get(1));
}

@Test
void convertSchema_nullableBlobField() {
HoodieSchema input = HoodieSchema.createRecord("testRecord", null, null, false, Arrays.asList(
HoodieSchemaField.of("id", HoodieSchema.create(HoodieSchemaType.INT)),
HoodieSchemaField.of("blob_data", HoodieSchema.createNullable(HoodieSchema.createBlob()))
));

Schema result = SCHEMA_RESOLVER.convertSchema(input);
Field blobField = result.getFields().get(1);
Assertions.assertEquals(Field.Mode.NULLABLE, blobField.getMode());
Assertions.assertEquals(StandardSQLTypeName.STRUCT, blobField.getType().getStandardType());
}

@Test
void convertSchema_nestedBlobField() {
HoodieSchema inner = HoodieSchema.createRecord("media", null, null, false, Arrays.asList(
HoodieSchemaField.of("title", HoodieSchema.create(HoodieSchemaType.STRING)),
HoodieSchemaField.of("content", HoodieSchema.createBlob())
));
HoodieSchema input = HoodieSchema.createRecord("testRecord", null, null, false, Arrays.asList(
HoodieSchemaField.of("id", HoodieSchema.create(HoodieSchemaType.INT)),
HoodieSchemaField.of("media", inner)
));

Schema result = SCHEMA_RESOLVER.convertSchema(input);
Field mediaField = result.getFields().get(1);
Assertions.assertEquals(StandardSQLTypeName.STRUCT, mediaField.getType().getStandardType());
// Verify the nested "content" sub-field is a STRUCT (BLOB)
Field contentField = mediaField.getSubFields().stream()
.filter(f -> f.getName().equals("content")).findFirst().get();
Assertions.assertEquals(StandardSQLTypeName.STRUCT, contentField.getType().getStandardType());
}

@Test
void convertSchema_vectorField() {
HoodieSchema input = HoodieSchema.createRecord("testRecord", null, null, false, Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private static String convertField(final HoodieSchema fieldSchema, boolean suppo
HoodieSchema valueType = nonNullType.getValueType();
return createHiveMap(convertField(keyType, supportTimestamp, doFormat), convertField(valueType, supportTimestamp, doFormat), doFormat);
case RECORD:
case BLOB:
return createHiveStruct(nonNullType.getFields(), supportTimestamp, doFormat);
default:
throw new UnsupportedOperationException("Cannot convert type " + nonNullType.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ void testSchemaTypeConversion() throws IOException {
HoodieSchemaField.of("time_micros_field", HoodieSchema.createTimeMicros()),
HoodieSchemaField.of("decimal_field", HoodieSchema.createDecimal(10, 2)),
HoodieSchemaField.of("uuid_field", HoodieSchema.create(HoodieSchemaType.UUID)),
HoodieSchemaField.of("vector_field", HoodieSchema.createVector(128))
HoodieSchemaField.of("vector_field", HoodieSchema.createVector(128)),
HoodieSchemaField.of("blob_field", HoodieSchema.createBlob()),
HoodieSchemaField.of("nullable_blob_field", HoodieSchema.createNullable(HoodieSchema.createBlob())),
HoodieSchemaField.of("nested_blob_field", HoodieSchema.createRecord("media", null, null, false, Arrays.asList(
HoodieSchemaField.of("title", HoodieSchema.create(HoodieSchemaType.STRING)),
HoodieSchemaField.of("content", HoodieSchema.createBlob())
)))
)
);

Expand All @@ -174,6 +180,12 @@ void testSchemaTypeConversion() throws IOException {
expected.put("`decimal_field`", "DECIMAL(10 , 2)");
expected.put("`uuid_field`", "binary");
expected.put("`vector_field`", "binary");
expected.put("`blob_field`",
"STRUCT< `type` : string, `data` : binary, `reference` : STRUCT< `external_path` : string, `offset` : bigint, `length` : bigint, `managed` : boolean>>");
expected.put("`nullable_blob_field`",
"STRUCT< `type` : string, `data` : binary, `reference` : STRUCT< `external_path` : string, `offset` : bigint, `length` : bigint, `managed` : boolean>>");
expected.put("`nested_blob_field`",
"STRUCT< `title` : string, `content` : STRUCT< `type` : string, `data` : binary, `reference` : STRUCT< `external_path` : string, `offset` : bigint, `length` : bigint, `managed` : boolean>>>");
assertEquals(expected, actual);
}
}
Loading