From 095af9bcdefc82b786b518b408e39a1518a0d0ae Mon Sep 17 00:00:00 2001 From: Dalia Shaaban Date: Sat, 7 Dec 2024 01:36:14 +0100 Subject: [PATCH 1/9] implement join --- .../Dialect/Substrait/IR/SubstraitOps.td | 30 + lib/Dialect/Substrait/IR/Substrait.cpp | 21 + lib/Target/SubstraitPB/Export.cpp | 45 ++ lib/Target/SubstraitPB/Import.cpp | 32 + lib/Target/SubstraitPB/ProtobufUtils.cpp | 4 + test/Dialect/Substrait/join.mlir | 138 +++++ test/Target/SubstraitPB/Export/join.mlir | 200 +++++++ test/Target/SubstraitPB/Import/join.textpb | 559 ++++++++++++++++++ 8 files changed, 1029 insertions(+) create mode 100644 test/Dialect/Substrait/join.mlir create mode 100644 test/Target/SubstraitPB/Export/join.mlir create mode 100644 test/Target/SubstraitPB/Import/join.textpb diff --git a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td index 8e1ffed..cf3a4e2 100644 --- a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td +++ b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td @@ -474,6 +474,36 @@ def Substrait_FilterOp : Substrait_RelOp<"filter", [ }]; } +def JoinTypeKind : I32EnumAttr<"JoinTypeKind", + "The enum values correspond to those in the JoinRel.JoinType message.", [ + I32EnumAttrCase<"unspecified", 0>, + I32EnumAttrCase<"inner", 1>, + I32EnumAttrCase<"outer", 2>, + I32EnumAttrCase<"left", 3>, + I32EnumAttrCase<"right", 4>, + I32EnumAttrCase<"semi", 5>, + I32EnumAttrCase<"anti", 6>, + I32EnumAttrCase<"single", 7>] >; + +def Substrait_JoinOp : Substrait_RelOp<"join", [DeclareOpInterfaceMethods]> { + let summary = "join operation"; + let description = [{ + Represents a `JoinRel` message together with the `RelCommon`, left and + right `Rel` messages and `JoinType` enumeration it contains. The current + implementation assumes the join expression to be True. + }]; + //TODO(daliashaaban): Add support for join expressions. + let arguments = (ins + Substrait_Relation:$left, + Substrait_Relation:$right, + JoinTypeKind:$join_type + ); + let results = (outs Substrait_Relation:$result); + let assemblyFormat = [{ + $join_type $left `j` $right attr-dict `:` type($left) `j` type($right) + }]; +} + def Substrait_NamedTableOp : Substrait_RelOp<"named_table", [ ]> { let summary = "Read operation of a named table"; diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index 8b1b429..dcbd307 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -256,6 +256,27 @@ LiteralOp::inferReturnTypes(MLIRContext *context, std::optional loc, return success(); } +LogicalResult +JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, + ValueRange operands, DictionaryAttr attributes, + OpaqueProperties properties, RegionRange regions, + llvm::SmallVectorImpl &inferredReturnTypes) { + Value leftInput = operands[0]; + Value rightInput = operands[1]; + + TypeRange leftFieldTypes = cast(leftInput.getType()).getTypes(); + TypeRange rightFieldTypes = cast(rightInput.getType()).getTypes(); + + SmallVector fieldTypes; + llvm::append_range(fieldTypes, leftFieldTypes); + llvm::append_range(fieldTypes, rightFieldTypes); + auto resultType = TupleType::get(context, fieldTypes); + + inferredReturnTypes = SmallVector{resultType}; + + return success(); +} + /// Verifies that the provided field names match the provided field types. While /// the field types are potentially nested, the names are given in a single, /// flat list and correspond to the field types in depth first order (where each diff --git a/lib/Target/SubstraitPB/Export.cpp b/lib/Target/SubstraitPB/Export.cpp index a6b1b4c..f74b762 100644 --- a/lib/Target/SubstraitPB/Export.cpp +++ b/lib/Target/SubstraitPB/Export.cpp @@ -50,6 +50,7 @@ class SubstraitExporter { DECLARE_EXPORT_FUNC(FieldReferenceOp, Expression) DECLARE_EXPORT_FUNC(FetchOp, Rel) DECLARE_EXPORT_FUNC(FilterOp, Rel) + DECLARE_EXPORT_FUNC(JoinOp, Rel) DECLARE_EXPORT_FUNC(LiteralOp, Expression) DECLARE_EXPORT_FUNC(ModuleOp, Plan) DECLARE_EXPORT_FUNC(NamedTableOp, Rel) @@ -261,6 +262,49 @@ FailureOr> SubstraitExporter::exportOperation(EmitOp op) { return inputRel; } +FailureOr> +SubstraitExporter::exportOperation(JoinOp op) { + // Build `RelCommon` message. + auto relCommon = std::make_unique(); + auto direct = std::make_unique(); + relCommon->set_allocated_direct(direct.release()); + + // Build `left` input message. + auto leftOp = + llvm::dyn_cast_if_present(op.getLeft().getDefiningOp()); + if (!leftOp) + return op->emitOpError( + "left input was not produced by Substrait relation op"); + + FailureOr> leftRel = exportOperation(leftOp); + if (failed(leftRel)) + return failure(); + + // Build `right` input message. + auto rightOp = + llvm::dyn_cast_if_present(op.getRight().getDefiningOp()); + if (!rightOp) + return op->emitOpError( + "right input was not produced by Substrait relation op"); + + FailureOr> rightRel = exportOperation(rightOp); + if (failed(rightRel)) + return failure(); + + // Build `JoinRel` message. + auto joinRel = std::make_unique(); + joinRel->set_allocated_common(relCommon.release()); + joinRel->set_allocated_left(leftRel->release()); + joinRel->set_allocated_right(rightRel->release()); + joinRel->set_type(static_cast(op.getJoinType())); + + // Build `Rel` message. + auto rel = std::make_unique(); + rel->set_allocated_join(joinRel.release()); + + return rel; +} + FailureOr> SubstraitExporter::exportOperation(ExpressionOpInterface op) { return llvm::TypeSwitch>>( @@ -791,6 +835,7 @@ SubstraitExporter::exportOperation(RelOpInterface op) { FetchOp, FieldReferenceOp, FilterOp, + JoinOp, NamedTableOp, ProjectOp, SetOp diff --git a/lib/Target/SubstraitPB/Import.cpp b/lib/Target/SubstraitPB/Import.cpp index 11e688e..cf75722 100644 --- a/lib/Target/SubstraitPB/Import.cpp +++ b/lib/Target/SubstraitPB/Import.cpp @@ -53,6 +53,7 @@ DECLARE_IMPORT_FUNC(SetRel, Rel, SetOp) DECLARE_IMPORT_FUNC(Expression, Expression, ExpressionOpInterface) DECLARE_IMPORT_FUNC(FieldReference, Expression::FieldReference, FieldReferenceOp) +DECLARE_IMPORT_FUNC(JoinRel, Rel, JoinOp) DECLARE_IMPORT_FUNC(Literal, Expression::Literal, LiteralOp) DECLARE_IMPORT_FUNC(NamedTable, Rel, NamedTableOp) DECLARE_IMPORT_FUNC(Plan, Plan, PlanOp) @@ -247,6 +248,34 @@ importFieldReference(ImplicitLocOpBuilder builder, return builder.create(container, indices); } +static mlir::FailureOr importJoinRel(ImplicitLocOpBuilder builder, + const Rel &message) { + const JoinRel &joinRel = message.join(); + + // Import left and right inputs. + const Rel &leftRel = joinRel.left(); + const Rel &rightRel = joinRel.right(); + + mlir::FailureOr leftOp = importRel(builder, leftRel); + mlir::FailureOr rightOp = importRel(builder, rightRel); + + if (failed(leftOp) || failed(rightOp)) + return failure(); + + // Build `JoinOp`. + Value leftVal = leftOp.value()->getResult(0); + Value rightVal = rightOp.value()->getResult(0); + + std::optional join_type = static_cast<::JoinTypeKind>(joinRel.type()); + + // Check for unsupported set operations. + if (!join_type) + return mlir::emitError(builder.getLoc(), "unexpected 'operation' found"); + + + return builder.create(leftVal, rightVal, *join_type); + } + static mlir::FailureOr importLiteral(ImplicitLocOpBuilder builder, const Expression::Literal &message) { @@ -586,6 +615,9 @@ static mlir::FailureOr importRel(ImplicitLocOpBuilder builder, case Rel::RelTypeCase::kFilter: maybeOp = importFilterRel(builder, message); break; + case Rel::RelTypeCase::kJoin: + maybeOp = importJoinRel(builder, message); + break; case Rel::RelTypeCase::kProject: maybeOp = importProjectRel(builder, message); break; diff --git a/lib/Target/SubstraitPB/ProtobufUtils.cpp b/lib/Target/SubstraitPB/ProtobufUtils.cpp index 554bc62..397fcb0 100644 --- a/lib/Target/SubstraitPB/ProtobufUtils.cpp +++ b/lib/Target/SubstraitPB/ProtobufUtils.cpp @@ -33,6 +33,8 @@ FailureOr getCommon(const Rel &rel, Location loc) { return getCommon(rel.fetch()); case Rel::RelTypeCase::kFilter: return getCommon(rel.filter()); + case Rel::RelTypeCase::kJoin: + return getCommon(rel.join()); case Rel::RelTypeCase::kProject: return getCommon(rel.project()); case Rel::RelTypeCase::kRead: @@ -60,6 +62,8 @@ FailureOr getMutableCommon(Rel *rel, Location loc) { return getMutableCommon((rel->mutable_fetch())); case Rel::RelTypeCase::kFilter: return getMutableCommon(rel->mutable_filter()); + case Rel::RelTypeCase::kJoin: + return getMutableCommon(rel->mutable_join()); case Rel::RelTypeCase::kProject: return getMutableCommon(rel->mutable_project()); case Rel::RelTypeCase::kRead: diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir new file mode 100644 index 0000000..c630bbe --- /dev/null +++ b/test/Dialect/Substrait/join.mlir @@ -0,0 +1,138 @@ +// RUN: substrait-opt -split-input-file %s \ +// RUN: | FileCheck %s + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join unspecified %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join inner %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join outer %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join left %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join left %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join right %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join right %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join semi %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join anti %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// CHECK-LABEL: substrait.plan +// CHECK: relation +// CHECK: %[[V0:.*]] = named_table +// CHECK: %[[V1:.*]] = named_table +// CHECK-NEXT: %[[V2:.*]] = join single %[[V0]] j %[[V1]] +// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: yield %[[V2]] : tuple + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join single %0 j %1 : tuple j tuple + yield %2 : tuple + } +} \ No newline at end of file diff --git a/test/Target/SubstraitPB/Export/join.mlir b/test/Target/SubstraitPB/Export/join.mlir new file mode 100644 index 0000000..5031dcb --- /dev/null +++ b/test/Target/SubstraitPB/Export/join.mlir @@ -0,0 +1,200 @@ +// RUN: substrait-translate -substrait-to-protobuf --split-input-file %s \ +// RUN: | FileCheck %s + +// RUN: substrait-translate -substrait-to-protobuf %s \ +// RUN: --split-input-file --output-split-marker="# -----" \ +// RUN: | substrait-translate -protobuf-to-substrait \ +// RUN: --split-input-file="# -----" --output-split-marker="// ""-----" \ +// RUN: | substrait-translate -substrait-to-protobuf \ +// RUN: --split-input-file --output-split-marker="# -----" \ +// RUN: | FileCheck %s + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join unspecified %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_INNER + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join inner %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_OUTER + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join outer %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_LEFT + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join left %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_RIGHT + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join right %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_SEMI + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join semi %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_ANTI + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join anti %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + +// ----- + +// CHECK-LABEL: relations { +// CHECK-NEXT: rel { +// CHECK-NEXT: join { +// CHECK-NEXT: common { +// CHECK-NEXT: direct { +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: left { +// CHECK-NEXT: read { +// CHECK: right { +// CHECK-NEXT: read { +// CHECK: type: JOIN_TYPE_SINGLE + +substrait.plan version 0 : 42 : 1 { + relation { + %0 = named_table @t1 as ["a"] : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join single %0 j %1 : tuple j tuple + yield %2 : tuple + } +} + diff --git a/test/Target/SubstraitPB/Import/join.textpb b/test/Target/SubstraitPB/Import/join.textpb new file mode 100644 index 0000000..016466b --- /dev/null +++ b/test/Target/SubstraitPB/Import/join.textpb @@ -0,0 +1,559 @@ +# RUN: substrait-translate -protobuf-to-substrait %s \ +# RUN: --split-input-file="# ""-----" \ +# RUN: | FileCheck %s + +# RUN: substrait-translate -protobuf-to-substrait %s \ +# RUN: --split-input-file="# ""-----" --output-split-marker="// -----" \ +# RUN: | substrait-translate -substrait-to-protobuf \ +# RUN: --split-input-file --output-split-marker="# ""-----" \ +# RUN: | substrait-translate -protobuf-to-substrait \ +# RUN: --split-input-file="# ""-----" --output-split-marker="// -----" \ +# RUN: | FileCheck %s + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_INNER + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_OUTER + } + } +} +version { + minor_number: 42 + patch_number: 1 +} +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join left %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_LEFT + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join right %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_RIGHT + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_SEMI + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_ANTI + } + } +} +version { + minor_number: 42 + patch_number: 1 +} + +# ----- + +# CHECK-LABEL: substrait.plan +# CHECK: relation { +# CHECK: %[[V0:.*]] = named_table +# CHECK: %[[V1:.*]] = named_table +# CHECK-NEXT: %[[V2:.*]] = join single %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: yield %[[V2]] : tuple + +relations { + rel { + join { + common { + direct { + } + } + left { + read { + common { + direct { + } + } + base_schema { + names: "a" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t1" + } + } + } + right { + read { + common { + direct { + } + } + base_schema { + names: "b" + struct { + types { + i32 { + nullability: NULLABILITY_REQUIRED + } + } + nullability: NULLABILITY_REQUIRED + } + } + named_table { + names: "t2" + } + } + } + type: JOIN_TYPE_SINGLE + } + } +} +version { + minor_number: 42 + patch_number: 1 +} \ No newline at end of file From 959c39614cd936af6643bb6f48f87e50ef0c2016 Mon Sep 17 00:00:00 2001 From: Dalia Shaaban Date: Sat, 7 Dec 2024 01:37:41 +0100 Subject: [PATCH 2/9] cLaNg sAgA :skull: --- lib/Dialect/Substrait/IR/Substrait.cpp | 8 ++++---- lib/Target/SubstraitPB/Export.cpp | 5 ++--- lib/Target/SubstraitPB/Import.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index dcbd307..35cb525 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -256,11 +256,11 @@ LiteralOp::inferReturnTypes(MLIRContext *context, std::optional loc, return success(); } -LogicalResult +LogicalResult JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, - ValueRange operands, DictionaryAttr attributes, - OpaqueProperties properties, RegionRange regions, - llvm::SmallVectorImpl &inferredReturnTypes) { + ValueRange operands, DictionaryAttr attributes, + OpaqueProperties properties, RegionRange regions, + llvm::SmallVectorImpl &inferredReturnTypes) { Value leftInput = operands[0]; Value rightInput = operands[1]; diff --git a/lib/Target/SubstraitPB/Export.cpp b/lib/Target/SubstraitPB/Export.cpp index f74b762..02a8ce2 100644 --- a/lib/Target/SubstraitPB/Export.cpp +++ b/lib/Target/SubstraitPB/Export.cpp @@ -262,8 +262,7 @@ FailureOr> SubstraitExporter::exportOperation(EmitOp op) { return inputRel; } -FailureOr> -SubstraitExporter::exportOperation(JoinOp op) { +FailureOr> SubstraitExporter::exportOperation(JoinOp op) { // Build `RelCommon` message. auto relCommon = std::make_unique(); auto direct = std::make_unique(); @@ -297,7 +296,7 @@ SubstraitExporter::exportOperation(JoinOp op) { joinRel->set_allocated_left(leftRel->release()); joinRel->set_allocated_right(rightRel->release()); joinRel->set_type(static_cast(op.getJoinType())); - + // Build `Rel` message. auto rel = std::make_unique(); rel->set_allocated_join(joinRel.release()); diff --git a/lib/Target/SubstraitPB/Import.cpp b/lib/Target/SubstraitPB/Import.cpp index cf75722..3e77f87 100644 --- a/lib/Target/SubstraitPB/Import.cpp +++ b/lib/Target/SubstraitPB/Import.cpp @@ -249,7 +249,7 @@ importFieldReference(ImplicitLocOpBuilder builder, } static mlir::FailureOr importJoinRel(ImplicitLocOpBuilder builder, - const Rel &message) { + const Rel &message) { const JoinRel &joinRel = message.join(); // Import left and right inputs. @@ -266,15 +266,15 @@ static mlir::FailureOr importJoinRel(ImplicitLocOpBuilder builder, Value leftVal = leftOp.value()->getResult(0); Value rightVal = rightOp.value()->getResult(0); - std::optional join_type = static_cast<::JoinTypeKind>(joinRel.type()); + std::optional join_type = + static_cast<::JoinTypeKind>(joinRel.type()); // Check for unsupported set operations. if (!join_type) return mlir::emitError(builder.getLoc(), "unexpected 'operation' found"); - return builder.create(leftVal, rightVal, *join_type); - } +} static mlir::FailureOr importLiteral(ImplicitLocOpBuilder builder, From fa7646e4026a7718dfe8fd9f77fe6490bb093f69 Mon Sep 17 00:00:00 2001 From: Dalia Shaaban Date: Mon, 9 Dec 2024 16:51:38 +0100 Subject: [PATCH 3/9] hi --- include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td index cf3a4e2..aac8b5c 100644 --- a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td +++ b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td @@ -500,7 +500,7 @@ def Substrait_JoinOp : Substrait_RelOp<"join", [DeclareOpInterfaceMethods Date: Wed, 11 Dec 2024 15:33:41 +0100 Subject: [PATCH 4/9] minor --- include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td | 2 +- test/Dialect/Substrait/join.mlir | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td index aac8b5c..8475ea4 100644 --- a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td +++ b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td @@ -500,7 +500,7 @@ def Substrait_JoinOp : Substrait_RelOp<"join", [DeclareOpInterfaceMethods type($result) }]; } diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir index c630bbe..5f63ca9 100644 --- a/test/Dialect/Substrait/join.mlir +++ b/test/Dialect/Substrait/join.mlir @@ -135,4 +135,4 @@ substrait.plan version 0 : 42 : 1 { %2 = join single %0 j %1 : tuple j tuple yield %2 : tuple } -} \ No newline at end of file +} From f60e77db57befa6d38a880246ab2c499c70718e4 Mon Sep 17 00:00:00 2001 From: Dalia Shaaban <144673861+dshaaban01@users.noreply.github.com> Date: Thu, 26 Dec 2024 18:47:28 +0100 Subject: [PATCH 5/9] first draft new join - i have commented out my first attempt at proper type inference. will adjust in next commit. unable to test locally so doing this via CI :skull: --- .../Dialect/Substrait/IR/SubstraitOps.td | 2 +- lib/Dialect/Substrait/IR/Substrait.cpp | 43 +++++++++++++ test/Dialect/Substrait/join.mlir | 62 ++++++++++++------- test/Target/SubstraitPB/Export/join.mlir | 17 ++--- test/Target/SubstraitPB/Import/join.textpb | 16 ++--- 5 files changed, 99 insertions(+), 41 deletions(-) diff --git a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td index 8475ea4..ba25afe 100644 --- a/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td +++ b/include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td @@ -500,7 +500,7 @@ def Substrait_JoinOp : Substrait_RelOp<"join", [DeclareOpInterfaceMethods type($result) + $join_type $left `,` $right attr-dict `:` type($left) `,` type($right) `->` type($result) }]; } diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index 35cb525..119053f 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -267,6 +267,49 @@ JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, TypeRange leftFieldTypes = cast(leftInput.getType()).getTypes(); TypeRange rightFieldTypes = cast(rightInput.getType()).getTypes(); + // // check join type + // Adaptor adaptor(operands, attributes, properties, regions); + + // JoinTypeKind join_type = adaptor.getJoinType(); + + // // get instance of join_type inner, outer, right, left + // std::set join_types = { + // JoinTypeKind::unspecified, + // JoinTypeKind::inner, + // JoinTypeKind::outer, + // JoinTypeKind::right, + // JoinTypeKind::left, + // JoinTypeKind::anti, + // JoinTypeKind::single + // }; + + // JoinTypeKind join_type_semi = JoinTypeKind::semi; + // // JoinTypeKind join_type_anti = JoinTypeKind::anti; + + + // SmallVector fieldTypes; + + // bool is_match = join_types.find(join_type) != join_types.end(); + + // if(is_match){ + // // return all record for left and right input + // llvm::append_range(fieldTypes, leftFieldTypes); + // llvm::append_range(fieldTypes, rightFieldTypes); + + // } else { + // if (join_type == join_type_semi){ + // // return records from left input only + // llvm::append_range(fieldTypes, leftFieldTypes); + + // // } else if (join_type == join_type_anti){ + // // // return no records + + // } else { + // // error - join type not defined + // return failure(); + // } + // } + SmallVector fieldTypes; llvm::append_range(fieldTypes, leftFieldTypes); llvm::append_range(fieldTypes, rightFieldTypes); diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir index 5f63ca9..f096df6 100644 --- a/test/Dialect/Substrait/join.mlir +++ b/test/Dialect/Substrait/join.mlir @@ -5,134 +5,148 @@ // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join unspecified %0 j %1 : tuple j tuple + %2 = join unspecified %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join inner %0 j %1 : tuple j tuple + %2 = join inner %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join outer %0 j %1 : tuple j tuple + %2 = join outer %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join left %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join left %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join left %0 j %1 : tuple j tuple + %2 = join left %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join right %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join right %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join right %0 j %1 : tuple j tuple + %2 = join right %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join semi %0 j %1 : tuple j tuple + %2 = join semi %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join anti %0 j %1 : tuple j tuple + %2 = join anti %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } +// ----- + // CHECK-LABEL: substrait.plan // CHECK: relation // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table -// CHECK-NEXT: %[[V2:.*]] = join single %[[V0]] j %[[V1]] -// CHECK-SAME: : tuple j tuple +// CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join single %0 j %1 : tuple j tuple + %2 = join single %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } diff --git a/test/Target/SubstraitPB/Export/join.mlir b/test/Target/SubstraitPB/Export/join.mlir index 5031dcb..3c43498 100644 --- a/test/Target/SubstraitPB/Export/join.mlir +++ b/test/Target/SubstraitPB/Export/join.mlir @@ -20,12 +20,13 @@ // CHECK-NEXT: read { // CHECK: right { // CHECK-NEXT: read { +// CHECK-NOT: op: substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join unspecified %0 j %1 : tuple j tuple + %2 = join unspecified %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -49,7 +50,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join inner %0 j %1 : tuple j tuple + %2 = join inner %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -73,7 +74,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join outer %0 j %1 : tuple j tuple + %2 = join outer %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -97,7 +98,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join left %0 j %1 : tuple j tuple + %2 = join left %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -121,7 +122,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join right %0 j %1 : tuple j tuple + %2 = join right %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -145,7 +146,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join semi %0 j %1 : tuple j tuple + %2 = join semi %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -169,7 +170,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join anti %0 j %1 : tuple j tuple + %2 = join anti %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } @@ -193,7 +194,7 @@ substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join single %0 j %1 : tuple j tuple + %2 = join single %0, %1 : tuple , tuple -> tuple yield %2 : tuple } } diff --git a/test/Target/SubstraitPB/Import/join.textpb b/test/Target/SubstraitPB/Import/join.textpb index 016466b..2fce58b 100644 --- a/test/Target/SubstraitPB/Import/join.textpb +++ b/test/Target/SubstraitPB/Import/join.textpb @@ -14,7 +14,7 @@ # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -82,7 +82,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -151,7 +151,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -219,7 +219,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join left %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join left %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -288,7 +288,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join right %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join right %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -357,7 +357,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -426,7 +426,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -495,7 +495,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join single %[[V0]] j %[[V1]] : tuple j tuple +# CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] : tuple, tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { From f77df3d0672b5fde2bcb798c758d3e3bf6511502 Mon Sep 17 00:00:00 2001 From: Dalia Shaaban <144673861+dshaaban01@users.noreply.github.com> Date: Thu, 26 Dec 2024 20:48:10 +0100 Subject: [PATCH 6/9] small error --- test/Dialect/Substrait/join.mlir | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir index f096df6..a57aefb 100644 --- a/test/Dialect/Substrait/join.mlir +++ b/test/Dialect/Substrait/join.mlir @@ -26,14 +26,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] // CHECK-SAME: : tuple, tuple -> tuple -// CHECK-NEXT: yield %[[V2]] : tuple +// CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple - %1 = named_table @t2 as ["b"] : tuple + %1 = named_table @t2 as ["b"] : tuple %2 = join inner %0, %1 : tuple , tuple -> tuple - yield %2 : tuple + yield %2 : tuple } } From 396a9d70515dd69f605af782bcead893f4a0ad1e Mon Sep 17 00:00:00 2001 From: Dalia Shaaban <144673861+dshaaban01@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:21:43 +0100 Subject: [PATCH 7/9] fix tests --- lib/Dialect/Substrait/IR/Substrait.cpp | 50 ++++++++++---------------- test/Dialect/Substrait/join.mlir | 32 ++++++++--------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index 119053f..8794418 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -272,47 +272,33 @@ JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, // JoinTypeKind join_type = adaptor.getJoinType(); - // // get instance of join_type inner, outer, right, left - // std::set join_types = { - // JoinTypeKind::unspecified, - // JoinTypeKind::inner, - // JoinTypeKind::outer, - // JoinTypeKind::right, - // JoinTypeKind::left, - // JoinTypeKind::anti, - // JoinTypeKind::single - // }; - - // JoinTypeKind join_type_semi = JoinTypeKind::semi; - // // JoinTypeKind join_type_anti = JoinTypeKind::anti; - - // SmallVector fieldTypes; - // bool is_match = join_types.find(join_type) != join_types.end(); - - // if(is_match){ - // // return all record for left and right input - // llvm::append_range(fieldTypes, leftFieldTypes); - // llvm::append_range(fieldTypes, rightFieldTypes); - - // } else { - // if (join_type == join_type_semi){ - // // return records from left input only + // switch (join_type) { + // case JoinTypeKind::unspecified: + // case JoinTypeKind::inner: + // case JoinTypeKind::outer: + // case JoinTypeKind::right: + // case JoinTypeKind::left: // llvm::append_range(fieldTypes, leftFieldTypes); - - // // } else if (join_type == join_type_anti){ - // // // return no records - - // } else { - // // error - join type not defined + // llvm::append_range(fieldTypes, rightFieldTypes); + // break; + // case JoinTypeKind::semi: + // case JoinTypeKind::anti: + // llvm::append_range(fieldTypes, leftFieldTypes); + // break; + // case JoinTypeKind::single: + // llvm::append_range(fieldTypes, rightFieldTypes); + // break; + // default: // return failure(); - // } // } SmallVector fieldTypes; + llvm::append_range(fieldTypes, leftFieldTypes); llvm::append_range(fieldTypes, rightFieldTypes); + auto resultType = TupleType::get(context, fieldTypes); inferredReturnTypes = SmallVector{resultType}; diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir index a57aefb..5ea7169 100644 --- a/test/Dialect/Substrait/join.mlir +++ b/test/Dialect/Substrait/join.mlir @@ -6,14 +6,14 @@ // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join unspecified %0, %1 : tuple , tuple -> tuple + %2 = join unspecified %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -25,14 +25,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join inner %0, %1 : tuple , tuple -> tuple + %2 = join inner %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -44,14 +44,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join outer %0, %1 : tuple , tuple -> tuple + %2 = join outer %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -63,14 +63,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join left %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join left %0, %1 : tuple , tuple -> tuple + %2 = join left %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -82,14 +82,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join right %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join right %0, %1 : tuple , tuple -> tuple + %2 = join right %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -101,14 +101,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join semi %0, %1 : tuple , tuple -> tuple + %2 = join semi %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -120,14 +120,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join anti %0, %1 : tuple , tuple -> tuple + %2 = join anti %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } @@ -139,14 +139,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-SAME: : tuple, tuple -> tuple // CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join single %0, %1 : tuple , tuple -> tuple + %2 = join single %0, %1 : tuple, tuple -> tuple yield %2 : tuple } } From afc3b8e64bfb70e7a208407bce712020374932bf Mon Sep 17 00:00:00 2001 From: Dalia Shaaban <144673861+dshaaban01@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:34:16 +0100 Subject: [PATCH 8/9] TYPE INFERENCE HALLELUJAH --- lib/Dialect/Substrait/IR/Substrait.cpp | 49 ++++++++++------------ test/Dialect/Substrait/join.mlir | 30 ++++++------- test/Target/SubstraitPB/Export/join.mlir | 18 ++++---- test/Target/SubstraitPB/Import/join.textpb | 29 ++++++------- 4 files changed, 61 insertions(+), 65 deletions(-) diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index 8794418..3a92877 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -267,37 +267,32 @@ JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, TypeRange leftFieldTypes = cast(leftInput.getType()).getTypes(); TypeRange rightFieldTypes = cast(rightInput.getType()).getTypes(); - // // check join type - // Adaptor adaptor(operands, attributes, properties, regions); + // get join type + Adaptor adaptor(operands, attributes, properties, regions); - // JoinTypeKind join_type = adaptor.getJoinType(); - - // SmallVector fieldTypes; - - // switch (join_type) { - // case JoinTypeKind::unspecified: - // case JoinTypeKind::inner: - // case JoinTypeKind::outer: - // case JoinTypeKind::right: - // case JoinTypeKind::left: - // llvm::append_range(fieldTypes, leftFieldTypes); - // llvm::append_range(fieldTypes, rightFieldTypes); - // break; - // case JoinTypeKind::semi: - // case JoinTypeKind::anti: - // llvm::append_range(fieldTypes, leftFieldTypes); - // break; - // case JoinTypeKind::single: - // llvm::append_range(fieldTypes, rightFieldTypes); - // break; - // default: - // return failure(); - // } + JoinTypeKind join_type = adaptor.getJoinType(); SmallVector fieldTypes; - llvm::append_range(fieldTypes, leftFieldTypes); - llvm::append_range(fieldTypes, rightFieldTypes); + switch (join_type) { + case JoinTypeKind::unspecified: + case JoinTypeKind::inner: + case JoinTypeKind::outer: + case JoinTypeKind::right: + case JoinTypeKind::left: + llvm::append_range(fieldTypes, leftFieldTypes); + llvm::append_range(fieldTypes, rightFieldTypes); + break; + case JoinTypeKind::semi: + case JoinTypeKind::anti: + llvm::append_range(fieldTypes, leftFieldTypes); + break; + case JoinTypeKind::single: + llvm::append_range(fieldTypes, rightFieldTypes); + break; + default: + return failure(); + } auto resultType = TupleType::get(context, fieldTypes); diff --git a/test/Dialect/Substrait/join.mlir b/test/Dialect/Substrait/join.mlir index 5ea7169..c6176c4 100644 --- a/test/Dialect/Substrait/join.mlir +++ b/test/Dialect/Substrait/join.mlir @@ -101,15 +101,15 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple -// CHECK-NEXT: yield %[[V2]] : tuple +// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { - %0 = named_table @t1 as ["a"] : tuple + %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join semi %0, %1 : tuple, tuple -> tuple - yield %2 : tuple + %2 = join semi %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } @@ -120,15 +120,15 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple -// CHECK-NEXT: yield %[[V2]] : tuple +// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { - %0 = named_table @t1 as ["a"] : tuple + %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join anti %0, %1 : tuple, tuple -> tuple - yield %2 : tuple + %2 = join anti %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } @@ -139,14 +139,14 @@ substrait.plan version 0 : 42 : 1 { // CHECK: %[[V0:.*]] = named_table // CHECK: %[[V1:.*]] = named_table // CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] -// CHECK-SAME: : tuple, tuple -> tuple -// CHECK-NEXT: yield %[[V2]] : tuple +// CHECK-SAME: : tuple, tuple -> tuple +// CHECK-NEXT: yield %[[V2]] : tuple substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple - %1 = named_table @t2 as ["b"] : tuple - %2 = join single %0, %1 : tuple, tuple -> tuple - yield %2 : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join single %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } diff --git a/test/Target/SubstraitPB/Export/join.mlir b/test/Target/SubstraitPB/Export/join.mlir index 3c43498..f7cba8d 100644 --- a/test/Target/SubstraitPB/Export/join.mlir +++ b/test/Target/SubstraitPB/Export/join.mlir @@ -144,10 +144,10 @@ substrait.plan version 0 : 42 : 1 { substrait.plan version 0 : 42 : 1 { relation { - %0 = named_table @t1 as ["a"] : tuple + %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join semi %0, %1 : tuple , tuple -> tuple - yield %2 : tuple + %2 = join semi %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } @@ -168,10 +168,10 @@ substrait.plan version 0 : 42 : 1 { substrait.plan version 0 : 42 : 1 { relation { - %0 = named_table @t1 as ["a"] : tuple + %0 = named_table @t1 as ["a"] : tuple %1 = named_table @t2 as ["b"] : tuple - %2 = join anti %0, %1 : tuple , tuple -> tuple - yield %2 : tuple + %2 = join anti %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } @@ -193,9 +193,9 @@ substrait.plan version 0 : 42 : 1 { substrait.plan version 0 : 42 : 1 { relation { %0 = named_table @t1 as ["a"] : tuple - %1 = named_table @t2 as ["b"] : tuple - %2 = join single %0, %1 : tuple , tuple -> tuple - yield %2 : tuple + %1 = named_table @t2 as ["b"] : tuple + %2 = join single %0, %1 : tuple, tuple -> tuple + yield %2 : tuple } } diff --git a/test/Target/SubstraitPB/Import/join.textpb b/test/Target/SubstraitPB/Import/join.textpb index 2fce58b..743935f 100644 --- a/test/Target/SubstraitPB/Import/join.textpb +++ b/test/Target/SubstraitPB/Import/join.textpb @@ -14,7 +14,7 @@ # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]], %[[V1]] : tuple, tuple +# CHECK-NEXT: %[[V2:.*]] = join unspecified %[[V0]], %[[V1]] : tuple, tuple -> tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -82,7 +82,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] : tuple, tuple +# CHECK-NEXT: %[[V2:.*]] = join inner %[[V0]], %[[V1]] : tuple, tuple -> tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -151,7 +151,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]], %[[V1]] : tuple, tuple +# CHECK-NEXT: %[[V2:.*]] = join outer %[[V0]], %[[V1]] : tuple, tuple -> tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -213,13 +213,14 @@ version { minor_number: 42 patch_number: 1 } + # ----- # CHECK-LABEL: substrait.plan # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join left %[[V0]], %[[V1]] : tuple, tuple +# CHECK-NEXT: %[[V2:.*]] = join left %[[V0]], %[[V1]] : tuple, tuple -> tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -288,7 +289,7 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join right %[[V0]], %[[V1]] : tuple, tuple +# CHECK-NEXT: %[[V2:.*]] = join right %[[V0]], %[[V1]] : tuple, tuple -> tuple # CHECK-NEXT: yield %[[V2]] : tuple relations { @@ -357,8 +358,8 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] : tuple, tuple -# CHECK-NEXT: yield %[[V2]] : tuple +# CHECK-NEXT: %[[V2:.*]] = join semi %[[V0]], %[[V1]] : tuple, tuple -> tuple +# CHECK-NEXT: yield %[[V2]] : tuple relations { rel { @@ -377,7 +378,7 @@ relations { names: "a" struct { types { - i32 { + bool { nullability: NULLABILITY_REQUIRED } } @@ -426,8 +427,8 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] : tuple, tuple -# CHECK-NEXT: yield %[[V2]] : tuple +# CHECK-NEXT: %[[V2:.*]] = join anti %[[V0]], %[[V1]] : tuple, tuple -> tuple +# CHECK-NEXT: yield %[[V2]] : tuple relations { rel { @@ -446,7 +447,7 @@ relations { names: "a" struct { types { - i32 { + bool { nullability: NULLABILITY_REQUIRED } } @@ -495,8 +496,8 @@ version { # CHECK: relation { # CHECK: %[[V0:.*]] = named_table # CHECK: %[[V1:.*]] = named_table -# CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] : tuple, tuple -# CHECK-NEXT: yield %[[V2]] : tuple +# CHECK-NEXT: %[[V2:.*]] = join single %[[V0]], %[[V1]] : tuple, tuple -> tuple +# CHECK-NEXT: yield %[[V2]] : tuple relations { rel { @@ -537,7 +538,7 @@ relations { names: "b" struct { types { - i32 { + bool { nullability: NULLABILITY_REQUIRED } } From ff2b1e6978c11829c109e26673b5e47b79b3b531 Mon Sep 17 00:00:00 2001 From: Dalia Shaaban <144673861+dshaaban01@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:36:30 +0100 Subject: [PATCH 9/9] clang tingz --- lib/Dialect/Substrait/IR/Substrait.cpp | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Dialect/Substrait/IR/Substrait.cpp b/lib/Dialect/Substrait/IR/Substrait.cpp index 3a92877..eafea3b 100644 --- a/lib/Dialect/Substrait/IR/Substrait.cpp +++ b/lib/Dialect/Substrait/IR/Substrait.cpp @@ -269,29 +269,29 @@ JoinOp::inferReturnTypes(MLIRContext *context, std::optional loc, // get join type Adaptor adaptor(operands, attributes, properties, regions); - + JoinTypeKind join_type = adaptor.getJoinType(); SmallVector fieldTypes; switch (join_type) { - case JoinTypeKind::unspecified: - case JoinTypeKind::inner: - case JoinTypeKind::outer: - case JoinTypeKind::right: - case JoinTypeKind::left: - llvm::append_range(fieldTypes, leftFieldTypes); - llvm::append_range(fieldTypes, rightFieldTypes); - break; - case JoinTypeKind::semi: - case JoinTypeKind::anti: - llvm::append_range(fieldTypes, leftFieldTypes); - break; - case JoinTypeKind::single: - llvm::append_range(fieldTypes, rightFieldTypes); - break; - default: - return failure(); + case JoinTypeKind::unspecified: + case JoinTypeKind::inner: + case JoinTypeKind::outer: + case JoinTypeKind::right: + case JoinTypeKind::left: + llvm::append_range(fieldTypes, leftFieldTypes); + llvm::append_range(fieldTypes, rightFieldTypes); + break; + case JoinTypeKind::semi: + case JoinTypeKind::anti: + llvm::append_range(fieldTypes, leftFieldTypes); + break; + case JoinTypeKind::single: + llvm::append_range(fieldTypes, rightFieldTypes); + break; + default: + return failure(); } auto resultType = TupleType::get(context, fieldTypes);