forked from substrait-io/substrait-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved ReadRel handling (substrait-io#194)
* feat: builder util for equal fn * test: additional ReadRel coverage * fix: rel to proto NamedScan conversion skipped filter * fix: rel to proto VirtualScan conversion skipped filter * fix: proto expression converter should use table schema The use of the EMPTY_TYPE caused failures when attempting to convert filters with field reference on VirtualScans, because the field references were seen as out-of-bounds. * fix: allow proto to rel conversion of empty VirtualScan
- Loading branch information
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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
59 changes: 59 additions & 0 deletions
59
core/src/test/java/io/substrait/type/proto/ReadRelRoundtripTest.java
This file contains 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,59 @@ | ||
package io.substrait.type.proto; | ||
|
||
import io.substrait.TestBase; | ||
import io.substrait.expression.ExpressionCreator; | ||
import io.substrait.relation.EmptyScan; | ||
import io.substrait.relation.NamedScan; | ||
import io.substrait.relation.VirtualTableScan; | ||
import io.substrait.type.NamedStruct; | ||
import io.substrait.type.Type; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ReadRelRoundtripTest extends TestBase { | ||
|
||
@Test | ||
void namedScan() { | ||
var tableName = Stream.of("a_table").collect(Collectors.toList()); | ||
var columnNames = Stream.of("column1", "column2").collect(Collectors.toList()); | ||
List<Type> columnTypes = Stream.of(R.I64, R.I64).collect(Collectors.toList()); | ||
|
||
var namedScan = b.namedScan(tableName, columnNames, columnTypes); | ||
namedScan = | ||
NamedScan.builder() | ||
.from(namedScan) | ||
.filter(b.equal(b.fieldReference(namedScan, 0), b.fieldReference(namedScan, 1))) | ||
.build(); | ||
|
||
verifyRoundTrip(namedScan); | ||
} | ||
|
||
@Test | ||
void emptyScan() { | ||
var emptyScan = | ||
EmptyScan.builder() | ||
.initialSchema(NamedStruct.of(Collections.emptyList(), R.struct())) | ||
.build(); | ||
verifyRoundTrip(emptyScan); | ||
} | ||
|
||
@Test | ||
void virtualTable() { | ||
var virtTable = | ||
VirtualTableScan.builder() | ||
.addAllDfsNames(Stream.of("column1", "column2").collect(Collectors.toList())) | ||
.addRows( | ||
ExpressionCreator.struct( | ||
false, ExpressionCreator.i64(false, 1), ExpressionCreator.i64(false, 2))) | ||
.build(); | ||
virtTable = | ||
VirtualTableScan.builder() | ||
.from(virtTable) | ||
.filter(b.equal(b.fieldReference(virtTable, 0), b.fieldReference(virtTable, 1))) | ||
.build(); | ||
verifyRoundTrip(virtTable); | ||
} | ||
} |