You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by Shuxiong Ye <ye...@gmail.com> on 2015/06/10 18:58:21 UTC
Questions about test testOrderByOrderPreservingRev in QueryCompilerTest
Hi community,
I have a question about test testOrderByOrderPreservingRev in
QueryCompilerTest.
@Test
public void testOrderByOrderPreservingRev() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE t (k1 date not
null, k2 date not null, k3 date not null, v varchar, constraint pk
primary key(k1,k2 DESC,k3))");
String[] queries = {
"SELECT * FROM T ORDER BY INVERT(k1),k2",
"SELECT * FROM T ORDER BY INVERT(k1)",
"SELECT * FROM T ORDER BY TRUNC(k1, 'DAY') DESC,
CEIL(k2, 'HOUR') DESC", // <---- I have a question here.
"SELECT * FROM T ORDER BY k1 DESC",
};
String query;
for (int i = 0; i < queries.length; i++) {
query = queries[i];
QueryPlan plan =
conn.createStatement().unwrap(PhoenixStatement.class).compileQuery(query);
assertTrue("Expected order by to be compiled out: " +
query, plan.getOrderBy() == OrderBy.REV_ROW_KEY_ORDER_BY);
}
}
In the third query, why is CEIL(k2, 'HOUR') DESC instead of CEIL(k2,
'HOUR')?
In the primary key definition, "primary key(k1,k2 DESC,k3))", k2 is
descending.
When the order by clause is "TRUNC(k1, 'DAY') DESC, CEIL(k2, 'HOUR')", it
will be opposite with the primary key definition, "primary key(k1,k2
DESC,k3))", so the QueryPlan has an empty order by, for we can scan the
data forward. Is my understanding right?
see it in jira here [1].
Thanks.
[1]
https://issues.apache.org/jira/browse/PHOENIX-1987?focusedCommentId=14574255&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14574255
Shuxiong Ye