()
| 1743 | } |
| 1744 | |
| 1745 | func (qc *AQLQueryContext) processMeasure() { |
| 1746 | // OOPK engine only supports one measure per query. |
| 1747 | if len(qc.Query.Measures) != 1 { |
| 1748 | qc.Error = utils.StackError(nil, "expect one measure per query, but got %d", |
| 1749 | len(qc.Query.Measures)) |
| 1750 | return |
| 1751 | } |
| 1752 | |
| 1753 | if _, ok := qc.Query.Measures[0].ExprParsed.(*expr.NumberLiteral); ok { |
| 1754 | qc.IsNonAggregationQuery = true |
| 1755 | // in case user forgot to provide limit |
| 1756 | if qc.Query.Limit == 0 { |
| 1757 | qc.Query.Limit = nonAggregationQueryLimit |
| 1758 | } |
| 1759 | return |
| 1760 | } |
| 1761 | |
| 1762 | // Match and strip the aggregate function. |
| 1763 | aggregate, ok := qc.Query.Measures[0].ExprParsed.(*expr.Call) |
| 1764 | if !ok { |
| 1765 | qc.Error = utils.StackError(nil, "expect aggregate function, but got %s", |
| 1766 | qc.Query.Measures[0].Expr) |
| 1767 | return |
| 1768 | } |
| 1769 | |
| 1770 | if qc.ReturnHLLData && aggregate.Name != expr.HllCallName { |
| 1771 | qc.Error = utils.StackError(nil, "expect hll aggregate function as client specify 'Accept' as "+ |
| 1772 | "'application/hll', but got %s", |
| 1773 | qc.Query.Measures[0].Expr) |
| 1774 | return |
| 1775 | } |
| 1776 | |
| 1777 | if len(aggregate.Args) != 1 { |
| 1778 | qc.Error = utils.StackError(nil, |
| 1779 | "expect one parameter for aggregate function %s, but got %d", |
| 1780 | aggregate.Name, len(aggregate.Args)) |
| 1781 | return |
| 1782 | } |
| 1783 | qc.OOPK.Measure = aggregate.Args[0] |
| 1784 | // default is 4 bytes |
| 1785 | qc.OOPK.MeasureBytes = 4 |
| 1786 | switch strings.ToLower(aggregate.Name) { |
| 1787 | case expr.CountCallName: |
| 1788 | qc.OOPK.Measure = &expr.NumberLiteral{ |
| 1789 | Int: 1, |
| 1790 | Expr: "1", |
| 1791 | ExprType: expr.Unsigned, |
| 1792 | } |
| 1793 | qc.OOPK.AggregateType = C.AGGR_SUM_UNSIGNED |
| 1794 | case expr.SumCallName: |
| 1795 | qc.OOPK.MeasureBytes = 8 |
| 1796 | switch qc.OOPK.Measure.Type() { |
| 1797 | case expr.Float: |
| 1798 | qc.OOPK.AggregateType = C.AGGR_SUM_FLOAT |
| 1799 | case expr.Signed: |
| 1800 | qc.OOPK.AggregateType = C.AGGR_SUM_SIGNED |
| 1801 | case expr.Unsigned: |
| 1802 | qc.OOPK.AggregateType = C.AGGR_SUM_UNSIGNED |
no test coverage detected