phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject [19/36] PHOENIX-118 Type mismatch error on upsert for unsigned_date and date
Date Mon, 10 Mar 2014 04:21:50 GMT
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
index 58b2465..3db94f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
@@ -67,7 +67,7 @@ public class IndexUtil {
     // row key was already done, so here we just need to covert from one built-in type to
     // another.
     public static PDataType getIndexColumnDataType(boolean isNullable, PDataType dataType)
{
-        if (dataType == null || !isNullable || !dataType.isFixedWidth() || dataType == PDataType.BINARY)
{
+        if (dataType == null || !isNullable || !dataType.isFixedWidth()) {
             return dataType;
         }
         // for INT, BIGINT
@@ -78,6 +78,11 @@ public class IndexUtil {
         if (dataType.isCoercibleTo(PDataType.VARCHAR)) {
             return PDataType.VARCHAR;
         }
+        // for BOOLEAN, since it has no null representation
+        // TODO: we should have a null for BOOLEAN
+        if (dataType == PDataType.BOOLEAN) {
+            return PDataType.VARBINARY;
+        }
         throw new IllegalArgumentException("Unsupported non nullable index type " + dataType);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
index ab0afea..1943b6b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/NumberUtil.java
@@ -40,13 +40,17 @@ public class NumberUtil {
         return bigDecimal.stripTrailingZeros().round(PDataType.DEFAULT_MATH_CONTEXT);
     }
 
-    public static BigDecimal setDecimalWidthAndScale(BigDecimal decimal, int precision, int
scale) {
+    public static BigDecimal setDecimalWidthAndScale(BigDecimal decimal, Integer precisionOrNull,
Integer scaleOrNull) {
+        int precision = precisionOrNull == null ? PDataType.MAX_PRECISION : precisionOrNull;
+        int scale = scaleOrNull == null ? 0 : scaleOrNull;
         // If we could not fit all the digits before decimal point into the new desired precision
and
         // scale, return null and the caller method should handle the error.
         if (((precision - scale) < (decimal.precision() - decimal.scale()))){
             return null;
         }
-        decimal = decimal.setScale(scale, BigDecimal.ROUND_DOWN);
+        if (scaleOrNull != null) {
+            decimal = decimal.setScale(scale, BigDecimal.ROUND_DOWN); // FIXME: should this
be ROUND_UP?
+        }
         return decimal;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
index 9924d71..97cf665 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
@@ -78,7 +78,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,0)"));
         }
 
         // Pass since we roll out imposing precisioin and scale.
@@ -102,7 +101,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,2)"));
         }
         
         // Decimal with no precision and scale.
@@ -174,7 +172,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,0)"));
         }
 
         // Pass since we roll up precision and scale imposing.
@@ -198,7 +195,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,2)"));
         }
         
         // Decimal with no precision and scale.
@@ -242,7 +238,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,0)"));
         }
 
         // Values exceeds scale.
@@ -255,7 +250,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,2)"));
         }
         
         // Decimal with no precision and scale.
