You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2020/06/29 12:09:01 UTC
[phoenix] branch 4.x updated: PHOENIX-5937 Order by on nullable
column sometimes filters rows
This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push:
new 26848bb PHOENIX-5937 Order by on nullable column sometimes filters rows
26848bb is described below
commit 26848bbe205f43fc0a02bd9629ed2244b7e3cf56
Author: Richard Antal <an...@gmail.com>
AuthorDate: Thu Jun 11 14:03:18 2020 +0200
PHOENIX-5937 Order by on nullable column sometimes filters rows
---
.../org/apache/phoenix/end2end/BaseOrderByIT.java | 43 ++++++++++++++++++++++
.../phoenix/iterate/BaseResultIterators.java | 19 ++++++++++
2 files changed, 62 insertions(+)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseOrderByIT.java
index 31bf050..2791d0f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseOrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseOrderByIT.java
@@ -36,6 +36,7 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Properties;
import com.google.common.collect.Lists;
@@ -937,4 +938,46 @@ public abstract class BaseOrderByIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testOrderByNullable() throws SQLException {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String sql = "CREATE TABLE IF NOT EXISTS us_population (state CHAR(2) NOT NULL," +
+ "city VARCHAR NOT NULL, population BIGINT CONSTRAINT my_pk PRIMARY KEY" +
+ " (state, city))";
+ conn.createStatement().execute(sql);
+
+ sql = "select ORDINAL_POSITION from SYSTEM.CATALOG where TABLE_NAME = 'US_POPULATION'";
+ ResultSet rs = conn.createStatement().executeQuery(sql);
+ int expected = 0;
+ while (rs.next()){
+ expected += 1;
+ }
+
+ QueryBuilder queryBuilder = new QueryBuilder()
+ .setSelectColumns(Lists.newArrayList("*"))
+ .setFullTableName("SYSTEM.CATALOG")
+ .setWhereClause("TABLE_NAME = 'US_POPULATION'")
+ .setOrderByClause("ORDINAL_POSITION");
+ rs = executeQuery(conn, queryBuilder);
+ int linesCount = 0;
+ while (rs.next()){
+ linesCount += 1;
+ }
+ assertEquals(expected, linesCount);
+
+ queryBuilder = new QueryBuilder()
+ .setSelectColumns(Lists.newArrayList("COLUMN_NAME"))
+ .setFullTableName("SYSTEM.CATALOG")
+ .setWhereClause("TABLE_NAME = 'US_POPULATION'")
+ .setOrderByClause("ORDINAL_POSITION");
+ rs = executeQuery(conn, queryBuilder);
+ linesCount = 0;
+ while (rs.next()){
+ linesCount += 1;
+ }
+ assertEquals(expected, linesCount);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index 6c15957..c54a472 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -83,6 +83,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.execute.MutationState;
import org.apache.phoenix.execute.ScanPlan;
+import org.apache.phoenix.expression.OrderByExpression;
import org.apache.phoenix.filter.BooleanExpressionFilter;
import org.apache.phoenix.filter.ColumnProjectionFilter;
import org.apache.phoenix.filter.DistinctPrefixFilter;
@@ -253,6 +254,24 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
}
}
}
+ } else {
+ boolean containsNullableGroubBy = false;
+ if (!plan.getOrderBy().isEmpty()) {
+ for (OrderByExpression orderByExpression : plan.getOrderBy()
+ .getOrderByExpressions()) {
+ if (orderByExpression.getExpression().isNullable()) {
+ containsNullableGroubBy = true;
+ break;
+ }
+ }
+ }
+ if(containsNullableGroubBy){
+ byte[] ecf = SchemaUtil.getEmptyColumnFamily(table);
+ if (!familyMap.containsKey(ecf) || familyMap.get(ecf) != null) {
+ scan.addColumn(ecf, EncodedColumnsUtil.getEmptyKeyValueInfo(table)
+ .getFirst());
+ }
+ }
}
// Add FirstKeyOnlyFilter if there are no references to key value columns
if (keyOnlyFilter) {