Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Concourse is adding calculations (cinchapi/concourse#1417), which are new
functions, grouped calculations, ranges of numbers or time, and several
calculations in one statement. CCL must parse each of them into a
CalculateSymbolthat Concourse can turn into a command. A calculate statementnamed only one of
sum,avg,average,count,minormax, had nogrouping, and its symbol had no
equals,hashCodeor text.This change adds the functions and a
group byclause to the calculatestatement, and exposes them through a
CalculationSymbolfor each calculationand a
GroupSymbolfor the group. The existing constructors and accessors ofCalculateSymbolkeep their meaning, so a caller that readsfunction(),key(),records()andtimestamp()works as before. The page and the resultorder of a grouped statement belong to its
GroupSymbol, because they page andorder groups rather than records, and a grouped statement cannot order its
groups by a key.
Closes #89
Behavior
countDistinct,median,percentile,stddev,stddevPopulation,varianceandvariancePopulation, in any letter case.percentiletakes a fraction from 0 to 1 before its key, as incalculate percentile 0.99 latency.CalculationSymbol#function()andCalculateSymbol#function()return acanonical name. It is camelCase for a new function, such as
countDistinct,which is the name of the Concourse calculation it asks for. It is lower case
for
sum,avg,average,count,minandmax, as before.group byclause comes after the scope (records or awherecondition) andthe timestamp. Its parts come in this order, and each part after the keys is
optional.
per <number>orper "<duration>"groups the values of the last key intonumber ranges of that width or time ranges of that period. A duration has
the form of a
withinduration.between <a> and <b>followsperand bounds the ranges. The bounds arenumbers for number ranges and timestamps for time ranges.
having <function> <operator> <value>keeps the groups whose resultsatisfies a comparison.
order by <function> [asc|desc]orders the groups by a result, ascending bydefault.
limitandoffsetpage the groups.havingandorder bynames one of the statement'scalculations in any letter case, and
avgandaveragename the samefunction. A function that names none of the calculations, or more than one, is
a syntax error. So
order by <key>in a grouped statement is a syntax error.groups.
calculations()returns them in the order the statement lists them,and
function()andkey()return those of the first.GroupSymbolexposeskeys(),width(),lowerBound()andupperBound()as numbers,
period()as ajava.time.Duration,start()andend()asTimestampSymbols, andhaving(),order()andpage(). Each part thestatement leaves out is
null. A whole number is anIntegeror aLong,and a decimal is a
Double.calculation()of aHavingSymbolor aResultOrderSymbolis the one ofcalculations()that its function names.CommandTree. Agrouped statement has no
OrderTreeorPageTreechild.atright after a comparison belongs to the comparison, as it does forfind.as of, oratafter a parenthesized condition, sets the timestampof the calculation.
CalculateSymbol,CalculationSymbol,GroupSymbol,HavingSymbolandResultOrderSymbolimplementequalsandhashCode. Numbers in a group areequal when they have the same value, such as
10and10.0. The text of aCalculateSymbolis its statement without the condition, and that text parsesto an equal symbol.
value function, such as
age | avg, keeps theequalsandhashCodecontract.
CalculateSymbolorGroupSymbolbuilt from its parts follows the rules ofthe grammar, and an invalid one throws
IllegalArgumentExceptionor, fromGroupSymbol.Builder#build(),IllegalStateException.Compiler#analyzereports the key of every calculation and every group key.group byis reserved in any letter case, even when a longer wordstarts with
by, as ingroup bypass. A value that contains it must bequoted. The words
perandhavingare not reserved, so a key may haveeither name.