Skip to content

Commit ff51934

Browse files
committed
feat(core): add SubstraitBuilder.fieldReference(s) methods for joins
Signed-off-by: Niels Pardon <par@zurich.ibm.com>
1 parent a3c566f commit ff51934

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

core/src/main/java/io/substrait/dsl/SubstraitBuilder.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,40 @@ public List<FieldReference> fieldReferences(Rel input, int... indexes) {
508508
.collect(java.util.stream.Collectors.toList());
509509
}
510510

511+
/**
512+
* Creates a field reference for a join operation by index across both left and right relations.
513+
* The index spans across the combined schema of both join inputs, where fields from the left
514+
* relation come first, followed by fields from the right relation.
515+
*
516+
* @param inputs the join inputs containing both left and right relations
517+
* @param index the zero-based field index across the combined schema of both relations
518+
* @return a {@link FieldReference} pointing to the specified field in the join context
519+
*/
520+
public FieldReference fieldReference(JoinInput inputs, int index) {
521+
return FieldReference.newInputRelReference(index, List.of(inputs.left, inputs.right));
522+
}
523+
511524
public FieldReference fieldReference(List<Rel> inputs, int index) {
512525
return FieldReference.newInputRelReference(index, inputs);
513526
}
514527

528+
/**
529+
* Creates multiple field references for a join operation by indexes across both left and right
530+
* relations. Each index spans across the combined schema of both join inputs, where fields from
531+
* the left relation come first, followed by fields from the right relation.
532+
*
533+
* @param inputs the join inputs containing both left and right relations
534+
* @param indexes the zero-based field indexes across the combined schema of both relations
535+
* @return a list of {@link FieldReference} objects pointing to the specified fields in the join
536+
* context
537+
*/
538+
public List<FieldReference> fieldReferences(JoinInput inputs, int... indexes) {
539+
final List<Rel> inputsList = List.of(inputs.left, inputs.right);
540+
return Arrays.stream(indexes)
541+
.mapToObj(index -> fieldReference(inputsList, index))
542+
.collect(java.util.stream.Collectors.toList());
543+
}
544+
515545
public List<FieldReference> fieldReferences(List<Rel> inputs, int... indexes) {
516546
return Arrays.stream(indexes)
517547
.mapToObj(index -> fieldReference(inputs, index))

core/src/test/java/io/substrait/type/proto/JoinRoundtripTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ void mergeJoin() {
4848

4949
@Test
5050
void nestedLoopJoin() {
51-
List<Rel> inputRels = Arrays.asList(leftTable, rightTable);
5251
Rel rel =
5352
NestedLoopJoin.builder()
5453
.from(
5554
sb.nestedLoopJoin(
56-
__ ->
55+
inputRels ->
5756
sb.equal(sb.fieldReference(inputRels, 0), sb.fieldReference(inputRels, 5)),
5857
NestedLoopJoin.JoinType.INNER,
5958
leftTable,

0 commit comments

Comments
 (0)