-
Notifications
You must be signed in to change notification settings - Fork 95
feat: add missing extension YAMLs and test for completeness #723
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
1
commit into
main
Choose a base branch
from
add-missing-extensions-test
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.
Open
Changes from all commits
Commits
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
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
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
66 changes: 66 additions & 0 deletions
66
core/src/test/java/io/substrait/extension/DefaultExtensionCatalogTest.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,66 @@ | ||
| package io.substrait.extension; | ||
|
|
||
| import static io.substrait.extension.DefaultExtensionCatalog.DEFAULT_COLLECTION; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Verifies that every extension YAML in substrait/extensions is loaded by {@link | ||
| * DefaultExtensionCatalog}. | ||
| */ | ||
| class DefaultExtensionCatalogTest { | ||
|
|
||
| private static final Set<String> UNSUPPORTED_FILES = | ||
| Set.of( | ||
| // TODO: aggregate_decimal_output defines count and approx_count_distinct with | ||
| // decimal<38,0> return types instead of i64. When loaded alongside aggregate_generic, | ||
| // the same function key (e.g. count:any) maps to the same Calcite operator twice, | ||
| // which breaks the reverse lookup in FunctionConverter.getSqlOperatorFromSubstraitFunc. | ||
| // Fixing this requires either deduplicating the operator map or adding type-based | ||
| // disambiguation for aggregate functions. | ||
| "functions_aggregate_decimal_output.yaml", | ||
| "functions_geometry.yaml", // user-defined types not supported in Calcite type conversion | ||
| "functions_list.yaml", // TODO(#688): remove once lambda types are supported | ||
| "type_variations.yaml", // type variations not yet supported by extension loader | ||
| "unknown.yaml" // unknown type extension not yet loaded | ||
| ); | ||
|
|
||
| private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory()); | ||
|
|
||
| @Test | ||
| void allExtensionYamlFilesAreLoaded() throws IOException { | ||
| List<File> yamlFiles = getExtensionYamlFiles(); | ||
|
|
||
| for (File file : yamlFiles) { | ||
| if (UNSUPPORTED_FILES.contains(file.getName())) { | ||
| continue; | ||
| } | ||
| String urn = parseUrn(file); | ||
| assertTrue( | ||
| DEFAULT_COLLECTION.containsUrn(urn), | ||
| file.getName() + " not loaded by DefaultExtensionCatalog (urn: " + urn + ")"); | ||
| } | ||
| } | ||
|
|
||
| private static String parseUrn(File yamlFile) throws IOException { | ||
| JsonNode doc = YAML_MAPPER.readTree(yamlFile); | ||
| JsonNode urnNode = doc.get("urn"); | ||
| return urnNode == null ? null : urnNode.asText(); | ||
| } | ||
|
|
||
| private static List<File> getExtensionYamlFiles() { | ||
| File extensionsDir = new File("../substrait/extensions"); | ||
| assertTrue(extensionsDir.isDirectory(), "substrait/extensions directory not found"); | ||
| File[] files = extensionsDir.listFiles((dir, name) -> name.endsWith(".yaml")); | ||
| assertTrue(files != null && files.length > 0, "No YAML files found"); | ||
| return List.of(files); | ||
| } | ||
| } | ||
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.
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 this should check the extension YAML files on the classpath instead of relying on the current working directory (especially given that @vbarua is planning to remove the submodule and move packaging the extension YAMLs into a separate JAR into substrait-packaging). The YAMLs should be already on the classpath. We're already loading classgraph for the isthmus-cli which can be useful to scan the classpath for any
*.yamlfiles.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.
Sounds good to me, I'll make that change shortly. Thanks!
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.
btw. it might be better to relocate the YAML files on the classpath into a subfolder like
substrait/extensionsto be easier recognizable as default YAML files. right now they are being added into the root of the classpath