- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.7k
 
HHH-16861 HQL ordinal() function #8991
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
Conversation
| 
           Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated.  | 
    
f283017    to
    6ea6a64      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good so far, but I think what would be really nice is if in the case of a STRING enum mapping, it would generate a SQL case expression mapping the string values to their ordinal values.
        
          
                hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlLexer.g4
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4
              
                Outdated
          
            Show resolved
            Hide resolved
        
      6ea6a64    to
    bdf889d      
    Compare
  
    
          
 I'm working on that part now  | 
    
          
 Awesome, that's great, thanks man.  | 
    
bdf889d    to
    80bcd88      
    Compare
  
            
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good first step. A few comments.
        
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting there :)
After you fix the last few things, please squash everything to a single commit and rebase
        
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                ...nate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JdbcType.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      531ac99    to
    9b71811      
    Compare
  
            
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/OrdinalFunction.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      9b71811    to
    76e2c43      
    Compare
  
    The `ordinal` function returns the `ordinal` property of Java enums, for both enums mapped as ORDINAL and enums mapped as STRING generating different SQL in each case `ordinal(field)` is equivalent to `cast(enum as Integer)`, implementation taken from CastStrEmulation when used on ordinal mapped enums. Lexer and parser don't need to be changed as there is nakedIdentifier that matches custom function names `ordinal` function is validated to work only on Java enum fields Use convertToRelationalValue to generate enum value inside the SQL query Co-authored-by: Christian Beikov <[email protected]>
76e2c43    to
    c674798      
    Compare
  
    | 
           Thanks for the great work @lucamolteni. Would very much appreciate if you could add some documentation for this function as well e.g. in   | 
    
| 
           Thanks @lucamolteni !!  | 
    
Created the
hqlordinal(field)function equivalent tocast(enum as Integer).Implementation taken from CastStrEmulation
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-16861