Search in sources :

Example 1 with CountAggregateFunction

use of org.apache.phoenix.expression.function.CountAggregateFunction in project phoenix by apache.

the class HavingCompilerTest method testAndHavingToAndWhere.

@Test
public void testAndHavingToAndWhere() throws SQLException {
    String query = "select count(1) from atable where b_string > 'bar' group by a_string having count(1) >= 1 and a_string = 'foo'";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query, binds);
    Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(), 1L);
    Expression w = and(constantComparison(CompareOp.GREATER, B_STRING, "bar"), constantComparison(CompareOp.EQUAL, A_STRING, "foo"));
    assertEquals(w, expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
Also used : CountAggregateFunction(org.apache.phoenix.expression.function.CountAggregateFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) Expression(org.apache.phoenix.expression.Expression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 2 with CountAggregateFunction

use of org.apache.phoenix.expression.function.CountAggregateFunction in project phoenix by apache.

the class HavingCompilerTest method testAggFuncInHaving.

@Test
public void testAggFuncInHaving() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(a_string) >= 1";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query, binds);
    Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(Arrays.asList(A_STRING)), 1L);
    assertNull(expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
Also used : CountAggregateFunction(org.apache.phoenix.expression.function.CountAggregateFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) Expression(org.apache.phoenix.expression.Expression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 3 with CountAggregateFunction

use of org.apache.phoenix.expression.function.CountAggregateFunction in project phoenix by apache.

the class HavingCompilerTest method testOrAggFuncInHaving.

@Test
public void testOrAggFuncInHaving() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(1) >= 1 or a_string = 'foo'";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query, binds);
    PColumn aCol = ATABLE.getColumnForColumnName("A_STRING");
    Expression h = or(constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(), 1L), constantComparison(CompareOp.EQUAL, new // a_string comes from group by key in this case
    RowKeyColumnExpression(// a_string comes from group by key in this case
    aCol, new RowKeyValueAccessor(Arrays.<PColumn>asList(aCol), 0)), "foo"));
    assertNull(expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) CountAggregateFunction(org.apache.phoenix.expression.function.CountAggregateFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) Expression(org.apache.phoenix.expression.Expression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 4 with CountAggregateFunction

use of org.apache.phoenix.expression.function.CountAggregateFunction in project phoenix by apache.

the class HavingCompilerTest method testAndHavingToWhere.

@Test
public void testAndHavingToWhere() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(1) >= 1 and a_string = 'foo'";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query, binds);
    Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(), 1L);
    Expression w = constantComparison(CompareOp.EQUAL, A_STRING, "foo");
    assertEquals(w, expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
Also used : CountAggregateFunction(org.apache.phoenix.expression.function.CountAggregateFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) Expression(org.apache.phoenix.expression.Expression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

Expression (org.apache.phoenix.expression.Expression)4 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)4 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)4 CountAggregateFunction (org.apache.phoenix.expression.function.CountAggregateFunction)4 RoundDateExpression (org.apache.phoenix.expression.function.RoundDateExpression)4 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)4 Test (org.junit.Test)4 PColumn (org.apache.phoenix.schema.PColumn)1 RowKeyValueAccessor (org.apache.phoenix.schema.RowKeyValueAccessor)1