Repository: phoenix Updated Branches: refs/heads/master 3d259d57a -> f02fb1b06
PHOENIX-2313 TypeMismatchException thrown while querying a table that has an index with a Boolean(Rajeshbabu) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f02fb1b0 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f02fb1b0 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f02fb1b0 Branch: refs/heads/master Commit: f02fb1b06e55b6d870a42ec051d3fbf18bb39e01 Parents: 3d259d5 Author: Rajeshbabu Chintaguntla <[email protected]> Authored: Sun Oct 18 09:50:05 2015 +0530 Committer: Rajeshbabu Chintaguntla <[email protected]> Committed: Sun Oct 18 09:50:05 2015 +0530 ---------------------------------------------------------------------- .../phoenix/end2end/index/BaseMutableIndexIT.java | 17 +++++++++++++++++ .../org/apache/phoenix/schema/types/PBoolean.java | 4 ++++ 2 files changed, 21 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/f02fb1b0/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseMutableIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseMutableIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseMutableIndexIT.java index b2f8630..68998cf 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseMutableIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseMutableIndexIT.java @@ -110,6 +110,23 @@ public abstract class BaseMutableIndexIT extends BaseHBaseManagedTimeIT { } @Test + public void testIndexWithBooleanCol() throws Exception { + Connection conn1 = DriverManager.getConnection(getUrl()); + conn1.createStatement().execute( + "create table t( a integer primary key, b boolean, c varchar)"); + conn1.createStatement().execute( + "create " + (localIndex ? "LOCAL" : "") + " index i on t(b)"); + conn1.createStatement().execute("upsert into t values(1,true,'foo')"); + conn1.createStatement().execute("upsert into t values(2,false,'foo')"); + conn1.commit(); + ResultSet rs = conn1.createStatement().executeQuery("select b from t"); + rs.next(); + assertEquals(true, rs.getBoolean(1)); + rs.next(); + assertEquals(false, rs.getBoolean(1)); + } + + @Test public void testIndexWithNullableFixedWithCols() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); http://git-wip-us.apache.org/repos/asf/phoenix/blob/f02fb1b0/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java index 66991c5..9892426 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java @@ -17,6 +17,7 @@ */ package org.apache.phoenix.schema.types; +import java.math.BigDecimal; import java.sql.Types; import org.apache.phoenix.schema.SortOrder; @@ -131,6 +132,9 @@ public class PBoolean extends PDataType<Boolean> { byte[] bytes = (byte[]) object; return toObject(bytes, 0, bytes.length); } + if (actualType == PDecimal.INSTANCE) { + return ((BigDecimal) object).equals(BigDecimal.ONE) ? Boolean.TRUE : Boolean.FALSE; + } return throwConstraintViolationException(actualType, this); }
