You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2010/02/08 18:12:28 UTC

[jira] Created: (THRIFT-697) Union support in Ruby

Union support in Ruby
---------------------

                 Key: THRIFT-697
                 URL: https://issues.apache.org/jira/browse/THRIFT-697
             Project: Thrift
          Issue Type: New Feature
          Components: Compiler (Ruby), Library (Ruby)
    Affects Versions: 0.3
            Reporter: Bryan Duxbury
            Assignee: Bryan Duxbury
             Fix For: 0.3


We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834342#action_12834342 ] 

Bryan Duxbury commented on THRIFT-697:
--------------------------------------

bq. struct_union.rb
I know it was moved from before, but is there a reason each_field needs to exist? Seems like a needless sort/copy/method call, but maybe there's a reason we were doing this that I've forgotten? If it does need to exist, is there a reason name_to_ids doesn't use it?

each_field is the method used to do serialization. I previously changed it to make sure that it is iterated in field id order so that it will be consistently serialized with other languages. name_to_id doesn't need them in sorted order, so it iterates struct_fields on its own.

bq. union_spec.rb
Is there a reason you're testing that .new does't return nil? I'm not sure how to make that fail.

This is actually a test for the == method, not for the constructor. There was a bug at some point where it wasn't checking that the other being compared to was non-nil.


> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-697) Union support in Ruby

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834100#action_12834100 ] 

Kevin Clark commented on THRIFT-697:
------------------------------------

Also, I'm getting a crash on the specs. Seems you've got a dangling require:

rb/spec/union_spec.rb:21:require 'ruby-debug'

If I take that out, and put in my initializer, specs seem to pass.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-697:
---------------------------------

    Attachment: thrift-697.patch

Here's my first go at this patch. The bulk of the patch was written by Rapleaf intern Jonathan Yip. I've just put a little polish on it.

Ruby Thrift users and developers - please take a look at what I have here. It's a big patch, and I'd appreciate review.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury closed THRIFT-697.
--------------------------------

    Resolution: Fixed

I have just committed the latest version of this patch. Thanks for your review, Kevin!

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697-v2.patch, thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-697) Union support in Ruby

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834400#action_12834400 ] 

Kevin Clark commented on THRIFT-697:
------------------------------------

What I really meant on those getters/setters was to kill the handwritten versions and to just use the attr_reader outside of protected (get_* is un-idiomatic). Other than that, +1, looks good.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697-v2.patch, thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834439#action_12834439 ] 

Bryan Duxbury commented on THRIFT-697:
--------------------------------------

Oh, I forgot to address the getter thing. I actually don't want setfield and value to have standard getters, because they could interfere with generated field methods. The fact that they basically look like getters is incidental; they should not be considered instance variables by outside users. In this respect, the objective was to make the implementation look for of like the Java implementation.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697-v2.patch, thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834342#action_12834342 ] 

Bryan Duxbury edited comment on THRIFT-697 at 2/16/10 6:03 PM:
---------------------------------------------------------------

{quote}
 struct_union.rb
I know it was moved from before, but is there a reason each_field needs to exist? Seems like a needless sort/copy/method call, but maybe there's a reason we were doing this that I've forgotten? If it does need to exist, is there a reason name_to_ids doesn't use it?
{quote}

each_field is the method used to do serialization. I previously changed it to make sure that it is iterated in field id order so that it will be consistently serialized with other languages. name_to_id doesn't need them in sorted order, so it iterates struct_fields on its own.

{quote}
union_spec.rb
Is there a reason you're testing that .new does't return nil? I'm not sure how to make that fail.
{quote}

This is actually a test for the == method, not for the constructor. There was a bug at some point where it wasn't checking that the other being compared to was non-nil.


      was (Author: bryanduxbury):
    bq. struct_union.rb
I know it was moved from before, but is there a reason each_field needs to exist? Seems like a needless sort/copy/method call, but maybe there's a reason we were doing this that I've forgotten? If it does need to exist, is there a reason name_to_ids doesn't use it?