@@ -303,7 +297,6 @@ public class ArithmeticOperationTest {
             evaluated = e.evaluate(null, ptr);
             fail("Evaluation should have failed");
         } catch (ValueTypeIncompatibleException ex) {
-            assertTrue(ex.getMessage(), ex.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. DECIMAL(38,0)"));
         }
         
         // Decimal with no precision and scale.
@@ -315,8 +308,7 @@ public class ArithmeticOperationTest {
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333"), ptr);
-        // TODO: review, as this seems wrong: assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"),
ptr);
+        assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"),
ptr);
     }
 
     private static void assertEqualValue(PDataType type, Object value, ImmutableBytesWritable
ptr) {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValue.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValue.java
b/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValue.java
index 02e06c7..01ec4b6 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValue.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValue.java
@@ -33,10 +33,16 @@ import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.util.ClientKeyValue;
+import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
+import org.apache.phoenix.util.MinVersionTestRunner;
+import org.apache.phoenix.util.MinVersionTestRunner.MinVersion;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+@RunWith(MinVersionTestRunner.class)
+@MinVersion(KeyValueBuilder.CLIENT_KEY_VALUE_MIN_VERSION)
 public class TestClientKeyValue {
   private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
   private static byte[] ROW = Bytes.toBytes("testRow");
@@ -175,4 +181,4 @@ public class TestClientKeyValue {
     if (right == null && left.length == 0) return true;
     return Bytes.equals(left, right);
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValueLocal.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValueLocal.java
b/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValueLocal.java
index b6e2853..4b89011 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValueLocal.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/client/TestClientKeyValueLocal.java
@@ -35,13 +35,19 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.phoenix.hbase.index.util.ClientKeyValue;
+import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
+import org.apache.phoenix.util.MinVersionTestRunner;
+import org.apache.phoenix.util.MinVersionTestRunner.MinVersion;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
 /**
  * Ensure that we can accss a {@link ClientKeyValue} as expected. For instance, write it
to bytes
  * and then read it back into a {@link KeyValue} as expected or compare columns to other
  * {@link KeyValue}s.
  */
+@RunWith(MinVersionTestRunner.class)
+@MinVersion(KeyValueBuilder.CLIENT_KEY_VALUE_MIN_VERSION)
 public class TestClientKeyValueLocal {
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
index 3d8efde..2e58067 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
@@ -30,8 +30,10 @@ 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 org.apache.phoenix.exception.SQLExceptionCode;
 import org.junit.Test;
 
 import com.google.common.primitives.Doubles;
@@ -102,8 +104,8 @@ public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
                 stmt.execute();
                 conn.commit();
                 fail("Should have caught bad values.");
-            } catch (Exception e) {
-                assertTrue(e.getMessage(), e.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. value=12345678901234567890123456789012 columnName=COL1"));
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
             }
             try {
                 query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3) VALUES(?,?,?,?)";
@@ -116,8 +118,8 @@ public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
                 stmt.execute();
                 conn.commit();
                 fail("Should have caught bad values.");
-            } catch (Exception e) {
-                assertTrue(e.getMessage(), e.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. value=123456 columnName=COL2"));
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
             }
         } finally {
             conn.close();
@@ -182,8 +184,8 @@ public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
                 stmt.execute();
                 conn.commit();
                 fail("Should have caught bad upsert.");
-            } catch (Exception e) {
-                assertTrue(e.getMessage(), e.getMessage().contains("ERROR 206 (22003): The
value is outside the range for the data type. columnName=COL3"));
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
             }
             
             // Evaluate on server side.
@@ -437,8 +439,8 @@ public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
             	assertTrue(rs.next());
             	result = rs.getBigDecimal(1);
             	fail("Should have caught error.");
-            } catch (Exception e) {
-            	assertTrue(e.getMessage(), e.getMessage().contains("ERROR 206 (22003): The value
is outside the range for the data type. DECIMAL(38,0)"));
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
             }
             
             try {
@@ -448,8 +450,8 @@ public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
             	assertTrue(rs.next());
             	result = rs.getBigDecimal(1);
             	fail("Should have caught error.");
-            } catch (Exception e) {
-            	assertTrue(e.getMessage(), e.getMessage().contains("ERROR 206 (22003): The value
is outside the range for the data type. DECIMAL(38,0)"));
+            } catch (SQLException e) {
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
             }
             
             query = "SELECT col4 * col5 FROM testDecimalArithmetic WHERE pk='testValueOne'";

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java
index 48d473f..c8435a2 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java
@@ -42,10 +42,10 @@ import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.List;
 
-import org.junit.Test;
-
+import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.Test;
 
 
 public class ExecuteStatementsTest extends BaseHBaseManagedTimeTest {
@@ -256,7 +256,7 @@ public class ExecuteStatementsTest extends BaseHBaseManagedTimeTest {
                 statement.executeUpdate();
                 fail("Should fail when bigger than expected character is inserted");
             } catch (SQLException ex) {
-                assertTrue(ex.getMessage().contains("The value is outside the range for the
data type. columnName=A_STRING"));
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(), ex.getErrorCode());
             }
             
             // upsert non-rowkey value greater than its limit
@@ -271,7 +271,7 @@ public class ExecuteStatementsTest extends BaseHBaseManagedTimeTest {
                 fail("Should fail when bigger than expected character is inserted");
             }
             catch (SQLException ex) {
-                assertTrue(ex.getMessage().contains("The value is outside the range for the
data type. columnName=B_STRING"));
+                assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(), ex.getErrorCode());
             }
                         
             //where selecting from a CHAR(x) and upserting into a CHAR(y) where x<=y.

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitTest.java
index ef68847..6016b79 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitTest.java
@@ -71,7 +71,7 @@ public class UpsertSelectAutoCommitTest extends BaseHBaseManagedTimeTest
{
         assertFalse(rs.next());
         
         conn.createStatement().execute("CREATE TABLE atable2 (ORGANIZATION_ID CHAR(15) NOT
NULL, ENTITY_ID CHAR(15) NOT NULL, A_STRING VARCHAR\n" +
-        "CONSTRAINT pk PRIMARY KEY (organization_id, entity_id))");
+        "CONSTRAINT pk PRIMARY KEY (organization_id, entity_id DESC))");
         
         conn.createStatement().execute("UPSERT INTO atable2 SELECT * FROM ATABLE");
         query = "SELECT entity_id, a_string FROM ATABLE2";

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
index 84dbb11..f15a6e7 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/UpsertValuesTest.java
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Connection;
 import java.sql.Date;
 import java.sql.DriverManager;
@@ -285,6 +287,37 @@ public class UpsertValuesTest extends BaseClientManagedTimeTest {
              closeStmtAndConn(stmt, conn);
         }
         
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
+        try {
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("select t from UpsertTimestamp LIMIT 1");
+            ResultSet rs = stmt.executeQuery();
+            assertTrue(rs.next());
+            assertEquals(ts1, rs.getTimestamp(1));
+            assertFalse(rs.next());
+        } finally {
+             closeStmtAndConn(stmt, conn);
+        }
+
+        BigDecimal msInDay = BigDecimal.valueOf(1*24*60*60*1000);
+        BigDecimal nanosInDay = BigDecimal.valueOf(1*24*60*60*1000).multiply(BigDecimal.valueOf(1000000));
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
+        try {
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("select 500.0/(1*24*60*60*1000) c1, 10.0/(1*24*60*60*1000*1000000)
c2  from UpsertTimestamp LIMIT 1");
+            ResultSet rs = stmt.executeQuery();
+            assertTrue(rs.next());
+            BigDecimal c1 = rs.getBigDecimal(1);
+            BigDecimal rc1 = c1.multiply(msInDay).setScale(0,RoundingMode.HALF_UP);
+            BigDecimal c2 = rs.getBigDecimal(2);
+            BigDecimal rc2 = c2.multiply(nanosInDay).setScale(0,RoundingMode.HALF_UP);
+            assertTrue(BigDecimal.valueOf(500).compareTo(rc1) == 0);
+            assertTrue(BigDecimal.valueOf(10).compareTo(rc2) == 0);
+            assertFalse(rs.next());
+        } finally {
+             closeStmtAndConn(stmt, conn);
+        }
+
         Timestamp ts2 = new Timestamp(ts1.getTime() + 500);
         ts2.setNanos(ts2.getNanos() + extraNanos + 10); //setting the extra nanos as well
as what spilled over from timestamp millis.
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
@@ -461,7 +494,7 @@ public class UpsertValuesTest extends BaseClientManagedTimeTest {
     }
     
     @Test
-    public void testUpsertDateIntoUnsignedDate() throws Exception {
+    public void testUpsertDateIntoDescUnsignedDate() throws Exception {
         long ts = nextTimestamp();
         Properties props = new Properties();
         props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
@@ -469,7 +502,7 @@ public class UpsertValuesTest extends BaseClientManagedTimeTest {
         PreparedStatement stmt = null;
         try {
             conn = DriverManager.getConnection(getUrl(), props);
-            stmt = conn.prepareStatement("create table UpsertTimestamp (k varchar, v unsigned_date
not null, constraint pk primary key (k,v))");
+            stmt = conn.prepareStatement("create table UpsertTimestamp (k varchar, v unsigned_date
not null, constraint pk primary key (k,v desc))");
             stmt.execute();
         } finally {
             closeStmtAndConn(stmt, conn);

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/VariableLengthPKTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/VariableLengthPKTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/VariableLengthPKTest.java
index cb481e1..924fe51 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/VariableLengthPKTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/VariableLengthPKTest.java
@@ -35,17 +35,18 @@ import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Types;
 import java.text.Format;
 import java.text.ParseException;
 import java.util.Properties;
 
-import org.junit.Test;
-
+import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.schema.ConstraintViolationException;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.Test;
 
 
 public class VariableLengthPKTest extends BaseClientManagedTimeTest {
@@ -1045,8 +1046,8 @@ public class VariableLengthPKTest extends BaseClientManagedTimeTest
{
         try {
             stmt.execute();
             fail();
-        } catch (ConstraintViolationException e) {
-            assertTrue(e.getMessage().contains(" may not exceed 2 bytes"));
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
         } finally {
             conn.close();
         }
@@ -1084,8 +1085,8 @@ public class VariableLengthPKTest extends BaseClientManagedTimeTest
{
         try {
             stmt.execute();
             fail();
-        } catch (ConstraintViolationException e) {
-            assertTrue(e.getMessage().contains(" may not exceed 3 bytes"));
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
         } finally {
             conn.close();
         }

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/MutableIndexTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/MutableIndexTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/MutableIndexTest.java
index 88d5c63..032bbc8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/MutableIndexTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/index/MutableIndexTest.java
@@ -785,7 +785,6 @@ public class MutableIndexTest extends BaseMutableIndexTest {
         }
     }
 
-    @Ignore("PHOENIX-62")
     @Test
     public void testIndexWithDecimalCol() throws Exception {
         Properties props = new Properties(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java
index 407e9d0..e882273 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java
@@ -35,9 +35,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Test;
-
 import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
 
 
 public class PDataTypeTest {
@@ -1219,7 +1218,6 @@ public class PDataTypeTest {
 
         // Testing coercing long to other values.
         assertTrue(PDataType.LONG.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.FLOAT));
         assertFalse(PDataType.LONG.isCoercibleTo(PDataType.INTEGER));
         assertFalse(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Long.MAX_VALUE));
         assertFalse(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Integer.MAX_VALUE + 10L));
@@ -1378,7 +1376,6 @@ public class PDataTypeTest {
 
         // Testing coercing unsigned_long to other values.
         assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.FLOAT));
         assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER));
         assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER, 10L));
         assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER, 0L));
@@ -1399,7 +1396,6 @@ public class PDataTypeTest {
         assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0L));
         assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 1000L));
         assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
         
         // Testing coercing unsigned_smallint to other values.
         assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.DOUBLE));
@@ -1509,6 +1505,12 @@ public class PDataTypeTest {
             testReadDecimalPrecisionAndScaleFromRawBytes(bds[i]);
             testReadDecimalPrecisionAndScaleFromRawBytes(bds[i].negate());
         }
+        
+        assertTrue(new BigDecimal("5").remainder(BigDecimal.ONE).equals(BigDecimal.ZERO));
+        assertTrue(new BigDecimal("5.0").remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO)==0);
+        assertTrue(new BigDecimal("5.00").remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO)==0);
+        assertFalse(new BigDecimal("5.01").remainder(BigDecimal.ONE).equals(BigDecimal.ZERO));
+        assertFalse(new BigDecimal("-5.1").remainder(BigDecimal.ONE).equals(BigDecimal.ZERO));
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/schema/SortOrderTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/SortOrderTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/SortOrderTest.java
index 5b61d94..d60c2c9 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/SortOrderTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/SortOrderTest.java
@@ -21,8 +21,10 @@ package org.apache.phoenix.schema;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.junit.Test;
@@ -39,6 +41,17 @@ public class SortOrderTest {
 	    	assertSame(op, SortOrder.ASC.transform(op));
 	    }
 	}
+	
+	@Test
+	public void booleanLogic() {
+	    assertTrue(PDataType.BOOLEAN.toObject(PDataType.TRUE_BYTES, SortOrder.ASC) == PDataType.BOOLEAN.toObject(PDataType.FALSE_BYTES,
SortOrder.DESC));
+        assertTrue(PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(true), SortOrder.ASC)
== PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false), SortOrder.DESC));
+        assertTrue(PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(true,SortOrder.ASC))
== PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false,SortOrder.DESC)));
+
+        assertFalse(PDataType.BOOLEAN.toObject(PDataType.FALSE_BYTES, SortOrder.ASC) == PDataType.BOOLEAN.toObject(PDataType.FALSE_BYTES,
SortOrder.DESC));
+        assertFalse(PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false), SortOrder.ASC)
== PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false), SortOrder.DESC));
+        assertFalse(PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false,SortOrder.ASC))
== PDataType.BOOLEAN.toObject(PDataType.BOOLEAN.toBytes(false,SortOrder.DESC)));
+	}
 
 	@Test
 	public void descSortOrderTransformsOp() {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
index 2f7c6cd..f0334f5 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/MetaDataUtilTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.VersionInfo;
 import org.apache.phoenix.hbase.index.util.ClientKeyValueBuilder;
 import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
@@ -61,7 +62,8 @@ public class MetaDataUtilTest {
    */
   @Test
   public void testGetMutationKeyValue() throws Exception {
-    KeyValueBuilder builder = GenericKeyValueBuilder.INSTANCE;
+    String version = VersionInfo.getVersion();
+    KeyValueBuilder builder = KeyValueBuilder.get(version);
     byte[] row = Bytes.toBytes("row");
     byte[] family = PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
     byte[] qualifier = Bytes.toBytes("qual");
@@ -78,20 +80,22 @@ public class MetaDataUtilTest {
       ByteUtil.BYTES_PTR_COMPARATOR.compare(ptr, wrap(value)));
 
     // try again, this time with the clientkeyvalue builder
-    builder = ClientKeyValueBuilder.INSTANCE;
-    value = Bytes.toBytes("client-value");
-    kv = builder.buildPut(wrap(row), wrap(family), wrap(qualifier), wrap(value));
-    put = new Put(row);
-    KeyValueBuilder.addQuietly(put, builder, kv);
-
-    // read back out the value
-    assertTrue(MetaDataUtil.getMutationValue(put, qualifier, builder, ptr));
-    assertEquals("Value returned doesn't match stored value for " + builder.getClass().getName()
-        + "!", 0,
-      ByteUtil.BYTES_PTR_COMPARATOR.compare(ptr, wrap(value)));
-
-    // ensure that we don't get matches for qualifiers that don't match
-    assertFalse(MetaDataUtil.getMutationValue(put, Bytes.toBytes("not a match"), builder,
ptr));
+    if (builder != GenericKeyValueBuilder.INSTANCE) {
+        builder = GenericKeyValueBuilder.INSTANCE;
+        value = Bytes.toBytes("client-value");
+        kv = builder.buildPut(wrap(row), wrap(family), wrap(qualifier), wrap(value));
+        put = new Put(row);
+        KeyValueBuilder.addQuietly(put, builder, kv);
+    
+        // read back out the value
+        assertTrue(MetaDataUtil.getMutationValue(put, qualifier, builder, ptr));
+        assertEquals("Value returned doesn't match stored value for " + builder.getClass().getName()
+            + "!", 0,
+          ByteUtil.BYTES_PTR_COMPARATOR.compare(ptr, wrap(value)));
+    
+        // ensure that we don't get matches for qualifiers that don't match
+        assertFalse(MetaDataUtil.getMutationValue(put, Bytes.toBytes("not a match"), builder,
ptr));
+    }
   }
 
   private static ImmutableBytesPtr wrap(byte[] bytes) {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/65ac0ca3/phoenix-core/src/test/java/org/apache/phoenix/util/MinVersionTestRunner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/MinVersionTestRunner.java
b/phoenix-core/src/test/java/org/apache/phoenix/util/MinVersionTestRunner.java
new file mode 100644
index 0000000..8106f04
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/MinVersionTestRunner.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.hadoop.hbase.util.VersionInfo;
+import org.apache.phoenix.hbase.index.util.VersionUtil;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * 
+ * Conditionally run tests based on HBase version. Uses a
+ * @minVersion(versionStr) annotation on either the test class
+ * or the test method.
+ *
+ */
+public class MinVersionTestRunner extends BlockJUnit4ClassRunner {
+    
+    public MinVersionTestRunner(Class klass) throws InitializationError {
+        super(klass);
+    }
+    @Override
+    public void runChild(FrameworkMethod method, RunNotifier notifier) {
+        MinVersion methodCondition = method.getAnnotation(MinVersion.class);
+        MinVersion classCondition = this.getTestClass().getJavaClass().getAnnotation(MinVersion.class);
+        String versionStr = VersionInfo.getVersion();
+        int version = VersionUtil.encodeVersion(versionStr);
+        if (  (methodCondition == null || version >= VersionUtil.encodeVersion(methodCondition.value()))
+           && (classCondition == null || version >= VersionUtil.encodeVersion(classCondition.value())))
{
+            super.runChild(method, notifier);
+        } else {
+            notifier.fireTestIgnored(describeChild(method));
+        }
+    }
+    
+    @Target( {ElementType.TYPE, ElementType.METHOD} )
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface MinVersion {
+        /** The minimum version supported for this test class or test method */
+        String value();
+    }}
+


Mime
View raw message