-
Notifications
You must be signed in to change notification settings - Fork 95
feat(core): expose metadata from YAML extension files #691
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
Open
benbellick
wants to merge
2
commits into
main
Choose a base branch
from
benbellick/expose-yaml-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−6
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
core/src/test/java/io/substrait/extension/MetadataExtensionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package io.substrait.extension; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import io.substrait.TestBase; | ||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Verifies that metadata can be read from extension YAML files at multiple levels: | ||
| * | ||
| * <ul> | ||
| * <li>Extension-level metadata (top-level) | ||
| * <li>Type-level metadata | ||
| * <li>Function-level metadata (scalar, aggregate, window) | ||
| * </ul> | ||
| */ | ||
| class MetadataExtensionTest extends TestBase { | ||
|
|
||
| static final String URN = "extension:test:metadata_extensions"; | ||
| static final SimpleExtension.ExtensionCollection METADATA_EXTENSION; | ||
|
|
||
| static { | ||
| try { | ||
| String extensionStr = asString("extensions/metadata_extensions.yaml"); | ||
| METADATA_EXTENSION = SimpleExtension.load(URN, extensionStr); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| } | ||
|
|
||
| MetadataExtensionTest() { | ||
| super(METADATA_EXTENSION); | ||
| } | ||
|
|
||
| @Test | ||
| void testExtensionLevelMetadata() { | ||
| Map<String, Object> metadata = extensions.getExtensionMetadata(URN).orElseThrow(); | ||
| assertEquals("1.0", metadata.get("version")); | ||
| assertEquals("test-team", metadata.get("author")); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| Map<String, Object> customData = (Map<String, Object>) metadata.get("custom_data"); | ||
| assertEquals(true, customData.get("nested_value")); | ||
| assertEquals(42, customData.get("numeric_value")); | ||
| } | ||
|
|
||
| @Test | ||
| void testExtensionLevelMetadataMissing() { | ||
| assertTrue(extensions.getExtensionMetadata("extension:nonexistent:urn").isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testTypeMetadata() { | ||
| SimpleExtension.TypeAnchor anchor = SimpleExtension.TypeAnchor.of(URN, "metadataType"); | ||
| Map<String, Object> metadata = extensions.getType(anchor).metadata().orElseThrow(); | ||
| assertEquals("custom-type-metadata", metadata.get("type_info")); | ||
| assertEquals("user-defined", metadata.get("category")); | ||
| } | ||
|
|
||
| @Test | ||
| void testScalarFunctionMetadata() { | ||
| SimpleExtension.FunctionAnchor anchor = | ||
| SimpleExtension.FunctionAnchor.of(URN, "metadataScalar:i64"); | ||
| Map<String, Object> metadata = extensions.getScalarFunction(anchor).metadata().orElseThrow(); | ||
| assertEquals("vectorized", metadata.get("perf_hint")); | ||
| assertEquals(1, metadata.get("cost")); | ||
| } | ||
|
|
||
| @Test | ||
| void testAggregateFunctionMetadata() { | ||
| SimpleExtension.FunctionAnchor anchor = | ||
| SimpleExtension.FunctionAnchor.of(URN, "metadataAggregate:i64"); | ||
| assertEquals( | ||
| "incremental", | ||
| extensions.getAggregateFunction(anchor).metadata().orElseThrow().get("agg_info")); | ||
| } | ||
|
|
||
| @Test | ||
| void testWindowFunctionMetadata() { | ||
| SimpleExtension.FunctionAnchor anchor = | ||
| SimpleExtension.FunctionAnchor.of(URN, "metadataWindow:i64"); | ||
| assertEquals( | ||
| "partitioned", | ||
| extensions.getWindowFunction(anchor).metadata().orElseThrow().get("window_info")); | ||
| } | ||
|
|
||
| @Test | ||
| void testMergePreservesMetadata() throws IOException { | ||
| String customExtensionStr = asString("extensions/custom_extensions.yaml"); | ||
| SimpleExtension.ExtensionCollection customExtension = | ||
| SimpleExtension.load("extension:test:custom_extensions", customExtensionStr); | ||
|
|
||
| SimpleExtension.ExtensionCollection merged = METADATA_EXTENSION.merge(customExtension); | ||
|
|
||
| assertEquals("1.0", merged.getExtensionMetadata(URN).orElseThrow().get("version")); | ||
| assertTrue(merged.getExtensionMetadata("extension:test:custom_extensions").isEmpty()); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
core/src/test/resources/extensions/metadata_extensions.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| %YAML 1.2 | ||
| --- | ||
| urn: extension:test:metadata_extensions | ||
| metadata: | ||
| version: "1.0" | ||
| author: "test-team" | ||
| custom_data: | ||
| nested_value: true | ||
| numeric_value: 42 | ||
| types: | ||
| - name: "metadataType" | ||
| metadata: | ||
| type_info: "custom-type-metadata" | ||
| category: "user-defined" | ||
| scalar_functions: | ||
| - name: "metadataScalar" | ||
| metadata: | ||
| perf_hint: "vectorized" | ||
| cost: 1 | ||
| impls: | ||
| - args: | ||
| - value: i64 | ||
| return: i64 | ||
| aggregate_functions: | ||
| - name: "metadataAggregate" | ||
| metadata: | ||
| agg_info: "incremental" | ||
| impls: | ||
| - args: | ||
| - value: i64 | ||
| return: i64 | ||
| window_functions: | ||
| - name: "metadataWindow" | ||
| metadata: | ||
| window_info: "partitioned" | ||
| impls: | ||
| - args: | ||
| - value: i64 | ||
| return: i64 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether it would be useful to have an interface instead of
Objectfor e.g. creating custom YAML deserializers / serializers and whether we should allow to add them to theObjectMapperinSimpleExtension.load().Otherwise I'm fine with the changes.