Cassandra
  1. Cassandra
  2. CASSANDRA-5075

CQL Add support for AS keyword in select

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Fix Version/s: 2.0 beta 1
    • Component/s: API
    • Labels:
      None

      Description

      It would be nice to have support of AS keyword in select statement. It would allow to use jpa frameworks without writing custom sql/cql's.

        Activity

        Hide
        Jonathan Ellis added a comment -

        I think you're enormously underestimating how far CQL is from supporting JPA out of the box. We don't support joins, by design. Given that, what benefit would AS support give us?

        Show
        Jonathan Ellis added a comment - I think you're enormously underestimating how far CQL is from supporting JPA out of the box. We don't support joins, by design. Given that, what benefit would AS support give us?
        Hide
        Alexandr Kulik added a comment -

        Hibernate by default use column alias in select statements. For example this is hibernate debug log statement:
        18.12.2012 23:58:39 DEBUG AbstractEntityPersister: Snapshot select: /* get current state com.bipper.bsafe.model.safetymode.UserSafetyModeSession */ select usersafety_.id, usersafety_.active as active22_, usersafety_.endDate as endDate22_, usersafety_.startDate as startDate22_, usersafety_.user_id as user9_22_, usersafety_.userTriggeredTimestamp as userTrig6_22_ from user_safety_mode_session usersafety_ where usersafety_.id=? (AbstractEntityPersister.java, line 2960)

        Even if i don't use joins hibernate still will use column and table alias.

        Show
        Alexandr Kulik added a comment - Hibernate by default use column alias in select statements. For example this is hibernate debug log statement: 18.12.2012 23:58:39 DEBUG AbstractEntityPersister: Snapshot select: /* get current state com.bipper.bsafe.model.safetymode.UserSafetyModeSession */ select usersafety_.id, usersafety_.active as active22_, usersafety_.endDate as endDate22_, usersafety_.startDate as startDate22_, usersafety_.user_id as user9_22_, usersafety_.userTriggeredTimestamp as userTrig6_22_ from user_safety_mode_session usersafety_ where usersafety_.id=? (AbstractEntityPersister.java, line 2960) Even if i don't use joins hibernate still will use column and table alias.
        Hide
        Jonathan Ellis added a comment -

        How hard would this be, Sylvain Lebresne Aleksey Yeschenko?

        Show
        Jonathan Ellis added a comment - How hard would this be, Sylvain Lebresne Aleksey Yeschenko ?
        Hide
        Aleksey Yeschenko added a comment -

        Shouldn't be hard to implement, but will be nice to have (to override blobAsType()-converted column names in result sets, for example).

        Show
        Aleksey Yeschenko added a comment - Shouldn't be hard to implement, but will be nice to have (to override blobAsType()-converted column names in result sets, for example).
        Hide
        Aleksey Yeschenko added a comment -

        https://github.com/iamaleksey/cassandra/compare/5075

        Like in SQL, aliases can't be used in WHERE clause. Unlike in SQL, aliases also can't be used in ORDER BY clause, because:
        1) It's simpler, don't want to complicate SelectStatement any further
        2) It's more consistent - we put otherwise very similar restrictions to what can go into WHERE and ORDER BY

        Haven't updated the docs or cqlsh completion rules yet.

        Show
        Aleksey Yeschenko added a comment - https://github.com/iamaleksey/cassandra/compare/5075 Like in SQL, aliases can't be used in WHERE clause. Unlike in SQL, aliases also can't be used in ORDER BY clause, because: 1) It's simpler, don't want to complicate SelectStatement any further 2) It's more consistent - we put otherwise very similar restrictions to what can go into WHERE and ORDER BY Haven't updated the docs or cqlsh completion rules yet.
        Hide
        Aleksey Yeschenko added a comment -

        Requires rebasing and some slight changes.

        Show
        Aleksey Yeschenko added a comment - Requires rebasing and some slight changes.
        Hide
        Aleksey Yeschenko added a comment -

        https://github.com/iamaleksey/cassandra/compare/5075 (https://github.com/iamaleksey/cassandra/compare/5075.patch)

        Rewritten against current trunk.
        Will add docs/news/dtest/cqslh rule after this is reviewed, but before resolving the issue.

        Show
        Aleksey Yeschenko added a comment - https://github.com/iamaleksey/cassandra/compare/5075 ( https://github.com/iamaleksey/cassandra/compare/5075.patch ) Rewritten against current trunk. Will add docs/news/dtest/cqslh rule after this is reviewed, but before resolving the issue.
        Hide
        Sylvain Lebresne added a comment -

        I'd prefer separating the aliasing from the other RawSelector. We pretty much always need to call getUnaliased() first to retrieve the "real" selector, so having AliasedSelector and the other selector being of the same type feels error prone for no advantages. Instead, I would typically rename the current RawSelector interface to say "Selectable", and then make RawSelector be a pair of a "Selectable" and a (potentially null) alias. Anecdotally this would also avoid adding new methods to ColumnIdentifier which bugs me for some reason.

        Nit: could be nice to throw a specific "aliases are not supported in <x> clause" message if someone uses an alias in a WHERE or ORDER BY clause.

        Show
        Sylvain Lebresne added a comment - I'd prefer separating the aliasing from the other RawSelector. We pretty much always need to call getUnaliased() first to retrieve the "real" selector, so having AliasedSelector and the other selector being of the same type feels error prone for no advantages. Instead, I would typically rename the current RawSelector interface to say "Selectable", and then make RawSelector be a pair of a "Selectable" and a (potentially null) alias. Anecdotally this would also avoid adding new methods to ColumnIdentifier which bugs me for some reason. Nit: could be nice to throw a specific "aliases are not supported in <x> clause" message if someone uses an alias in a WHERE or ORDER BY clause.
        Hide
        Aleksey Yeschenko added a comment -

        Makes sense. Will update soonish.

        Show
        Aleksey Yeschenko added a comment - Makes sense. Will update soonish.
        Hide
        Aleksey Yeschenko added a comment -

        Pushed the updated branch. Can you have another look please?

        Show
        Aleksey Yeschenko added a comment - Pushed the updated branch. Can you have another look please?
        Hide
        Sylvain Lebresne added a comment -

        lgtm, +1

        Show
        Sylvain Lebresne added a comment - lgtm, +1
        Hide
        Aleksey Yeschenko added a comment -

        Thanks. Committed in 08df0b8604cd34c4f1fb384f9f6eaba86203d116, will resolve once the dtest is done and pushed.

        Show
        Aleksey Yeschenko added a comment - Thanks. Committed in 08df0b8604cd34c4f1fb384f9f6eaba86203d116, will resolve once the dtest is done and pushed.
        Show
        Aleksey Yeschenko added a comment - Committed the dtest ( https://github.com/riptano/cassandra-dtest/commit/67acb6be519954c5349230cce75a97eda747dd3e )

          People

          • Assignee:
            Aleksey Yeschenko
            Reporter:
            Alexandr Kulik
            Reviewer:
            Sylvain Lebresne
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development