Skip to content

NH-2558 - NoViableAltException with boolean expression in OrderBy clause #1000

@nhibernate-bot

Description

@nhibernate-bot

James Crowley created an issue — 3rd March 2011, 8:07:32:

The following types of queries:

_queryService.SomeMappedType
   .OrderByDescending(t=>t.LastReleaseDate == null)
   .Take(250)
   .ToList();

are not supported. They throw the following exception:

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown.

 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.expr() Line 6461
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.orderExprs() Line 1957 + 0xc bytes
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.orderClause() Line 1892 + 0xc bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery() Line 1743 + 0xc bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query() Line 1510 + 0xc bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement() Line 536 + 0xc bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement() Line 435 + 0xc bytes	
	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() Line 589 + 0x1b bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(string collectionRole) Line 448 + 0x12 bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(System.Collections.Generic.IDictionary<string,string> replacements, bool shallow, string collectionRole) Line 353 + 0x13 bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(System.Collections.Generic.IDictionary<string,string> replacements, bool shallow) Line 71	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(NHibernate.Hql.Ast.ANTLR.Tree.IASTNode ast, string queryIdentifier, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> filters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 43 + 0xa3 bytes	
 	NHibernate.dll!NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(string queryIdentifier, NHibernate.IQueryExpression queryExpression, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> filters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 27 + 0x69 bytes	
 	NHibernate.dll!NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(string expressionStr, NHibernate.IQueryExpression queryExpression, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 34 + 0x63 bytes	
 	NHibernate.dll!NHibernate.Engine.Query.HQLExpressionQueryPlan.HQLExpressionQueryPlan(string expressionStr, NHibernate.IQueryExpression queryExpression, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 23 + 0x4b bytes	
 	NHibernate.dll!NHibernate.Engine.Query.HQLExpressionQueryPlan.HQLExpressionQueryPlan(string expressionStr, NHibernate.IQueryExpression queryExpression, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 21	
 	NHibernate.dll!NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(NHibernate.IQueryExpression queryExpression, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters) Line 88 + 0x65 bytes	
 	NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(NHibernate.IQueryExpression queryExpression, bool shallow) Line 312 + 0x87 bytes	
 	NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.CreateQuery(NHibernate.IQueryExpression queryExpression) Line 268 + 0x24 bytes	
 	NHibernate.dll!NHibernate.Linq.NhQueryProvider.PrepareQuery(System.Linq.Expressions.Expression expression, out NHibernate.IQuery query, out NHibernate.Linq.NhLinqExpression nhQuery) Line 43 + 0x48 bytes	
 	NHibernate.dll!NHibernate.Linq.NhQueryProvider.Execute(System.Linq.Expressions.Expression expression) Line 26 + 0x19 bytes	
 	

Fabio Maulo added a comment — 4th March 2011, 6:53:56:

Can you compile that code ?


James Crowley added a comment — 4th March 2011, 7:09:15:

Fabio - failing unit test that compiles when placed in "NHibernate.Test.Linq.ByMethod.OrderByTests"

[Test]
public void AscendingOrderByClauseWithExpression()
{
    var query = from c in db.Customers
                orderby (c.Address.Country == "Belgium") ascending
                select c.Address.City;
    var ids = query.ToList();
    if (ids.Count > 1)
    {
        Assert.Greater(ids[0], ids[1]);
    }
}

Fabio Maulo added a comment — 4th March 2011, 12:04:24:

Sorry... I didn't see that what you want is an orderby over bool

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions