Friday, January 24, 2020

EntitySpaces - SQL Window Frame Clause

When adding new fluent query API functionality to EntitySpaces it is important to me that the syntax looks and feels like SQL itself. That way, if you understand one you understand the other. In order to finish out the SQL OVER syntax I needed to support the "Window Frame Clause". I liked the way this document outlines the Window Frame Clause and after studying the syntax was able to come with a very elegant representation in EntitySpaces.

SQL - Window Frame Clause

{ ROWS }
{
  { UNBOUNDED PRECEDING | numeric_expression PRECEDING | CURRENT ROW }
  |
  {
    BETWEEN 
      { UNBOUNDED PRECEDING | numeric_expression { PRECEDING | FOLLOWING } | CURRENT ROW }
      AND
      { UNBOUNDED FOLLOWING | numeric_expression { PRECEDING | FOLLOWING } | CURRENT ROW }
  }
}

EntitiySpaces - Window Frame Clause Implementation

{ Rows.UnBoundedPreceding | Rows(x).Preceding | Rows.CurrentRow }.As() 
  |
{ Rows.
  { Between.UnboundedPreceding     | { Between(x).Preceding | Between(x).Following } | Between.CurrentRow     }
  { And.Between.UnboundedFollowing | { And(x).Preceding     | And(x).Following     } | And.Between.CurrentRow }
  .As()
}

Real Working Examples

Notice how similar the two syntaxes are to each other.
/* SQL */ SELECT ...  OVER(... ROWS UNBOUNDED PRECEDING) "Rows"
/* EntitySpaces */            .Rows.UnBoundedPreceding.As("Rows"))

/* SQL */ SELECT ...  OVER(... ROWS BETWEEN 3  PRECEDING  AND CURRENT ROW) as "Rows"
/* EntitySpaces */            .Rows.Between(3).Precending.And.CurrentRow.As("Rows"))


/* SQL */ SELECT ...  OVER(... ROWS BETWEEN 1  PRECEDING  AND 1  FOLLOWING) as "Rows"
/* EntitySpaces */            .Rows.Between(1).Precending.And(1).Following.As("Rows"))
Once I get this finished up I will release updated NuGet packages, should be in the next week or so.


No comments:

Post a Comment