Skip to content
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

feat: check that VirtualTableScan field names correspond to schema #284

Merged
merged 1 commit into from
Jul 18, 2024
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
13 changes: 12 additions & 1 deletion core/src/main/java/io/substrait/relation/VirtualTableScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ public abstract class VirtualTableScan extends AbstractReadRel {
@Value.Check
protected void check() {
var names = getInitialSchema().names();

assert names.size()
== NamedFieldCountingTypeVisitor.countNames(this.getInitialSchema().struct());
Copy link
Member Author

Choose a reason for hiding this comment

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

It may make more sense to move this check into the NamedStruct itself in the long-term. Avoiding this for now because there's some stuff I'd like to verify around names going to and from Calcite and Substrait.

var rows = getRows();

assert rows.size() > 0
&& names.stream().noneMatch(s -> s == null)
&& rows.stream().noneMatch(r -> r == null)
&& rows.stream()
.allMatch(r -> r.getType().accept(new NamedFieldCountingTypeVisitor()) == names.size());
.allMatch(r -> NamedFieldCountingTypeVisitor.countNames(r.getType()) == names.size());
}

@Override
Expand All @@ -44,6 +47,14 @@ public static ImmutableVirtualTableScan.Builder builder() {

private static class NamedFieldCountingTypeVisitor
implements TypeVisitor<Integer, RuntimeException> {

private static final NamedFieldCountingTypeVisitor VISITOR =
new NamedFieldCountingTypeVisitor();

private static Integer countNames(Type type) {
return type.accept(VISITOR);
}

@Override
public Integer visit(Type.Bool type) throws RuntimeException {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void check() {
R.struct(
R.STRING,
R.struct(R.STRING, R.STRING),
R.list(R.STRING),
R.map(R.STRING, R.STRING))))
R.list(R.struct(R.STRING)),
R.map(R.struct(R.STRING), R.struct(R.STRING)))))
Copy link
Member Author

Choose a reason for hiding this comment

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

The types here did not match the actual row types, which led to some confusion.

.addRows(
struct(
false,
Expand Down
Loading