Search in sources :

Example 1 with ClientAggregators

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

the class RowKeyOrderedAggregateResultIteratorTest method testSpanThree.

@Test
public void testSpanThree() throws Exception {
    Tuple[] results1 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(2L))) };
    Tuple[] results2 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))) };
    Tuple[] results3 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(4L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(5L))) };
    final List<PeekingResultIterator> results = Arrays.asList(new PeekingResultIterator[] { new MaterializedResultIterator(Arrays.asList(results1)), new MaterializedResultIterator(Arrays.asList(results2)), new MaterializedResultIterator(Arrays.asList(results3)) });
    ResultIterators iterators = new MaterializedResultIterators(results);
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(9L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(5L))) };
    ClientAggregators aggregators = TestUtil.getSingleSumAggregator(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    ResultIterator scanner = new RowKeyOrderedAggregateResultIterator(iterators, aggregators);
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 2 with ClientAggregators

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

the class TestUtil method getSingleSumAggregator.

public static ClientAggregators getSingleSumAggregator(String url, Properties props) throws SQLException {
    try (PhoenixConnection pconn = DriverManager.getConnection(url, props).unwrap(PhoenixConnection.class)) {
        PhoenixStatement statement = new PhoenixStatement(pconn);
        StatementContext context = new StatementContext(statement, null, new Scan(), new SequenceManager(statement));
        AggregationManager aggregationManager = context.getAggregationManager();
        SumAggregateFunction func = new SumAggregateFunction(Arrays.<Expression>asList(new KeyValueColumnExpression(new PLongColumn() {

            @Override
            public PName getName() {
                return SINGLE_COLUMN_NAME;
            }

            @Override
            public PName getFamilyName() {
                return SINGLE_COLUMN_FAMILY_NAME;
            }

            @Override
            public int getPosition() {
                return 0;
            }

            @Override
            public SortOrder getSortOrder() {
                return SortOrder.getDefault();
            }

            @Override
            public Integer getArraySize() {
                return 0;
            }

            @Override
            public byte[] getViewConstant() {
                return null;
            }

            @Override
            public boolean isViewReferenced() {
                return false;
            }

            @Override
            public String getExpressionStr() {
                return null;
            }

            @Override
            public boolean isRowTimestamp() {
                return false;
            }

            @Override
            public boolean isDynamic() {
                return false;
            }

            @Override
            public byte[] getColumnQualifierBytes() {
                return SINGLE_COLUMN_NAME.getBytes();
            }
        })), null);
        aggregationManager.setAggregators(new ClientAggregators(Collections.<SingleAggregateFunction>singletonList(func), 1));
        ClientAggregators aggregators = aggregationManager.getAggregators();
        return aggregators;
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SortOrder(org.apache.phoenix.schema.SortOrder) PhoenixStatement(org.apache.phoenix.jdbc.PhoenixStatement) SequenceManager(org.apache.phoenix.compile.SequenceManager) StatementContext(org.apache.phoenix.compile.StatementContext) AggregationManager(org.apache.phoenix.compile.AggregationManager) PName(org.apache.phoenix.schema.PName) SumAggregateFunction(org.apache.phoenix.expression.function.SumAggregateFunction) Scan(org.apache.hadoop.hbase.client.Scan) PLongColumn(org.apache.phoenix.schema.PLongColumn) SingleAggregateFunction(org.apache.phoenix.expression.function.SingleAggregateFunction) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression)

Example 3 with ClientAggregators

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

the class AggregateResultScannerTest method testAggregatingMergeSort.

@Test
public void testAggregatingMergeSort() throws Throwable {
    Tuple[] results1 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))) };
    Tuple[] results2 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))) };
    Tuple[] results3 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))) };
    Tuple[] results4 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))) };
    final List<PeekingResultIterator> results = new ArrayList<PeekingResultIterator>(Arrays.asList(new PeekingResultIterator[] { new MaterializedResultIterator(Arrays.asList(results1)), new MaterializedResultIterator(Arrays.asList(results2)), new MaterializedResultIterator(Arrays.asList(results3)), new MaterializedResultIterator(Arrays.asList(results4)) }));
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(3L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(2L))) };
    ResultIterators iterators = new MaterializedResultIterators(results);
    ClientAggregators aggregators = TestUtil.getSingleSumAggregator(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
    ResultIterator scanner = new GroupedAggregatingResultIterator(new MergeSortRowKeyResultIterator(iterators), aggregators);
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) ArrayList(java.util.ArrayList) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 4 with ClientAggregators

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

the class RowKeyOrderedAggregateResultIteratorTest method testSpanEnd.

@Test
public void testSpanEnd() throws Exception {
    Tuple[] results1 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1L))) };
    Tuple[] results2 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(2L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(4L))), new SingleKeyValueTuple(new KeyValue(D, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(5L))) };
    Tuple[] results3 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(D, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(6L))) };
    final List<PeekingResultIterator> results = Arrays.asList(new PeekingResultIterator[] { new MaterializedResultIterator(Arrays.asList(results1)), new MaterializedResultIterator(Arrays.asList(results2)), new MaterializedResultIterator(Arrays.asList(results3)) });
    ResultIterators iterators = new MaterializedResultIterators(results);
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))), new SingleKeyValueTuple(new KeyValue(C, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(4L))), new SingleKeyValueTuple(new KeyValue(D, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(11L))) };
    ClientAggregators aggregators = TestUtil.getSingleSumAggregator(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    ResultIterator scanner = new RowKeyOrderedAggregateResultIterator(iterators, aggregators);
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 5 with ClientAggregators

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

the class RowKeyOrderedAggregateResultIteratorTest method testSpanAll.

@Test
public void testSpanAll() throws Exception {
    Tuple[] results1 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(2L))) };
    Tuple[] results2 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(3L))) };
    Tuple[] results3 = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(4L))) };
    final List<PeekingResultIterator> results = Arrays.asList(new PeekingResultIterator[] { new MaterializedResultIterator(Arrays.asList(results1)), new MaterializedResultIterator(Arrays.asList(results2)), new MaterializedResultIterator(Arrays.asList(results3)) });
    ResultIterators iterators = new MaterializedResultIterators(results);
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(9L))) };
    ClientAggregators aggregators = TestUtil.getSingleSumAggregator(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
    ResultIterator scanner = new RowKeyOrderedAggregateResultIterator(iterators, aggregators);
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ClientAggregators(org.apache.phoenix.expression.aggregator.ClientAggregators) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

ClientAggregators (org.apache.phoenix.expression.aggregator.ClientAggregators)7 KeyValue (org.apache.hadoop.hbase.KeyValue)5 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)5 SingleKeyValueTuple (org.apache.phoenix.schema.tuple.SingleKeyValueTuple)5 Tuple (org.apache.phoenix.schema.tuple.Tuple)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 SingleAggregateFunction (org.apache.phoenix.expression.function.SingleAggregateFunction)2 Iterator (java.util.Iterator)1 Scan (org.apache.hadoop.hbase.client.Scan)1 AggregationManager (org.apache.phoenix.compile.AggregationManager)1 SequenceManager (org.apache.phoenix.compile.SequenceManager)1 StatementContext (org.apache.phoenix.compile.StatementContext)1 Expression (org.apache.phoenix.expression.Expression)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 SumAggregateFunction (org.apache.phoenix.expression.function.SumAggregateFunction)1 SingleAggregateFunctionVisitor (org.apache.phoenix.expression.visitor.SingleAggregateFunctionVisitor)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 PhoenixStatement (org.apache.phoenix.jdbc.PhoenixStatement)1 PLongColumn (org.apache.phoenix.schema.PLongColumn)1