-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Substrait] Create
emit
op to represent output mapping.
The commit introduces handling for the `emit_kind` field of the `RelCommon` message, which is a common field of all (?) cases of the `Rel` message. The current design models this field as a dedicated op such that the output mapping is only ever present in that op, `emit`. There are at least two alternatives to this IR design. The first one consists of making the output mapping part of each of the ops the represnet `Rel` messages and expose it through the `RelOpInterface`. However, this would mean that (1) the custom assembly of each op would have to represent the mapping, which is manual effort and a possible source for inconsistencies, (2) each op would have to implement type inference in the presence of a mapping, and (3) most rewrites of all ops would have to take that mapping into account for their semantics. Having the mapping in one place makes all of this simpler. The downside is that what is kept in a single place in the Substrait protobuf format is now spread across two ops in the MLIR representation. However, I believe that this is the smaller of two evils and the current import and export seems to work. Another alternative would be to combine the two: make the mapping part of all ops but *also* introduce a dedicated `emit` op. Then, two passes could move the mapping from one to the other depending on which of the two representations would be more convenient. However, this would not get rid of Issues (1) and (2) above and lead to more concepts and code. Signed-off-by: Ingo Müller <[email protected]>
- Loading branch information
1 parent
6375d94
commit dfd6939
Showing
9 changed files
with
500 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: structured-opt -verify-diagnostics -split-input-file %s | ||
|
||
substrait.plan version 0 : 42 : 1 { | ||
relation { | ||
%0 = named_table @t1 as ["a"] : tuple<si32> | ||
// expected-error@+2 {{'substrait.emit' op failed to infer returned types}} | ||
// expected-error@+1 {{1 is not a valid index into 'tuple<si32>'}} | ||
%1 = emit [1] from %0 : tuple<si32> -> tuple<si32> | ||
yield %1 : tuple<si32> | ||
} | ||
} | ||
|
||
// ----- | ||
|
||
substrait.plan version 0 : 42 : 1 { | ||
relation { | ||
%0 = named_table @t1 as ["a"] : tuple<si32> | ||
// expected-error@+2 {{'substrait.emit' op failed to infer returned types}} | ||
// expected-error@+1 {{-1 is not a valid index into 'tuple<si32>'}} | ||
%1 = emit [-1] from %0 : tuple<si32> -> tuple<si32> | ||
yield %1 : tuple<si32> | ||
} | ||
} |
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,48 @@ | ||
// RUN: structured-opt -split-input-file %s \ | ||
// RUN: | FileCheck %s | ||
|
||
// CHECK-LABEL: substrait.plan | ||
// CHECK-NEXT: relation | ||
// CHECK-NEXT: %[[V0:.*]] = named_table | ||
// CHECK-NEXT: %[[V1:.*]] = emit [1, 0] from %[[V0]] : | ||
// CHECK-SAME: tuple<si1, si32> -> tuple<si32, si1> | ||
|
||
substrait.plan version 0 : 42 : 1 { | ||
relation { | ||
%0 = named_table @t1 as ["a", "b"] : tuple<si1, si32> | ||
%1 = emit [1, 0] from %0 : tuple<si1, si32> -> tuple<si32, si1> | ||
yield %1 : tuple<si32, si1> | ||
} | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: substrait.plan | ||
// CHECK-NEXT: relation | ||
// CHECK-NEXT: %[[V0:.*]] = named_table | ||
// CHECK-NEXT: %[[V1:.*]] = emit [0, 0] from %[[V0]] : | ||
// CHECK-SAME: tuple<si32> -> tuple<si32, si32> | ||
|
||
substrait.plan version 0 : 42 : 1 { | ||
relation { | ||
%0 = named_table @t1 as ["a"] : tuple<si32> | ||
%1 = emit [0, 0] from %0 : tuple<si32> -> tuple<si32, si32> | ||
yield %1 : tuple<si32, si32> | ||
} | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: substrait.plan | ||
// CHECK-NEXT: relation | ||
// CHECK-NEXT: %[[V0:.*]] = named_table | ||
// CHECK-NEXT: %[[V1:.*]] = emit [1] from %[[V0]] : | ||
// CHECK-SAME: tuple<si32, si1> -> tuple<si1> | ||
|
||
substrait.plan version 0 : 42 : 1 { | ||
relation { | ||
%0 = named_table @t1 as ["a", "b"] : tuple<si32, si1> | ||
%1 = emit [1] from %0 : tuple<si32, si1> -> tuple<si1> | ||
yield %1 : tuple<si1> | ||
} | ||
} |
Oops, something went wrong.