Search in sources :

Example 1 with CountAggregator

use of org.apache.phoenix.expression.aggregator.CountAggregator in project phoenix by apache.

the class QueryCompilerTest method testCountAggregatorFirst.

@Test
public void testCountAggregatorFirst() throws Exception {
    String[] queries = new String[] { "SELECT sum(2.5),organization_id FROM atable GROUP BY organization_id,entity_id", "SELECT avg(a_integer) FROM atable GROUP BY organization_id,substr(entity_id,1,3),entity_id", "SELECT count(a_string) FROM atable GROUP BY substr(organization_id,1),entity_id", "SELECT min('foo') FROM atable GROUP BY entity_id,organization_id", "SELECT min('foo'),sum(a_integer),avg(2.5),4.5,max(b_string) FROM atable GROUP BY substr(organization_id,1),entity_id", "SELECT sum(2.5) FROM atable", "SELECT avg(a_integer) FROM atable", "SELECT count(a_string) FROM atable", "SELECT min('foo') FROM atable LIMIT 5", "SELECT min('foo'),sum(a_integer),avg(2.5),4.5,max(b_string) FROM atable" };
    List<Object> binds = Collections.emptyList();
    String query = null;
    try {
        for (int i = 0; i < queries.length; i++) {
            query = queries[i];
            Scan scan = compileQuery(query, binds);
            ServerAggregators aggregators = ServerAggregators.deserialize(scan.getAttribute(BaseScannerRegionObserver.AGGREGATORS), null);
            Aggregator aggregator = aggregators.getAggregators()[0];
            assertTrue(aggregator instanceof CountAggregator);
        }
    } catch (Exception e) {
        throw new Exception(query, e);
    }
}
Also used : CountAggregator(org.apache.phoenix.expression.aggregator.CountAggregator) ServerAggregators(org.apache.phoenix.expression.aggregator.ServerAggregators) CountAggregator(org.apache.phoenix.expression.aggregator.CountAggregator) Aggregator(org.apache.phoenix.expression.aggregator.Aggregator) Scan(org.apache.hadoop.hbase.client.Scan) AmbiguousColumnException(org.apache.phoenix.schema.AmbiguousColumnException) SQLException(java.sql.SQLException) ColumnAlreadyExistsException(org.apache.phoenix.schema.ColumnAlreadyExistsException) ColumnNotFoundException(org.apache.phoenix.schema.ColumnNotFoundException) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 2 with CountAggregator

use of org.apache.phoenix.expression.aggregator.CountAggregator in project phoenix by apache.

the class CountAggregateFunction method newServerAggregator.

@Override
public Aggregator newServerAggregator(Configuration config, ImmutableBytesWritable ptr) {
    LongSumAggregator sumAgg = newClientAggregator();
    sumAgg.aggregate(null, ptr);
    return new CountAggregator(sumAgg);
}
Also used : LongSumAggregator(org.apache.phoenix.expression.aggregator.LongSumAggregator) CountAggregator(org.apache.phoenix.expression.aggregator.CountAggregator)

Aggregations

CountAggregator (org.apache.phoenix.expression.aggregator.CountAggregator)2 SQLException (java.sql.SQLException)1 Scan (org.apache.hadoop.hbase.client.Scan)1 Aggregator (org.apache.phoenix.expression.aggregator.Aggregator)1 LongSumAggregator (org.apache.phoenix.expression.aggregator.LongSumAggregator)1 ServerAggregators (org.apache.phoenix.expression.aggregator.ServerAggregators)1 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)1 AmbiguousColumnException (org.apache.phoenix.schema.AmbiguousColumnException)1 ColumnAlreadyExistsException (org.apache.phoenix.schema.ColumnAlreadyExistsException)1 ColumnNotFoundException (org.apache.phoenix.schema.ColumnNotFoundException)1 Test (org.junit.Test)1