each_field is the method used to do serialization. I previously changed it to make sure that it is iterated in field id order so that it will be consistently serialized with other languages. name_to_id doesn't need them in sorted order, so it iterates struct_fields on its own.

bq. union_spec.rb
Is there a reason you're testing that .new does't return nil? I'm not sure how to make that fail.

This is actually a test for the == method, not for the constructor. There was a bug at some point where it wasn't checking that the other being compared to was non-nil.

  
> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury updated THRIFT-697:
---------------------------------

    Attachment: thrift-697-v2.patch

This patch incorporates all of Kevin's other comments. Unless there are any objections, I will commit this later today.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697-v2.patch, thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (THRIFT-697) Union support in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834439#action_12834439 ] 

Bryan Duxbury edited comment on THRIFT-697 at 2/16/10 8:33 PM:
---------------------------------------------------------------

Oh, I forgot to address the getter thing. I actually don't want setfield and value to have standard getters, because they could interfere with generated field methods. The fact that they basically look like getters is incidental; they should not be considered instance variables by outside users. In this respect, the objective was to make the implementation look like the Java implementation.

      was (Author: bryanduxbury):
    Oh, I forgot to address the getter thing. I actually don't want setfield and value to have standard getters, because they could interfere with generated field methods. The fact that they basically look like getters is incidental; they should not be considered instance variables by outside users. In this respect, the objective was to make the implementation look for of like the Java implementation.
  
> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697-v2.patch, thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (THRIFT-697) Union support in Ruby

Posted by "Kevin Clark (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12834099#action_12834099 ] 

Kevin Clark commented on THRIFT-697:
------------------------------------

Generally looks fine, but could use some cleanup. Some of this is nitpicky, so take it with a grain of salt. My notes follow.

struct.c
There's a dangling TODO (to raise an exception) in rb_thrift_union_read and another in _write. For read, we should throw and remove the TODO. For write, it looks like it comes down to a .to_sym call in the Ruby. Maybe it'd be worth benchmarking?


union.rb
If you think the current version is inelegant, I think you can rewrite Thrift::Union#initialize as:
def initialize(name = nil, value = nil)
  if name && value.nil?
    raise Exception ..
  end
  
  if name
    Thrift.check_type ...
    @field_id = name_to_id(name.to_s)
  end

  @setfield = name
  @value = value
end

It avoids an extra call to name_to_id (and the .to_s) and reads a little cleaner.

You may want to benchmark if there's a difference in performance for uses of define_method vs class eval. I thought I remember there being a significant difference, but that might not be the case anymore.

Why the handwritten getter/setter (and then a protected version of the exact same thing)? Feels very un-ruby

Is the 'set' required used anywhere?


struct_union.rb
I know it was moved from before, but is there a reason each_field needs to exist? Seems like a needless sort/copy/method call, but maybe there's a reason we were doing this that I've forgotten? If it does need to exist, is there a reason name_to_ids doesn't use it?

union_spec.rb
Is there a reason you're testing that .new does't return nil? I'm not sure how to make that fail.


t_rb_generator.cc
Looks like there might be some spacing issues with the if in generate_struct (if tstruct->is_union)

In generate_union_accessors, I'd probably move the declaration of m_iter into the for, or atleast into the if clause, but it's really nitpicky and I don't have an issue with it staying that way.

If we're going to do a copy (from f_iter to field) in generate_rb_union_validatior, might as well declare field as const.

> Union support in Ruby
> ---------------------
>
>                 Key: THRIFT-697
>                 URL: https://issues.apache.org/jira/browse/THRIFT-697
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Ruby), Library (Ruby)
>    Affects Versions: 0.3
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>             Fix For: 0.3
>
>         Attachments: thrift-697.patch
>
>
> We'd like to have direct native support for Union-style structs in Ruby. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.