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: add string type #41

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

dshaaban01
Copy link
Contributor

@dshaaban01 dshaaban01 commented Dec 27, 2024

Added string types + string attribute types.

This is a stacked PR, please only review latest commit (15d2e21)

@ingomueller-net

@dshaaban01 dshaaban01 changed the title feat: implement string type feat: add string type Dec 27, 2024
@dshaaban01
Copy link
Contributor Author

Note: 2 missing test files, have weird failures I will analyze later today.

@dshaaban01 dshaaban01 force-pushed the dalia/types/string branch 2 times, most recently from b09bd62 to 46dace8 Compare January 6, 2025 18:59
@dshaaban01
Copy link
Contributor Author

dshaaban01 commented Jan 6, 2025

Note: 2 missing test files, have weird failures I will analyze later today.

The conclusion of my analysis is that the round tripping of the string attribute tests fail because it does not recognize !substrait.string as a type and recognizes is as none instead. I have therefore rebased this PR on top of the Substrait_Attr Base class PR so I can write my own custom string attr base class (currently I use MLIR built in string attr).

My new String Attribute is called StrAttr to disambiguate from MLIR's StringAttr.

@dshaaban01 dshaaban01 force-pushed the dalia/types/string branch 2 times, most recently from 2ce1477 to 15d2e21 Compare January 6, 2025 19:41
Copy link
Collaborator

@ingomueller-net ingomueller-net left a comment

Choose a reason for hiding this comment

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

LGTM, modulo the question about the built-in string attribute.

}];
}

def Substrait_StrAttr : Substrait_Attr<"Str", "string", [DeclareAttrInterfaceMethods<TypedAttrInterface>]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that there is a StringAttr in the built-in dialect. I don't understand all subtleties about using it but if we don't use it, it should be a conscious decision. Did you look at it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I originally was using the StringAttr (built-in type) but was getting failing tests on the literals.

"The conclusion of my analysis is that the round tripping of the string attribute tests fail because it does not recognize !substrait.string as a type and recognizes is as none instead. I have therefore rebased this PR on top of the Substrait_Attr Base class PR so I can write my own custom string attr base class (currently I use MLIR built in string attr).

My new String Attribute is called StrAttr to disambiguate from MLIR's StringAttr."

That's why I created this custom type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to understand this in more detail. Do you happen to have an old version of the code where the problem occurred? Does this do what you wanted to achieve? It yes, it's probably a good starting point for doing the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I was using the builtin StrAttr and wrote this test case.

// RUN: substrait-translate -substrait-to-protobuf %s \
// RUN: | FileCheck %s

// RUN: substrait-translate -substrait-to-protobuf %s \
// RUN: | substrait-translate -protobuf-to-substrait \
// RUN: | substrait-translate -substrait-to-protobuf \
// RUN: | FileCheck %s

// CHECK-LABEL: relations {
// CHECK-NEXT:    rel {
// CHECK-NEXT:      project {
// CHECK-NEXT:        common {
// CHECK-NEXT:          direct {
// CHECK-NEXT:          }
// CHECK-NEXT:        }
// CHECK-NEXT:        input {
// CHECK-NEXT:          read {
// CHECK:             expressions {
// CHECK-NEXT:          literal {
// CHECK-NEXT:            string: "hi"

substrait.plan version 0 : 42 : 1 {
  relation {
    %0 = named_table @t1 as ["a"] : tuple<si1>
    %1 = project %0 : tuple<si1> -> tuple<si1, !substrait.string> {
    ^bb0(%arg : tuple<si1>):
      %hi = literal "hi" : !substrait.string
      yield %hi : !substrait.string
    }
    yield %1 : tuple<si1, !substrait.string> 
  }
}

This test was failing and the problem I was getting was that it was inferring the return type of the literal Op as none, and subsequently the project op as tuple(s1, none) was the note/error I was getting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I figured it out, see #55.

@@ -77,6 +77,14 @@ void printCountAsAll(OpAsmPrinter &printer, Operation *op, IntegerAttr count) {
// Normal integer.
printer << count.getValue();
}

//===----------------------------------------------------------------------===//
// Substrait types
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Substrait types
// Substrait attributes

version {
minor_number: 42
patch_number: 1
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: final new line.

@dshaaban01 dshaaban01 force-pushed the dalia/types/string branch 2 times, most recently from 6af53a3 to 4bacf51 Compare January 9, 2025 11:27
@dshaaban01 dshaaban01 force-pushed the dalia/types/string branch 2 times, most recently from a060767 to 434cbeb Compare January 9, 2025 12:43
@dshaaban01
Copy link
Contributor Author

@ingomueller-net
I implemented your feedback from #55 and it worked! Genius! Thanks so much for figuring it out :)

@ingomueller-net ingomueller-net merged commit e196c31 into substrait-io:main Jan 14, 2025
7 checks passed
@ingomueller-net
Copy link
Collaborator

Nice!! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants