You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by nd...@apache.org on 2014/12/18 01:11:39 UTC

[01/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Repository: phoenix
Updated Branches:
  refs/heads/master a8d9eec60 -> 04ef859b7


http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java
index 444dd87..13e3f5e 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java
@@ -20,11 +20,9 @@ package org.apache.phoenix.util;
 import static org.junit.Assert.*;
 
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.types.PInteger;
 import org.junit.Test;
 
-import org.apache.phoenix.schema.PDataType;
-
-
 public class ByteUtilTest {
 
     @Test
@@ -57,9 +55,9 @@ public class ByteUtilTest {
         byte[] nextKey = ByteUtil.nextKey(key);
         byte[] expectedKey = new byte[] {2,(byte)0};
         assertArrayEquals(expectedKey, nextKey); 
-        key = ByteUtil.concat(Bytes.toBytes("00D300000000XHP"), PDataType.INTEGER.toBytes(Integer.MAX_VALUE));
+        key = ByteUtil.concat(Bytes.toBytes("00D300000000XHP"), PInteger.INSTANCE.toBytes(Integer.MAX_VALUE));
         nextKey = ByteUtil.nextKey(key);
-        expectedKey = ByteUtil.concat(Bytes.toBytes("00D300000000XHQ"), PDataType.INTEGER.toBytes(Integer.MIN_VALUE));
+        expectedKey = ByteUtil.concat(Bytes.toBytes("00D300000000XHQ"), PInteger.INSTANCE.toBytes(Integer.MIN_VALUE));
         assertArrayEquals(expectedKey, nextKey);
         
         key = new byte[] {(byte)255};

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
index 847aed9..a642e80 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
index b1246b8..991ee72 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/ScanUtilTest.java
@@ -26,8 +26,10 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.KeyRange.Bound;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SortOrder;
@@ -62,7 +64,7 @@ public class ScanUtilTest {
                     }
                     @Override
                     public PDataType getDataType() {
-                        return PDataType.CHAR;
+                        return PChar.INSTANCE;
                     }
                     @Override
                     public Integer getMaxLength() {
@@ -85,7 +87,7 @@ public class ScanUtilTest {
                     }
                     @Override
                     public PDataType getDataType() {
-                        return PDataType.VARCHAR;
+                        return PVarchar.INSTANCE;
                     }
                     @Override
                     public Integer getMaxLength() {
@@ -124,181 +126,181 @@ public class ScanUtilTest {
         // 1, Lower bound, all single keys, all inclusive.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a1A"),
+                PChar.INSTANCE.toBytes("a1A"),
                 Bound.LOWER
                 ));
         // 2, Lower bound, all range keys, all inclusive.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a1A"),
+                PChar.INSTANCE.toBytes("a1A"),
                 Bound.LOWER
                 ));
         // 3, Lower bound, mixed single and range keys, all inclusive.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a1A"),
+                PChar.INSTANCE.toBytes("a1A"),
                 Bound.LOWER
                 ));
         // 4, Lower bound, all range key, all exclusive on lower bound.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), false, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), false, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("b2B"),
+                PChar.INSTANCE.toBytes("b2B"),
                 Bound.LOWER
                 ));
         // 5, Lower bound, all range key, some exclusive.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("b1B"),
+                PChar.INSTANCE.toBytes("b1B"),
                 Bound.LOWER
                 ));
         // 6, Lower bound, mixed single and range key, mixed inclusive and exclusive.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a1B"),
+                PChar.INSTANCE.toBytes("a1B"),
                 Bound.LOWER
                 ));
         // 7, Lower bound, unbound key in the middle, fixed length.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
                         KeyRange.EVERYTHING_RANGE,},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a"),
+                PChar.INSTANCE.toBytes("a"),
                 Bound.LOWER
                 ));
         // 8, Lower bound, unbound key in the middle, variable length.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
                             KeyRange.EVERYTHING_RANGE,}},
                     new int[] {1,1},
-                    PDataType.CHAR.toBytes("a"),
+                    PChar.INSTANCE.toBytes("a"),
                     Bound.LOWER
                     ));
         // 9, Lower bound, unbound key at end, variable length.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
                         KeyRange.EVERYTHING_RANGE,},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a"),
+                PChar.INSTANCE.toBytes("a"),
                 Bound.LOWER
                 ));
         // 10, Upper bound, all single keys, all inclusive, increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("a1B"),
+                PChar.INSTANCE.toBytes("a1B"),
                 Bound.UPPER
                 ));
         // 11, Upper bound, all range keys, all inclusive, increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("b2C"),
+                PChar.INSTANCE.toBytes("b2C"),
                 Bound.UPPER
                 ));
         // 12, Upper bound, all range keys, all exclusive, no increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), false),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), false),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), false),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), false),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), false),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), false),}},
                 new int[] {1,1,1},
-                PDataType.CHAR.toBytes("b2B"),
+                PChar.INSTANCE.toBytes("b2B"),
                 Bound.UPPER
                 ));
         // 13, Upper bound, single inclusive, range inclusive, increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("a3"),
+                PChar.INSTANCE.toBytes("a3"),
                 Bound.UPPER
                 ));
         // 14, Upper bound, range exclusive, single inclusive, increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), false),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), false),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("b2"),
+                PChar.INSTANCE.toBytes("b2"),
                 Bound.UPPER
                 ));
         // 15, Upper bound, range inclusive, single inclusive, increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("b"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("b2"),
+                PChar.INSTANCE.toBytes("b2"),
                 Bound.UPPER
                 ));
         // 16, Upper bound, single inclusive, range exclusive, no increment at end.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), false),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), false),}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("a2"),
+                PChar.INSTANCE.toBytes("a2"),
                 Bound.UPPER
                 ));
         // 17, Upper bound, unbound key, fixed length;
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
                         KeyRange.EVERYTHING_RANGE,}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("b"),
+                PChar.INSTANCE.toBytes("b"),
                 Bound.UPPER
                 ));
         // 18, Upper bound, unbound key, variable length;
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
                     KeyRange.EVERYTHING_RANGE,}},
                 new int[] {1,1},
-                PDataType.CHAR.toBytes("b"),
+                PChar.INSTANCE.toBytes("b"),
                 Bound.UPPER
                 ));
         // 19, Upper bound, keys wrapped around when incrementing.
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                PDataType.CHAR.getKeyRange(new byte[] {-1}, true, new byte[] {-1}, true)},{
-                PDataType.CHAR.getKeyRange(new byte[] {-1}, true, new byte[] {-1}, true)}},
+                PChar.INSTANCE.getKeyRange(new byte[] {-1}, true, new byte[] {-1}, true)},{
+                PChar.INSTANCE.getKeyRange(new byte[] {-1}, true, new byte[] {-1}, true)}},
                 new int[] {1, 1},
                 ByteUtil.EMPTY_BYTE_ARRAY,
                 Bound.UPPER
@@ -306,10 +308,10 @@ public class ScanUtilTest {
         // 20, Variable length
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
-                    PDataType.VARCHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),},{
+                    PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),}},
                 new int[] {1,0},
-                ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes("aB"), QueryConstants.SEPARATOR_BYTE_ARRAY)),
+                ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes("aB"), QueryConstants.SEPARATOR_BYTE_ARRAY)),
                 Bound.UPPER
                 ));
         return testCases;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index f1e98f8..8c55f1b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -77,7 +77,7 @@ import org.apache.phoenix.parse.LikeParseNode.LikeType;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.tuple.Tuple;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/CsvUpsertExecutorTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/csv/CsvUpsertExecutorTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/CsvUpsertExecutorTest.java
index 21b985c..84f44f3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/csv/CsvUpsertExecutorTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/CsvUpsertExecutorTest.java
@@ -24,8 +24,9 @@ import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PIntegerArray;
+import org.apache.phoenix.schema.types.PArrayDataType;
 import org.apache.phoenix.util.ColumnInfo;
 import org.junit.After;
 import org.junit.Before;
@@ -60,7 +61,7 @@ public class CsvUpsertExecutorTest extends BaseConnectionlessQueryTest {
                 new ColumnInfo("ID", Types.BIGINT),
                 new ColumnInfo("NAME", Types.VARCHAR),
                 new ColumnInfo("AGE", Types.INTEGER),
-                new ColumnInfo("VALUES", PDataType.INTEGER_ARRAY.getSqlType()));
+                new ColumnInfo("VALUES", PIntegerArray.INSTANCE.getSqlType()));
 
         preparedStatement = mock(PreparedStatement.class);
         upsertListener = mock(CsvUpsertExecutor.UpsertListener.class);
@@ -83,7 +84,7 @@ public class CsvUpsertExecutorTest extends BaseConnectionlessQueryTest {
         verify(preparedStatement).setObject(1, Long.valueOf(123L));
         verify(preparedStatement).setObject(2, "NameValue");
         verify(preparedStatement).setObject(3, Integer.valueOf(42));
-        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PDataType.INTEGER, new Object[]{1,2,3}));
+        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PInteger.INSTANCE, new Object[]{1,2,3}));
         verify(preparedStatement).execute();
         verifyNoMoreInteractions(preparedStatement);
     }
@@ -108,7 +109,7 @@ public class CsvUpsertExecutorTest extends BaseConnectionlessQueryTest {
         verify(preparedStatement).setObject(1, Long.valueOf(123L));
         verify(preparedStatement).setObject(2, "NameValue");
         verify(preparedStatement).setObject(3, Integer.valueOf(42));
-        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PDataType.INTEGER, new Object[]{1,2,3}));
+        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PInteger.INSTANCE, new Object[]{1,2,3}));
         verify(preparedStatement).execute();
         verifyNoMoreInteractions(preparedStatement);
     }
@@ -123,7 +124,7 @@ public class CsvUpsertExecutorTest extends BaseConnectionlessQueryTest {
         verify(preparedStatement).setObject(1, Long.valueOf(123L));
         verify(preparedStatement).setObject(2, "NameValue");
         verify(preparedStatement).setNull(3, columnInfoList.get(2).getSqlType());
-        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PDataType.INTEGER, new Object[]{1,2,3}));
+        verify(preparedStatement).setObject(4, PArrayDataType.instantiatePhoenixArray(PInteger.INSTANCE, new Object[]{1,2,3}));
         verify(preparedStatement).execute();
         verifyNoMoreInteractions(preparedStatement);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/StringToArrayConverterTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/csv/StringToArrayConverterTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/StringToArrayConverterTest.java
index 8f2b0e5..25d9d80 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/csv/StringToArrayConverterTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/csv/StringToArrayConverterTest.java
@@ -26,7 +26,8 @@ import java.sql.DriverManager;
 import java.sql.SQLException;
 
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,7 +40,7 @@ public class StringToArrayConverterTest extends BaseConnectionlessQueryTest {
     @Before
     public void setUp() throws SQLException {
         conn = DriverManager.getConnection(getUrl());
-        converter = new StringToArrayConverter(conn, ":", PDataType.VARCHAR);
+        converter = new StringToArrayConverter(conn, ":", PVarchar.INSTANCE);
     }
 
     @After
@@ -73,7 +74,7 @@ public class StringToArrayConverterTest extends BaseConnectionlessQueryTest {
     @Test
     public void testToArray_IntegerValues() throws SQLException {
         StringToArrayConverter intArrayConverter = new StringToArrayConverter(
-                                                            conn, ":", PDataType.INTEGER);
+            conn, ":", PInteger.INSTANCE);
         Array intArray = intArrayConverter.toArray("1:2:3");
         assertArrayEquals(
                 new int[]{1, 2, 3},

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/RegexEventSerializer.java
----------------------------------------------------------------------
diff --git a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/RegexEventSerializer.java b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/RegexEventSerializer.java
index cb188e2..6562eb7 100644
--- a/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/RegexEventSerializer.java
+++ b/phoenix-flume/src/main/java/org/apache/phoenix/flume/serializer/RegexEventSerializer.java
@@ -35,7 +35,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 public class RegexEventSerializer extends BaseEventSerializer {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtil.java b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtil.java
index 4f7d776..69bcd73 100644
--- a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtil.java
+++ b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/PhoenixPigSchemaUtil.java
@@ -28,7 +28,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
 import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil.SchemaType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.pig.ResourceSchema;
 import org.apache.pig.ResourceSchema.ResourceFieldSchema;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
index 1da2d01..bdee3a4 100644
--- a/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
+++ b/phoenix-pig/src/main/java/org/apache/phoenix/pig/util/TypeUtil.java
@@ -28,7 +28,31 @@ import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.phoenix.pig.writable.PhoenixPigDBWritable;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PSmallint;
+import org.apache.phoenix.schema.types.PTime;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PTinyint;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedDouble;
+import org.apache.phoenix.schema.types.PUnsignedFloat;
+import org.apache.phoenix.schema.types.PUnsignedInt;
+import org.apache.phoenix.schema.types.PUnsignedLong;
+import org.apache.phoenix.schema.types.PUnsignedSmallint;
+import org.apache.phoenix.schema.types.PUnsignedTime;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.pig.PigException;
 import org.apache.pig.ResourceSchema.ResourceFieldSchema;
 import org.apache.pig.backend.hadoop.hbase.HBaseBinaryConverter;
@@ -47,7 +71,7 @@ public final class TypeUtil {
 	
     private static final Log LOG = LogFactory.getLog(TypeUtil.class);
     private static final HBaseBinaryConverter binaryConverter = new HBaseBinaryConverter ();
-	private static final ImmutableMap<PDataType,Byte> phoenixTypeToPigDataType = init();	
+	private static final ImmutableMap<PDataType,Byte> phoenixTypeToPigDataType = init();
 	
 	private TypeUtil(){
 	}
@@ -58,29 +82,29 @@ public final class TypeUtil {
 	 */
 	private static ImmutableMap<PDataType, Byte> init() {
         final ImmutableMap.Builder<PDataType,Byte> builder = new Builder<PDataType,Byte> ();
-        builder.put(PDataType.LONG,DataType.LONG);
-        builder.put(PDataType.VARBINARY,DataType.BYTEARRAY);
-        builder.put(PDataType.CHAR,DataType.CHARARRAY);
-        builder.put(PDataType.VARCHAR,DataType.CHARARRAY);
-        builder.put(PDataType.DOUBLE,DataType.DOUBLE);
-        builder.put(PDataType.FLOAT,DataType.FLOAT);
-        builder.put(PDataType.INTEGER,DataType.INTEGER);
-        builder.put(PDataType.TINYINT,DataType.INTEGER);
-        builder.put(PDataType.SMALLINT,DataType.INTEGER);
-        builder.put(PDataType.DECIMAL,DataType.BIGDECIMAL);
-        builder.put(PDataType.TIME,DataType.DATETIME);
-        builder.put(PDataType.TIMESTAMP,DataType.DATETIME);
-        builder.put(PDataType.BOOLEAN,DataType.BOOLEAN);
-        builder.put(PDataType.DATE,DataType.DATETIME);
-        builder.put(PDataType.UNSIGNED_DATE,DataType.DATETIME);
-        builder.put(PDataType.UNSIGNED_DOUBLE,DataType.DOUBLE);
-        builder.put(PDataType.UNSIGNED_FLOAT,DataType.FLOAT);
-        builder.put(PDataType.UNSIGNED_INT,DataType.INTEGER);
-        builder.put(PDataType.UNSIGNED_LONG,DataType.LONG);
-        builder.put(PDataType.UNSIGNED_SMALLINT,DataType.INTEGER);
-        builder.put(PDataType.UNSIGNED_TIME,DataType.DATETIME);
-        builder.put(PDataType.UNSIGNED_TIMESTAMP,DataType.DATETIME);
-        builder.put(PDataType.UNSIGNED_TINYINT,DataType.INTEGER);
+        builder.put(PLong.INSTANCE,DataType.LONG);
+        builder.put(PVarbinary.INSTANCE,DataType.BYTEARRAY);
+        builder.put(PChar.INSTANCE,DataType.CHARARRAY);
+        builder.put(PVarchar.INSTANCE,DataType.CHARARRAY);
+        builder.put(PDouble.INSTANCE,DataType.DOUBLE);
+        builder.put(PFloat.INSTANCE,DataType.FLOAT);
+        builder.put(PInteger.INSTANCE,DataType.INTEGER);
+        builder.put(PTinyint.INSTANCE,DataType.INTEGER);
+        builder.put(PSmallint.INSTANCE,DataType.INTEGER);
+        builder.put(PDecimal.INSTANCE,DataType.BIGDECIMAL);
+        builder.put(PTime.INSTANCE,DataType.DATETIME);
+        builder.put(PTimestamp.INSTANCE,DataType.DATETIME);
+        builder.put(PBoolean.INSTANCE,DataType.BOOLEAN);
+        builder.put(PDate.INSTANCE,DataType.DATETIME);
+        builder.put(PUnsignedDate.INSTANCE,DataType.DATETIME);
+        builder.put(PUnsignedDouble.INSTANCE,DataType.DOUBLE);
+        builder.put(PUnsignedFloat.INSTANCE,DataType.FLOAT);
+        builder.put(PUnsignedInt.INSTANCE,DataType.INTEGER);
+        builder.put(PUnsignedLong.INSTANCE,DataType.LONG);
+        builder.put(PUnsignedSmallint.INSTANCE,DataType.INTEGER);
+        builder.put(PUnsignedTime.INSTANCE,DataType.DATETIME);
+        builder.put(PUnsignedTimestamp.INSTANCE,DataType.DATETIME);
+        builder.put(PUnsignedTinyint.INSTANCE,DataType.INTEGER);
         return builder.build();
     }
     /**
@@ -102,33 +126,33 @@ public final class TypeUtil {
 
 		switch (type) {
 		case DataType.BYTEARRAY:
-			sqlType = PDataType.VARBINARY;
+			sqlType = PVarbinary.INSTANCE;
 			break;
 		case DataType.CHARARRAY:
-			sqlType = PDataType.VARCHAR;
+			sqlType = PVarchar.INSTANCE;
 			break;
 		case DataType.DOUBLE:
 		case DataType.BIGDECIMAL:
-			sqlType = PDataType.DOUBLE;
+			sqlType = PDouble.INSTANCE;
 			break;
 		case DataType.FLOAT:
-			sqlType = PDataType.FLOAT;
+			sqlType = PFloat.INSTANCE;
 			break;
 		case DataType.INTEGER:
-			sqlType = PDataType.INTEGER;
+			sqlType = PInteger.INSTANCE;
 			break;
 		case DataType.LONG:
 		case DataType.BIGINTEGER:
-			sqlType = PDataType.LONG;
+			sqlType = PLong.INSTANCE;
 			break;
 		case DataType.BOOLEAN:
-			sqlType = PDataType.BOOLEAN;
+			sqlType = PBoolean.INSTANCE;
 			break;
 		case DataType.DATETIME:
-			sqlType = PDataType.DATE;
+			sqlType = PDate.INSTANCE;
 			break;
 		case DataType.BYTE:
-			sqlType = PDataType.TINYINT;
+			sqlType = PTinyint.INSTANCE;
 			break;
 		default:
 			throw new RuntimeException("Unknown type " + obj.getClass().getName()
@@ -156,17 +180,17 @@ public final class TypeUtil {
 			return null;
 		}
 
-		if(inferredPType == PDataType.VARBINARY) {
+		if(inferredPType == PVarbinary.INSTANCE) {
 			try {
 				o = castBytes(o, targetPhoenixType);
-				if(targetPhoenixType != PDataType.VARBINARY && targetPhoenixType != PDataType.BINARY) {
+				if(targetPhoenixType != PVarbinary.INSTANCE && targetPhoenixType != PBinary.INSTANCE) {
 					inferredPType = getType(o, DataType.findType(o));	
 				}
 			} catch (IOException e) {
 				throw new RuntimeException("Error while casting bytes for object " +o);
 			}
 		}
-		if(inferredPType == PDataType.DATE) {
+		if(inferredPType == PDate.INSTANCE) {
 			int inferredSqlType = targetPhoenixType.getSqlType();
 
 			if(inferredSqlType == Types.DATE) {
@@ -200,36 +224,27 @@ public final class TypeUtil {
 	 */
 	private static Object castBytes(Object o, PDataType targetPhoenixType) throws IOException {
         byte[] bytes = ((DataByteArray)o).get();
-        
-        switch(targetPhoenixType) {
-        case CHAR:
-        case VARCHAR:
+
+        if (PDataType.equalsAny(targetPhoenixType, PChar.INSTANCE, PVarchar.INSTANCE)) {
             return binaryConverter.bytesToCharArray(bytes);
-        case UNSIGNED_SMALLINT:
-        case SMALLINT:
+        } else if (PDataType.equalsAny(targetPhoenixType, PUnsignedSmallint.INSTANCE, PSmallint.INSTANCE)) {
             return binaryConverter.bytesToInteger(bytes).shortValue();
-        case UNSIGNED_TINYINT:
-        case TINYINT:
+        } else if (PDataType.equalsAny(targetPhoenixType, PUnsignedTinyint.INSTANCE, PTinyint.INSTANCE)) {
             return binaryConverter.bytesToInteger(bytes).byteValue();
-        case UNSIGNED_INT:
-        case INTEGER:
-        	return binaryConverter.bytesToInteger(bytes);
-        case BOOLEAN:
+        } else if (PDataType.equalsAny(targetPhoenixType, PUnsignedInt.INSTANCE, PInteger.INSTANCE)) {
+            return binaryConverter.bytesToInteger(bytes);
+        } else if (targetPhoenixType.equals(PBoolean.INSTANCE)) {
             return binaryConverter.bytesToBoolean(bytes);
-        case FLOAT:
-        case UNSIGNED_FLOAT:
+        } else if (PDataType.equalsAny(targetPhoenixType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
             return binaryConverter.bytesToFloat(bytes);
-        case DOUBLE:
-        case UNSIGNED_DOUBLE:
+        } else if (PDataType.equalsAny(targetPhoenixType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
             return binaryConverter.bytesToDouble(bytes);
-        case UNSIGNED_LONG:
-        case LONG:
+        } else if (PDataType.equalsAny(targetPhoenixType, PUnsignedLong.INSTANCE, PLong.INSTANCE)) {
             return binaryConverter.bytesToLong(bytes);
-        case VARBINARY : 
-        case BINARY:
-        	 return bytes;
-        default:
-        	return o;
+        } else if (PDataType.equalsAny(targetPhoenixType, PVarbinary.INSTANCE, PBinary.INSTANCE)) {
+            return bytes;
+        } else {
+            return o;
         }        
     }
     
@@ -259,7 +274,7 @@ public final class TypeUtil {
                 
                 switch(fieldSchema.getType()) {
                     case DataType.BYTEARRAY:
-                        byte[] bytes = PDataType.fromTypeId(PDataType.BINARY.getSqlType()).toBytes(object);
+                        byte[] bytes = PDataType.fromTypeId(PBinary.INSTANCE.getSqlType()).toBytes(object);
                         tuple.set(i,new DataByteArray(bytes,0,bytes.length));
                         break;
                     case DataType.CHARARRAY:

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-pig/src/main/java/org/apache/phoenix/pig/writable/PhoenixPigDBWritable.java
----------------------------------------------------------------------
diff --git a/phoenix-pig/src/main/java/org/apache/phoenix/pig/writable/PhoenixPigDBWritable.java b/phoenix-pig/src/main/java/org/apache/phoenix/pig/writable/PhoenixPigDBWritable.java
index a7399c9..566e427 100644
--- a/phoenix-pig/src/main/java/org/apache/phoenix/pig/writable/PhoenixPigDBWritable.java
+++ b/phoenix-pig/src/main/java/org/apache/phoenix/pig/writable/PhoenixPigDBWritable.java
@@ -26,7 +26,7 @@ import java.util.List;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.mapreduce.lib.db.DBWritable;
 import org.apache.phoenix.pig.util.TypeUtil;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.pig.ResourceSchema.ResourceFieldSchema;
 import org.apache.pig.data.DataType;


[03/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java
index bc2ad15..bcd08f0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeySchemaTest.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java
index be965ab..23ec4bf 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/RowKeyValueAccessorTest.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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 f836ccf..39838d5 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
@@ -27,6 +27,8 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.junit.Test;
 
 /**
@@ -43,13 +45,22 @@ public class SortOrderTest {
 	
 	@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)));
+	    assertTrue(PBoolean.INSTANCE.toObject(PDataType.TRUE_BYTES, SortOrder.ASC) == PBoolean.INSTANCE.toObject(
+          PDataType.FALSE_BYTES, SortOrder.DESC));
+        assertTrue(
+            PBoolean.INSTANCE.toObject(PBoolean.INSTANCE.toBytes(true), SortOrder.ASC) == PBoolean.INSTANCE.toObject(
+                PBoolean.INSTANCE.toBytes(false), SortOrder.DESC));
+        assertTrue(
+            PBoolean.INSTANCE.toObject(PBoolean.INSTANCE.toBytes(true,SortOrder.ASC)) == PBoolean.INSTANCE.toObject(
+                PBoolean.INSTANCE.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)));
+        assertFalse(PBoolean.INSTANCE.toObject(PDataType.FALSE_BYTES, SortOrder.ASC) == PBoolean.INSTANCE.toObject(PDataType.FALSE_BYTES, SortOrder.DESC));
+        assertFalse(
+            PBoolean.INSTANCE.toObject(PBoolean.INSTANCE.toBytes(false), SortOrder.ASC) == PBoolean.INSTANCE.toObject(
+                PBoolean.INSTANCE.toBytes(false), SortOrder.DESC));
+        assertFalse(
+            PBoolean.INSTANCE.toObject(PBoolean.INSTANCE.toBytes(false,SortOrder.ASC)) == PBoolean.INSTANCE.toObject(
+                PBoolean.INSTANCE.toBytes(false,SortOrder.DESC)));
 	}
 
 	@Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
index 766917c..5456532 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/ValueBitSetTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
+import org.apache.phoenix.schema.types.PDataType;
 import org.junit.Test;
 
 


[16/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
deleted file mode 100644
index 8d96b87..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
+++ /dev/null
@@ -1,660 +0,0 @@
-/*
- * 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.schema;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.tuple.Tuple;
-import org.apache.phoenix.util.ByteUtil;
-import org.apache.phoenix.util.TrustedByteArrayOutputStream;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-/**
- * The datatype for PColummns that are Arrays. Any variable length array would follow the below order. 
- * Every element would be seperated by a seperator byte '0'. Null elements are counted and once a first 
- * non null element appears we write the count of the nulls prefixed with a seperator byte.
- * Trailing nulls are not taken into account. The last non null element is followed by two seperator bytes. 
- * For eg a, b, null, null, c, null -> 65 0 66 0 0 2 67 0 0 0 
- * a null null null b c null d -> 65 0 0 3 66 0 67 0 0 1 68 0 0 0.
- * The reason we use this serialization format is to allow the
- * byte array of arrays of the same type to be directly comparable against each other. 
- * This prevents a costly deserialization on compare and allows an array column to be used as the last column in a primary key constraint.
- */
-public class PArrayDataType {
-
-    public static final byte ARRAY_SERIALIZATION_VERSION = 1;
-	public PArrayDataType() {
-	}
-
-	public byte[] toBytes(Object object, PDataType baseType, SortOrder sortOrder) {
-		if(object == null) {
-			throw new ConstraintViolationException(this + " may not be null");
-		}
-		PhoenixArray arr = ((PhoenixArray)object);
-        int noOfElements = arr.numElements;
-        if(noOfElements == 0) {
-        	return ByteUtil.EMPTY_BYTE_ARRAY;
-        }
-        TrustedByteArrayOutputStream byteStream = null;
-		if (!baseType.isFixedWidth()) {
-	        Pair<Integer, Integer> nullsVsNullRepeationCounter = new Pair<Integer, Integer>();
-	        int size = estimateByteSize(object, nullsVsNullRepeationCounter,
-	                PDataType.fromTypeId((baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE)));
-		    size += ((2 * Bytes.SIZEOF_BYTE) + (noOfElements - nullsVsNullRepeationCounter.getFirst()) * Bytes.SIZEOF_BYTE)
-		                                + (nullsVsNullRepeationCounter.getSecond() * 2 * Bytes.SIZEOF_BYTE);
-		    // Assume an offset array that fit into Short.MAX_VALUE.  Also not considering nulls that could be > 255
-		    // In both of these cases, finally an array copy would happen
-		    int capacity = noOfElements * Bytes.SIZEOF_SHORT;
-		    // Here the int for noofelements, byte for the version, int for the offsetarray position and 2 bytes for the end seperator
-            byteStream = new TrustedByteArrayOutputStream(size + capacity + Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE +  Bytes.SIZEOF_INT);
-		} else {
-		    int size = arr.getMaxLength() * noOfElements;
-		    // Here the int for noofelements, byte for the version
-		    byteStream = new TrustedByteArrayOutputStream(size);
-		}
-		DataOutputStream oStream = new DataOutputStream(byteStream);
-		// Handles bit inversion also
-		return createArrayBytes(byteStream, oStream, (PhoenixArray)object, noOfElements, baseType, sortOrder);
-	}
-	
-    public static int serializeNulls(DataOutputStream oStream, int nulls) throws IOException {
-        // We need to handle 3 different cases here
-        // 1) Arrays with repeating nulls in the middle which is less than 255
-        // 2) Arrays with repeating nulls in the middle which is less than 255 but greater than bytes.MAX_VALUE
-        // 3) Arrays with repeating nulls in the middle greaterh than 255
-        // Take a case where we have two arrays that has the following elements
-        // Array 1 - size : 240, elements = abc, bcd, null, null, bcd,null,null......,null, abc
-        // Array 2 - size : 16 : elements = abc, bcd, null, null, bcd, null, null...null, abc
-        // In both case the elements and the value array will be the same but the Array 1 is actually smaller because it has more nulls.
-        // Now we should have mechanism to show that we treat arrays with more nulls as lesser.  Hence in the above case as 
-        // 240 > Bytes.MAX_VALUE, by always inverting the number of nulls we would get a +ve value
-        // For Array 2, by inverting we would get a -ve value.  On comparison Array 2 > Array 1.
-        // Now for cases where the number of nulls is greater than 255, we would write an those many (byte)1, it is bigger than 255.
-        // This would ensure that we don't compare with triple zero which is used as an end  byte
-        if (nulls > 0) {
-            oStream.write(QueryConstants.SEPARATOR_BYTE);
-            int nMultiplesOver255 = nulls / 255;
-            while (nMultiplesOver255-- > 0) {
-                // Don't write a zero byte, as we need to ensure that the only triple zero
-                // byte occurs at the end of the array (i.e. the terminator byte for the
-                // element plus the double zero byte at the end of the array).
-                oStream.write((byte)1); 
-            }
-            int nRemainingNulls = nulls % 255; // From 0 to 254
-            // Write a byte for the remaining null elements
-            if (nRemainingNulls > 0) {
-                // Remaining null elements is from 1 to 254.
-                // Subtract one and invert so that more remaining nulls becomes smaller than less 
-                // remaining nulls and min byte value is always greater than 1, the repeating value  
-                // used for arrays with more than 255 repeating null elements.
-                // The reason we invert is that  an array with less null elements has a non
-                // null element sooner than an array with more null elements. Thus, the more
-                // null elements you have, the smaller the array becomes.
-                byte nNullByte = SortOrder.invert((byte)(nRemainingNulls-1));
-                oStream.write(nNullByte); // Single byte for repeating nulls
-            }
-        }
-        return 0;
-    }
- 
-    public static void writeEndSeperatorForVarLengthArray(DataOutputStream oStream) throws IOException {
-        oStream.write(QueryConstants.SEPARATOR_BYTE);
-        oStream.write(QueryConstants.SEPARATOR_BYTE);
-    }
-
-	public static boolean useShortForOffsetArray(int maxOffset) {
-		// If the max offset is less than Short.MAX_VALUE then offset array can use short
-		if (maxOffset <= (2 * Short.MAX_VALUE)) {
-			return true;
-		}
-		// else offset array can use Int
-		return false;
-	}
-
-	public int toBytes(Object object, byte[] bytes, int offset) {
-	    PhoenixArray array = (PhoenixArray)object;
-        if (array == null || array.baseType == null) {
-            return 0;
-        }
-        return estimateByteSize(object, null, PDataType.fromTypeId((array.baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE)));
-	}
-
-	// Estimates the size of the given array and also calculates the number of nulls and its repetition factor
-    public int estimateByteSize(Object o, Pair<Integer, Integer> nullsVsNullRepeationCounter, PDataType baseType) {
-        if (baseType.isFixedWidth()) { return baseType.getByteSize(); }
-        if (baseType.isArrayType()) {
-            PhoenixArray array = (PhoenixArray)o;
-            int noOfElements = array.numElements;
-            int totalVarSize = 0;
-            int nullsRepeationCounter = 0;
-            int nulls = 0;
-            int totalNulls = 0;
-            for (int i = 0; i < noOfElements; i++) {
-                totalVarSize += array.estimateByteSize(i);
-                if (!PDataType.fromTypeId((baseType.getSqlType() - PDataType.ARRAY_TYPE_BASE)).isFixedWidth()) {
-                    if (array.isNull(i)) {
-                        nulls++;
-                    } else {
-                        if (nulls > 0) {
-                            totalNulls += nulls;
-                            nulls = 0;
-                            nullsRepeationCounter++;
-                        }
-                    }
-                }
-            }
-            if (nullsVsNullRepeationCounter != null) {
-                if (nulls > 0) {
-                    totalNulls += nulls;
-                    // do not increment nullsRepeationCounter to identify trailing nulls
-                }
-                nullsVsNullRepeationCounter.setFirst(totalNulls);
-                nullsVsNullRepeationCounter.setSecond(nullsRepeationCounter);
-            }
-            return totalVarSize;
-        }
-        // Non fixed width types must override this
-        throw new UnsupportedOperationException();
-    }
-    
-	public boolean isCoercibleTo(PDataType targetType, Object value) {
-	    return targetType.isCoercibleTo(targetType, value);
-	}
-	
-	public boolean isCoercibleTo(PDataType targetType, PDataType expectedTargetType) {
-		if(!targetType.isArrayType()) {
-			return false;
-		} else {
-			PDataType targetElementType = PDataType.fromTypeId(targetType.getSqlType()
-					- PDataType.ARRAY_TYPE_BASE);
-			PDataType expectedTargetElementType = PDataType.fromTypeId(expectedTargetType
-					.getSqlType() - PDataType.ARRAY_TYPE_BASE);
-			return expectedTargetElementType.isCoercibleTo(targetElementType);
-		}
-    }
-	
-	public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value,
-			PDataType srcType, Integer maxLength, Integer scale,
-			Integer desiredMaxLength, Integer desiredScale) {
-        if (value == null) return true;
-		PhoenixArray pArr = (PhoenixArray) value;
-		Object[] arr = (Object[]) pArr.array;
-		PDataType baseType = PDataType.fromTypeId(srcType.getSqlType()
-				- PDataType.ARRAY_TYPE_BASE);
-		for (int i = 0 ; i < arr.length; i++) {
-			if (!baseType.isSizeCompatible(ptr, arr[i], baseType, srcType.getMaxLength(arr[i]),
-					scale, desiredMaxLength, desiredScale)) {
-				return false;
-			}
-		}
-		return true;
-	}
-	
-    public void coerceBytes(ImmutableBytesWritable ptr, Object value, PDataType actualType, Integer maxLength,
-            Integer scale, Integer desiredMaxLength, Integer desiredScale, PDataType desiredType,
-            SortOrder actualModifer, SortOrder expectedModifier) {
-        if (ptr.getLength() == 0) { // a zero length ptr means null which will not be coerced to anything different
-            return;
-        }
-        PDataType baseType = PDataType.fromTypeId(actualType.getSqlType() - PDataType.ARRAY_TYPE_BASE);
-        PDataType desiredBaseType = PDataType.fromTypeId(desiredType.getSqlType() - PDataType.ARRAY_TYPE_BASE);
-        if ((Objects.equal(maxLength, desiredMaxLength) || maxLength == null || desiredMaxLength == null)
-                && actualType.isBytesComparableWith(desiredType)
-                && baseType.isFixedWidth() == desiredBaseType.isFixedWidth() && actualModifer == expectedModifier) { 
-            return; 
-        }
-        if (value == null || actualType != desiredType) {
-            value = toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), baseType, actualModifer, maxLength,
-                    desiredScale, desiredBaseType);
-            PhoenixArray pArr = (PhoenixArray)value;
-            // VARCHAR <=> CHAR
-            if(baseType.isFixedWidth() != desiredBaseType.isFixedWidth()) {
-                if (!pArr.isPrimitiveType()) {
-                    pArr = new PhoenixArray(pArr, desiredMaxLength);
-                }
-            }
-            baseType = desiredBaseType;
-            ptr.set(toBytes(pArr, baseType, expectedModifier));
-        } else {
-            PhoenixArray pArr = (PhoenixArray)value;
-            pArr = new PhoenixArray(pArr, desiredMaxLength);
-            ptr.set(toBytes(pArr, baseType, expectedModifier));
-        }
-    }
-
-
-    public Object toObject(String value) {
-		throw new IllegalArgumentException("This operation is not suppported");
-	}
-
-	public Object toObject(byte[] bytes, int offset, int length, PDataType baseType, 
-			SortOrder sortOrder, Integer maxLength, Integer scale, PDataType desiredDataType) {
-		return createPhoenixArray(bytes, offset, length, sortOrder,
-				baseType, maxLength, desiredDataType);
-	}
-
-    public static boolean positionAtArrayElement(Tuple tuple, ImmutableBytesWritable ptr, int index,
-            Expression arrayExpr, PDataType pDataType, Integer maxLen) {
-        if (!arrayExpr.evaluate(tuple, ptr)) {
-            return false;
-        } else if (ptr.getLength() == 0) { return true; }
-
-        // Given a ptr to the entire array, set ptr to point to a particular element within that array
-        // given the type of an array element (see comments in PDataTypeForArray)
-        positionAtArrayElement(ptr, index - 1, pDataType, maxLen);
-        return true;
-    }
-    public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
-            Integer byteSize) {
-        byte[] bytes = ptr.get();
-        int initPos = ptr.getOffset();
-        if (!baseDataType.isFixedWidth()) {
-            int noOfElements = Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)),
-                    Bytes.SIZEOF_INT);
-            boolean useShort = true;
-            if (noOfElements < 0) {
-                noOfElements = -noOfElements;
-                useShort = false;
-            }
-            if (arrayIndex >= noOfElements) {
-                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
-                return;
-            }
-
-            int indexOffset = Bytes.toInt(bytes,
-                    (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT))) + ptr.getOffset();
-            if(arrayIndex >= noOfElements) {
-                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
-            } else {
-                // Skip those many offsets as given in the arrayIndex
-                // If suppose there are 5 elements in the array and the arrayIndex = 3
-                // This means we need to read the 4th element of the array
-                // So inorder to know the length of the 4th element we will read the offset of 4th element and the
-                // offset of 5th element.
-                // Subtracting the offset of 5th element and 4th element will give the length of 4th element
-                // So we could just skip reading the other elements.
-                int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
-                int elementLength = 0;
-                if (arrayIndex == (noOfElements - 1)) {
-                    elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE ? 0 : indexOffset
-                            - (currOffset + initPos) - 3;
-                } else {
-                    elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE ? 0 : getOffset(bytes,
-                            arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
-                }
-                ptr.set(bytes, currOffset + initPos, elementLength);
-            }
-        } else {
-            int elemByteSize = (byteSize == null ? baseDataType.getByteSize() : byteSize);
-            int offset = arrayIndex * elemByteSize;
-            if (offset >= ptr.getLength()) {
-                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
-            } else {
-                ptr.set(bytes, ptr.getOffset() + offset, elemByteSize);
-            }
-        }
-    }
-    
-    public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
-            Integer byteSize, int offset, int length, int noOfElements, boolean first) {
-        byte[] bytes = ptr.get();
-        if (!baseDataType.isFixedWidth()) {
-            int indexOffset = Bytes.toInt(bytes, (offset + length - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT)))
-                    + offset;
-            boolean useShort = true;
-            if (first) {
-                int count = Bytes.toInt(bytes,
-                        (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)), Bytes.SIZEOF_INT);
-                if (count < 0) {
-                    count = -count;
-                    useShort = false;
-                }
-            }
-            if (arrayIndex >= noOfElements) {
-                return;
-            } else {
-                // Skip those many offsets as given in the arrayIndex
-                // If suppose there are 5 elements in the array and the arrayIndex = 3
-                // This means we need to read the 4th element of the array
-                // So inorder to know the length of the 4th element we will read the offset of 4th element and the
-                // offset of 5th element.
-                // Subtracting the offset of 5th element and 4th element will give the length of 4th element
-                // So we could just skip reading the other elements.
-                int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
-                int elementLength = 0;
-                if (arrayIndex == (noOfElements - 1)) {
-                    elementLength = bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE ? 0 : indexOffset
-                            - (currOffset + offset) - 3;
-                } else {
-                    elementLength = bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE ? 0 : getOffset(bytes,
-                            arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
-                }
-                ptr.set(bytes, currOffset + offset, elementLength);
-            }
-        } else {
-            int elemByteSize = (byteSize == null ? baseDataType.getByteSize() : byteSize);
-            offset += arrayIndex * elemByteSize;
-            if (offset >= offset + length) {
-                return;
-            } else {
-                ptr.set(bytes, offset, elemByteSize);
-            }
-        }
-    }
-
-    private static int getOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset) {
-        int offset;
-        if (useShort) {
-            offset = indexOffset + (Bytes.SIZEOF_SHORT * arrayIndex);
-            return Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT) + Short.MAX_VALUE;
-        } else {
-            offset = indexOffset + (Bytes.SIZEOF_INT * arrayIndex);
-            return Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT);
-        }
-    }
-    
-    private static int getOffset(ByteBuffer indexBuffer, int arrayIndex, boolean useShort, int indexOffset ) {
-        int offset;
-        if(useShort) {
-            offset = indexBuffer.getShort() + Short.MAX_VALUE;
-        } else {
-            offset = indexBuffer.getInt();
-        }
-        return offset;
-    }
-
-	public Object toObject(Object object, PDataType actualType) {
-		return object;
-	}
-
-	public Object toObject(Object object, PDataType actualType, SortOrder sortOrder) {
-		// How to use the sortOrder ? Just reverse the elements
-		return toObject(object, actualType);
-	}
-	
-	/**
-	 * creates array bytes
-	 * @param byteStream
-	 * @param oStream
-	 * @param array
-	 * @param noOfElements
-	 * @param baseType
-	 * @param sortOrder 
-	 * @param maxLength 
-	 * @param capacity
-	 * @return
-	 */
-    private byte[] createArrayBytes(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
-            PhoenixArray array, int noOfElements, PDataType baseType, SortOrder sortOrder) {
-        try {
-            if (!baseType.isFixedWidth()) {
-                int[] offsetPos = new int[noOfElements];
-                int nulls = 0;
-                for (int i = 0; i < noOfElements; i++) {
-                    byte[] bytes = array.toBytes(i);
-                    if (bytes.length == 0) {
-                        offsetPos[i] = byteStream.size();
-                        nulls++;
-                    } else {
-                        nulls = serializeNulls(oStream, nulls);
-                        offsetPos[i] = byteStream.size();
-                        if (sortOrder == SortOrder.DESC) {
-                            SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
-                        }
-                        oStream.write(bytes, 0, bytes.length);
-                        oStream.write(QueryConstants.SEPARATOR_BYTE);
-                    }
-                }
-                // Double seperator byte to show end of the non null array
-                PArrayDataType.writeEndSeperatorForVarLengthArray(oStream);
-                noOfElements = PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
-                        offsetPos[offsetPos.length - 1], offsetPos);
-                serializeHeaderInfoIntoStream(oStream, noOfElements);
-            } else {
-                for (int i = 0; i < noOfElements; i++) {
-                    byte[] bytes = array.toBytes(i);
-                    int length = bytes.length;
-                    if (sortOrder == SortOrder.DESC) {
-                        SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
-                    }
-                    oStream.write(bytes, 0, length);
-                }
-            }
-            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-            ptr.set(byteStream.getBuffer(), 0, byteStream.size());
-            return ByteUtil.copyKeyBytesIfNecessary(ptr);
-        } catch (IOException e) {
-            try {
-                byteStream.close();
-                oStream.close();
-            } catch (IOException ioe) {
-
-            }
-        }
-        // This should not happen
-        return null;
-    }
-
-    public static int serailizeOffsetArrayIntoStream(DataOutputStream oStream, TrustedByteArrayOutputStream byteStream,
-            int noOfElements, int maxOffset, int[] offsetPos) throws IOException {
-        int offsetPosition = (byteStream.size());
-        byte[] offsetArr = null;
-        boolean useInt = true;
-        if (PArrayDataType.useShortForOffsetArray(maxOffset)) {
-            offsetArr = new byte[PArrayDataType.initOffsetArray(noOfElements, Bytes.SIZEOF_SHORT)];
-            useInt = false;
-        } else {
-            offsetArr = new byte[PArrayDataType.initOffsetArray(noOfElements, Bytes.SIZEOF_INT)];
-            noOfElements = -noOfElements;
-        }
-        int off = 0;
-        if(useInt) {
-            for (int pos : offsetPos) {
-                Bytes.putInt(offsetArr, off, pos);
-                off += Bytes.SIZEOF_INT;
-            }
-        } else {
-            for (int pos : offsetPos) {
-                Bytes.putShort(offsetArr, off, (short)(pos - Short.MAX_VALUE));
-                off += Bytes.SIZEOF_SHORT;
-            }
-        }
-        oStream.write(offsetArr);
-        oStream.writeInt(offsetPosition);
-        return noOfElements;
-    }
-
-    public static void serializeHeaderInfoIntoBuffer(ByteBuffer buffer, int noOfElements) {
-        // No of elements
-        buffer.putInt(noOfElements);
-        // Version of the array
-        buffer.put(ARRAY_SERIALIZATION_VERSION);
-    }
-
-    public static void serializeHeaderInfoIntoStream(DataOutputStream oStream, int noOfElements) throws IOException {
-        // No of elements
-        oStream.writeInt(noOfElements);
-        // Version of the array
-        oStream.write(ARRAY_SERIALIZATION_VERSION);
-    }
-
-	public static int initOffsetArray(int noOfElements, int baseSize) {
-		// for now create an offset array equal to the noofelements
-		return noOfElements * baseSize;
-    }
-
-    // Any variable length array would follow the below order
-    // Every element would be seperated by a seperator byte '0'
-    // Null elements are counted and once a first non null element appears we
-    // write the count of the nulls prefixed with a seperator byte
-    // Trailing nulls are not taken into account
-    // The last non null element is followed by two seperator bytes
-    // For eg
-    // a, b, null, null, c, null would be 
-    // 65 0 66 0 0 2 67 0 0 0
-    // a null null null b c null d would be
-    // 65 0 0 3 66 0 67 0 0 1 68 0 0 0
-	// Follow the above example to understand how this works
-    private Object createPhoenixArray(byte[] bytes, int offset, int length, SortOrder sortOrder,
-            PDataType baseDataType, Integer maxLength, PDataType desiredDataType) {
-        if (bytes == null || bytes.length == 0) { return null; }
-        Object[] elements;
-        if (!baseDataType.isFixedWidth()) {
-            ByteBuffer buffer = ByteBuffer.wrap(bytes, offset, length);
-            int initPos = buffer.position();
-            buffer.position((buffer.limit() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)));
-            int noOfElements = buffer.getInt();
-            boolean useShort = true;
-            int baseSize = Bytes.SIZEOF_SHORT;
-            if (noOfElements < 0) {
-                noOfElements = -noOfElements;
-                baseSize = Bytes.SIZEOF_INT;
-                useShort = false;
-            }
-            if (baseDataType == desiredDataType) {
-                elements = (Object[])java.lang.reflect.Array.newInstance(baseDataType.getJavaClass(), noOfElements);
-            } else {
-                elements = (Object[])java.lang.reflect.Array.newInstance(desiredDataType.getJavaClass(), noOfElements);
-            }
-            buffer.position(buffer.limit() - (Bytes.SIZEOF_BYTE + (2 * Bytes.SIZEOF_INT)));
-            int indexOffset = buffer.getInt();
-            buffer.position(initPos);
-            buffer.position(indexOffset + initPos);
-            ByteBuffer indexArr = ByteBuffer.allocate(initOffsetArray(noOfElements, baseSize));
-            byte[] array = indexArr.array();
-            buffer.get(array);
-            int countOfElementsRead = 0;
-            int i = 0;
-            int currOffset = -1;
-            int nextOff = -1;
-            boolean foundNull = false;
-            if (noOfElements != 0) {
-                while (countOfElementsRead <= noOfElements) {
-                    if (countOfElementsRead == 0) {
-                        currOffset = getOffset(indexArr, countOfElementsRead, useShort, indexOffset);
-                        countOfElementsRead++;
-                    } else {
-                        currOffset = nextOff;
-                    }
-                    if (countOfElementsRead == noOfElements) {
-                        nextOff = indexOffset - 2;
-                    } else {
-                        nextOff = getOffset(indexArr, countOfElementsRead + 1, useShort, indexOffset);
-                    }
-                    countOfElementsRead++;
-                    if ((bytes[currOffset + initPos] != QueryConstants.SEPARATOR_BYTE) && foundNull) {
-                        // Found a non null element
-                        foundNull = false;
-                    }
-                    if (bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE) {
-                        // Null element
-                        foundNull = true;
-                        i++;
-                        continue;
-                    }
-                    int elementLength = nextOff - currOffset;
-                    buffer.position(currOffset + initPos);
-                    // Subtract the seperator from the element length
-                    byte[] val = new byte[elementLength - 1];
-                    buffer.get(val);
-                    if (baseDataType == desiredDataType) {
-                        elements[i++] = baseDataType.toObject(val, sortOrder);
-                    } else {
-                        elements[i++] = desiredDataType.toObject(val, sortOrder, baseDataType);
-                    }
-                }
-            }
-        } else {
-            int elemLength = (maxLength == null ? baseDataType.getByteSize() : maxLength);
-            int noOfElements = length / elemLength;
-            if (baseDataType == desiredDataType) {
-                elements = (Object[])java.lang.reflect.Array.newInstance(baseDataType.getJavaClass(), noOfElements);
-            } else {
-                elements = (Object[])java.lang.reflect.Array.newInstance(desiredDataType.getJavaClass(), noOfElements);
-            }
-            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-            for (int i = 0; i < noOfElements; i++) {
-                ptr.set(bytes, offset + i * elemLength, elemLength);
-                if (baseDataType == desiredDataType) {
-                    elements[i] = baseDataType.toObject(ptr, sortOrder);
-                } else {
-                    elements[i] = desiredDataType.toObject(ptr, baseDataType, sortOrder);
-                }
-            }
-        }
-        if(baseDataType == desiredDataType) {
-            return PArrayDataType.instantiatePhoenixArray(baseDataType, elements);
-        } else {
-            return PArrayDataType.instantiatePhoenixArray(desiredDataType, elements);
-        }
-    }
-	
-    public static PhoenixArray instantiatePhoenixArray(PDataType actualType, Object[] elements) {
-        return PDataType.instantiatePhoenixArray(actualType, elements);
-    }
-	
-	public int compareTo(Object lhs, Object rhs) {
-		PhoenixArray lhsArr = (PhoenixArray) lhs;
-		PhoenixArray rhsArr = (PhoenixArray) rhs;
-		if(lhsArr.equals(rhsArr)) {
-			return 0;
-		}
-		return 1;
-	}
-
-	public static int getArrayLength(ImmutableBytesWritable ptr,
-			PDataType baseType, Integer maxLength) {
-		byte[] bytes = ptr.get();
-		if(baseType.isFixedWidth()) {
-		    int elemLength = maxLength == null ? baseType.getByteSize() : maxLength;
-			return (ptr.getLength() / elemLength);
-		}
-		return Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)));
-	}
-
-    public static int estimateSize(int size, PDataType baseType) {
-        if(baseType.isFixedWidth()) {
-            return baseType.getByteSize() * size;
-        } else {
-            return size * ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
-        }
-        
-    }
-    
-    public Object getSampleValue(PDataType baseType, Integer arrayLength, Integer elemLength) {
-        Preconditions.checkArgument(arrayLength == null || arrayLength >= 0);
-        if (arrayLength == null) {
-            arrayLength = 1;
-        }
-        Object[] array = new Object[arrayLength];
-        for (int i = 0; i < arrayLength; i++) {
-            array[i] = baseType.getSampleValue(elemLength, arrayLength);
-        }
-        return instantiatePhoenixArray(baseType, array);
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
index e0143c3..47963c2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnImpl.java
@@ -19,6 +19,7 @@ package org.apache.phoenix.schema;
 
 import org.apache.phoenix.coprocessor.generated.PTableProtos;
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.SizedUtil;
 
 import com.google.common.base.Preconditions;


[09/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index 1ca246f..e8aff8a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -48,11 +48,13 @@ import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SaltingUtil;
@@ -82,7 +84,7 @@ public class SchemaUtil {
     
         @Override
         public PDataType getDataType() {
-            return PDataType.VARBINARY;
+            return PVarbinary.INSTANCE;
         }
     
         @Override
@@ -343,7 +345,7 @@ public class SchemaUtil {
     }
 
     public static String toString(PDataType type, byte[] value) {
-        boolean isString = type.isCoercibleTo(PDataType.VARCHAR);
+        boolean isString = type.isCoercibleTo(PVarchar.INSTANCE);
         return isString ? ("'" + type.toObject(value).toString() + "'") : type.toObject(value).toString();
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index 56c101f..a3fee72 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -38,7 +38,8 @@ import org.apache.phoenix.coprocessor.MetaDataProtocol;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTable;
@@ -208,7 +209,7 @@ public class UpgradeUtil {
                     PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                     PhoenixDatabaseMetaData.SALT_BUCKETS_BYTES,
                     MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
-                    PDataType.INTEGER.toBytes(nSaltBuckets));
+                    PInteger.INSTANCE.toBytes(nSaltBuckets));
             Put saltPut = new Put(seqTableKey);
             saltPut.add(saltKV);
             // Prevent multiple clients from doing this upgrade
@@ -221,12 +222,12 @@ public class UpgradeUtil {
                 }
                 // We can detect upgrade from 4.2.0 -> 4.2.1 based on the timestamp of the table row
                 if (oldTable.getTimeStamp() == MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP-1) {
-                    byte[] oldSeqNum = PDataType.LONG.toBytes(oldTable.getSequenceNumber());
+                    byte[] oldSeqNum = PLong.INSTANCE.toBytes(oldTable.getSequenceNumber());
                     KeyValue seqNumKV = KeyValueUtil.newKeyValue(seqTableKey, 
                             PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                             PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES,
                             MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
-                            PDataType.LONG.toBytes(oldTable.getSequenceNumber()+1));
+                            PLong.INSTANCE.toBytes(oldTable.getSequenceNumber()+1));
                     Put seqNumPut = new Put(seqTableKey);
                     seqNumPut.add(seqNumKV);
                     // Increment TABLE_SEQ_NUM in checkAndPut as semaphore so that only single client
@@ -317,7 +318,7 @@ public class UpgradeUtil {
                                         PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                                         PhoenixDatabaseMetaData.SALT_BUCKETS_BYTES,
                                         MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
-                                        PDataType.INTEGER.toBytes(0));
+                                        PInteger.INSTANCE.toBytes(0));
                                 Put unsaltPut = new Put(seqTableKey);
                                 unsaltPut.add(unsaltKV);
                                 try {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
index dbb09d5..d0f9c24 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
@@ -21,7 +21,7 @@ import com.google.common.base.Function;
 import com.google.common.collect.Lists;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.phoenix.util.QueryUtil;
 import org.slf4j.Logger;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/StringToArrayConverter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/StringToArrayConverter.java b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/StringToArrayConverter.java
index cfe2589..d50863b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/StringToArrayConverter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/StringToArrayConverter.java
@@ -23,7 +23,7 @@ import java.sql.SQLException;
 
 import javax.annotation.Nullable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.base.Function;
 import com.google.common.base.Splitter;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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 d90c6b6..c0b0c20 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
@@ -34,7 +34,9 @@ import org.apache.phoenix.expression.DecimalMultiplyExpression;
 import org.apache.phoenix.expression.DecimalSubtractExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
 import org.junit.Test;
 
 
@@ -51,27 +53,27 @@ public class ArithmeticOperationTest {
         DecimalAddExpression e;
         boolean evaluated;
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDataType.DECIMAL, 31, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDecimal.INSTANCE, 31, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1234567890123456789012345691246"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1234567890123456789012345691246"), ptr);
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDecimal.INSTANCE, 5, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("12468.45"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("12468.45"), ptr);
 
         // Exceeds precision.
-        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDecimal.INSTANCE, 3, 0);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -82,19 +84,19 @@ public class ArithmeticOperationTest {
         }
 
         // Pass since we roll out imposing precisioin and scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
-        op3 = LiteralExpression.newConstant(new BigDecimal("-123"), PDataType.DECIMAL, 3, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDecimal.INSTANCE, 3, 0);
+        op3 = LiteralExpression.newConstant(new BigDecimal("-123"), PDecimal.INSTANCE, 3, 0);
         children = Arrays.<Expression>asList(op1, op2, op3);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("99999999999999999999999999999999999999"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("99999999999999999999999999999999999999"), ptr);
 
         // Exceeds scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDecimal.INSTANCE, 5, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -105,14 +107,14 @@ public class ArithmeticOperationTest {
         }
         
         // Decimal with no precision and scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("9999.1"), PDataType.DECIMAL);
-        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
+        op1 = LiteralExpression.newConstant(new BigDecimal("9999.1"), PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDecimal.INSTANCE, 5, 4);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("10000.2111"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("10000.2111"), ptr);
     }
 
     @Test
@@ -123,15 +125,15 @@ public class ArithmeticOperationTest {
         DecimalAddExpression e;
         boolean evaluated;
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDataType.DECIMAL);
+        op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDecimal.INSTANCE);
         assertNull(op1.getScale());
-        op2 = LiteralExpression.newConstant(1, PDataType.INTEGER);
+        op2 = LiteralExpression.newConstant(1, PInteger.INSTANCE);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalAddExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1235.111"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1235.111"), ptr);
     }
 
     // Subtraction
@@ -145,27 +147,27 @@ public class ArithmeticOperationTest {
         DecimalSubtractExpression e;
         boolean evaluated;
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDataType.DECIMAL, 31, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDecimal.INSTANCE, 31, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1234567890123456789012345666556"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1234567890123456789012345666556"), ptr);
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDecimal.INSTANCE, 5, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("12221.55"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("12221.55"), ptr);
 
         // Excceds precision
-        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), PDataType.DECIMAL, 3, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), PDecimal.INSTANCE, 3, 0);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -176,19 +178,19 @@ public class ArithmeticOperationTest {
         }
 
         // Pass since we roll up precision and scale imposing.
-        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), PDataType.DECIMAL, 3, 0);
-        op3 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), PDecimal.INSTANCE, 3, 0);
+        op3 = LiteralExpression.newConstant(new BigDecimal("123"), PDecimal.INSTANCE, 3, 0);
         children = Arrays.<Expression>asList(op1, op2, op3);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("99999999999999999999999999999999999999"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("99999999999999999999999999999999999999"), ptr);
 
         // Exceeds scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDecimal.INSTANCE, 5, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -199,14 +201,14 @@ public class ArithmeticOperationTest {
         }
         
         // Decimal with no precision and scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDataType.DECIMAL);
-        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
+        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDecimal.INSTANCE, 5, 4);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalSubtractExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1109.9889"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1109.9889"), ptr);
     }
 
     // Multiplication
@@ -220,18 +222,18 @@ public class ArithmeticOperationTest {
         DecimalMultiplyExpression e;
         boolean evaluated;
 
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDecimal.INSTANCE, 5, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalMultiplyExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1523990.25"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1523990.25"), ptr);
 
         // Value too big, exceeds precision.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalMultiplyExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -242,8 +244,8 @@ public class ArithmeticOperationTest {
         }
 
         // Values exceeds scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("1.45"), PDataType.DECIMAL, 3, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.45"), PDecimal.INSTANCE, 3, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalMultiplyExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -254,15 +256,15 @@ public class ArithmeticOperationTest {
         }
         
         // Decimal with no precision and scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDataType.DECIMAL);
+        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDecimal.INSTANCE);
         assertNull(op1.getScale());
-        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDecimal.INSTANCE, 5, 4);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalMultiplyExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1234.54321"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1234.54321"), ptr);
     }
 
     // Division
@@ -279,18 +281,18 @@ public class ArithmeticOperationTest {
         // The value should be 1234500.0000...00 because we set to scale to be 24. However, in
         // PhoenixResultSet.getBigDecimal, the case to (BigDecimal) actually cause the scale to be eradicated. As
         // a result, the resulting value does not have the right form.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDecimal.INSTANCE, 2, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalDivideExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1.2345E+6"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("1.2345E+6"), ptr);
 
         // Exceeds precision.
-        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
-        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDecimal.INSTANCE, 2, 2);
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalDivideExpression(children);
         ptr = new ImmutableBytesWritable();
@@ -301,15 +303,15 @@ public class ArithmeticOperationTest {
         }
         
         // Decimal with no precision and scale.
-        op1 = LiteralExpression.newConstant(new BigDecimal("10"), PDataType.DECIMAL);
-        op2 = LiteralExpression.newConstant(new BigDecimal("3"), PDataType.DECIMAL, 5, 4);
+        op1 = LiteralExpression.newConstant(new BigDecimal("10"), PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("3"), PDecimal.INSTANCE, 5, 4);
         assertEquals(Integer.valueOf(4),op2.getScale());
         children = Arrays.<Expression>asList(op1, op2);
         e = new DecimalDivideExpression(children);
         ptr = new ImmutableBytesWritable();
         evaluated = e.evaluate(null, ptr);
         assertTrue(evaluated);
-        assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
+        assertEqualValue(PDecimal.INSTANCE, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
     }
 
     private static void assertEqualValue(PDataType type, Object value, ImmutableBytesWritable ptr) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/compile/LimitCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/LimitCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/LimitCompilerTest.java
index cb0d4ef..30d926d 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/LimitCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/LimitCompilerTest.java
@@ -34,7 +34,7 @@ import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.TestUtil;
@@ -59,8 +59,8 @@ public class LimitCompilerTest extends BaseConnectionlessQueryTest {
         Scan scan = plan.getContext().getScan();
         
         assertNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
         assertEquals(plan.getLimit(),Integer.valueOf(5));
     }
 
@@ -74,8 +74,8 @@ public class LimitCompilerTest extends BaseConnectionlessQueryTest {
 
         assertNull(scan.getFilter());
         assertNull(plan.getLimit());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
     
     @Test
@@ -87,8 +87,8 @@ public class LimitCompilerTest extends BaseConnectionlessQueryTest {
         Scan scan = plan.getContext().getScan();
 
         assertNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
         assertEquals(plan.getLimit(),Integer.valueOf(5));
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java
index 6f3dccc..e5a9878 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesIntersectTest.java
@@ -29,8 +29,9 @@ import java.util.List;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.filter.SkipScanFilter;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SortOrder;
@@ -56,8 +57,8 @@ public class ScanRangesIntersectTest {
         Collections.sort(expectedKeys,KeyRange.COMPARATOR);
         Scan scan = new Scan();
         scan.setFilter(ranges.getSkipScanFilter());
-        byte[] startKey = lowerRange == null ? KeyRange.UNBOUND : PDataType.VARCHAR.toBytes(lowerRange);
-        byte[] stopKey = upperRange == null ? KeyRange.UNBOUND : PDataType.VARCHAR.toBytes(upperRange);
+        byte[] startKey = lowerRange == null ? KeyRange.UNBOUND : PVarchar.INSTANCE.toBytes(lowerRange);
+        byte[] stopKey = upperRange == null ? KeyRange.UNBOUND : PVarchar.INSTANCE.toBytes(upperRange);
         Scan newScan = ranges.intersectScan(scan, startKey, stopKey, 0, true);
         if (expectedPoints.length == 0) {
             assertNull(newScan);
@@ -71,7 +72,7 @@ public class ScanRangesIntersectTest {
     private static List<KeyRange> points(String... points) {
         List<KeyRange> keys = Lists.newArrayListWithExpectedSize(points.length);
         for (String point : points) {
-            keys.add(KeyRange.getKeyRange(PDataType.VARCHAR.toBytes(point)));
+            keys.add(KeyRange.getKeyRange(PVarchar.INSTANCE.toBytes(point)));
         }
         return keys;
     }
@@ -85,7 +86,7 @@ public class ScanRangesIntersectTest {
             }
             @Override
             public PDataType getDataType() {
-                return PDataType.VARCHAR;
+                return PVarchar.INSTANCE;
             }
             @Override
             public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
index 279d866..b5d20ab 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/ScanRangesTest.java
@@ -24,8 +24,10 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.ByteUtil;
@@ -82,383 +84,383 @@ public class ScanRangesTest {
         // must be added at end
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.VARCHAR.getKeyRange(Bytes.toBytes("b"), false, Bytes.toBytes("c"), true),
+                        PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("b"), false, Bytes.toBytes("c"), true),
                     }},
-                    new int[] {0}, 
-                    PDataType.VARCHAR.getKeyRange(Bytes.toBytes("ba"), true, Bytes.toBytes("bb"), true),
+                    new int[] {0},
+                    PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("ba"), true, Bytes.toBytes("bb"), true),
                     true));
         // KeyRange covers the first scan range.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a9Z"), true, Bytes.toBytes("c0A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a9Z"), true, Bytes.toBytes("c0A"), true),
                     true));
         // KeyRange that requires a fixed width exclusive lower bound to be bumped up
         // and made inclusive. Otherwise, the comparison thinks its bigger than it really is.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), false, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1A"), true, Bytes.toBytes("b1A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1A"), true, Bytes.toBytes("b1A"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b1C"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b1C"), true),
                     true));
         // KeyRange intersect with the first scan range on range's upper end.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b1B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b1B"), true),
                     true));
          // ScanRanges is everything.
         testCases.addAll(
                 foreach(ScanRanges.EVERYTHING, 
                     null,
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     true));
         // ScanRanges is nothing.
         testCases.addAll(
                 foreach(ScanRanges.NOTHING,
                     null,
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     false));
         // KeyRange below the first scan range.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }},
                     new int[] {1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("C"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("C"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b0Y"), true, Bytes.toBytes("b0Z"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b0Y"), true, Bytes.toBytes("b0Z"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("C"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("C"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b2A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b0A"), true, Bytes.toBytes("b2A"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1A"), true, Bytes.toBytes("b1B"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1A"), true, Bytes.toBytes("b1B"), false),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("E"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a0Z"), false, Bytes.toBytes("a1A"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a0Z"), false, Bytes.toBytes("a1A"), false),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("c"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("2"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("C"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("C"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a1A"), true, Bytes.toBytes("b1B"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a1A"), true, Bytes.toBytes("b1B"), false),
                     false));
         // KeyRange intersects with the first scan range on range's lower end.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1C"), true, Bytes.toBytes("b2E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1C"), true, Bytes.toBytes("b2E"), true),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1D"), true, Bytes.toBytes("b2E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1D"), true, Bytes.toBytes("b2E"), true),
                     true));
         // KeyRange above the first scan range, no intersect.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("H"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("H"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1E"), true, Bytes.toBytes("b1F"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1E"), true, Bytes.toBytes("b1F"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("G"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("G"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a1I"), true, Bytes.toBytes("a2A"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a1I"), true, Bytes.toBytes("a2A"), false),
                     false));
         // KeyRange above the first scan range, with intersects.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1E"), true, Bytes.toBytes("b1H"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1E"), true, Bytes.toBytes("b1H"), true),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("c"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("d"), true, Bytes.toBytes("d"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("c"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("d"), true, Bytes.toBytes("d"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b00"), true, Bytes.toBytes("d00"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b00"), true, Bytes.toBytes("d00"), true),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("c"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("d"), true, Bytes.toBytes("d"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("c"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("d"), true, Bytes.toBytes("d"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("3"), true, Bytes.toBytes("4"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("3"), true, Bytes.toBytes("4"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("I"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b20"), true, Bytes.toBytes("b50"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b20"), true, Bytes.toBytes("b50"), true),
                     true));
         // KeyRange above the last scan range.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b1B"), false, Bytes.toBytes("b2A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b1B"), false, Bytes.toBytes("b2A"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), false),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), false),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), false),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), false),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), false),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), false),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b2A"), true, Bytes.toBytes("b2A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b2A"), true, Bytes.toBytes("b2A"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1},
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c1A"), false, Bytes.toBytes("c9Z"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c1A"), false, Bytes.toBytes("c9Z"), true),
                     false));
         // KeyRange contains unbound lower bound.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a0Z"), true),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a0Z"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a0Z"), true),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a0Z"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a1C"), true),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a1C"), true),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a1D"), true),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a1D"), true),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("D"), true, Bytes.toBytes("E"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a2D"), true),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, Bytes.toBytes("a2D"), true),
                     true));
         // KeyRange contains unbound upper bound
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a0A"), true, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a0A"), true, KeyRange.UNBOUND, false),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a1B"), true, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a1B"), true, KeyRange.UNBOUND, false),
                     true));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a1C"), true, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a1C"), true, KeyRange.UNBOUND, false),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a3A"), true, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a3A"), true, KeyRange.UNBOUND, false),
                     false));
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("d0A"), true, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("d0A"), true, KeyRange.UNBOUND, false),
                     false));
         // KeyRange is unbound to unbound.
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                         },{
-                        PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
+                        PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("B"), true),
                     }},
                     new int[] {1,1,1}, 
-                    PDataType.CHAR.getKeyRange(KeyRange.UNBOUND, false, KeyRange.UNBOUND, false),
+                    PChar.INSTANCE.getKeyRange(KeyRange.UNBOUND, false, KeyRange.UNBOUND, false),
                     true));
         return testCases;
     }
@@ -483,7 +485,7 @@ public class ScanRangesTest {
                     }
                     @Override
                     public PDataType getDataType() {
-                        return PDataType.CHAR;
+                        return PChar.INSTANCE;
                     }
                     @Override
                     public Integer getMaxLength() {
@@ -506,7 +508,7 @@ public class ScanRangesTest {
                     }
                     @Override
                     public PDataType getDataType() {
-                        return PDataType.VARCHAR;
+                        return PVarchar.INSTANCE;
                     }
                     @Override
                     public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
index d8da994..d15051c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereCompilerTest.java
@@ -60,7 +60,9 @@ import org.apache.phoenix.query.BaseConnectionlessQueryTest;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.util.ByteUtil;
@@ -104,9 +106,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] key = new byte[PDataType.LONG.getByteSize() + 1];
-        PDataType.LONG.toBytes(1L, key, 1);
-        key[0] = SaltingUtil.getSaltingByte(key, 1, PDataType.LONG.getByteSize(), 20);
+        byte[] key = new byte[PLong.INSTANCE.getByteSize() + 1];
+        PLong.INSTANCE.toBytes(1L, key, 1);
+        key[0] = SaltingUtil.getSaltingByte(key, 1, PLong.INSTANCE.getByteSize(), 20);
         byte[] expectedStartKey = key;
         byte[] expectedEndKey = ByteUtil.nextKey(key);
         byte[] startKey = scan.getStartRow();
@@ -126,7 +128,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNull(filter);
         byte[] key = new byte[2];
-        PDataType.VARCHAR.toBytes("a", key, 1);
+        PVarchar.INSTANCE.toBytes("a", key, 1);
         key[0] = SaltingUtil.getSaltingByte(key, 1, 1, 20);
         byte[] expectedStartKey = key;
         byte[] expectedEndKey = ByteUtil.nextKey(ByteUtil.concat(key, QueryConstants.SEPARATOR_BYTE_ARRAY));
@@ -145,14 +147,14 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
-        byte[] key = new byte[PDataType.LONG.getByteSize() + 1];
-        PDataType.LONG.toBytes(1L, key, 1);
-        key[0] = SaltingUtil.getSaltingByte(key, 1, PDataType.LONG.getByteSize(), 20);
+        byte[] key = new byte[PLong.INSTANCE.getByteSize() + 1];
+        PLong.INSTANCE.toBytes(1L, key, 1);
+        key[0] = SaltingUtil.getSaltingByte(key, 1, PLong.INSTANCE.getByteSize(), 20);
         byte[] startKey1 = key;
 
-        key = new byte[PDataType.LONG.getByteSize() + 1];
-        PDataType.LONG.toBytes(3L, key, 1);
-        key[0] = SaltingUtil.getSaltingByte(key, 1, PDataType.LONG.getByteSize(), 20);
+        key = new byte[PLong.INSTANCE.getByteSize() + 1];
+        PLong.INSTANCE.toBytes(3L, key, 1);
+        key[0] = SaltingUtil.getSaltingByte(key, 1, PLong.INSTANCE.getByteSize(), 20);
         byte[] startKey2 = key;
 
         byte[] startKey = scan.getStartRow();
@@ -415,7 +417,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
     public void testDegenerateBiggerThanMaxLengthVarchar() throws SQLException {
         byte[] tooBigValue = new byte[101];
         Arrays.fill(tooBigValue, (byte)50);
-        String aString = (String)PDataType.VARCHAR.toObject(tooBigValue);
+        String aString = (String) PVarchar.INSTANCE.toObject(tooBigValue);
         String query = "select * from atable where a_string=?";
         List<Object> binds = Arrays.<Object>asList(aString);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
@@ -502,7 +504,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         assertNull(scan.getFilter());
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -524,7 +526,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                 0)),
             filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -545,7 +547,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                 A_INTEGER,
                 0)),
             filter);
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -561,7 +563,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -575,7 +577,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -600,9 +602,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId1);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = PDataType.VARCHAR.toBytes(tenantId3);
+        byte[] stopRow = PVarchar.INSTANCE.toBytes(tenantId3);
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
 
         Filter filter = scan.getFilter();
@@ -638,9 +640,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                 plan.getContext().getResolver().getTables().get(0).getTable().getRowKeySchema()),
             filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId1);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = PDataType.VARCHAR.toBytes(tenantId3);
+        byte[] stopRow = PVarchar.INSTANCE.toBytes(tenantId3);
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
     }
 
@@ -655,9 +657,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId + entityId1);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId + entityId1);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = PDataType.VARCHAR.toBytes(tenantId + entityId2);
+        byte[] stopRow = PVarchar.INSTANCE.toBytes(tenantId + entityId2);
         assertArrayEquals(ByteUtil.concat(stopRow, QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
 
         Filter filter = scan.getFilter();
@@ -693,7 +695,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                         pointRange(tenantId1),
                         pointRange(tenantId2),
                         pointRange(tenantId3)),
-                    Arrays.asList(PDataType.CHAR.getKeyRange(
+                    Arrays.asList(PChar.INSTANCE.getKeyRange(
                         Bytes.toBytes(entityId1),
                         true,
                         Bytes.toBytes(entityId2),
@@ -737,9 +739,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId1), PDataType.VARCHAR.toBytes(entityId));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId1), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId3), PDataType.VARCHAR.toBytes(entityId));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId3), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(ByteUtil.concat(stopRow, QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
         // TODO: validate scan ranges
     }
@@ -812,9 +814,9 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId1),PDataType.VARCHAR.toBytes(entityId1));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId1), PVarchar.INSTANCE.toBytes(entityId1));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId3),PDataType.VARCHAR.toBytes(entityId2));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId3), PVarchar.INSTANCE.toBytes(entityId2));
         assertArrayEquals(ByteUtil.concat(stopRow, QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
         // TODO: validate scan ranges
     }
@@ -891,7 +893,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                     "foo"))),
             filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId + tenantTypeId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId + tenantTypeId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
@@ -923,7 +925,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
                     "foo"))),
             filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         byte[] stopRow = startRow;
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());


[18/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LpadFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LpadFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LpadFunction.java
index 9ddc7e7..9dfc8fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LpadFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LpadFunction.java
@@ -22,7 +22,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.StringUtil;
@@ -33,9 +36,9 @@ import org.apache.phoenix.util.StringUtil;
  * Fills up the input to length (number of characters) by prepending characters in fill (space by default). If the input
  * is already longer than length then it is truncated on the right.
  */
-@BuiltInFunction(name = LpadFunction.NAME, args = { @Argument(allowedTypes = { PDataType.VARCHAR }),
-    @Argument(allowedTypes = { PDataType.INTEGER }),
-    @Argument(allowedTypes = { PDataType.VARCHAR }, defaultValue = "' '") })
+@BuiltInFunction(name = LpadFunction.NAME, args = { @Argument(allowedTypes = { PVarchar.class }),
+    @Argument(allowedTypes = { PInteger.class }),
+    @Argument(allowedTypes = { PVarchar.class }, defaultValue = "' '") })
 public class LpadFunction extends ScalarFunction {
     public static final String NAME = "LPAD";
 
@@ -97,8 +100,8 @@ public class LpadFunction extends ScalarFunction {
             return false;
         }
 
-        boolean isStrCharType = getStrExpr().getDataType() == PDataType.CHAR;
-        boolean isFillCharType = getFillExpr().getDataType() == PDataType.CHAR;
+        boolean isStrCharType = getStrExpr().getDataType() == PChar.INSTANCE;
+        boolean isFillCharType = getFillExpr().getDataType() == PChar.INSTANCE;
         SortOrder strSortOrder = getStrExpr().getSortOrder();
         SortOrder fillSortOrder = getFillExpr().getSortOrder();
         int inputStrLen = getUTF8Length(ptr, strSortOrder, isStrCharType);
@@ -165,7 +168,7 @@ public class LpadFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
index 3bac400..e4c3c98 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MD5Function.java
@@ -26,7 +26,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 @BuiltInFunction(name = MD5Function.NAME, args = { @Argument() })
@@ -66,7 +67,7 @@ public class MD5Function extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BINARY;
+        return PBinary.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
index d33f41c..4913f91 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
@@ -26,8 +26,8 @@ import org.apache.phoenix.expression.aggregator.MaxAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.MaxAggregateParseNode;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PDataType;
 
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
index 00c87cb..5b99e13 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
@@ -27,8 +27,8 @@ import org.apache.phoenix.expression.aggregator.MinAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.MinAggregateParseNode;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
index 5614088..969fda9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NthValueFunction.java
@@ -26,7 +26,8 @@ import org.apache.phoenix.expression.aggregator.FirstLastValueBaseClientAggregat
 import org.apache.phoenix.expression.aggregator.FirstLastValueServerAggregator;
 import org.apache.phoenix.parse.NthValueAggregateParseNode;
 import org.apache.phoenix.parse.FunctionParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PInteger;
 
 /**
  * Built-in function for NTH_VALUE(<expression>, <expression>) WITHIN GROUP (ORDER BY <expression> ASC/DESC)
@@ -35,9 +36,9 @@ import org.apache.phoenix.schema.PDataType;
  */
 @FunctionParseNode.BuiltInFunction(name = NthValueFunction.NAME, nodeClass = NthValueAggregateParseNode.class, args = {
     @FunctionParseNode.Argument(),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.BOOLEAN}, isConstant = true),
+    @FunctionParseNode.Argument(allowedTypes = { PBoolean.class }, isConstant = true),
     @FunctionParseNode.Argument(),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.INTEGER}, isConstant = true)})
+    @FunctionParseNode.Argument(allowedTypes = { PInteger.class }, isConstant = true)})
 public class NthValueFunction extends FirstLastValueBaseFunction {
 
     public static final String NAME = "NTH_VALUE";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentRankAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentRankAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentRankAggregateFunction.java
index 776b736..51dc816 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentRankAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentRankAggregateFunction.java
@@ -28,7 +28,9 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggr
 import org.apache.phoenix.expression.aggregator.PercentRankClientAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -38,7 +40,7 @@ import org.apache.phoenix.schema.PDataType;
  * @since 1.2.1
  */
 @BuiltInFunction(name = PercentRankAggregateFunction.NAME, args = { @Argument(),
-        @Argument(allowedTypes = { PDataType.BOOLEAN }, isConstant = true), @Argument(isConstant = true) })
+        @Argument(allowedTypes = { PBoolean.class }, isConstant = true), @Argument(isConstant = true) })
 public class PercentRankAggregateFunction extends DistinctValueWithCountAggregateFunction {
     public static final String NAME = "PERCENT_RANK";
 
@@ -67,6 +69,6 @@ public class PercentRankAggregateFunction extends DistinctValueWithCountAggregat
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileContAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileContAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileContAggregateFunction.java
index 9226384..17bb33c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileContAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileContAggregateFunction.java
@@ -28,7 +28,9 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggr
 import org.apache.phoenix.expression.aggregator.PercentileClientAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -37,9 +39,9 @@ import org.apache.phoenix.schema.PDataType;
  * 
  * @since 1.2.1
  */
-@BuiltInFunction(name = PercentileContAggregateFunction.NAME, args = { @Argument(allowedTypes = { PDataType.DECIMAL }),
-        @Argument(allowedTypes = { PDataType.BOOLEAN }, isConstant = true),
-        @Argument(allowedTypes = { PDataType.DECIMAL }, isConstant = true, minValue = "0", maxValue = "1") })
+@BuiltInFunction(name = PercentileContAggregateFunction.NAME, args = { @Argument(allowedTypes = { PDecimal.class }),
+        @Argument(allowedTypes = { PBoolean.class }, isConstant = true),
+        @Argument(allowedTypes = { PDecimal.class }, isConstant = true, minValue = "0", maxValue = "1") })
 public class PercentileContAggregateFunction extends DistinctValueWithCountAggregateFunction {
     public static final String NAME = "PERCENTILE_CONT";
 
@@ -68,6 +70,6 @@ public class PercentileContAggregateFunction extends DistinctValueWithCountAggre
     
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileDiscAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileDiscAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileDiscAggregateFunction.java
index 26d78b7..13482f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileDiscAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PercentileDiscAggregateFunction.java
@@ -28,8 +28,8 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggr
 import org.apache.phoenix.expression.aggregator.PercentileDiscClientAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
-
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
 
 /**
  * 
@@ -38,9 +38,9 @@ import org.apache.phoenix.schema.PDataType;
  * 
  * @since 1.2.1
  */
-@BuiltInFunction(name = PercentileDiscAggregateFunction.NAME, args = { @Argument(allowedTypes = { PDataType.DECIMAL }),
-        @Argument(allowedTypes = { PDataType.BOOLEAN }, isConstant = true),
-        @Argument(allowedTypes = { PDataType.DECIMAL }, isConstant = true, minValue = "0", maxValue = "1") })
+@BuiltInFunction(name = PercentileDiscAggregateFunction.NAME, args = { @Argument(allowedTypes = { PDecimal.class }),
+        @Argument(allowedTypes = { PBoolean.class }, isConstant = true),
+        @Argument(allowedTypes = { PDecimal.class }, isConstant = true, minValue = "0", maxValue = "1") })
 public class PercentileDiscAggregateFunction extends DistinctValueWithCountAggregateFunction {
 
 	public static final String NAME = "PERCENTILE_DISC";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
index 40d2467..3373df7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/PrefixFunction.java
@@ -26,7 +26,7 @@ import org.apache.phoenix.compile.KeyPart;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.StringUtil;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
index a19a1bf..911ed19 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RTrimFunction.java
@@ -29,7 +29,8 @@ import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -45,7 +46,7 @@ import org.apache.phoenix.util.StringUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=RTrimFunction.NAME, args={
-    @Argument(allowedTypes={PDataType.VARCHAR})})
+    @Argument(allowedTypes={PVarchar.class})})
 public class RTrimFunction extends ScalarFunction {
     public static final String NAME = "RTRIM";
 
@@ -152,7 +153,7 @@ public class RTrimFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
index b62a79f..3f470a9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
@@ -28,7 +28,8 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -39,18 +40,18 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * REGEXP_REPLACE(<source_char>,<pattern>,<replace_string>)
  * source_char is the string in which we want to perform string replacement. pattern is a
  * Java compatible regular expression string, and we replace all the matching part with 
- * replace_string. The first 2 arguments are required and are {@link org.apache.phoenix.schema.PDataType#VARCHAR},
+ * replace_string. The first 2 arguments are required and are {@link org.apache.phoenix.schema.types.PVarchar},
  * the replace_string is default to empty string.
  * 
- * The function returns a {@link org.apache.phoenix.schema.PDataType#VARCHAR}
+ * The function returns a {@link org.apache.phoenix.schema.types.PVarchar}
  * 
  * 
  * @since 0.1
  */
 @BuiltInFunction(name=RegexpReplaceFunction.NAME, args= {
-    @Argument(allowedTypes={PDataType.VARCHAR}),
-    @Argument(allowedTypes={PDataType.VARCHAR}),
-    @Argument(allowedTypes={PDataType.VARCHAR},defaultValue="null")} )
+    @Argument(allowedTypes={PVarchar.class}),
+    @Argument(allowedTypes={PVarchar.class}),
+    @Argument(allowedTypes={PVarchar.class},defaultValue="null")} )
 public class RegexpReplaceFunction extends ScalarFunction {
     public static final String NAME = "REGEXP_REPLACE";
 
@@ -83,7 +84,7 @@ public class RegexpReplaceFunction extends ScalarFunction {
         if (!sourceStrExpression.evaluate(tuple, ptr)) {
             return false;
         }
-        String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, sourceStrExpression.getSortOrder());
+        String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, sourceStrExpression.getSortOrder());
         if (sourceStr == null) {
             return false;
         }
@@ -93,12 +94,12 @@ public class RegexpReplaceFunction extends ScalarFunction {
             if (!replaceStrExpression.evaluate(tuple, ptr)) {
                 return false;
             }
-            replaceStr = (String)PDataType.VARCHAR.toObject(ptr, replaceStrExpression.getSortOrder());
+            replaceStr = (String) PVarchar.INSTANCE.toObject(ptr, replaceStrExpression.getSortOrder());
         } else {
             replaceStr = "";
         }
         String replacedStr = pattern.matcher(sourceStr).replaceAll(replaceStr);
-        ptr.set(PDataType.VARCHAR.toBytes(replacedStr));
+        ptr.set(PVarchar.INSTANCE.toBytes(replacedStr));
         return true;
     }
 
@@ -112,7 +113,7 @@ public class RegexpReplaceFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
index 5dd70c4..89c7c9e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
@@ -25,8 +25,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.parse.FunctionParseNode;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PhoenixArray;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarcharArray;
+import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 
@@ -42,11 +44,11 @@ import com.google.common.collect.Lists;
  * {@code source_str} is the string in which we want to split. {@code split_pattern} is a
  * Java compatible regular expression string to split the source string.
  *
- * The function returns a {@link org.apache.phoenix.schema.PDataType#VARCHAR_ARRAY}
+ * The function returns a {@link org.apache.phoenix.schema.types.PVarcharArray}
  */
  @FunctionParseNode.BuiltInFunction(name=RegexpSplitFunction.NAME, args= {
-        @FunctionParseNode.Argument(allowedTypes={PDataType.VARCHAR}),
-        @FunctionParseNode.Argument(allowedTypes={PDataType.VARCHAR})})
+        @FunctionParseNode.Argument(allowedTypes={PVarchar.class}),
+        @FunctionParseNode.Argument(allowedTypes={PVarchar.class})})
 public class RegexpSplitFunction extends ScalarFunction {
 
     public static final String NAME = "REGEXP_SPLIT";
@@ -88,7 +90,7 @@ public class RegexpSplitFunction extends ScalarFunction {
         }
 
         Expression sourceStrExpression = children.get(0);
-        String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, sourceStrExpression.getSortOrder());
+        String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, sourceStrExpression.getSortOrder());
         if (sourceStr == null) { // sourceStr evaluated to null
             ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
             return true;
@@ -108,20 +110,20 @@ public class RegexpSplitFunction extends ScalarFunction {
                 return true; // ptr is already set to null
             }
 
-            String patternStr = (String) PDataType.VARCHAR.toObject(
+            String patternStr = (String) PVarchar.INSTANCE.toObject(
                     ptr, patternExpression.getSortOrder());
             splitter = Splitter.onPattern(patternStr);
         }
 
         List<String> splitStrings = Lists.newArrayList(splitter.split(sourceStr));
-        PhoenixArray splitArray = new PhoenixArray(PDataType.VARCHAR, splitStrings.toArray());
-        ptr.set(PDataType.VARCHAR_ARRAY.toBytes(splitArray));
+        PhoenixArray splitArray = new PhoenixArray(PVarchar.INSTANCE, splitStrings.toArray());
+        ptr.set(PVarcharArray.INSTANCE.toBytes(splitArray));
         return true;
     }
 
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR_ARRAY;
+        return PVarcharArray.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
index 840e3d7..93d8706 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSubstrFunction.java
@@ -28,7 +28,9 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 
@@ -46,9 +48,9 @@ import org.apache.phoenix.util.ByteUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=RegexpSubstrFunction.NAME, args={
-    @Argument(allowedTypes={PDataType.VARCHAR}),
-    @Argument(allowedTypes={PDataType.VARCHAR}),
-    @Argument(allowedTypes={PDataType.LONG}, defaultValue="1")} )
+    @Argument(allowedTypes={PVarchar.class}),
+    @Argument(allowedTypes={PVarchar.class}),
+    @Argument(allowedTypes={PLong.class}, defaultValue="1")} )
 public class RegexpSubstrFunction extends PrefixFunction {
     public static final String NAME = "REGEXP_SUBSTR";
 
@@ -96,7 +98,7 @@ public class RegexpSubstrFunction extends PrefixFunction {
         if (!getSourceStrExpression().evaluate(tuple, ptr)) {
             return false;
         }
-        String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, getSourceStrExpression().getSortOrder());
+        String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getSourceStrExpression().getSortOrder());
         if (sourceStr == null) {
             return false;
         }
@@ -124,7 +126,7 @@ public class RegexpSubstrFunction extends PrefixFunction {
             return true;
         }
         String subString = matcher.group();
-        ptr.set(PDataType.VARCHAR.toBytes(subString));
+        ptr.set(PVarchar.INSTANCE.toBytes(subString));
         return true;
     }
 
@@ -171,7 +173,7 @@ public class RegexpSubstrFunction extends PrefixFunction {
     public PDataType getDataType() {
         // ALways VARCHAR since we do not know in advanced how long the 
         // matched string will be.
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ReverseFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ReverseFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ReverseFunction.java
index 91cc332..dd1f3a8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ReverseFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ReverseFunction.java
@@ -26,13 +26,14 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.StringUtil;
 
 @BuiltInFunction(name=ReverseFunction.NAME,  args={
-        @Argument(allowedTypes={PDataType.VARCHAR})} )
+        @Argument(allowedTypes={PVarchar.class})} )
 public class ReverseFunction extends ScalarFunction {
     public static final String NAME = "REVERSE";
     
@@ -77,7 +78,7 @@ public class ReverseFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
index 58ff652..d8fa1dc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDateExpression.java
@@ -33,9 +33,11 @@ import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDataType.PDataCodec;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -47,7 +49,7 @@ import com.google.common.collect.Lists;
  * an even increment.  Usage:
  * ROUND(<date/time col ref>,<'day'|'hour'|'minute'|'second'|'millisecond'>,<optional integer multiplier>)
  * The integer multiplier is optional and is used to do rollups to a partial time unit (i.e. 10 minute rollup)
- * The function returns a {@link org.apache.phoenix.schema.PDataType#DATE}
+ * The function returns a {@link org.apache.phoenix.schema.types.PDate}
 
  * 
  * @since 0.1
@@ -93,11 +95,11 @@ public class RoundDateExpression extends ScalarFunction {
     }
     
     static Expression getTimeUnitExpr(TimeUnit timeUnit) throws SQLException {
-        return LiteralExpression.newConstant(timeUnit.name(), PDataType.VARCHAR, Determinism.ALWAYS);
+        return LiteralExpression.newConstant(timeUnit.name(), PVarchar.INSTANCE, Determinism.ALWAYS);
     }
     
     static Expression getMultiplierExpr(int multiplier) throws SQLException {
-        return LiteralExpression.newConstant(multiplier, PDataType.INTEGER, Determinism.ALWAYS);
+        return LiteralExpression.newConstant(multiplier, PInteger.INSTANCE, Determinism.ALWAYS);
     }
     
     RoundDateExpression(List<Expression> children) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
index e8d96a8..e81650f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundDecimalExpression.java
@@ -30,8 +30,11 @@ import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 import com.google.common.collect.Lists;
@@ -40,12 +43,11 @@ import org.apache.hadoop.hbase.filter.CompareFilter;
 import org.apache.phoenix.compile.KeyPart;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.PColumn;
-import static org.apache.phoenix.schema.PDataType.DECIMAL;
 
 /**
  *
  * Class encapsulating the process for rounding off a column/literal of type
- * {@link org.apache.phoenix.schema.PDataType#DECIMAL}
+ * {@link org.apache.phoenix.schema.types.PDecimal}
  *
  *
  * @since 3.0.0
@@ -59,10 +61,10 @@ public class RoundDecimalExpression extends ScalarFunction {
      *
      */
     public static Expression create(Expression expr, int scale) throws SQLException {
-        if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+        if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
-        Expression scaleExpr = LiteralExpression.newConstant(scale, PDataType.INTEGER, Determinism.ALWAYS);
+        Expression scaleExpr = LiteralExpression.newConstant(scale, PInteger.INSTANCE, Determinism.ALWAYS);
         List<Expression> expressions = Lists.newArrayList(expr, scaleExpr);
         return new RoundDecimalExpression(expressions);
     }
@@ -77,11 +79,11 @@ public class RoundDecimalExpression extends ScalarFunction {
 
     public static Expression create(List<Expression> exprs) throws SQLException {
         Expression expr = exprs.get(0);
-        if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+        if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
         if (exprs.size() == 1) {
-            Expression scaleExpr = LiteralExpression.newConstant(0, PDataType.INTEGER, Determinism.ALWAYS);
+            Expression scaleExpr = LiteralExpression.newConstant(0, PInteger.INSTANCE, Determinism.ALWAYS);
             exprs = Lists.newArrayList(expr, scaleExpr);
         }
         return new RoundDecimalExpression(exprs);
@@ -95,8 +97,8 @@ public class RoundDecimalExpression extends ScalarFunction {
         PDataType scaleType = scaleChild.getDataType();
         Object scaleValue = scaleChild.getValue();
         if(scaleValue != null) {
-            if (scaleType.isCoercibleTo(PDataType.INTEGER, scaleValue)) {
-                int scale = (Integer)PDataType.INTEGER.toObject(scaleValue, scaleType);
+            if (scaleType.isCoercibleTo(PInteger.INSTANCE, scaleValue)) {
+                int scale = (Integer) PInteger.INSTANCE.toObject(scaleValue, scaleType);
                 if (scale >=0 && scale <= PDataType.MAX_PRECISION) {
                     this.scale = scale;
                     return;
@@ -110,9 +112,9 @@ public class RoundDecimalExpression extends ScalarFunction {
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         Expression childExpr = children.get(0);
         if(childExpr.evaluate(tuple, ptr)) {
-            BigDecimal value = (BigDecimal)PDataType.DECIMAL.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder());
+            BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder());
             BigDecimal scaledValue = value.setScale(scale, getRoundingMode());
-            ptr.set(PDataType.DECIMAL.toBytes(scaledValue));
+            ptr.set(PDecimal.INSTANCE.toBytes(scaledValue));
             return true;
         }
         return false;
@@ -120,7 +122,7 @@ public class RoundDecimalExpression extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 
     protected RoundingMode getRoundingMode() {
@@ -175,7 +177,7 @@ public class RoundDecimalExpression extends ScalarFunction {
 
             @Override
             public KeyRange getKeyRange(CompareFilter.CompareOp op, Expression rhs) {
-                final BigDecimal rhsDecimal = (BigDecimal) DECIMAL.toObject(evaluateExpression(rhs));
+                final BigDecimal rhsDecimal = (BigDecimal) PDecimal.INSTANCE.toObject(evaluateExpression(rhs));
                 
                 // equality requires an exact match. if rounding would cut off more precision
                 // than needed for a match, it's impossible for there to be any matches
@@ -289,8 +291,8 @@ public class RoundDecimalExpression extends ScalarFunction {
             throw new IllegalArgumentException("Cannot produce input range for decimal " + result 
                 + ", not enough precision with scale " + getRoundingScale());
         }
-        byte[] lowerRange = DECIMAL.toBytes(halfStepPrevInScale(result));
-        byte[] upperRange = DECIMAL.toBytes(halfStepNextInScale(result));
+        byte[] lowerRange = PDecimal.INSTANCE.toBytes(halfStepPrevInScale(result));
+        byte[] upperRange = PDecimal.INSTANCE.toBytes(halfStepNextInScale(result));
         // inclusiveness changes depending on sign
         // e.g. -0.5 rounds "up" to -1 even though it is the lower boundary
         boolean lowerInclusive = result.signum() > 0;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
index 0ebf385..9277716 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
@@ -23,8 +23,10 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.RoundParseNode;
-import org.apache.phoenix.schema.PDataType;
-
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
 
 /**
  * Base class for RoundFunction.
@@ -35,9 +37,9 @@ import org.apache.phoenix.schema.PDataType;
 @BuiltInFunction(name = RoundFunction.NAME, 
                  nodeClass = RoundParseNode.class,
                  args = {
-                        @Argument(allowedTypes={PDataType.TIMESTAMP, PDataType.DECIMAL}),
-                        @Argument(allowedTypes={PDataType.VARCHAR, PDataType.INTEGER}, defaultValue = "null", isConstant=true),
-                        @Argument(allowedTypes={PDataType.INTEGER}, defaultValue="1", isConstant=true)
+                        @Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
+                        @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+                        @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
                         } 
                 )
 public abstract class RoundFunction extends ScalarFunction {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
index fff29cc..215cf79 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundTimestampExpression.java
@@ -27,15 +27,19 @@ import com.google.common.collect.Lists;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDataType.PDataCodec;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
  * 
  * Class encapsulating the process for rounding off a column/literal of 
- * type {@link org.apache.phoenix.schema.PDataType#TIMESTAMP}
+ * type {@link org.apache.phoenix.schema.types.PTimestamp}
  * This class only supports rounding off the milliseconds that is for
  * {@link TimeUnit#MILLISECOND}. If you want more options of rounding like 
  * using {@link TimeUnit#HOUR} use {@link RoundDateExpression}
@@ -70,17 +74,18 @@ public class RoundTimestampExpression extends RoundDateExpression {
         }
         // Coerce TIMESTAMP to DATE, as the nanos has no affect
         List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
-        newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PDataType.TIMESTAMP ? PDataType.DATE : PDataType.UNSIGNED_DATE));
+        newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ?
+            PDate.INSTANCE : PUnsignedDate.INSTANCE));
         newChildren.addAll(children.subList(1, children.size()));
         return RoundDateExpression.create(newChildren);
     }
     
     @Override
     protected PDataCodec getKeyRangeCodec(PDataType columnDataType) {
-        return columnDataType == PDataType.TIMESTAMP 
-                ? PDataType.DATE.getCodec() 
-                : columnDataType == PDataType.UNSIGNED_TIMESTAMP 
-                    ? PDataType.UNSIGNED_DATE.getCodec() 
+        return columnDataType == PTimestamp.INSTANCE
+                ? PDate.INSTANCE.getCodec()
+                : columnDataType == PUnsignedTimestamp.INSTANCE
+                    ? PUnsignedDate.INSTANCE.getCodec()
                     : super.getKeyRangeCodec(columnDataType);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
index 617e977..14b7dea 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLIndexTypeFunction.java
@@ -24,8 +24,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTable.IndexType;
+import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -40,7 +42,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 2.2
  */
 @BuiltInFunction(name=SQLIndexTypeFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.UNSIGNED_TINYINT)} )
+    @Argument(allowedTypes= PUnsignedTinyint.class)} )
 public class SQLIndexTypeFunction extends ScalarFunction {
     public static final String NAME = "SQLIndexType";
 
@@ -67,7 +69,7 @@ public class SQLIndexTypeFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLTableTypeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLTableTypeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLTableTypeFunction.java
index 825c2d0..5970512 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLTableTypeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLTableTypeFunction.java
@@ -25,8 +25,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -41,7 +43,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 2.2
  */
 @BuiltInFunction(name=SQLTableTypeFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.CHAR)} )
+    @Argument(allowedTypes= PChar.class)} )
 public class SQLTableTypeFunction extends ScalarFunction {
     public static final String NAME = "SQLTableType";
 
@@ -68,7 +70,7 @@ public class SQLTableTypeFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLViewTypeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLViewTypeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLViewTypeFunction.java
index 17151c8..d105d21 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLViewTypeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SQLViewTypeFunction.java
@@ -25,8 +25,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTable.ViewType;
+import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -41,7 +43,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 2.2
  */
 @BuiltInFunction(name=SQLViewTypeFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.UNSIGNED_TINYINT)} )
+    @Argument(allowedTypes= PUnsignedTinyint.class)} )
 public class SQLViewTypeFunction extends ScalarFunction {
     public static final String NAME = "SQLViewType";
 
@@ -68,7 +70,7 @@ public class SQLViewTypeFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SingleAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SingleAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SingleAggregateFunction.java
index d33d555..6155e1d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SingleAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SingleAggregateFunction.java
@@ -30,7 +30,7 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.aggregator.Aggregator;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SqlTypeNameFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SqlTypeNameFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SqlTypeNameFunction.java
index 34ccd0c..bbd7efa 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SqlTypeNameFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SqlTypeNameFunction.java
@@ -26,7 +26,9 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 
@@ -42,7 +44,7 @@ import org.apache.phoenix.util.ByteUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=SqlTypeNameFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.INTEGER)} )
+    @Argument(allowedTypes= PInteger.class)} )
 public class SqlTypeNameFunction extends ScalarFunction {
     public static final String NAME = "SqlTypeName";
 
@@ -74,7 +76,7 @@ public class SqlTypeNameFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevPopFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevPopFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevPopFunction.java
index b5ba63a..338031b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevPopFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevPopFunction.java
@@ -29,7 +29,8 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggr
 import org.apache.phoenix.expression.aggregator.StddevPopAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -38,7 +39,7 @@ import org.apache.phoenix.schema.PDataType;
  * 
  * @since 1.2.1
  */
-@BuiltInFunction(name = StddevPopFunction.NAME, args = { @Argument(allowedTypes={PDataType.DECIMAL})})
+@BuiltInFunction(name = StddevPopFunction.NAME, args = { @Argument(allowedTypes={PDecimal.class})})
 public class StddevPopFunction extends DistinctValueWithCountAggregateFunction {
     public static final String NAME = "STDDEV_POP";
 
@@ -57,7 +58,7 @@ public class StddevPopFunction extends DistinctValueWithCountAggregateFunction {
 
     @Override
     public DistinctValueWithCountClientAggregator newClientAggregator() {
-        if (children.get(0).getDataType() == PDataType.DECIMAL) {
+        if (children.get(0).getDataType() == PDecimal.INSTANCE) {
             // Special Aggregators for DECIMAL datatype for more precision than double
             return new DecimalStddevPopAggregator(children, getAggregatorExpression().getSortOrder());
         }
@@ -71,6 +72,6 @@ public class StddevPopFunction extends DistinctValueWithCountAggregateFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevSampFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevSampFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevSampFunction.java
index 9684cc9..0f22c75 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevSampFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/StddevSampFunction.java
@@ -29,7 +29,8 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggr
 import org.apache.phoenix.expression.aggregator.StddevSampAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -38,7 +39,7 @@ import org.apache.phoenix.schema.PDataType;
  * 
  * @since 1.2.1
  */
-@BuiltInFunction(name = StddevSampFunction.NAME, args = { @Argument(allowedTypes={PDataType.DECIMAL})})
+@BuiltInFunction(name = StddevSampFunction.NAME, args = { @Argument(allowedTypes={PDecimal.class})})
 public class StddevSampFunction extends DistinctValueWithCountAggregateFunction {
     public static final String NAME = "STDDEV_SAMP";
 
@@ -57,7 +58,7 @@ public class StddevSampFunction extends DistinctValueWithCountAggregateFunction
 
     @Override
     public DistinctValueWithCountClientAggregator newClientAggregator() {
-        if (children.get(0).getDataType() == PDataType.DECIMAL) {
+        if (children.get(0).getDataType() == PDecimal.INSTANCE) {
             // Special Aggregators for DECIMAL datatype for more precision than double
             return new DecimalStddevSampAggregator(children, getAggregatorExpression().getSortOrder());
         }
@@ -71,6 +72,6 @@ public class StddevSampFunction extends DistinctValueWithCountAggregateFunction
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
index a7f15ac..4b21736 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SubstrFunction.java
@@ -19,7 +19,6 @@ package org.apache.phoenix.expression.function;
 
 import java.io.DataInput;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
@@ -27,7 +26,10 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.StringUtil;
@@ -47,9 +49,9 @@ import org.apache.phoenix.util.StringUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=SubstrFunction.NAME,  args={
-    @Argument(allowedTypes={PDataType.VARCHAR}),
-    @Argument(allowedTypes={PDataType.LONG}), // These are LONG because negative numbers end up as longs
-    @Argument(allowedTypes={PDataType.LONG},defaultValue="null")} )
+    @Argument(allowedTypes={PVarchar.class}),
+    @Argument(allowedTypes={PLong.class}), // These are LONG because negative numbers end up as longs
+    @Argument(allowedTypes={PLong.class},defaultValue="null")} )
 public class SubstrFunction extends PrefixFunction {
     public static final String NAME = "SUBSTR";
     private boolean hasLengthExpression;
@@ -115,7 +117,7 @@ public class SubstrFunction extends PrefixFunction {
             return false;
         }
     
-        boolean isCharType = getStrExpression().getDataType() == PDataType.CHAR;
+        boolean isCharType = getStrExpression().getDataType() == PChar.INSTANCE;
         SortOrder sortOrder = getStrExpression().getSortOrder();
         int strlen = isCharType ? ptr.getLength() : StringUtil.calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), sortOrder);
         
@@ -140,7 +142,7 @@ public class SubstrFunction extends PrefixFunction {
     public PDataType getDataType() {
         // If fixed width, then return child expression type.
         // If not fixed width, then we don't know how big this will be across the board
-        return isFixedWidth ? getStrExpression().getDataType() : PDataType.VARCHAR;
+        return isFixedWidth ? getStrExpression().getDataType() : PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SumAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SumAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SumAggregateFunction.java
index 4c5ce4a..d761a78 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SumAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/SumAggregateFunction.java
@@ -32,8 +32,14 @@ import org.apache.phoenix.expression.aggregator.NumberSumAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.SumAggregateParseNode;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PUnsignedDouble;
+import org.apache.phoenix.schema.types.PUnsignedFloat;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -44,7 +50,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * 
  * @since 0.1
  */
-@BuiltInFunction(name=SumAggregateFunction.NAME, nodeClass=SumAggregateParseNode.class, args= {@Argument(allowedTypes={PDataType.DECIMAL})} )
+@BuiltInFunction(name=SumAggregateFunction.NAME, nodeClass=SumAggregateParseNode.class, args= {@Argument(allowedTypes={PDecimal.class})} )
 public class SumAggregateFunction extends DelegateConstantToCountAggregateFunction {
     public static final String NAME = "SUM";
     
@@ -61,26 +67,22 @@ public class SumAggregateFunction extends DelegateConstantToCountAggregateFuncti
     }
     
     private Aggregator newAggregator(final PDataType type, SortOrder sortOrder, ImmutableBytesWritable ptr) {
-        switch( type ) {
-            case DECIMAL:
-                return new DecimalSumAggregator(sortOrder, ptr);
-            case UNSIGNED_DOUBLE:
-            case UNSIGNED_FLOAT:
-            case DOUBLE:
-            case FLOAT:
-                return new DoubleSumAggregator(sortOrder, ptr) {
-                    @Override
-                    protected PDataType getInputDataType() {
-                        return type;
-                    }
-                };
-            default:
-                return new NumberSumAggregator(sortOrder, ptr) {
-                    @Override
-                    protected PDataType getInputDataType() {
-                        return type;
-                    }
-                };
+        if (type == PDecimal.INSTANCE) {
+          return new DecimalSumAggregator(sortOrder, ptr);
+        } else if (PDataType.equalsAny(type, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PFloat.INSTANCE)) {
+          return new DoubleSumAggregator(sortOrder, ptr) {
+            @Override
+            protected PDataType getInputDataType() {
+              return type;
+            }
+          };
+        } else {
+          return new NumberSumAggregator(sortOrder, ptr) {
+            @Override
+            protected PDataType getInputDataType() {
+              return type;
+            }
+          };
         }
     }
 
@@ -109,9 +111,9 @@ public class SumAggregateFunction extends DelegateConstantToCountAggregateFuncti
         if (isConstantExpression()) {
             PDataType type = getDataType();
             Object constantValue = ((LiteralExpression)children.get(0)).getValue();
-            if (type == PDataType.DECIMAL) {
-                BigDecimal value = ((BigDecimal)constantValue).multiply((BigDecimal)PDataType.DECIMAL.toObject(ptr, PDataType.LONG));
-                ptr.set(PDataType.DECIMAL.toBytes(value));
+            if (type == PDecimal.INSTANCE) {
+                BigDecimal value = ((BigDecimal)constantValue).multiply((BigDecimal) PDecimal.INSTANCE.toObject(ptr, PLong.INSTANCE));
+                ptr.set(PDecimal.INSTANCE.toBytes(value));
             } else {
                 long constantLongValue = ((Number)constantValue).longValue();
                 long value = constantLongValue * type.getCodec().decodeLong(ptr, SortOrder.getDefault());
@@ -125,16 +127,13 @@ public class SumAggregateFunction extends DelegateConstantToCountAggregateFuncti
 
     @Override
     public PDataType getDataType() {
-        switch(super.getDataType()) {
-        case DECIMAL:
-            return PDataType.DECIMAL;
-        case UNSIGNED_FLOAT:
-        case UNSIGNED_DOUBLE:
-        case FLOAT:
-        case DOUBLE:
-            return PDataType.DOUBLE;
-        default:
-            return PDataType.LONG;
+        if (super.getDataType() == PDecimal.INSTANCE) {
+          return PDecimal.INSTANCE;
+        } else if (PDataType.equalsAny(super.getDataType(), PUnsignedFloat.INSTANCE, PUnsignedDouble.INSTANCE,
+            PFloat.INSTANCE, PDouble.INSTANCE)) {
+          return PDouble.INSTANCE;
+        } else {
+          return PLong.INSTANCE;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TimezoneOffsetFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TimezoneOffsetFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TimezoneOffsetFunction.java
index 870e0fa..2cfbc25 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TimezoneOffsetFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TimezoneOffsetFunction.java
@@ -29,16 +29,18 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
-
 /**
  * Returns offset (shift in minutes) of timezone at particular datetime in minutes.
  */
 @FunctionParseNode.BuiltInFunction(name = TimezoneOffsetFunction.NAME, args = {
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.VARCHAR}),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.DATE})})
+    @FunctionParseNode.Argument(allowedTypes = {PVarchar.class}),
+    @FunctionParseNode.Argument(allowedTypes = {PDate.class})})
 public class TimezoneOffsetFunction extends ScalarFunction {
 
     public static final String NAME = "TIMEZONE_OFFSET";
@@ -77,16 +79,16 @@ public class TimezoneOffsetFunction extends ScalarFunction {
             cachedTimeZones.put(timezone, tz);
         }
 
-		Date date = (Date)PDataType.DATE.toObject(ptr, children.get(1).getSortOrder());
+		Date date = (Date) PDate.INSTANCE.toObject(ptr, children.get(1).getSortOrder());
 		int offset = cachedTimeZones.get(timezone).getOffset(date.getTime());
 
-        ptr.set(PDataType.INTEGER.toBytes(offset / MILLIS_TO_MINUTES));
+        ptr.set(PInteger.INSTANCE.toBytes(offset / MILLIS_TO_MINUTES));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.INTEGER;
+        return PInteger.INSTANCE;
     }
 
 	@Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
index c088735..e0bc68b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
@@ -30,7 +30,10 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.*;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -43,8 +46,8 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 0.1
  */
 @BuiltInFunction(name=ToCharFunction.NAME, nodeClass=ToCharParseNode.class, args={
-    @Argument(allowedTypes={PDataType.TIMESTAMP, PDataType.DECIMAL}),
-    @Argument(allowedTypes={PDataType.VARCHAR},isConstant=true,defaultValue="null") } )
+    @Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
+    @Argument(allowedTypes={PVarchar.class},isConstant=true,defaultValue="null") } )
 public class ToCharFunction extends ScalarFunction {
     public static final String NAME = "TO_CHAR";
     private String formatString;
@@ -99,7 +102,7 @@ public class ToCharFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
index 28d1206..3e4cfae 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
@@ -30,7 +30,9 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.*;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.DateUtil;
 
@@ -46,9 +48,9 @@ import org.apache.phoenix.util.DateUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=ToDateFunction.NAME, nodeClass=ToDateParseNode.class,
-        args={@Argument(allowedTypes={PDataType.VARCHAR}),
-                @Argument(allowedTypes={PDataType.VARCHAR},isConstant=true,defaultValue="null"),
-                @Argument(allowedTypes={PDataType.VARCHAR}, isConstant=true, defaultValue = "null") } )
+        args={@Argument(allowedTypes={PVarchar.class}),
+                @Argument(allowedTypes={PVarchar.class},isConstant=true,defaultValue="null"),
+                @Argument(allowedTypes={PVarchar.class}, isConstant=true, defaultValue = "null") } )
 public class ToDateFunction extends ScalarFunction {
     public static final String NAME = "TO_DATE";
     private Format dateParser;
@@ -103,7 +105,7 @@ public class ToDateFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
index dcccd35..ed70f2d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
@@ -34,7 +34,10 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.*;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -46,8 +49,8 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 0.1
  */
 @BuiltInFunction(name=ToNumberFunction.NAME,  nodeClass=ToNumberParseNode.class, args= {
-        @Argument(allowedTypes={PDataType.VARCHAR, PDataType.TIMESTAMP}),
-        @Argument(allowedTypes={PDataType.VARCHAR}, isConstant=true, defaultValue="null")} )
+        @Argument(allowedTypes={PVarchar.class, PTimestamp.class}),
+        @Argument(allowedTypes={PVarchar.class}, isConstant=true, defaultValue="null")} )
 public class ToNumberFunction extends ScalarFunction {
 	public static final String NAME = "TO_NUMBER";
     
@@ -75,7 +78,7 @@ public class ToNumberFunction extends ScalarFunction {
         }
 
         PDataType type = expression.getDataType();
-        if (type.isCoercibleTo(PDataType.TIMESTAMP)) {
+        if (type.isCoercibleTo(PTimestamp.INSTANCE)) {
         	Date date = (Date) type.toObject(ptr, expression.getSortOrder());
         	BigDecimal time = new BigDecimal(date.getTime());
             byte[] byteValue = getDataType().toBytes(time);
@@ -116,7 +119,7 @@ public class ToNumberFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-    	return PDataType.DECIMAL;
+    	return PDecimal.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
index d14ddf9..12b53c7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TrimFunction.java
@@ -24,7 +24,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -39,7 +40,7 @@ import org.apache.phoenix.util.StringUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=TrimFunction.NAME, args={
-    @Argument(allowedTypes={PDataType.VARCHAR})} )
+    @Argument(allowedTypes={ PVarchar.class })} )
 public class TrimFunction extends ScalarFunction {
     public static final String NAME = "TRIM";
 
@@ -94,7 +95,7 @@ public class TrimFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
index 4fb16be..a4e79c2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
@@ -24,8 +24,10 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FloorParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
-
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
 
 /**
  * 
@@ -33,7 +35,7 @@ import org.apache.phoenix.schema.PDataType;
  * an even increment.  Usage:
  * TRUNC(<date/time col ref>,<'day'|'hour'|'minute'|'second'|'millisecond'>,[<optional integer multiplier>])
  * The integer multiplier is optional and is used to do rollups to a partial time unit (i.e. 10 minute rollup)
- * The function returns a {@link org.apache.phoenix.schema.PDataType#DATE}
+ * The function returns a {@link org.apache.phoenix.schema.types.PDate}
  *
  * 
  * @since 0.1
@@ -41,9 +43,9 @@ import org.apache.phoenix.schema.PDataType;
 @BuiltInFunction(name = TruncFunction.NAME,
 nodeClass = FloorParseNode.class,
 args = {
-       @Argument(allowedTypes={PDataType.TIMESTAMP, PDataType.DECIMAL}),
-       @Argument(allowedTypes={PDataType.VARCHAR, PDataType.INTEGER}, defaultValue = "null", isConstant=true),
-       @Argument(allowedTypes={PDataType.INTEGER}, defaultValue="1", isConstant=true)
+       @Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
+       @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+       @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
        } 
 )
 public abstract class TruncFunction extends ScalarFunction {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java
index 43b3766..3a6305c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/UpperFunction.java
@@ -25,11 +25,12 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 @FunctionParseNode.BuiltInFunction(name=UpperFunction.NAME,  args={
-        @FunctionParseNode.Argument(allowedTypes={PDataType.VARCHAR})} )
+        @FunctionParseNode.Argument(allowedTypes={PVarchar.class})} )
 public class UpperFunction extends ScalarFunction {
     public static final String NAME = "UPPER";
 
@@ -46,12 +47,12 @@ public class UpperFunction extends ScalarFunction {
             return false;
         }
 
-        String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, getStrExpression().getSortOrder());
+        String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder());
         if (sourceStr == null) {
             return true;
         }
 
-        ptr.set(PDataType.VARCHAR.toBytes(sourceStr.toUpperCase()));
+        ptr.set(PVarchar.INSTANCE.toBytes(sourceStr.toUpperCase()));
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index f8c73fc..61b6e68 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -50,7 +50,7 @@ import org.apache.phoenix.hbase.index.util.IndexManagementUtil.ReferencingColumn
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTable;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
index 46d09d6..a0bd7c5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.compile.ScanRanges;
 import org.apache.phoenix.hbase.index.covered.CoveredColumnsIndexBuilder;
 import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -57,7 +57,7 @@ public class PhoenixIndexBuilder extends CoveredColumnsIndexBuilder {
         ImmutableBytesWritable indexTableName = new ImmutableBytesWritable();
         for (int i = 0; i < miniBatchOp.size(); i++) {
             Mutation m = miniBatchOp.getOperation(i);
-            keys.add(PDataType.VARBINARY.getKeyRange(m.getRow()));
+            keys.add(PVarbinary.INSTANCE.getKeyRange(m.getRow()));
             List<IndexMaintainer> indexMaintainers = getCodec().getIndexMaintainers(m.getAttributesMap());
             
             for(IndexMaintainer indexMaintainer: indexMaintainers) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
index 565b28c..1c98c5c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
@@ -50,8 +50,8 @@ import org.apache.phoenix.coprocessor.generated.MetaDataProtos.UpdateIndexStateR
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.protobuf.ProtobufUtil;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.util.MetaDataUtil;
@@ -150,7 +150,7 @@ public class PhoenixIndexFailurePolicy extends  KillServerOnFailurePolicy {
             put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_STATE_BYTES,
                     PIndexState.DISABLE.getSerializedBytes());
             put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES,
-                    PDataType.LONG.toBytes(minTimeStamp));
+                PLong.INSTANCE.toBytes(minTimeStamp));
             final List<Mutation> tableMetadata = Collections.<Mutation>singletonList(put);
 
             final Map<byte[], MetaDataResponse> results =

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java
index 8c04383..9756871 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java
@@ -39,7 +39,8 @@ import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.KeyRange.Bound;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
@@ -162,7 +163,7 @@ public abstract class ExplainTable {
         Integer groupByLimit = null;
         byte[] groupByLimitBytes = scan.getAttribute(BaseScannerRegionObserver.GROUP_BY_LIMIT);
         if (groupByLimitBytes != null) {
-            groupByLimit = (Integer)PDataType.INTEGER.toObject(groupByLimitBytes);
+            groupByLimit = (Integer) PInteger.INSTANCE.toObject(groupByLimitBytes);
         }
         groupBy.explain(planSteps, groupByLimit);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterAggregatingResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterAggregatingResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterAggregatingResultIterator.java
index 15b9094..4fa2011 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterAggregatingResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterAggregatingResultIterator.java
@@ -23,7 +23,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -46,7 +46,7 @@ public class FilterAggregatingResultIterator  implements AggregatingResultIterat
     public FilterAggregatingResultIterator(AggregatingResultIterator delegate, Expression expression) {
         this.delegate = delegate;
         this.expression = expression;
-        if (expression.getDataType() != PDataType.BOOLEAN) {
+        if (expression.getDataType() != PBoolean.INSTANCE) {
             throw new IllegalArgumentException("FilterResultIterator requires a boolean expression, but got " + expression);
         }
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterResultIterator.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterResultIterator.java
index 6c332fa..eaa6956 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/FilterResultIterator.java
@@ -23,7 +23,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -49,7 +49,7 @@ public class FilterResultIterator  extends LookAheadResultIterator {
         }
         this.delegate = delegate;
         this.expression = expression;
-        if (expression.getDataType() != PDataType.BOOLEAN) {
+        if (expression.getDataType() != PBoolean.INSTANCE) {
             throw new IllegalArgumentException("FilterResultIterator requires a boolean expression, but got " + expression);
         }
     }


[20/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndOrExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndOrExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndOrExpression.java
index 89ad02e..ea8c375 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndOrExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndOrExpression.java
@@ -21,7 +21,8 @@ import java.util.BitSet;
 import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -45,7 +46,7 @@ public abstract class AndOrExpression extends BaseCompoundExpression {
     
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
 
     @Override
@@ -70,7 +71,7 @@ public abstract class AndOrExpression extends BaseCompoundExpression {
                 // evaluate versus getValue code path.
                 if (child.evaluate(tuple, ptr)) {
                     // Short circuit if we see our stop value
-                    if (isStopValue((Boolean)PDataType.BOOLEAN.toObject(ptr, child.getDataType()))) {
+                    if (isStopValue((Boolean) PBoolean.INSTANCE.toObject(ptr, child.getDataType()))) {
                         return true;
                     } else if (partialEvalState != null) {
                         partialEvalState.set(i);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArithmeticExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArithmeticExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArithmeticExpression.java
index 247e9d7..9212709 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArithmeticExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArithmeticExpression.java
@@ -19,7 +19,7 @@ package org.apache.phoenix.expression;
 
 import java.util.List;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 public abstract class ArithmeticExpression extends BaseCompoundExpression {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
index dd23534..9faab96 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ArrayConstructorExpression.java
@@ -19,8 +19,8 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.TrustedByteArrayOutputStream;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
index da7bd9f..43654b7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseAddSubtractExpression.java
@@ -19,7 +19,7 @@ package org.apache.phoenix.expression;
 
 import java.util.List;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 
 abstract public class BaseAddSubtractExpression extends ArithmeticExpression {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
index 8993e37..e4f53ae 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/BaseExpression.java
@@ -33,14 +33,15 @@ import org.apache.phoenix.expression.function.FloorDateExpression;
 import org.apache.phoenix.expression.function.FloorDecimalExpression;
 import org.apache.phoenix.expression.function.TimeUnit;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 import com.google.common.collect.Lists;
 
-
-
 /**
  * 
  * Base class for Expression hierarchy that provides common
@@ -71,9 +72,9 @@ public abstract class BaseExpression implements Expression {
                 Expression e = rhs;
                 PDataType rhsType = rhs.getDataType();
                 PDataType lhsType = lhs.getDataType();
-                if (rhsType == PDataType.DECIMAL && lhsType != PDataType.DECIMAL) {
+                if (rhsType == PDecimal.INSTANCE && lhsType != PDecimal.INSTANCE) {
                     e = FloorDecimalExpression.create(rhs);
-                } else if ((rhsType == PDataType.TIMESTAMP || rhsType == PDataType.UNSIGNED_TIMESTAMP)  && (lhsType != PDataType.TIMESTAMP && lhsType != PDataType.UNSIGNED_TIMESTAMP)) {
+                } else if ((rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE)  && (lhsType != PTimestamp.INSTANCE && lhsType != PUnsignedTimestamp.INSTANCE)) {
                     e = FloorDateExpression.create(rhs, TimeUnit.MILLISECOND);
                 }
                 e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength());
@@ -90,9 +91,9 @@ public abstract class BaseExpression implements Expression {
                 Expression e = rhs;
                 PDataType rhsType = rhs.getDataType();
                 PDataType lhsType = lhs.getDataType();
-                if (rhsType == PDataType.DECIMAL && lhsType != PDataType.DECIMAL) {
+                if (rhsType == PDecimal.INSTANCE && lhsType != PDecimal.INSTANCE) {
                     e = CeilDecimalExpression.create(rhs);
-                } else if ((rhsType == PDataType.TIMESTAMP || rhsType == PDataType.UNSIGNED_TIMESTAMP)  && (lhsType != PDataType.TIMESTAMP && lhsType != PDataType.UNSIGNED_TIMESTAMP)) {
+                } else if ((rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE)  && (lhsType != PTimestamp.INSTANCE && lhsType != PUnsignedTimestamp.INSTANCE)) {
                     e = CeilTimestampExpression.create(rhs);
                 }
                 e = CoerceExpression.create(e, lhsType, lhs.getSortOrder(), lhs.getMaxLength());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
index d4784bb..96338cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
@@ -29,7 +29,9 @@ import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -73,8 +75,8 @@ public class CaseExpression extends BaseCompoundExpression {
         }
         // If we found an "unknown" child type and the return type is a number
         // make the return type be the most general number type of DECIMAL.
-        if (isChildTypeUnknown && returnType != null && returnType.isCoercibleTo(PDataType.DECIMAL)) {
-            returnType = PDataType.DECIMAL;
+        if (isChildTypeUnknown && returnType != null && returnType.isCoercibleTo(PDecimal.INSTANCE)) {
+            returnType = PDecimal.INSTANCE;
         }
         List<Expression> newChildren = children;
         for (int i = 0; i < children.size(); i+=2) {
@@ -156,7 +158,7 @@ public class CaseExpression extends BaseCompoundExpression {
             // If we get null, we have to re-evaluate from that point (special case this in filter, like is null)
             // We may only run this when we're done/have all values
             boolean evaluated = children.get(i+1).evaluate(tuple, ptr);
-            if (evaluated && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr))) {
+            if (evaluated && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr))) {
                 if (isPartiallyEvaluating()) {
                     foundIndex = true;
                 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
index 99c1934..275ed23 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
@@ -26,7 +26,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
index eb60591..2c9d378 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ColumnExpression.java
@@ -22,7 +22,7 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.hadoop.io.WritableUtils;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.SortOrder;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
index a1ed221..38b69b7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java
@@ -31,7 +31,14 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.function.InlineArrayElemRefExpression;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PUnsignedInt;
+import org.apache.phoenix.schema.types.PUnsignedLong;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -64,7 +71,7 @@ public class ComparisonExpression extends BaseCompoundExpression {
         boolean isLHSNull = ExpressionUtil.isNull(lhs, ptr);
         boolean isRHSNull = ExpressionUtil.isNull(rhs, ptr);
         if (isLHSNull && isRHSNull) { // null == null will end up making the query degenerate
-            andNodes.add(LiteralExpression.newConstant(false, PDataType.BOOLEAN));
+            andNodes.add(LiteralExpression.newConstant(false, PBoolean.INSTANCE));
         } else if (isLHSNull) { // AND rhs IS NULL
             andNodes.add(IsNullExpression.create(rhs, false, ptr));
         } else if (isRHSNull) { // AND lhs IS NULL
@@ -131,7 +138,8 @@ public class ComparisonExpression extends BaseCompoundExpression {
             }
             children = Arrays.asList(lhsExpr, rhsExpr);
         } else if(lhsExprDataType != null && rhsExprDataType != null && !lhsExprDataType.isComparableTo(rhsExprDataType)) {
-            throw TypeMismatchException.newException(lhsExprDataType, rhsExprDataType, toString(op, children));
+            throw TypeMismatchException.newException(lhsExprDataType, rhsExprDataType,
+                toString(op, children));
         }
         Determinism determinism =  lhsExpr.getDeterminism().combine(rhsExpr.getDeterminism());
         
@@ -142,7 +150,7 @@ public class ComparisonExpression extends BaseCompoundExpression {
         if (lhsExpr instanceof LiteralExpression) {
             lhsValue = ((LiteralExpression)lhsExpr).getValue();
             if (lhsValue == null) {
-                return LiteralExpression.newConstant(false, PDataType.BOOLEAN, lhsExpr.getDeterminism());
+                return LiteralExpression.newConstant(false, PBoolean.INSTANCE, lhsExpr.getDeterminism());
             }
         }
         Object rhsValue = null;
@@ -150,7 +158,7 @@ public class ComparisonExpression extends BaseCompoundExpression {
         if (rhsExpr instanceof LiteralExpression) {
             rhsValue = ((LiteralExpression)rhsExpr).getValue();
             if (rhsValue == null) {
-                return LiteralExpression.newConstant(false, PDataType.BOOLEAN, rhsExpr.getDeterminism());
+                return LiteralExpression.newConstant(false, PBoolean.INSTANCE, rhsExpr.getDeterminism());
             }
         }
         if (lhsValue != null && rhsValue != null) {
@@ -170,77 +178,74 @@ public class ComparisonExpression extends BaseCompoundExpression {
                     children = Arrays.asList(children.get(0), LiteralExpression.newConstant(rhsValue, lhsExprDataType, 
                             lhsExpr.getMaxLength(), null, lhsExpr.getSortOrder(), determinism));
                 } else if (op == CompareOp.EQUAL) {
-                    return LiteralExpression.newConstant(false, PDataType.BOOLEAN, Determinism.ALWAYS);
+                    return LiteralExpression.newConstant(false, PBoolean.INSTANCE, Determinism.ALWAYS);
                 } else if (op == CompareOp.NOT_EQUAL) {
-                    return LiteralExpression.newConstant(true, PDataType.BOOLEAN, Determinism.ALWAYS);
+                    return LiteralExpression.newConstant(true, PBoolean.INSTANCE, Determinism.ALWAYS);
                 } else { // TODO: generalize this with PDataType.getMinValue(), PDataTypeType.getMaxValue() methods
-                    switch(rhsExprDataType) {
-                    case DECIMAL:
+                  if (rhsExprDataType == PDecimal.INSTANCE) {
                         /*
                          * We're comparing an int/long to a constant decimal with a fraction part.
                          * We need the types to match in case this is used to form a key. To form the start/stop key,
                          * we need to adjust the decimal by truncating it or taking its ceiling, depending on the comparison
                          * operator, to get a whole number.
                          */
-                        int increment = 0;
-                        switch (op) {
-                        case GREATER_OR_EQUAL: 
-                        case LESS: // get next whole number
-                            increment = 1;
-                        default: // Else, we truncate the value
-                            BigDecimal bd = (BigDecimal)rhsValue;
-                            rhsValue = bd.longValue() + increment;
-                            children = Arrays.asList(lhsExpr, LiteralExpression.newConstant(rhsValue, lhsExprDataType, lhsExpr.getSortOrder(), rhsExpr.getDeterminism()));
-                            break;
-                        }
-                        break;
-                    case LONG:
+                    int increment = 0;
+                    switch (op) {
+                    case GREATER_OR_EQUAL:
+                    case LESS: // get next whole number
+                      increment = 1;
+                    default: // Else, we truncate the value
+                      BigDecimal bd = (BigDecimal)rhsValue;
+                      rhsValue = bd.longValue() + increment;
+                      children = Arrays.asList(lhsExpr, LiteralExpression.newConstant(rhsValue, lhsExprDataType, lhsExpr.getSortOrder(), rhsExpr.getDeterminism()));
+                      break;
+                    }
+                  } else if (rhsExprDataType == PLong.INSTANCE) {
                         /*
                          * We are comparing an int, unsigned_int to a long, or an unsigned_long to a negative long.
                          * int has range of -2147483648 to 2147483647, and unsigned_int has a value range of 0 to 4294967295.
-                         * 
-                         * If lhs is int or unsigned_int, since we already determined that we cannot coerce the rhs 
+                         *
+                         * If lhs is int or unsigned_int, since we already determined that we cannot coerce the rhs
                          * to become the lhs, we know the value on the rhs is greater than lhs if it's positive, or smaller than
                          * lhs if it's negative.
-                         * 
+                         *
                          * If lhs is an unsigned_long, then we know the rhs is definitely a negative long. rhs in this case
                          * will always be bigger than rhs.
                          */
-                        if (lhsExprDataType == PDataType.INTEGER || 
-                        lhsExprDataType == PDataType.UNSIGNED_INT) {
-                            switch (op) {
-                            case LESS:
-                            case LESS_OR_EQUAL:
-                                if ((Long)rhsValue > 0) {
-                                    return LiteralExpression.newConstant(true, PDataType.BOOLEAN, determinism);
-                                } else {
-                                    return LiteralExpression.newConstant(false, PDataType.BOOLEAN, determinism);
-                                }
-                            case GREATER:
-                            case GREATER_OR_EQUAL:
-                                if ((Long)rhsValue > 0) {
-                                    return LiteralExpression.newConstant(false, PDataType.BOOLEAN, determinism);
-                                } else {
-                                    return LiteralExpression.newConstant(true, PDataType.BOOLEAN, determinism);
-                                }
-                            default:
-                                break;
-                            }
-                        } else if (lhsExprDataType == PDataType.UNSIGNED_LONG) {
-                            switch (op) {
-                            case LESS:
-                            case LESS_OR_EQUAL:
-                                return LiteralExpression.newConstant(false, PDataType.BOOLEAN, determinism);
-                            case GREATER:
-                            case GREATER_OR_EQUAL:
-                                return LiteralExpression.newConstant(true, PDataType.BOOLEAN, determinism);
-                            default:
-                                break;
-                            }
+                    if (lhsExprDataType == PInteger.INSTANCE ||
+                        lhsExprDataType == PUnsignedInt.INSTANCE) {
+                      switch (op) {
+                      case LESS:
+                      case LESS_OR_EQUAL:
+                        if ((Long)rhsValue > 0) {
+                          return LiteralExpression.newConstant(true, PBoolean.INSTANCE, determinism);
+                        } else {
+                          return LiteralExpression.newConstant(false, PBoolean.INSTANCE, determinism);
                         }
-                        children = Arrays.asList(lhsExpr, LiteralExpression.newConstant(rhsValue, rhsExprDataType, lhsExpr.getSortOrder(), determinism));
+                      case GREATER:
+                      case GREATER_OR_EQUAL:
+                        if ((Long)rhsValue > 0) {
+                          return LiteralExpression.newConstant(false, PBoolean.INSTANCE, determinism);
+                        } else {
+                          return LiteralExpression.newConstant(true, PBoolean.INSTANCE, determinism);
+                        }
+                      default:
+                        break;
+                      }
+                    } else if (lhsExprDataType == PUnsignedLong.INSTANCE) {
+                      switch (op) {
+                      case LESS:
+                      case LESS_OR_EQUAL:
+                        return LiteralExpression.newConstant(false, PBoolean.INSTANCE, determinism);
+                      case GREATER:
+                      case GREATER_OR_EQUAL:
+                        return LiteralExpression.newConstant(true, PBoolean.INSTANCE, determinism);
+                      default:
                         break;
+                      }
                     }
+                    children = Arrays.asList(lhsExpr, LiteralExpression.newConstant(rhsValue, rhsExprDataType, lhsExpr.getSortOrder(), determinism));
+                  }
                 }
             }
 
@@ -249,9 +254,9 @@ public class ComparisonExpression extends BaseCompoundExpression {
             if (children.get(1).getMaxLength() != null && lhsExpr.getMaxLength() != null && lhsExpr.getMaxLength() < children.get(1).getMaxLength()) {
                 switch (op) {
                 case EQUAL:
-                    return LiteralExpression.newConstant(false, PDataType.BOOLEAN, determinism);
+                    return LiteralExpression.newConstant(false, PBoolean.INSTANCE, determinism);
                 case NOT_EQUAL:
-                    return LiteralExpression.newConstant(true, PDataType.BOOLEAN, determinism);
+                    return LiteralExpression.newConstant(true, PBoolean.INSTANCE, determinism);
                 default:
                     break;
                 }
@@ -291,7 +296,7 @@ public class ComparisonExpression extends BaseCompoundExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
 
     @Override
@@ -320,10 +325,10 @@ public class ComparisonExpression extends BaseCompoundExpression {
         int rhsLength = ptr.getLength();
         PDataType rhsDataType = children.get(1).getDataType();
         SortOrder rhsSortOrder = children.get(1).getSortOrder();   
-        if (rhsDataType == PDataType.CHAR) {
+        if (rhsDataType == PChar.INSTANCE) {
             rhsLength = StringUtil.getUnpaddedCharLength(rhsBytes, rhsOffset, rhsLength, rhsSortOrder);
         }
-        if (lhsDataType == PDataType.CHAR) {
+        if (lhsDataType == PChar.INSTANCE) {
             lhsLength = StringUtil.getUnpaddedCharLength(lhsBytes, lhsOffset, lhsLength, lhsSortOrder);
         }
         
@@ -368,4 +373,4 @@ public class ComparisonExpression extends BaseCompoundExpression {
     public String toString() {
         return toString(getFilterOp(), children);
     }    
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DateAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateAddExpression.java
index f39e6d1..bc79d15 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DateAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateAddExpression.java
@@ -23,8 +23,12 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -52,12 +56,12 @@ public class DateAddExpression extends AddExpression {
             long value;
             PDataType type = children.get(i).getDataType();
             SortOrder sortOrder = children.get(i).getSortOrder();
-            if (type == PDataType.DECIMAL) {
-                BigDecimal bd = (BigDecimal)PDataType.DECIMAL.toObject(ptr, sortOrder);
+            if (type == PDecimal.INSTANCE) {
+                BigDecimal bd = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sortOrder);
                 value = bd.multiply(BD_MILLIS_IN_DAY).longValue();
-            } else if (type.isCoercibleTo(PDataType.LONG)) {
+            } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                 value = type.getCodec().decodeLong(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY;
-            } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+            } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                 value = (long)(type.getCodec().decodeDouble(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY);
             } else {
                 value = type.getCodec().decodeLong(ptr, sortOrder);
@@ -72,7 +76,7 @@ public class DateAddExpression extends AddExpression {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DateSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateSubtractExpression.java
index d13ffee..3f5897c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DateSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DateSubtractExpression.java
@@ -23,8 +23,12 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -48,12 +52,12 @@ public class DateSubtractExpression extends SubtractExpression {
             long value;
             PDataType type = children.get(i).getDataType();
             SortOrder sortOrder = children.get(i).getSortOrder();
-            if (type == PDataType.DECIMAL) {
-                BigDecimal bd = (BigDecimal)PDataType.DECIMAL.toObject(ptr, sortOrder);
+            if (type == PDecimal.INSTANCE) {
+                BigDecimal bd = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sortOrder);
                 value = bd.multiply(BD_MILLIS_IN_DAY).longValue();
-            } else if (type.isCoercibleTo(PDataType.LONG)) {
+            } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                 value = type.getCodec().decodeLong(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY;
-            } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+            } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                 value = (long)(type.getCodec().decodeDouble(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY);
             } else {
                 value = type.getCodec().decodeLong(ptr, sortOrder);
@@ -72,7 +76,7 @@ public class DateSubtractExpression extends SubtractExpression {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
index 3e4e4ed..df1ec4f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalAddExpression.java
@@ -22,7 +22,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.NumberUtil;
@@ -61,7 +62,7 @@ public class DecimalAddExpression extends AddExpression {
             
             PDataType childType = childExpr.getDataType();
             SortOrder childSortOrder = childExpr.getSortOrder();
-            BigDecimal bd = (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childSortOrder);
+            BigDecimal bd = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childType, childSortOrder);
             
             if (result == null) {
                 result = bd;
@@ -73,15 +74,15 @@ public class DecimalAddExpression extends AddExpression {
             result = NumberUtil.setDecimalWidthAndScale(result, maxLength, scale);
         }
         if (result == null) {
-            throw new ValueTypeIncompatibleException(PDataType.DECIMAL, maxLength, scale);
+            throw new ValueTypeIncompatibleException(PDecimal.INSTANCE, maxLength, scale);
         }
-        ptr.set(PDataType.DECIMAL.toBytes(result));
+        ptr.set(PDecimal.INSTANCE.toBytes(result));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalDivideExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalDivideExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalDivideExpression.java
index fc37552..81ff3bc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalDivideExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalDivideExpression.java
@@ -22,7 +22,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.NumberUtil;
@@ -51,7 +52,7 @@ public class DecimalDivideExpression extends DivideExpression {
             
             PDataType childType = childExpr.getDataType();
             SortOrder childSortOrder = childExpr.getSortOrder();
-            BigDecimal bd= (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childSortOrder);
+            BigDecimal bd= (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childType, childSortOrder);
             
             if (result == null) {
                 result = bd;
@@ -63,14 +64,14 @@ public class DecimalDivideExpression extends DivideExpression {
             result = NumberUtil.setDecimalWidthAndScale(result, getMaxLength(), getScale());
         }
         if (result == null) {
-            throw new ValueTypeIncompatibleException(PDataType.DECIMAL, getMaxLength(), getScale());
+            throw new ValueTypeIncompatibleException(PDecimal.INSTANCE, getMaxLength(), getScale());
         }
-        ptr.set(PDataType.DECIMAL.toBytes(result));
+        ptr.set(PDecimal.INSTANCE.toBytes(result));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalMultiplyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalMultiplyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalMultiplyExpression.java
index ea34d36..0a9e3de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalMultiplyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalMultiplyExpression.java
@@ -22,7 +22,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.NumberUtil;
@@ -51,7 +52,7 @@ public class DecimalMultiplyExpression extends MultiplyExpression {
             
             PDataType childType = children.get(i).getDataType();
             SortOrder childSortOrder = children.get(i).getSortOrder();
-            BigDecimal bd = (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childSortOrder);
+            BigDecimal bd = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childType, childSortOrder);
             
             if (result == null) {
                 result = bd;
@@ -63,14 +64,14 @@ public class DecimalMultiplyExpression extends MultiplyExpression {
             result = NumberUtil.setDecimalWidthAndScale(result, getMaxLength(), getScale());
         }
         if (result == null) {
-            throw new ValueTypeIncompatibleException(PDataType.DECIMAL, getMaxLength(), getScale());
+            throw new ValueTypeIncompatibleException(PDecimal.INSTANCE, getMaxLength(), getScale());
         }
-        ptr.set(PDataType.DECIMAL.toBytes(result));
+        ptr.set(PDecimal.INSTANCE.toBytes(result));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
index 8188a90..c46a70f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DecimalSubtractExpression.java
@@ -22,7 +22,9 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.NumberUtil;
@@ -67,11 +69,11 @@ public class DecimalSubtractExpression extends SubtractExpression {
             }
             
             PDataType childType = childExpr.getDataType();
-            boolean isDate = childType.isCoercibleTo(PDataType.DATE);
+            boolean isDate = childType.isCoercibleTo(PDate.INSTANCE);
             SortOrder childSortOrder = childExpr.getSortOrder();
             BigDecimal bd = isDate ?
                     BigDecimal.valueOf(childType.getCodec().decodeLong(ptr, childSortOrder)) :
-                    (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childSortOrder);
+                    (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childType, childSortOrder);
             
             if (result == null) {
                 result = bd;
@@ -90,15 +92,15 @@ public class DecimalSubtractExpression extends SubtractExpression {
             result = NumberUtil.setDecimalWidthAndScale(result, maxLength, scale);
         }
         if (result == null) {
-            throw new ValueTypeIncompatibleException(PDataType.DECIMAL, maxLength, scale);
+            throw new ValueTypeIncompatibleException(PDecimal.INSTANCE, maxLength, scale);
         }
-        ptr.set(PDataType.DECIMAL.toBytes(result));
+        ptr.set(PDecimal.INSTANCE.toBytes(result));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DelegateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DelegateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DelegateExpression.java
index 87a0bc0..3ca93dd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DelegateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DelegateExpression.java
@@ -24,7 +24,7 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
index 5b5ffd8..d5ff956 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DivideExpression.java
@@ -20,7 +20,7 @@ package org.apache.phoenix.expression;
 import java.util.List;
 
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 
 /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleAddExpression.java
index f02327b..8ca2f05 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleAddExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class DoubleAddExpression extends AddExpression {
@@ -62,7 +63,7 @@ public class DoubleAddExpression extends AddExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleDivideExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleDivideExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleDivideExpression.java
index cedeadc..161e060 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleDivideExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleDivideExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class DoubleDivideExpression extends DivideExpression {
@@ -66,7 +67,7 @@ public class DoubleDivideExpression extends DivideExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleMultiplyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleMultiplyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleMultiplyExpression.java
index 45a29d8..28a381c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleMultiplyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleMultiplyExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class DoubleMultiplyExpression extends MultiplyExpression {
@@ -62,7 +63,7 @@ public class DoubleMultiplyExpression extends MultiplyExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleSubtractExpression.java
index 41da7c9..6d2ca3e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/DoubleSubtractExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class DoubleSubtractExpression extends SubtractExpression {
@@ -66,7 +67,7 @@ public class DoubleSubtractExpression extends SubtractExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
index fdb20ff..685a541 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
@@ -33,7 +33,8 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -60,7 +61,7 @@ public class InListExpression extends BaseSingleExpression {
         Expression firstChild = children.get(0);
         
         if (firstChild.isStateless() && (!firstChild.evaluate(null, ptr) || ptr.getLength() == 0)) {
-            return LiteralExpression.newConstant(null, PDataType.BOOLEAN, firstChild.getDeterminism());
+            return LiteralExpression.newConstant(null, PBoolean.INSTANCE, firstChild.getDeterminism());
         }
         if (children.size() == 2) {
             return ComparisonExpression.create(isNegate ? CompareOp.NOT_EQUAL : CompareOp.EQUAL, children, ptr);
@@ -86,7 +87,7 @@ public class InListExpression extends BaseSingleExpression {
             throw sqlE;
         }
         if (coercedKeyExpressions.size() == 2 && addedNull) {
-            return LiteralExpression.newConstant(null, PDataType.BOOLEAN, Determinism.ALWAYS);
+            return LiteralExpression.newConstant(null, PBoolean.INSTANCE, Determinism.ALWAYS);
         }
         Expression expression = new InListExpression(coercedKeyExpressions);
         if (isNegate) { 
@@ -178,7 +179,7 @@ public class InListExpression extends BaseSingleExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
 
     private int readValue(DataInput input, byte[] valuesBytes, int offset, ImmutableBytesPtr ptr) throws IOException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/IsNullExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/IsNullExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/IsNullExpression.java
index 3fb7a62..b4095e3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/IsNullExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/IsNullExpression.java
@@ -25,7 +25,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ExpressionUtil;
 
@@ -42,11 +43,11 @@ public class IsNullExpression extends BaseSingleExpression {
 
     public static Expression create(Expression child, boolean negate, ImmutableBytesWritable ptr) throws SQLException {
         if (!child.isNullable()) {
-            return LiteralExpression.newConstant(negate, PDataType.BOOLEAN, child.getDeterminism());
+            return LiteralExpression.newConstant(negate, PBoolean.INSTANCE, child.getDeterminism());
         }
         if (ExpressionUtil.isConstant(child)) {
             boolean evaluated = child.evaluate(null, ptr);
-            return LiteralExpression.newConstant(negate ^ (!evaluated || ptr.getLength() == 0), PDataType.BOOLEAN, child.getDeterminism());
+            return LiteralExpression.newConstant(negate ^ (!evaluated || ptr.getLength() == 0), PBoolean.INSTANCE, child.getDeterminism());
         }
         return new IsNullExpression(child, negate);
     }
@@ -92,7 +93,7 @@ public class IsNullExpression extends BaseSingleExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
index 4bb70bd..7f6323b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
@@ -26,7 +26,9 @@ import java.util.regex.Pattern;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
 import org.apache.phoenix.parse.LikeParseNode.LikeType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.StringUtil;
 import org.slf4j.Logger;
@@ -267,7 +269,7 @@ public class LikeExpression extends BaseCompoundExpression {
                 }
                 return false;
             }
-            String value = (String)PDataType.VARCHAR.toObject(ptr, getPatternExpression().getSortOrder());
+            String value = (String) PVarchar.INSTANCE.toObject(ptr, getPatternExpression().getSortOrder());
             pattern = compilePattern(value);
             if (logger.isDebugEnabled()) {
                 logger.debug("LIKE pattern is expression: " + pattern.pattern());
@@ -284,7 +286,7 @@ public class LikeExpression extends BaseCompoundExpression {
             return true;
         }
 
-        String value = (String)PDataType.VARCHAR.toObject(ptr, getStrExpression().getSortOrder());
+        String value = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder());
         boolean matched = pattern.matcher(value).matches();
         ptr.set(matched ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
         if (logger.isDebugEnabled()) {
@@ -306,7 +308,7 @@ public class LikeExpression extends BaseCompoundExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
index e9daf2d..757ba34 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java
@@ -25,8 +25,11 @@ import java.sql.SQLException;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PhoenixArray;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -55,8 +58,9 @@ public class LiteralExpression extends BaseTerminalExpression {
 	        for (int i = 0; i < PDataType.values().length; i++) {
 	            TYPED_NULL_EXPRESSIONS[i+PDataType.values().length*determinism.ordinal()] = new LiteralExpression(PDataType.values()[i], determinism);
 	        }        
-	        BOOLEAN_EXPRESSIONS[determinism.ordinal()] = new LiteralExpression(Boolean.FALSE, PDataType.BOOLEAN, PDataType.BOOLEAN.toBytes(Boolean.FALSE), determinism);
-	        BOOLEAN_EXPRESSIONS[Determinism.values().length+determinism.ordinal()] = new LiteralExpression(Boolean.TRUE, PDataType.BOOLEAN, PDataType.BOOLEAN.toBytes(Boolean.TRUE), determinism);
+	        BOOLEAN_EXPRESSIONS[determinism.ordinal()] = new LiteralExpression(Boolean.FALSE,
+              PBoolean.INSTANCE, PBoolean.INSTANCE.toBytes(Boolean.FALSE), determinism);
+	        BOOLEAN_EXPRESSIONS[Determinism.values().length+determinism.ordinal()] = new LiteralExpression(Boolean.TRUE, PBoolean.INSTANCE, PBoolean.INSTANCE.toBytes(Boolean.TRUE), determinism);
     	}
     }
     
@@ -111,10 +115,10 @@ public class LiteralExpression extends BaseTerminalExpression {
         if (type.isNull(b)) {
             return getTypedNullLiteralExpression(type, determinism);
         }
-        if (type == PDataType.VARCHAR) {
+        if (type == PVarchar.INSTANCE) {
             String s = (String) value;
             if (s.length() == b.length) { // single byte characters only
-                type = PDataType.CHAR;
+                type = PChar.INSTANCE;
             }
         }
         return new LiteralExpression(value, type, b, determinism);
@@ -161,8 +165,8 @@ public class LiteralExpression extends BaseTerminalExpression {
         }
         value = type.toObject(value, actualType);
         byte[] b = type.toBytes(value, sortOrder);
-        if (type == PDataType.VARCHAR || type == PDataType.CHAR) {
-            if (type == PDataType.CHAR && maxLength != null  && b.length < maxLength) {
+        if (type == PVarchar.INSTANCE || type == PChar.INSTANCE) {
+            if (type == PChar.INSTANCE && maxLength != null  && b.length < maxLength) {
                 b = StringUtil.padChar(b, maxLength);
             } else if (value != null) {
                 maxLength = ((String)value).length();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongAddExpression.java
index 9b295cf..161758a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongAddExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -46,7 +47,7 @@ public class LongAddExpression extends AddExpression {
             long childvalue = child.getDataType().getCodec().decodeLong(ptr, child.getSortOrder());
             finalResult += childvalue;
         }
-        byte[] resultPtr=new byte[PDataType.LONG.getByteSize()];
+        byte[] resultPtr=new byte[PLong.INSTANCE.getByteSize()];
         getDataType().getCodec().encodeLong(finalResult, resultPtr, 0);
         ptr.set(resultPtr);
         return true;
@@ -54,7 +55,7 @@ public class LongAddExpression extends AddExpression {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongDivideExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongDivideExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongDivideExpression.java
index 1803ca7..599b38e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongDivideExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongDivideExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -50,7 +51,7 @@ public class LongDivideExpression extends DivideExpression {
                 finalResult /= childvalue;
             }
         }
-        byte[] resultPtr=new byte[PDataType.LONG.getByteSize()];
+        byte[] resultPtr=new byte[PLong.INSTANCE.getByteSize()];
         getDataType().getCodec().encodeLong(finalResult, resultPtr, 0);
         ptr.set(resultPtr);
         return true;
@@ -58,7 +59,7 @@ public class LongDivideExpression extends DivideExpression {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongMultiplyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongMultiplyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongMultiplyExpression.java
index c94b1c1..40d6622 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongMultiplyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongMultiplyExpression.java
@@ -21,7 +21,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -57,7 +58,7 @@ public class LongMultiplyExpression extends MultiplyExpression {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongSubtractExpression.java
index c4c4d47..c7e1ee0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LongSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LongSubtractExpression.java
@@ -22,7 +22,9 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -52,7 +54,7 @@ public class LongSubtractExpression extends SubtractExpression {
                 return false;
             }
             PDataType childType = child.getDataType();
-            boolean isDate = childType.isCoercibleTo(PDataType.DATE);
+            boolean isDate = childType.isCoercibleTo(PDate.INSTANCE);
             long childvalue = childType.getCodec().decodeLong(ptr, child.getSortOrder());
             if (i == 0) {
                 finalResult = childvalue;
@@ -75,7 +77,7 @@ public class LongSubtractExpression extends SubtractExpression {
 
 	@Override
 	public final PDataType getDataType() {
-		return PDataType.LONG;
+		return PLong.INSTANCE;
 	}
 	
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/ModulusExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ModulusExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/ModulusExpression.java
index c8dfe93..bac52fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ModulusExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ModulusExpression.java
@@ -21,11 +21,8 @@ import java.sql.SQLException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.expression.function.ScalarFunction;
-import org.apache.phoenix.parse.FunctionParseNode.Argument;
-import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -80,7 +77,7 @@ public class ModulusExpression extends ArithmeticExpression {
         long remainder = dividend % divisor;
         
         // return the result, use encodeLong to avoid extra Long allocation
-        byte[] resultPtr=new byte[PDataType.LONG.getByteSize()];
+        byte[] resultPtr=new byte[PLong.INSTANCE.getByteSize()];
         getDataType().getCodec().encodeLong(remainder, resultPtr, 0);
         ptr.set(resultPtr);
         return true;
@@ -88,7 +85,7 @@ public class ModulusExpression extends ArithmeticExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
index 90a4706..fa669e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/MultiplyExpression.java
@@ -20,7 +20,7 @@ package org.apache.phoenix.expression;
 import java.util.List;
 
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 
 /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/NotExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/NotExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/NotExpression.java
index 0c17ab8..c2f214e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/NotExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/NotExpression.java
@@ -22,7 +22,8 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.tuple.Tuple;
 
@@ -38,14 +39,14 @@ import org.apache.phoenix.schema.tuple.Tuple;
 public class NotExpression extends BaseSingleExpression {
 
     public static Expression create(Expression child, ImmutableBytesWritable ptr) throws SQLException {
-        if (child.getDataType() != PDataType.BOOLEAN) {
-            throw TypeMismatchException.newException(child.getDataType(), PDataType.BOOLEAN, "NOT");
+        if (child.getDataType() != PBoolean.INSTANCE) {
+            throw TypeMismatchException.newException(child.getDataType(), PBoolean.INSTANCE, "NOT");
         }
         if (child.isStateless()) {
             if (!child.evaluate(null, ptr) || ptr.getLength() == 0) {
-                return LiteralExpression.newConstant(null, PDataType.BOOLEAN, child.getDeterminism());
+                return LiteralExpression.newConstant(null, PBoolean.INSTANCE, child.getDeterminism());
             }
-            return LiteralExpression.newConstant(!(Boolean)PDataType.BOOLEAN.toObject(ptr), PDataType.BOOLEAN, child.getDeterminism());
+            return LiteralExpression.newConstant(!(Boolean) PBoolean.INSTANCE.toObject(ptr), PBoolean.INSTANCE, child.getDeterminism());
         }
         return new NotExpression(child);
     }
@@ -66,13 +67,13 @@ public class NotExpression extends BaseSingleExpression {
             return true;
         }
         
-        ptr.set(Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr)) ? PDataType.FALSE_BYTES : PDataType.TRUE_BYTES);
+        ptr.set(Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr)) ? PDataType.FALSE_BYTES : PDataType.TRUE_BYTES);
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
index 7913ab8..240d013 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java
@@ -23,7 +23,7 @@ import java.io.IOException;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.tuple.Tuple;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyExpression.java
index cbd7853..d9f6b90 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyExpression.java
@@ -20,7 +20,8 @@ package org.apache.phoenix.expression;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class RowKeyExpression extends BaseTerminalExpression {
@@ -37,7 +38,7 @@ public class RowKeyExpression extends BaseTerminalExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 34bd35c..546962e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -33,7 +33,8 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.SchemaUtil;
@@ -98,7 +99,7 @@ public class RowValueConstructorExpression extends BaseCompoundExpression {
     
     @Override
     public PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/StringConcatExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/StringConcatExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/StringConcatExpression.java
index 942e0bd..b8fcd41 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/StringConcatExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/StringConcatExpression.java
@@ -23,8 +23,9 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 
@@ -76,10 +77,10 @@ public class StringConcatExpression extends BaseCompoundExpression {
             SortOrder sortOrder = children.get(i).getSortOrder();
             // We could potentially not invert the bytes, but we might as well since we're allocating
             // additional space here anyway.
-            if (childType.isCoercibleTo(PDataType.VARCHAR)) {
+            if (childType.isCoercibleTo(PVarchar.INSTANCE)) {
                 result = ByteUtil.concat(result, ByteUtil.concat(sortOrder, ptr));
             } else {
-                result = ByteUtil.concat(result, PDataType.VARCHAR.toBytes(childType.toObject(ptr, sortOrder).toString()));
+                result = ByteUtil.concat(result, PVarchar.INSTANCE.toBytes(childType.toObject(ptr, sortOrder).toString()));
             }
         }
         ptr.set(result);
@@ -88,6 +89,6 @@ public class StringConcatExpression extends BaseCompoundExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampAddExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampAddExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampAddExpression.java
index 80f3522..892a38c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampAddExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampAddExpression.java
@@ -25,14 +25,18 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.DateUtil;
 
 /**
  * 
- * Class to encapsulate addition arithmetic for {@link PDataType#TIMESTAMP}.
+ * Class to encapsulate addition arithmetic for {@link org.apache.phoenix.schema.types.PTimestamp}.
  *
  * 
  * @since 2.1.3
@@ -61,11 +65,11 @@ public class TimestampAddExpression extends AddExpression {
             BigDecimal value;
             PDataType type = children.get(i).getDataType();
             SortOrder sortOrder = children.get(i).getSortOrder();
-            if(type == PDataType.TIMESTAMP || type == PDataType.UNSIGNED_TIMESTAMP) {
-                value = (BigDecimal)(PDataType.DECIMAL.toObject(ptr, type, sortOrder));
-            } else if (type.isCoercibleTo(PDataType.DECIMAL)) {
-                value = (((BigDecimal)PDataType.DECIMAL.toObject(ptr, sortOrder)).multiply(QueryConstants.BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
-            } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+            if(type == PTimestamp.INSTANCE || type == PUnsignedTimestamp.INSTANCE) {
+                value = (BigDecimal)(PDecimal.INSTANCE.toObject(ptr, type, sortOrder));
+            } else if (type.isCoercibleTo(PDecimal.INSTANCE)) {
+                value = (((BigDecimal) PDecimal.INSTANCE.toObject(ptr, sortOrder)).multiply(QueryConstants.BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
+            } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                 value = ((BigDecimal.valueOf(type.getCodec().decodeDouble(ptr, sortOrder))).multiply(QueryConstants.BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
             } else {
                 value = BigDecimal.valueOf(type.getCodec().decodeLong(ptr, sortOrder));
@@ -74,14 +78,14 @@ public class TimestampAddExpression extends AddExpression {
         }
         Timestamp ts = DateUtil.getTimestamp(finalResult);
         byte[] resultPtr = new byte[getDataType().getByteSize()];
-        PDataType.TIMESTAMP.toBytes(ts, resultPtr, 0);
+        PTimestamp.INSTANCE.toBytes(ts, resultPtr, 0);
         ptr.set(resultPtr);
         return true;
     }
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.TIMESTAMP;
+        return PTimestamp.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampSubtractExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampSubtractExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampSubtractExpression.java
index 0df0c24..5718c94 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampSubtractExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/TimestampSubtractExpression.java
@@ -24,13 +24,17 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.DateUtil;
 /**
  * 
- * Class to encapsulate subtraction arithmetic for {@link PDataType#TIMESTAMP}.
+ * Class to encapsulate subtraction arithmetic for {@link org.apache.phoenix.schema.types.PTimestamp}.
  *
  * 
  * @since 2.1.3
@@ -58,11 +62,11 @@ public class TimestampSubtractExpression extends SubtractExpression {
             BigDecimal value;
             PDataType type = children.get(i).getDataType();
             SortOrder sortOrder = children.get(i).getSortOrder();
-            if(type == PDataType.TIMESTAMP || type == PDataType.UNSIGNED_TIMESTAMP) {
-                value = (BigDecimal)(PDataType.DECIMAL.toObject(ptr, type, sortOrder));
-            } else if (type.isCoercibleTo(PDataType.DECIMAL)) {
-                value = (((BigDecimal)PDataType.DECIMAL.toObject(ptr, sortOrder)).multiply(BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
-            } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+            if(type == PTimestamp.INSTANCE || type == PUnsignedTimestamp.INSTANCE) {
+                value = (BigDecimal)(PDecimal.INSTANCE.toObject(ptr, type, sortOrder));
+            } else if (type.isCoercibleTo(PDecimal.INSTANCE)) {
+                value = (((BigDecimal) PDecimal.INSTANCE.toObject(ptr, sortOrder)).multiply(BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
+            } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                 value = ((BigDecimal.valueOf(type.getCodec().decodeDouble(ptr, sortOrder))).multiply(BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP);
             } else {
                 value = BigDecimal.valueOf(type.getCodec().decodeLong(ptr, sortOrder));
@@ -75,13 +79,13 @@ public class TimestampSubtractExpression extends SubtractExpression {
         }
         Timestamp ts = DateUtil.getTimestamp(finalResult);
         byte[] resultPtr = new byte[getDataType().getByteSize()];
-        PDataType.TIMESTAMP.toBytes(ts, resultPtr, 0);
+        PTimestamp.INSTANCE.toBytes(ts, resultPtr, 0);
         ptr.set(resultPtr);
         return true;
     }
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.TIMESTAMP;
+        return PTimestamp.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java
index 576ce7c..38c3060 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseDecimalStddevAggregator.java
@@ -26,8 +26,9 @@ import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.expression.ColumnExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.BigDecimalUtil;
 import org.apache.phoenix.util.BigDecimalUtil.Operation;
@@ -76,7 +77,7 @@ public abstract class BaseDecimalStddevAggregator extends DistinctValueWithCount
         if (buffer == null) {
             initBuffer();
         }
-        buffer = PDataType.DECIMAL.toBytes(cachedResult);
+        buffer = PDecimal.INSTANCE.toBytes(cachedResult);
         ptr.set(buffer);
         return true;
     }
@@ -87,7 +88,7 @@ public abstract class BaseDecimalStddevAggregator extends DistinctValueWithCount
         BigDecimal m = mean();
         BigDecimal result = BigDecimal.ZERO;
         for (Entry<ImmutableBytesPtr, Integer> entry : valueVsCount.entrySet()) {
-            BigDecimal colValue = (BigDecimal)PDataType.DECIMAL.toObject(entry.getKey());
+            BigDecimal colValue = (BigDecimal) PDecimal.INSTANCE.toObject(entry.getKey());
             BigDecimal delta = colValue.subtract(m);
             result = result.add(delta.multiply(delta).multiply(new BigDecimal(entry.getValue())));
         }
@@ -97,7 +98,7 @@ public abstract class BaseDecimalStddevAggregator extends DistinctValueWithCount
     private BigDecimal mean() {
         BigDecimal sum = BigDecimal.ZERO;
         for (Entry<ImmutableBytesPtr, Integer> entry : valueVsCount.entrySet()) {
-            BigDecimal colValue = (BigDecimal)PDataType.DECIMAL.toObject(entry.getKey());
+            BigDecimal colValue = (BigDecimal) PDecimal.INSTANCE.toObject(entry.getKey());
             sum = sum.add(colValue.multiply(new BigDecimal(entry.getValue())));
         }
         return sum.divide(new BigDecimal(totalCount), PDataType.DEFAULT_MATH_CONTEXT);
@@ -105,6 +106,6 @@ public abstract class BaseDecimalStddevAggregator extends DistinctValueWithCount
 
     @Override
     protected PDataType getResultDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseStddevAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseStddevAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseStddevAggregator.java
index a1ed1df..cb9861a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseStddevAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/BaseStddevAggregator.java
@@ -24,8 +24,10 @@ import java.util.Map.Entry;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -52,7 +54,7 @@ public abstract class BaseStddevAggregator extends DistinctValueWithCountClientA
         if (buffer == null) {
             initBuffer();
         }
-        buffer = PDataType.DECIMAL.toBytes(cachedResult);
+        buffer = PDecimal.INSTANCE.toBytes(cachedResult);
         ptr.set(buffer);
         return true;
     }
@@ -63,7 +65,7 @@ public abstract class BaseStddevAggregator extends DistinctValueWithCountClientA
         double m = mean();
         double result = 0.0;
         for (Entry<ImmutableBytesPtr, Integer> entry : valueVsCount.entrySet()) {
-            double colValue = (Double)PDataType.DOUBLE.toObject(entry.getKey(), this.stdDevColExp.getDataType());
+            double colValue = (Double) PDouble.INSTANCE.toObject(entry.getKey(), this.stdDevColExp.getDataType());
             double delta = colValue - m;
             result += (delta * delta) * entry.getValue();
         }
@@ -73,7 +75,7 @@ public abstract class BaseStddevAggregator extends DistinctValueWithCountClientA
     private double mean() {
         double sum = 0.0;
         for (Entry<ImmutableBytesPtr, Integer> entry : valueVsCount.entrySet()) {
-            double colValue = (Double)PDataType.DOUBLE.toObject(entry.getKey(), this.stdDevColExp.getDataType());
+            double colValue = (Double) PDouble.INSTANCE.toObject(entry.getKey(), this.stdDevColExp.getDataType());
             sum += colValue * entry.getValue();
         }
         return sum / totalCount;
@@ -81,6 +83,6 @@ public abstract class BaseStddevAggregator extends DistinctValueWithCountClientA
     
     @Override
     protected PDataType getResultDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/CountAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/CountAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/CountAggregator.java
index d815975..bd6725b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/CountAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/CountAggregator.java
@@ -18,7 +18,8 @@
 package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SizedUtil;
@@ -66,7 +67,7 @@ public class CountAggregator extends BaseAggregator {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
     @Override


[13/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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
new file mode 100644
index 0000000..93f6dc1
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBoolean.java
@@ -0,0 +1,140 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Booleans;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PBoolean extends PDataType<Boolean> {
+
+  public static final PBoolean INSTANCE = new PBoolean();
+
+  private PBoolean() {
+    super("BOOLEAN", Types.BOOLEAN, Boolean.class, null, 21);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      // TODO: review - return null?
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return ((Boolean) object).booleanValue() ? TRUE_BYTES : FALSE_BYTES;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      // TODO: review - return null?
+      throw newIllegalDataException(this + " may not be null");
+    }
+    bytes[offset] = ((Boolean) object).booleanValue() ? TRUE_BYTE : FALSE_BYTE;
+    return BOOLEAN_LENGTH;
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    if (object == null) {
+      // TODO: review - return null?
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return ((Boolean) object).booleanValue() ^ sortOrder == SortOrder.ASC ?
+        TRUE_BYTES :
+        FALSE_BYTES;
+  }
+
+  @Override
+  public Boolean toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    Preconditions.checkNotNull(sortOrder);
+    if (length == 0) {
+      return null;
+    }
+    if (actualType == this) {
+      if (length > 1) {
+        throw newIllegalDataException("BOOLEAN may only be a single byte");
+      }
+      return ((bytes[offset] == FALSE_BYTE ^ sortOrder == SortOrder.DESC) ?
+          Boolean.FALSE :
+          Boolean.TRUE);
+    } else if (actualType == PDecimal.INSTANCE) {
+      // false translated to the ZERO_BYTE
+      return ((bytes[offset] == ZERO_BYTE ^ sortOrder == SortOrder.DESC) ?
+          Boolean.FALSE :
+          Boolean.TRUE);
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return super.isCoercibleTo(targetType) || targetType.equals(PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    // Allow cast to BOOLEAN so it can be used in an index or group by
+    return super.isCastableTo(targetType) || targetType.equals(PDecimal.INSTANCE);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return BOOLEAN_LENGTH;
+  }
+
+  @Override
+  public int estimateByteSize(Object o) {
+    return BOOLEAN_LENGTH;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return Booleans.compare((Boolean) lhs, (Boolean) rhs);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    return Boolean.parseBoolean(value);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (actualType == this || object == null) {
+      return object;
+    }
+    if (actualType == PVarbinary.INSTANCE || actualType == PBinary.INSTANCE) {
+      byte[] bytes = (byte[]) object;
+      return toObject(bytes, 0, bytes.length);
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return RANDOM.get().nextBoolean();
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBooleanArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBooleanArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBooleanArray.java
new file mode 100644
index 0000000..dfad7e3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBooleanArray.java
@@ -0,0 +1,108 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PBooleanArray extends PArrayDataType<boolean[]> {
+
+  public static final PBooleanArray INSTANCE = new PBooleanArray();
+
+  private PBooleanArray() {
+    super("BOOLEAN ARRAY", PDataType.ARRAY_TYPE_BASE + PBoolean.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 25);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PBoolean.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return toObject(bytes, offset, length, PBoolean.INSTANCE, sortOrder, maxLength, scale,
+        PBoolean.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] booleanArr = (Object[]) pArr.array;
+    for (Object i : booleanArr) {
+      if (!super.isCoercibleTo(PBoolean.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PBoolean.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
new file mode 100644
index 0000000..3100f89
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
@@ -0,0 +1,203 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Strings;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.exception.ValueTypeIncompatibleException;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.StringUtil;
+
+import java.sql.Types;
+import java.text.Format;
+import java.util.Arrays;
+
+/**
+ * Fixed length single byte characters
+ */
+public class PChar extends PDataType<String> {
+
+  public static final PChar INSTANCE = new PChar();
+
+  private PChar() {
+    super("CHAR", Types.CHAR, String.class, null, 1);
+  }
+
+    @Override
+    public void pad(ImmutableBytesWritable ptr, Integer maxLength) {
+      if (ptr.getLength() >= maxLength) {
+        return;
+      }
+      byte[] newBytes = new byte[maxLength];
+      System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength());
+      Arrays.fill(newBytes, ptr.getLength(), maxLength, StringUtil.SPACE_UTF8);
+      ptr.set(newBytes);
+    }
+
+    @Override
+    public Object pad(Object object, Integer maxLength) {
+      String s = (String) object;
+      if (s == null) {
+        return s;
+      }
+      if (s.length() == maxLength) {
+        return object;
+      }
+      if (s.length() > maxLength) {
+        throw new ValueTypeIncompatibleException(this,maxLength,null);
+      }
+      return Strings.padEnd(s, maxLength, ' ');
+    }
+
+    @Override
+    public byte[] toBytes(Object object) {
+      if (object == null) {
+        throw newIllegalDataException(this + " may not be null");
+      }
+      byte[] b = PVarchar.INSTANCE.toBytes(object);
+      if (b.length != ((String) object).length()) {
+        throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
+      }
+      return b;
+    }
+
+    @Override
+    public int toBytes(Object object, byte[] bytes, int offset) {
+      if (object == null) {
+        throw newIllegalDataException(this + " may not be null");
+      }
+      int len = PVarchar.INSTANCE.toBytes(object, bytes, offset);
+      if (len != ((String) object).length()) {
+        throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
+      }
+      return len;
+    }
+
+    @Override
+    public Object toObject(byte[] bytes, int offset, int length, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+      if (!actualType.isCoercibleTo(this)) { // TODO: have isCoercibleTo that takes bytes, offset?
+        throwConstraintViolationException(actualType,this);
+      }
+      if (length == 0) {
+        return null;
+      }
+      length = StringUtil.getUnpaddedCharLength(bytes, offset, length, sortOrder);
+      if (sortOrder == SortOrder.DESC) {
+        bytes = SortOrder.invert(bytes, offset, length);
+        offset = 0;
+      }
+      // TODO: UTF-8 decoder that will invert as it decodes
+      String s = Bytes.toString(bytes, offset, length);
+      if (length != s.length()) {
+        throw newIllegalDataException("CHAR types may only contain single byte characters (" + s + ")");
+      }
+      return s;
+    }
+
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+      if (equalsAny(actualType, PVarchar.INSTANCE, this)) {
+        String s = (String) object;
+        return s == null || s.length() > 0 ? s : null;
+      }
+      return throwConstraintViolationException(actualType,this);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+      return equalsAny(targetType, this, PVarchar.INSTANCE, PBinary.INSTANCE, PVarbinary.INSTANCE);
+    }
+
+    @Override
+    public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType,
+        Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
+        Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
+      if (o != null && actualType.equals(PVarchar.INSTANCE) && ((String)o).length() != ptr.getLength()) {
+        throw newIllegalDataException("CHAR types may only contain single byte characters (" + o + ")");
+      }
+      super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
+    }
+
+    @Override
+    public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+        Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) {
+      return PVarchar.INSTANCE.isSizeCompatible(ptr, value, srcType, maxLength, scale, desiredMaxLength, desiredScale);
+    }
+
+    @Override
+    public boolean isFixedWidth() {
+      return true;
+    }
+
+    @Override
+    public Integer getByteSize() {
+      return null;
+    }
+
+    @Override
+    public Integer getMaxLength(Object o) {
+      if (o == null) {
+        return null;
+      }
+      String value = (String) o;
+      return value.length();
+    }
+
+    @Override
+    public int estimateByteSize(Object o) {
+      String value = (String) o;
+      return value.length();
+    }
+
+    @Override
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+      return PVarchar.INSTANCE.compareTo(lhs, rhs, rhsType);
+    }
+
+    @Override
+    public Object toObject(String value) {
+      if (value == null || value.length() == 0) {
+        throw newIllegalDataException(this + " may not be null");
+      }
+      if (StringUtil.hasMultiByteChars(value)) {
+        throw newIllegalDataException("CHAR types may only contain single byte characters (" + value + ")");
+      }
+      return value;
+    }
+
+    @Override
+    public Integer estimateByteSizeFromLength(Integer length) {
+      return length;
+    }
+
+    @Override
+    public boolean isBytesComparableWith(PDataType otherType) {
+      return super.isBytesComparableWith(otherType) || otherType.equals(PVarchar.INSTANCE);
+    }
+
+    @Override
+    public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+      return PVarchar.INSTANCE.toStringLiteral(b, offset, length, formatter);
+    }
+
+    @Override
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+      return PVarchar.INSTANCE.getSampleValue(maxLength, arrayLength);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PCharArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PCharArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PCharArray.java
new file mode 100644
index 0000000..89ec5db
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PCharArray.java
@@ -0,0 +1,108 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PCharArray extends PArrayDataType<String[]> {
+
+  public static final PCharArray INSTANCE = new PCharArray();
+
+  private PCharArray() {
+    super("CHAR ARRAY", PDataType.ARRAY_TYPE_BASE + PChar.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 29);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PChar.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return toObject(bytes, offset, length, PChar.INSTANCE, sortOrder, maxLength, scale,
+        PChar.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] charArr = (Object[]) pArr.array;
+    for (Object i : charArr) {
+      if (!super.isCoercibleTo(PChar.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PChar.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
new file mode 100644
index 0000000..85e5711
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataType.java
@@ -0,0 +1,1178 @@
+/*
+ * 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.schema.types;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.text.Format;
+import java.util.Random;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.types.DataType;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.hadoop.hbase.util.PositionedByteRange;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.ConstraintViolationException;
+import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
+
+import com.google.common.base.Preconditions;
+import com.google.common.math.LongMath;
+import com.google.common.primitives.Doubles;
+import com.google.common.primitives.Longs;
+
+/**
+ * The data types of PColumns
+ */
+public abstract class PDataType<T> implements DataType<T>, Comparable<PDataType<?>> {
+
+  private final String sqlTypeName;
+  private final int sqlType;
+  private final Class clazz;
+  private final byte[] clazzNameBytes;
+  private final byte[] sqlTypeNameBytes;
+  private final PDataCodec codec;
+  private final int ordinal;
+
+  protected PDataType(String sqlTypeName, int sqlType, Class clazz, PDataCodec codec, int ordinal) {
+    this.sqlTypeName = sqlTypeName;
+    this.sqlType = sqlType;
+    this.clazz = clazz;
+    this.clazzNameBytes = Bytes.toBytes(clazz.getName());
+    this.sqlTypeNameBytes = Bytes.toBytes(sqlTypeName);
+    this.codec = codec;
+    this.ordinal = ordinal;
+  }
+
+  @Deprecated
+  public static PDataType[] values() {
+    return PDataTypeFactory.getInstance().getOrderedTypes();
+  }
+
+  @Deprecated
+  public int ordinal() {
+    return ordinal;
+  }
+
+  @Override
+  public Class<T> encodedClass() {
+    return getJavaClass();
+  }
+
+  public boolean isCastableTo(PDataType targetType) {
+    return isComparableTo(targetType);
+  }
+
+  public final PDataCodec getCodec() {
+    return codec;
+  }
+
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return this == otherType
+        || this.getClass() == PVarbinary.class
+        || otherType == PVarbinary.INSTANCE
+        || this.getClass() == PBinary.class
+        || otherType == PBinary.INSTANCE;
+  }
+
+  public int estimateByteSize(Object o) {
+    if (isFixedWidth()) {
+      return getByteSize();
+    }
+    if (isArrayType()) {
+      PhoenixArray array = (PhoenixArray) o;
+      int noOfElements = array.numElements;
+      int totalVarSize = 0;
+      for (int i = 0; i < noOfElements; i++) {
+        totalVarSize += array.estimateByteSize(i);
+      }
+      return totalVarSize;
+    }
+    // Non fixed width types must override this
+    throw new UnsupportedOperationException();
+  }
+
+  public Integer getMaxLength(Object o) {
+    return null;
+  }
+
+  public Integer getScale(Object o) {
+    return null;
+  }
+
+  /**
+   * Estimate the byte size from the type length. For example, for char, byte size would be the
+   * same as length. For decimal, byte size would have no correlation with the length.
+   */
+  public Integer estimateByteSizeFromLength(Integer length) {
+    if (isFixedWidth()) {
+      return getByteSize();
+    }
+    if (isArrayType()) {
+      return null;
+    }
+    // If not fixed width, default to say the byte size is the same as length.
+    return length;
+  }
+
+  public final String getSqlTypeName() {
+    return sqlTypeName;
+  }
+
+  public final int getSqlType() {
+    return sqlType;
+  }
+
+  public final Class getJavaClass() {
+    return clazz;
+  }
+
+  public boolean isArrayType() {
+    return false;
+  }
+
+  public final int compareTo(byte[] lhs, int lhsOffset, int lhsLength, SortOrder lhsSortOrder,
+      byte[] rhs, int rhsOffset, int rhsLength, SortOrder rhsSortOrder,
+      PDataType rhsType) {
+    Preconditions.checkNotNull(lhsSortOrder);
+    Preconditions.checkNotNull(rhsSortOrder);
+    if (this.isBytesComparableWith(rhsType)) { // directly compare the bytes
+      return compareTo(lhs, lhsOffset, lhsLength, lhsSortOrder, rhs, rhsOffset, rhsLength,
+          rhsSortOrder);
+    }
+    PDataCodec lhsCodec = this.getCodec();
+    if (lhsCodec
+        == null) { // no lhs native type representation, so convert rhsType to bytes representation of lhsType
+      byte[] rhsConverted =
+          this.toBytes(this.toObject(rhs, rhsOffset, rhsLength, rhsType, rhsSortOrder));
+      if (rhsSortOrder == SortOrder.DESC) {
+        rhsSortOrder = SortOrder.ASC;
+      }
+      if (lhsSortOrder == SortOrder.DESC) {
+        lhs = SortOrder.invert(lhs, lhsOffset, new byte[lhsLength], 0, lhsLength);
+      }
+      return Bytes.compareTo(lhs, lhsOffset, lhsLength, rhsConverted, 0, rhsConverted.length);
+    }
+    PDataCodec rhsCodec = rhsType.getCodec();
+    if (rhsCodec == null) {
+      byte[] lhsConverted =
+          rhsType.toBytes(rhsType.toObject(lhs, lhsOffset, lhsLength, this, lhsSortOrder));
+      if (lhsSortOrder == SortOrder.DESC) {
+        lhsSortOrder = SortOrder.ASC;
+      }
+      if (rhsSortOrder == SortOrder.DESC) {
+        rhs = SortOrder.invert(rhs, rhsOffset, new byte[rhsLength], 0, rhsLength);
+      }
+      return Bytes.compareTo(lhsConverted, 0, lhsConverted.length, rhs, rhsOffset, rhsLength);
+    }
+    // convert to native and compare
+    if (this.isCoercibleTo(PLong.INSTANCE)
+        && rhsType
+        .isCoercibleTo(PLong.INSTANCE)) { // native long to long comparison
+      return Longs.compare(this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder),
+          rhsType.getCodec().decodeLong(rhs, rhsOffset, rhsSortOrder));
+    } else if (isDoubleOrFloat(this) && isDoubleOrFloat(
+        rhsType)) { // native double to double comparison
+      return Doubles.compare(this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder),
+          rhsType.getCodec().decodeDouble(rhs, rhsOffset, rhsSortOrder));
+    } else { // native float/double to long comparison
+      float fvalue = 0.0F;
+      double dvalue = 0.0;
+      long lvalue = 0;
+      boolean isFloat = false;
+      int invert = 1;
+
+      if (this.isCoercibleTo(PLong.INSTANCE)) {
+        lvalue = this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder);
+      } else if (this.getClass() == PFloat.class) {
+        isFloat = true;
+        fvalue = this.getCodec().decodeFloat(lhs, lhsOffset, lhsSortOrder);
+      } else if (this.isCoercibleTo(PDouble.INSTANCE)) {
+        dvalue = this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder);
+      }
+      if (rhsType.isCoercibleTo(PLong.INSTANCE)) {
+        lvalue = rhsType.getCodec().decodeLong(rhs, rhsOffset, rhsSortOrder);
+      } else if (rhsType == PFloat.INSTANCE) {
+        invert = -1;
+        isFloat = true;
+        fvalue = rhsType.getCodec().decodeFloat(rhs, rhsOffset, rhsSortOrder);
+      } else if (rhsType.isCoercibleTo(PDouble.INSTANCE)) {
+        invert = -1;
+        dvalue = rhsType.getCodec().decodeDouble(rhs, rhsOffset, rhsSortOrder);
+      }
+      // Invert the comparison if float/double value is on the RHS
+      return invert * (isFloat ?
+          compareFloatToLong(fvalue, lvalue) :
+          compareDoubleToLong(dvalue, lvalue));
+    }
+  }
+
+  public static boolean isDoubleOrFloat(PDataType type) {
+    return type == PFloat.INSTANCE
+        || type == PDouble.INSTANCE
+        || type == PUnsignedFloat.INSTANCE || type == PUnsignedDouble.INSTANCE;
+  }
+
+  /**
+   * Compares a float against a long. Behaves better than
+   * {@link #compareDoubleToLong(double, long)} for float
+   * values outside of Integer.MAX_VALUE and Integer.MIN_VALUE.
+   *
+   * @param f a float value
+   * @param l a long value
+   * @return -1 if f is less than l, 1 if f is greater than l, and 0 if f is equal to l
+   */
+  private static int compareFloatToLong(float f, long l) {
+    if (f > Integer.MAX_VALUE || f < Integer.MIN_VALUE) {
+      return f < l ? -1 : f > l ? 1 : 0;
+    }
+    long diff = (long) f - l;
+    return Long.signum(diff);
+  }
+
+  /**
+   * Compares a double against a long.
+   *
+   * @param d a double value
+   * @param l a long value
+   * @return -1 if d is less than l, 1 if d is greater than l, and 0 if d is equal to l
+   */
+  private static int compareDoubleToLong(double d, long l) {
+    if (d > Long.MAX_VALUE) {
+      return 1;
+    }
+    if (d < Long.MIN_VALUE) {
+      return -1;
+    }
+    long diff = (long) d - l;
+    return Long.signum(diff);
+  }
+
+  protected static void checkForSufficientLength(byte[] b, int offset, int requiredLength) {
+    if (b.length < offset + requiredLength) {
+      throw new RuntimeException(new SQLExceptionInfo.Builder(SQLExceptionCode.ILLEGAL_DATA)
+          .setMessage(
+              "Expected length of at least " + requiredLength + " bytes, but had " + (b.length
+                  - offset)).build().buildException());
+    }
+  }
+
+  protected static Void throwConstraintViolationException(PDataType source, PDataType target) {
+    throw new ConstraintViolationException(
+        new SQLExceptionInfo.Builder(SQLExceptionCode.TYPE_MISMATCH)
+            .setMessage(source + " cannot be coerced to " + target).build().buildException());
+  }
+
+  protected static RuntimeException newIllegalDataException() {
+    return new IllegalDataException(new SQLExceptionInfo.Builder(SQLExceptionCode.ILLEGAL_DATA)
+        .build().buildException());
+  }
+
+  protected static RuntimeException newIllegalDataException(String msg) {
+    return new IllegalDataException(new SQLExceptionInfo.Builder(SQLExceptionCode.ILLEGAL_DATA)
+        .setMessage(msg).build().buildException());
+  }
+
+  protected static RuntimeException newIllegalDataException(Exception e) {
+    return new IllegalDataException(new SQLExceptionInfo.Builder(SQLExceptionCode.ILLEGAL_DATA)
+        .setRootCause(e).build().buildException());
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    // PDataType's are expected to be singletons.
+    // TODO: this doesn't jive with HBase's DataType
+    if (o == null) return false;
+    return getClass() == o.getClass();
+  }
+
+  /**
+   * @return true when {@code lhs} equals any of {@code rhs}.
+   */
+  public static boolean equalsAny(PDataType lhs, PDataType... rhs) {
+    for (int i = 0; i < rhs.length; i++) {
+      if (lhs.equals(rhs[i])) return true;
+    }
+    return false;
+  }
+
+  public static interface PDataCodec {
+    public long decodeLong(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder);
+
+    public int decodeInt(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder);
+
+    public byte decodeByte(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder);
+
+    public short decodeShort(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder);
+
+    public float decodeFloat(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder);
+
+    public double decodeDouble(ImmutableBytesWritable ptr, SortOrder sortOrder);
+
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder);
+
+    public int encodeLong(long v, ImmutableBytesWritable ptr);
+
+    public int encodeLong(long v, byte[] b, int o);
+
+    public int encodeInt(int v, ImmutableBytesWritable ptr);
+
+    public int encodeInt(int v, byte[] b, int o);
+
+    public int encodeByte(byte v, ImmutableBytesWritable ptr);
+
+    public int encodeByte(byte v, byte[] b, int o);
+
+    public int encodeShort(short v, ImmutableBytesWritable ptr);
+
+    public int encodeShort(short v, byte[] b, int o);
+
+    public int encodeFloat(float v, ImmutableBytesWritable ptr);
+
+    public int encodeFloat(float v, byte[] b, int o);
+
+    public int encodeDouble(double v, ImmutableBytesWritable ptr);
+
+    public int encodeDouble(double v, byte[] b, int o);
+
+    public PhoenixArrayFactory getPhoenixArrayFactory();
+  }
+
+  public static abstract class BaseCodec implements PDataCodec {
+    @Override
+    public int decodeInt(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeInt(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public long decodeLong(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public byte decodeByte(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeByte(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public short decodeShort(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeShort(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public float decodeFloat(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeFloat(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public double decodeDouble(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+      return decodeDouble(ptr.get(), ptr.getOffset(), sortOrder);
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeInt(int v, ImmutableBytesWritable ptr) {
+      return encodeInt(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeLong(long v, ImmutableBytesWritable ptr) {
+      return encodeLong(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeByte(byte v, ImmutableBytesWritable ptr) {
+      return encodeByte(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeShort(short v, ImmutableBytesWritable ptr) {
+      return encodeShort(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeFloat(float v, ImmutableBytesWritable ptr) {
+      return encodeFloat(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeDouble(double v, ImmutableBytesWritable ptr) {
+      return encodeDouble(v, ptr.get(), ptr.getOffset());
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      throw new UnsupportedOperationException();
+    }
+  }
+
+  public static final int MAX_PRECISION = 38;
+      // Max precision guaranteed to fit into a long (and this should be plenty)
+  public static final int MIN_DECIMAL_AVG_SCALE = 4;
+  public static final MathContext DEFAULT_MATH_CONTEXT =
+      new MathContext(MAX_PRECISION, RoundingMode.HALF_UP);
+  public static final int DEFAULT_SCALE = 0;
+
+  protected static final Integer MAX_BIG_DECIMAL_BYTES = 21;
+  protected static final Integer MAX_TIMESTAMP_BYTES = Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT;
+
+  protected static final byte ZERO_BYTE = (byte) 0x80;
+  protected static final byte NEG_TERMINAL_BYTE = (byte) 102;
+  protected static final int EXP_BYTE_OFFSET = 65;
+  protected static final int POS_DIGIT_OFFSET = 1;
+  protected static final int NEG_DIGIT_OFFSET = 101;
+  protected static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
+  protected static final BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
+  protected static final long MAX_LONG_FOR_DESERIALIZE = Long.MAX_VALUE / 1000;
+  protected static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
+
+  protected static final byte FALSE_BYTE = 0;
+  protected static final byte TRUE_BYTE = 1;
+  public static final byte[] FALSE_BYTES = new byte[] { FALSE_BYTE };
+  public static final byte[] TRUE_BYTES = new byte[] { TRUE_BYTE };
+  public static final byte[] NULL_BYTES = ByteUtil.EMPTY_BYTE_ARRAY;
+  protected static final Integer BOOLEAN_LENGTH = 1;
+
+  public final static Integer ZERO = 0;
+  public final static Integer INT_PRECISION = 10;
+  public final static Integer LONG_PRECISION = 19;
+  public final static Integer SHORT_PRECISION = 5;
+  public final static Integer BYTE_PRECISION = 3;
+
+  public static final int ARRAY_TYPE_BASE = 3000;
+  public static final String ARRAY_TYPE_SUFFIX = "ARRAY";
+
+  protected static final ThreadLocal<Random> RANDOM = new ThreadLocal<Random>() {
+    @Override
+    protected Random initialValue() {
+      return new Random();
+    }
+  };
+
+  /**
+   * Serialize a BigDecimal into a variable length byte array in such a way that it is
+   * binary comparable.
+   *
+   * @param v      the BigDecimal
+   * @param result the byte array to contain the serialized bytes.  Max size
+   *               necessary would be 21 bytes.
+   * @param length the number of bytes required to store the big decimal. May be
+   *               adjusted down if it exceeds {@link #MAX_BIG_DECIMAL_BYTES}
+   * @return the number of bytes that make up the serialized BigDecimal
+   */
+  protected static int toBytes(BigDecimal v, byte[] result, final int offset, int length) {
+    // From scale to exponent byte (if BigDecimal is positive):  (-(scale+(scale % 2 == 0 : 0 : 1)) / 2 + 65) | 0x80
+    // If scale % 2 is 1 (i.e. it's odd), then multiple last base-100 digit by 10
+    // For example: new BigDecimal(BigInteger.valueOf(1), -4);
+    // (byte)((-(-4+0) / 2 + 65) | 0x80) = -61
+    // From scale to exponent byte (if BigDecimal is negative): ~(-(scale+1)/2 + 65 + 128) & 0x7F
+    // For example: new BigDecimal(BigInteger.valueOf(1), 2);
+    // ~(-2/2 + 65 + 128) & 0x7F = 63
+    int signum = v.signum();
+    if (signum == 0) {
+      result[offset] = ZERO_BYTE;
+      return 1;
+    }
+    int index = offset + length;
+    int scale = v.scale();
+    int expOffset = scale % 2 * (scale < 0 ? -1 : 1);
+    // In order to get twice as much of a range for scale, it
+    // is multiplied by 2. If the scale is an odd number, then
+    // the first digit is multiplied by 10 to make up for the
+    // scale being off by one.
+    int multiplyBy;
+    BigInteger divideBy;
+    if (expOffset == 0) {
+      multiplyBy = 1;
+      divideBy = ONE_HUNDRED;
+    } else {
+      multiplyBy = 10;
+      divideBy = BigInteger.TEN;
+    }
+    // Normalize the scale based on what is necessary to end up with a base 100 decimal (i.e. 10.123e3)
+    int digitOffset;
+    BigInteger compareAgainst;
+    if (signum == 1) {
+      digitOffset = POS_DIGIT_OFFSET;
+      compareAgainst = MAX_LONG;
+      scale -= (length - 2) * 2;
+      result[offset] = (byte) ((-(scale + expOffset) / 2 + EXP_BYTE_OFFSET) | 0x80);
+    } else {
+      digitOffset = NEG_DIGIT_OFFSET;
+      compareAgainst = MIN_LONG;
+      // Scale adjustment shouldn't include terminal byte in length
+      scale -= (length - 2 - 1) * 2;
+      result[offset] = (byte) (~(-(scale + expOffset) / 2 + EXP_BYTE_OFFSET + 128) & 0x7F);
+      if (length <= MAX_BIG_DECIMAL_BYTES) {
+        result[--index] = NEG_TERMINAL_BYTE;
+      } else {
+        // Adjust length and offset down because we don't have enough room
+        length = MAX_BIG_DECIMAL_BYTES;
+        index = offset + length;
+      }
+    }
+    BigInteger bi = v.unscaledValue();
+    // Use BigDecimal arithmetic until we can fit into a long
+    while (bi.compareTo(compareAgainst) * signum > 0) {
+      BigInteger[] dandr = bi.divideAndRemainder(divideBy);
+      bi = dandr[0];
+      int digit = dandr[1].intValue();
+      result[--index] = (byte) (digit * multiplyBy + digitOffset);
+      multiplyBy = 1;
+      divideBy = ONE_HUNDRED;
+    }
+    long l = bi.longValue();
+    do {
+      long divBy = 100 / multiplyBy;
+      long digit = l % divBy;
+      l /= divBy;
+      result[--index] = (byte) (digit * multiplyBy + digitOffset);
+      multiplyBy = 1;
+    } while (l != 0);
+
+    return length;
+  }
+
+  /**
+   * Deserialize a variable length byte array into a BigDecimal. Note that because of
+   * the normalization that gets done to the scale, if you roundtrip a BigDecimal,
+   * it may not be equal before and after. However, the before and after number will
+   * always compare to be equal (i.e. <nBefore>.compareTo(<nAfter>) == 0)
+   *
+   * @param bytes  the bytes containing the number
+   * @param offset the offset into the byte array
+   * @param length the length of the serialized BigDecimal
+   * @return the BigDecimal value.
+   */
+  protected static BigDecimal toBigDecimal(byte[] bytes, int offset, int length) {
+    // From exponent byte back to scale: (<exponent byte> & 0x7F) - 65) * 2
+    // For example, (((-63 & 0x7F) - 65) & 0xFF) * 2 = 0
+    // Another example: ((-64 & 0x7F) - 65) * 2 = -2 (then swap the sign for the scale)
+    // If number is negative, going from exponent byte back to scale: (byte)((~<exponent byte> - 65 - 128) * 2)
+    // For example: new BigDecimal(new BigInteger("-1"), -2);
+    // (byte)((~61 - 65 - 128) * 2) = 2, so scale is -2
+    // Potentially, when switching back, the scale can be added by one and the trailing zero dropped
+    // For digits, just do a mod 100 on the BigInteger. Use long if BigInteger fits
+    if (length == 1 && bytes[offset] == ZERO_BYTE) {
+      return BigDecimal.ZERO;
+    }
+    int signum = ((bytes[offset] & 0x80) == 0) ? -1 : 1;
+    int scale;
+    int index;
+    int digitOffset;
+    long multiplier = 100L;
+    int begIndex = offset + 1;
+    if (signum == 1) {
+      scale = (byte) (((bytes[offset] & 0x7F) - 65) * -2);
+      index = offset + length;
+      digitOffset = POS_DIGIT_OFFSET;
+    } else {
+      scale = (byte) ((~bytes[offset] - 65 - 128) * -2);
+      index = offset + length - (bytes[offset + length - 1] == NEG_TERMINAL_BYTE ? 1 : 0);
+      digitOffset = -NEG_DIGIT_OFFSET;
+    }
+    length = index - offset;
+    long l = signum * bytes[--index] - digitOffset;
+    if (l % 10 == 0) { // trailing zero
+      scale--; // drop trailing zero and compensate in the scale
+      l /= 10;
+      multiplier = 10;
+    }
+    // Use long arithmetic for as long as we can
+    while (index > begIndex) {
+      if (l >= MAX_LONG_FOR_DESERIALIZE || multiplier >= Long.MAX_VALUE / 100) {
+        multiplier = LongMath.divide(multiplier, 100L, RoundingMode.UNNECESSARY);
+        break; // Exit loop early so we don't overflow our multiplier
+      }
+      int digit100 = signum * bytes[--index] - digitOffset;
+      l += digit100 * multiplier;
+      multiplier = LongMath.checkedMultiply(multiplier, 100);
+    }
+
+    BigInteger bi;
+    // If still more digits, switch to BigInteger arithmetic
+    if (index > begIndex) {
+      bi = BigInteger.valueOf(l);
+      BigInteger biMultiplier = BigInteger.valueOf(multiplier).multiply(ONE_HUNDRED);
+      do {
+        int digit100 = signum * bytes[--index] - digitOffset;
+        bi = bi.add(biMultiplier.multiply(BigInteger.valueOf(digit100)));
+        biMultiplier = biMultiplier.multiply(ONE_HUNDRED);
+      } while (index > begIndex);
+      if (signum == -1) {
+        bi = bi.negate();
+      }
+    } else {
+      bi = BigInteger.valueOf(l * signum);
+    }
+    // Update the scale based on the precision
+    scale += (length - 2) * 2;
+    BigDecimal v = new BigDecimal(bi, scale);
+    return v;
+  }
+
+  // Calculate the precision and scale of a raw decimal bytes. Returns the values as an int
+  // array. The first value is precision, the second value is scale.
+  // Default scope for testing
+  protected static int[] getDecimalPrecisionAndScale(byte[] bytes, int offset, int length) {
+    // 0, which should have no precision nor scale.
+    if (length == 1 && bytes[offset] == ZERO_BYTE) {
+      return new int[] { 0, 0 };
+    }
+    int signum = ((bytes[offset] & 0x80) == 0) ? -1 : 1;
+    int scale;
+    int index;
+    int digitOffset;
+    if (signum == 1) {
+      scale = (byte) (((bytes[offset] & 0x7F) - 65) * -2);
+      index = offset + length;
+      digitOffset = POS_DIGIT_OFFSET;
+    } else {
+      scale = (byte) ((~bytes[offset] - 65 - 128) * -2);
+      index = offset + length - (bytes[offset + length - 1] == NEG_TERMINAL_BYTE ? 1 : 0);
+      digitOffset = -NEG_DIGIT_OFFSET;
+    }
+    length = index - offset;
+    int precision = 2 * (length - 1);
+    int d = signum * bytes[--index] - digitOffset;
+    if (d % 10 == 0) { // trailing zero
+      // drop trailing zero and compensate in the scale and precision.
+      d /= 10;
+      scale--;
+      precision -= 1;
+    }
+    d = signum * bytes[offset + 1] - digitOffset;
+    if (d < 10) { // Leading single digit
+      // Compensate in the precision.
+      precision -= 1;
+    }
+    // Update the scale based on the precision
+    scale += (length - 2) * 2;
+    if (scale < 0) {
+      precision = precision - scale;
+      scale = 0;
+    }
+    return new int[] { precision, scale };
+  }
+
+  public boolean isCoercibleTo(PDataType targetType) {
+    return this.equals(targetType) || targetType.equals(PVarbinary.INSTANCE);
+  }
+
+  // Specialized on enums to take into account type hierarchy (i.e. UNSIGNED_LONG is comparable to INTEGER)
+  public boolean isComparableTo(PDataType targetType) {
+    return targetType.isCoercibleTo(this) || this.isCoercibleTo(targetType);
+  }
+
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return isCoercibleTo(targetType);
+  }
+
+  public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+      Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) {
+    return true;
+  }
+
+  public int compareTo(byte[] b1, byte[] b2) {
+    return compareTo(b1, 0, b1.length, SortOrder.getDefault(), b2, 0, b2.length,
+        SortOrder.getDefault());
+  }
+
+  public final int compareTo(ImmutableBytesWritable ptr1, ImmutableBytesWritable ptr2) {
+    return compareTo(ptr1.get(), ptr1.getOffset(), ptr1.getLength(), SortOrder.getDefault(),
+        ptr2.get(), ptr2.getOffset(), ptr2.getLength(), SortOrder.getDefault());
+  }
+
+  public final int compareTo(byte[] ba1, int offset1, int length1, SortOrder so1, byte[] ba2,
+      int offset2, int length2, SortOrder so2) {
+    Preconditions.checkNotNull(so1);
+    Preconditions.checkNotNull(so2);
+    if (so1 != so2) {
+      int length = Math.min(length1, length2);
+      for (int i = 0; i < length; i++) {
+        byte b1 = ba1[offset1 + i];
+        byte b2 = ba2[offset2 + i];
+        if (so1 == SortOrder.DESC) {
+          b1 = SortOrder.invert(b1);
+        } else {
+          b2 = SortOrder.invert(b2);
+        }
+        int c = b1 - b2;
+        if (c != 0) {
+          return c;
+        }
+      }
+      return (length1 - length2);
+    }
+    return Bytes.compareTo(ba1, offset1, length1, ba2, offset2, length2) * (so1 == SortOrder.DESC ?
+        -1 :
+        1);
+  }
+
+  public final int compareTo(ImmutableBytesWritable ptr1, SortOrder ptr1SortOrder,
+      ImmutableBytesWritable ptr2, SortOrder ptr2SortOrder, PDataType type2) {
+    return compareTo(ptr1.get(), ptr1.getOffset(), ptr1.getLength(), ptr1SortOrder, ptr2.get(),
+        ptr2.getOffset(), ptr2.getLength(), ptr2SortOrder, type2);
+  }
+
+  public int compareTo(Object lhs, Object rhs) {
+    return compareTo(lhs, rhs, this);
+  }
+
+  /*
+   * We need an empty byte array to mean null, since
+   * we have no other representation in the row key
+   * for null.
+   */
+  public final boolean isNull(byte[] value) {
+    return value == null || value.length == 0;
+  }
+
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    Preconditions.checkNotNull(sortOrder);
+    byte[] bytes = toBytes(object);
+    if (sortOrder == SortOrder.DESC) {
+      SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
+    }
+    return bytes;
+  }
+
+  public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType,
+      Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
+      Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
+    Preconditions.checkNotNull(actualModifier);
+    Preconditions.checkNotNull(expectedModifier);
+    if (ptr.getLength() == 0) {
+      return;
+    }
+    if (this.isBytesComparableWith(actualType)) { // No coerce necessary
+      if (actualModifier == expectedModifier) {
+        return;
+      }
+      byte[] b = ptr.copyBytes();
+      SortOrder.invert(b, 0, b, 0, b.length);
+      ptr.set(b);
+      return;
+    }
+
+    // Optimization for cases in which we already have the object around
+    if (o == null) {
+      o = actualType.toObject(ptr, actualType, actualModifier);
+    }
+
+    o = toObject(o, actualType);
+    byte[] b = toBytes(o, expectedModifier);
+    ptr.set(b);
+  }
+
+  public final void coerceBytes(ImmutableBytesWritable ptr, PDataType actualType,
+      SortOrder actualModifier, SortOrder expectedModifier) {
+    coerceBytes(ptr, null, actualType, null, null, actualModifier, null, null, expectedModifier);
+  }
+
+  public final void coerceBytes(ImmutableBytesWritable ptr, PDataType actualType,
+      SortOrder actualModifier,
+      SortOrder expectedModifier, Integer desiredMaxLength) {
+    coerceBytes(ptr, null, actualType, null, null, actualModifier, desiredMaxLength, null,
+        expectedModifier);
+  }
+
+  protected static boolean isNonNegativeDate(java.util.Date date) {
+    return (date == null || date.getTime() >= 0);
+  }
+
+  protected static void throwIfNonNegativeDate(java.util.Date date) {
+    if (!isNonNegativeDate(date)) {
+      throw newIllegalDataException("Value may not be negative(" + date + ")");
+    }
+  }
+
+  protected static boolean isNonNegativeNumber(Number v) {
+    return v == null || v.longValue() >= 0;
+  }
+
+  protected static void throwIfNonNegativeNumber(Number v) {
+    if (!isNonNegativeNumber(v)) {
+      throw newIllegalDataException("Value may not be negative(" + v + ")");
+    }
+  }
+
+  @Override
+  public boolean isNullable() {
+    return false;
+  }
+
+  public abstract Integer getByteSize();
+
+  @Override
+  public int encodedLength(T val) {
+    // default implementation based on existing PDataType methods.
+    return getByteSize();
+  }
+
+  @Override
+  public int skip(PositionedByteRange pbr) {
+    // default implementation based on existing PDataType methods.
+    int len = getByteSize();
+    pbr.setPosition(pbr.getPosition() + len);
+    return len;
+  }
+
+  @Override
+  public boolean isOrderPreserving() {
+    return true;
+  }
+
+  @Override
+  public boolean isSkippable() {
+    return true;
+  }
+
+  @Override
+  public Order getOrder() {
+    return Order.ASCENDING;
+  }
+
+  public abstract boolean isFixedWidth();
+
+  public abstract int compareTo(Object lhs, Object rhs, PDataType rhsType);
+
+  @Override
+  public int compareTo(PDataType<?> other) {
+    return Integer.compare(this.ordinal(), other.ordinal());
+  }
+
+  /**
+   * Convert from the object representation of a data type value into
+   * the serialized byte form.
+   *
+   * @param object the object to convert
+   * @param bytes  the byte array into which to put the serialized form of object
+   * @param offset the offset from which to start writing the serialized form
+   * @return the byte length of the serialized object
+   */
+  public abstract int toBytes(Object object, byte[] bytes, int offset);
+
+  @Override
+  public int encode(PositionedByteRange pbr, T val) {
+    // default implementation based on existing PDataType methods.
+    int pos = pbr.getPosition();
+    pbr.put(toBytes(val));
+    return pbr.getPosition() - pos;
+  }
+
+  @Override
+  public String toString() {
+    return sqlTypeName;
+  }
+
+  public abstract byte[] toBytes(Object object);
+
+  /**
+   * Convert from a string to the object representation of a given type
+   *
+   * @param value a stringified value
+   * @return the object representation of a string value
+   */
+  public abstract Object toObject(String value);
+
+  /*
+   * Each enum must override this to define the set of object it may be coerced to
+   */
+  public abstract Object toObject(Object object, PDataType actualType);
+
+  /*
+   * Each enum must override this to define the set of objects it may create
+   */
+  public abstract Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale);
+
+  @Override
+  public T decode(PositionedByteRange pbr) {
+    // default implementation based on existing PDataType methods.
+    byte[] b = new byte[getByteSize()];
+    pbr.get(b);
+    return (T) toObject(b, 0, b.length, this, SortOrder.ASC, getMaxLength(null), getScale(null));
+  }
+
+  /*
+     * Return a valid object of this enum type
+     */
+  public abstract Object getSampleValue(Integer maxLength, Integer arrayLength);
+
+  public final Object getSampleValue() {
+    return getSampleValue(null);
+  }
+
+  public final Object getSampleValue(Integer maxLength) {
+    return getSampleValue(maxLength, null);
+  }
+
+  public final Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder) {
+    return toObject(bytes, offset, length, actualType, sortOrder, null, null);
+  }
+
+  public final Object toObject(byte[] bytes, int offset, int length, PDataType actualType) {
+    return toObject(bytes, offset, length, actualType, SortOrder.getDefault());
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr, PDataType actualType) {
+    return toObject(ptr, actualType, SortOrder.getDefault());
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr, PDataType actualType,
+      SortOrder sortOrder) {
+    return this.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), actualType, sortOrder);
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return this
+        .toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), actualType, sortOrder, maxLength,
+            scale);
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return this
+        .toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), this, sortOrder, maxLength, scale);
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr) {
+    return toObject(ptr.get(), ptr.getOffset(), ptr.getLength());
+  }
+
+  public final Object toObject(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    return toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), this, sortOrder);
+  }
+
+  public final Object toObject(byte[] bytes, int offset, int length) {
+    return toObject(bytes, offset, length, this);
+  }
+
+  public final Object toObject(byte[] bytes) {
+    return toObject(bytes, SortOrder.getDefault());
+  }
+
+  public final Object toObject(byte[] bytes, SortOrder sortOrder) {
+    return toObject(bytes, 0, bytes.length, this, sortOrder);
+  }
+
+  public final Object toObject(byte[] bytes, SortOrder sortOrder, PDataType actualType) {
+    return toObject(bytes, 0, bytes.length, actualType, sortOrder);
+  }
+
+  public static PDataType fromSqlTypeName(String sqlTypeName) {
+    for (PDataType t : PDataTypeFactory.getInstance().getTypes()) {
+      if (t.getSqlTypeName().equals(sqlTypeName)) return t;
+    }
+    throw newIllegalDataException("Unsupported sql type: " + sqlTypeName);
+  }
+
+  public static int sqlArrayType(String sqlTypeName) {
+    PDataType fromSqlTypeName = fromSqlTypeName(sqlTypeName);
+    return fromSqlTypeName.getSqlType() + PDataType.ARRAY_TYPE_BASE;
+  }
+
+  protected static interface PhoenixArrayFactory {
+    PhoenixArray newArray(PDataType type, Object[] elements);
+  }
+
+  public static PDataType fromTypeId(int typeId) {
+    for (PDataType t : PDataTypeFactory.getInstance().getTypes()) {
+      if (t.getSqlType() == typeId) return t;
+    }
+    throw newIllegalDataException("Unsupported sql type: " + typeId);
+  }
+
+  public String getJavaClassName() {
+    return getJavaClass().getName();
+  }
+
+  public byte[] getJavaClassNameBytes() {
+    return clazzNameBytes;
+  }
+
+  public byte[] getSqlTypeNameBytes() {
+    return sqlTypeNameBytes;
+  }
+
+  /**
+   * By default returns sqlType for the PDataType,
+   * however it allows unknown types (our unsigned types)
+   * to return the regular corresponding sqlType so
+   * that tools like SQuirrel correctly display values
+   * of this type.
+   *
+   * @return integer representing the SQL type for display
+   * of a result set of this type
+   */
+  public int getResultSetSqlType() {
+    return this.sqlType;
+  }
+
+  public KeyRange getKeyRange(byte[] point) {
+    return getKeyRange(point, true, point, true);
+  }
+
+  public final String toStringLiteral(ImmutableBytesWritable ptr, Format formatter) {
+    return toStringLiteral(ptr.get(), ptr.getOffset(), ptr.getLength(), formatter);
+  }
+
+  public final String toStringLiteral(byte[] b, Format formatter) {
+    return toStringLiteral(b, 0, b.length, formatter);
+  }
+
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    Object o = toObject(b, offset, length);
+    if (formatter != null) {
+      return formatter.format(o);
+    }
+    return o.toString();
+  }
+
+  private static final PhoenixArrayFactory DEFAULT_ARRAY_FACTORY = new PhoenixArrayFactory() {
+    @Override public PhoenixArray newArray(PDataType type, Object[] elements) {
+      return new PhoenixArray(type, elements);
+    }
+  };
+
+  public PhoenixArrayFactory getArrayFactory() {
+    if (getCodec() != null)
+      return getCodec().getPhoenixArrayFactory();
+    else
+      return DEFAULT_ARRAY_FACTORY;
+  }
+
+  public static PhoenixArray instantiatePhoenixArray(PDataType actualType, Object[] elements) {
+    return actualType.getArrayFactory().newArray(actualType, elements);
+  }
+
+  public KeyRange getKeyRange(byte[] lowerRange, boolean lowerInclusive, byte[] upperRange,
+      boolean upperInclusive) {
+        /*
+         * Force lower bound to be inclusive for fixed width keys because it makes
+         * comparisons less expensive when you can count on one bound or the other
+         * being inclusive. Comparing two fixed width exclusive bounds against each
+         * other is inherently more expensive, because you need to take into account
+         * if the bigger key is equal to the next key after the smaller key. For
+         * example:
+         *   (A-B] compared against [A-B)
+         * An exclusive lower bound A is bigger than an exclusive upper bound B.
+         * Forcing a fixed width exclusive lower bound key to be inclusive prevents
+         * us from having to do this extra logic in the compare function.
+         */
+    if (lowerRange != KeyRange.UNBOUND && !lowerInclusive && isFixedWidth()) {
+      lowerRange = ByteUtil.nextKey(lowerRange);
+      lowerInclusive = true;
+    }
+    return KeyRange.getKeyRange(lowerRange, lowerInclusive, upperRange, upperInclusive);
+  }
+
+  public static PDataType fromLiteral(Object value) {
+    if (value == null) {
+      return null;
+    }
+    for (PDataType type : PDataType.values()) {
+      if (type.isArrayType()) {
+        PhoenixArray arr = (PhoenixArray) value;
+        if ((type.getSqlType() == arr.baseType.sqlType + PDataType.ARRAY_TYPE_BASE)
+            && type.getJavaClass().isInstance(value)) {
+          return type;
+        }
+      } else {
+        if (type.getJavaClass().isInstance(value)) {
+          return type;
+        }
+      }
+    }
+    throw new UnsupportedOperationException(
+        "Unsupported literal value [" + value + "] of type " + value.getClass().getName());
+  }
+
+  public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    throw new UnsupportedOperationException("Operation not supported for type " + this);
+  }
+
+  public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    throw new UnsupportedOperationException("Operation not supported for type " + this);
+  }
+
+  public Object pad(Object object, Integer maxLength) {
+    return object;
+  }
+
+  public void pad(ImmutableBytesWritable ptr, Integer maxLength) {
+  }
+
+  public static PDataType arrayBaseType(PDataType arrayType) {
+    Preconditions.checkArgument(arrayType.isArrayType(), "Not a phoenix array type");
+    return fromTypeId(arrayType.getSqlType() - ARRAY_TYPE_BASE);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataTypeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataTypeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataTypeFactory.java
new file mode 100644
index 0000000..45a9657
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDataTypeFactory.java
@@ -0,0 +1,118 @@
+/*
+ * 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.schema.types;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Factory avoids circular dependency problem in static initializers across types.
+ */
+public class PDataTypeFactory {
+
+  private static PDataTypeFactory INSTANCE;
+  private final PDataType[] orderedTypes;
+  private final SortedSet<PDataType> types;
+  private final Map<Class<? extends PDataType>, PDataType> classToInstance;
+
+  public static PDataTypeFactory getInstance() {
+    if (INSTANCE == null) {
+      INSTANCE = new PDataTypeFactory();
+    }
+    return INSTANCE;
+  }
+
+  private PDataTypeFactory() {
+    types = new TreeSet<>(new Comparator<PDataType>() {
+      @Override
+      public int compare(PDataType o1, PDataType o2) {
+        return Integer.compare(o1.ordinal(), o2.ordinal());
+      }
+    });    // TODO: replace with ServiceLoader or some other plugin system
+    types.add(PBinary.INSTANCE);
+    types.add(PBinaryArray.INSTANCE);
+    types.add(PChar.INSTANCE);
+    types.add(PCharArray.INSTANCE);
+    types.add(PDecimal.INSTANCE);
+    types.add(PDecimalArray.INSTANCE);
+    types.add(PBoolean.INSTANCE);
+    types.add(PBooleanArray.INSTANCE);
+    types.add(PDate.INSTANCE);
+    types.add(PDateArray.INSTANCE);
+    types.add(PDouble.INSTANCE);
+    types.add(PDoubleArray.INSTANCE);
+    types.add(PFloat.INSTANCE);
+    types.add(PFloatArray.INSTANCE);
+    types.add(PInteger.INSTANCE);
+    types.add(PIntegerArray.INSTANCE);
+    types.add(PLong.INSTANCE);
+    types.add(PLongArray.INSTANCE);
+    types.add(PTime.INSTANCE);
+    types.add(PTimeArray.INSTANCE);
+    types.add(PTimestamp.INSTANCE);
+    types.add(PTimestampArray.INSTANCE);
+    types.add(PSmallint.INSTANCE);
+    types.add(PSmallintArray.INSTANCE);
+    types.add(PTinyint.INSTANCE);
+    types.add(PTinyintArray.INSTANCE);
+    types.add(PUnsignedDate.INSTANCE);
+    types.add(PUnsignedDateArray.INSTANCE);
+    types.add(PUnsignedDouble.INSTANCE);
+    types.add(PUnsignedDoubleArray.INSTANCE);
+    types.add(PUnsignedFloat.INSTANCE);
+    types.add(PUnsignedFloatArray.INSTANCE);
+    types.add(PUnsignedInt.INSTANCE);
+    types.add(PUnsignedIntArray.INSTANCE);
+    types.add(PUnsignedLong.INSTANCE);
+    types.add(PUnsignedLongArray.INSTANCE);
+    types.add(PUnsignedSmallint.INSTANCE);
+    types.add(PUnsignedSmallintArray.INSTANCE);
+    types.add(PUnsignedTime.INSTANCE);
+    types.add(PUnsignedTimeArray.INSTANCE);
+    types.add(PUnsignedTimestamp.INSTANCE);
+    types.add(PUnsignedTimestampArray.INSTANCE);
+    types.add(PUnsignedTinyint.INSTANCE);
+    types.add(PUnsignedTinyintArray.INSTANCE);
+    types.add(PVarbinary.INSTANCE);
+    types.add(PVarbinaryArray.INSTANCE);
+    types.add(PVarchar.INSTANCE);
+    types.add(PVarcharArray.INSTANCE);
+
+    classToInstance = new HashMap<>(types.size());
+    for (PDataType t : types) {
+      classToInstance.put(t.getClass(), t);
+    }
+    orderedTypes = types.toArray(new PDataType[types.size()]);
+  }
+
+  public Set<PDataType> getTypes() {
+    return types;
+  }
+
+  public PDataType[] getOrderedTypes() {
+    return orderedTypes;
+  }
+
+  public PDataType instanceFromClass(Class<? extends PDataType> clazz) {
+    return classToInstance.get(clazz);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
new file mode 100644
index 0000000..9ab2226
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDate.java
@@ -0,0 +1,192 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.DateUtil;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Types;
+import java.text.Format;
+
+public class PDate extends PDataType<Date> {
+
+  public static final PDate INSTANCE = new PDate();
+
+  private PDate() {
+    super("DATE", Types.DATE, Date.class,
+        new DateCodec(), 11); // After TIMESTAMP and DATE to ensure toLiteral finds those first
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    byte[] bytes = new byte[getByteSize()];
+    toBytes(object, bytes, 0);
+    return bytes;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
+    return this.getByteSize();
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    if (equalsAny(actualType, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
+      return new Date(((java.sql.Time) object).getTime());
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      return new Date(((java.sql.Timestamp) object).getTime());
+    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return new Date((Long) object);
+    } else if (actualType == PDecimal.INSTANCE) {
+      return new Date(((BigDecimal) object).longValueExact());
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Date toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (l == 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE, PDate.INSTANCE,
+        PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE, PLong.INSTANCE,
+        PUnsignedLong.INSTANCE)) {
+      return new Date(actualType.getCodec().decodeLong(b, o, sortOrder));
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return new Date(bd.longValueExact());
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return super.isCastableTo(targetType) || equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, PDate.INSTANCE, PTime.INSTANCE, PTimestamp.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      if (equalsAny(targetType, PUnsignedTimestamp.INSTANCE, PUnsignedDate.INSTANCE,
+          PUnsignedTime.INSTANCE)) {
+        return ((java.util.Date) value).getTime() >= 0;
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_LONG;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PTimestamp.INSTANCE || rhsType == PUnsignedTimestamp.INSTANCE) {
+      return -rhsType.compareTo(rhs, lhs, PTime.INSTANCE);
+    }
+    return ((java.util.Date) rhs).compareTo((java.util.Date) lhs);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    return DateUtil.parseDate(value);
+  }
+
+  @Override
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return super.isBytesComparableWith(otherType) || otherType == PTime.INSTANCE;
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
+      // If default formatter has not been overridden,
+      // use one that displays milliseconds.
+      formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
+    }
+    return "'" + super.toStringLiteral(b, offset, length, formatter) + "'";
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+      SortOrder expectedModifier) {
+    if (ptr.getLength() > 0 && actualType == PTimestamp.INSTANCE
+        && actualModifier == expectedModifier) {
+      ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
+      return;
+    }
+    super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+        desiredScale, expectedModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new Date((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class DateCodec extends PLong.LongCodec {
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDateArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDateArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDateArray.java
new file mode 100644
index 0000000..764401c
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDateArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+import java.sql.Date;
+
+public class PDateArray extends PArrayDataType<Date[]> {
+
+  public static final PDateArray INSTANCE = new PDateArray();
+
+  private PDateArray() {
+    super("DATE ARRAY", PDataType.ARRAY_TYPE_BASE + PDate.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 40);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PDate.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return toObject(bytes, offset, length, PDate.INSTANCE, sortOrder, maxLength, scale,
+        PDate.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] dateArr = (Object[]) pArr.array;
+    for (Object i : dateArr) {
+      if (!super.isCoercibleTo(PDate.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale,SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PDate.INSTANCE, arrayLength, maxLength);
+  }
+}


[15/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
deleted file mode 100644
index 59b1417..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ /dev/null
@@ -1,7452 +0,0 @@
-/*
- * 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.schema;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.math.MathContext;
-import java.math.RoundingMode;
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.text.Format;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Random;
-
-import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.util.Base64;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.exception.SQLExceptionInfo;
-import org.apache.phoenix.exception.ValueTypeIncompatibleException;
-import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.util.ByteUtil;
-import org.apache.phoenix.util.DateUtil;
-import org.apache.phoenix.util.NumberUtil;
-import org.apache.phoenix.util.StringUtil;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.math.LongMath;
-import com.google.common.primitives.Booleans;
-import com.google.common.primitives.Doubles;
-import com.google.common.primitives.Longs;
-
-/**
- * The data types of PColumns
- *
- * 
- * 
- * @since 0.1
- *
- * TODO: cleanup implementation to reduce copy/paste duplication
- */
-@SuppressWarnings("rawtypes")
-public enum PDataType {
-	
-    VARCHAR("VARCHAR", Types.VARCHAR, String.class, null) {
-        @Override
-        public byte[] toBytes(Object object) {
-            // TODO: consider using avro UTF8 object instead of String
-            // so that we get get the size easily
-            if (object == null) {
-                return ByteUtil.EMPTY_BYTE_ARRAY;
-            }
-            return Bytes.toBytes((String)object);
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                return 0;
-            }
-            byte[] b = toBytes(object); // TODO: no byte[] allocation: use CharsetEncoder
-            System.arraycopy(b, 0, bytes, offset, b.length);
-            return b.length;
-        }
-
-        @Override
-        public Object toObject(byte[] bytes, int offset, int length, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (!actualType.isCoercibleTo(this)) {
-                throwConstraintViolationException(actualType, this);
-            }
-            if (length == 0) {
-                return null;
-            }
-            if (sortOrder == SortOrder.DESC) {
-                bytes = SortOrder.invert(bytes, offset, length);
-                offset = 0;
-            }
-            return Bytes.toString(bytes, offset, length);
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            switch (actualType) {
-            case VARCHAR:
-            case CHAR:
-                String s = (String)object;
-                return s == null || s.length() > 0 ? s : null;
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || targetType == CHAR || targetType == VARBINARY || targetType == BINARY;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (isCoercibleTo(targetType)) {
-                if (targetType == PDataType.CHAR) {
-                    return value != null;
-                }
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
-                Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) {
-            if (ptr.getLength() != 0 && maxLength != null && desiredMaxLength != null) {
-                return maxLength <= desiredMaxLength;
-            }
-            return true;
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return false;
-        }
-
-        @Override
-        public int estimateByteSize(Object o) {
-            String value = (String) o;
-            return value == null ? 1 : value.length();
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return null;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return ((String)lhs).compareTo((String)rhs);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            return value;
-        }
-
-        @Override
-        public boolean isBytesComparableWith(PDataType otherType) {
-            return super.isBytesComparableWith(otherType) || this == CHAR;
-        }
-
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            while (b[length-1] == 0) {
-                length--;
-            }
-            if (formatter != null) {
-                Object o = toObject(b,offset,length);
-                return "'" + formatter.format(o) + "'";
-            }
-            return "'" + Bytes.toStringBinary(b, offset, length) + "'";
-        }
-
-        private char[] sampleChars = new char[1];
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            Preconditions.checkArgument(maxLength == null || maxLength >= 0);
-            int length = maxLength != null ? maxLength : 1;
-            if (length != sampleChars.length) {
-                sampleChars = new char[length];
-            }
-            for (int i = 0; i < length; i++) {
-                sampleChars[i] = (char) RANDOM.get().nextInt(Byte.MAX_VALUE);
-            }
-            return new String(sampleChars);
-        }
-    },
-    /**
-     * Fixed length single byte characters
-     */
-    CHAR("CHAR", Types.CHAR, String.class, null) { // Delegate to VARCHAR
-        @Override
-        public void pad(ImmutableBytesWritable ptr, Integer maxLength) {
-            if (ptr.getLength() >= maxLength) {
-                return;
-            }
-            byte[] newBytes = new byte[maxLength];
-            System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength());
-            Arrays.fill(newBytes, ptr.getLength(), maxLength, StringUtil.SPACE_UTF8);
-            ptr.set(newBytes);
-        }
-
-        @Override
-        public Object pad(Object object, Integer maxLength) {
-            String s = (String) object;
-            if (s == null) {
-                return s;
-            }
-            if (s.length() == maxLength) {
-                return object;
-            }
-            if (s.length() > maxLength) {
-                throw new ValueTypeIncompatibleException(this,maxLength,null);
-            }
-            return Strings.padEnd(s, maxLength, ' ');
-        }
-        
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            byte[] b = VARCHAR.toBytes(object);
-            if (b.length != ((String) object).length()) {
-                throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
-            }
-            return b;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            int len = VARCHAR.toBytes(object, bytes, offset);
-            if (len != ((String) object).length()) {
-                throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
-            }
-            return len;
-        }
-
-        @Override
-        public Object toObject(byte[] bytes, int offset, int length, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (!actualType.isCoercibleTo(this)) { // TODO: have isCoercibleTo that takes bytes, offset?
-                throwConstraintViolationException(actualType,this);
-            }
-            if (length == 0) {
-                return null;
-            }
-            length = StringUtil.getUnpaddedCharLength(bytes, offset, length, sortOrder);
-            if (sortOrder == SortOrder.DESC) {
-                bytes = SortOrder.invert(bytes, offset, length);
-                offset = 0;
-            }
-            // TODO: UTF-8 decoder that will invert as it decodes
-            String s = Bytes.toString(bytes, offset, length);
-            if (length != s.length()) {
-               throw newIllegalDataException("CHAR types may only contain single byte characters (" + s + ")");
-            }
-            return s;
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            switch (actualType) {
-            case VARCHAR:
-            case CHAR:
-                String s = (String)object;
-                return s == null || s.length() > 0 ? s : null;
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || targetType == VARCHAR || targetType == BINARY || targetType == VARBINARY;
-        }
-
-        @Override
-        public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, 
-                Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
-                Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
-            if (o != null && actualType == PDataType.VARCHAR && ((String)o).length() != ptr.getLength()) {
-                throw newIllegalDataException("CHAR types may only contain single byte characters (" + o + ")");
-            }
-            super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
-        }
-        
-        @Override
-        public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
-                Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) {
-            return VARCHAR.isSizeCompatible(ptr, value, srcType, maxLength, scale, desiredMaxLength, desiredScale);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return null;
-        }
-
-        @Override
-        public Integer getMaxLength(Object o) {
-            if (o == null) {
-                return null;
-            }
-            String value = (String) o;
-            return value.length();
-        }
-
-        @Override
-        public int estimateByteSize(Object o) {
-            String value = (String) o;
-            return value.length();
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return VARCHAR.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            if (StringUtil.hasMultiByteChars(value)) {
-                throw newIllegalDataException("CHAR types may only contain single byte characters (" + value + ")");
-            }
-            return value;
-        }
-
-        @Override
-        public Integer estimateByteSizeFromLength(Integer length) {
-            return length;
-        }
-
-        @Override
-        public boolean isBytesComparableWith(PDataType otherType) {
-            return super.isBytesComparableWith(otherType) || this == VARCHAR;
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            return VARCHAR.toStringLiteral(b, offset, length, formatter);
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return VARCHAR.getSampleValue(maxLength, arrayLength);
-        }
-    },
-    LONG("BIGINT", Types.BIGINT, Long.class, new LongCodec()) {
-        @Override
-        public Integer getScale(Object o) {
-            return ZERO;
-        }
-
-        @Override
-        public byte[] toBytes(Object object) {
-            byte[] b = new byte[Bytes.SIZEOF_LONG];
-            toBytes(object, b, 0);
-            return b;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] b, int o) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            return this.getCodec().encodeLong(((Number)object).longValue(), b, o);
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case LONG:
-            case UNSIGNED_LONG:
-                return object;
-            case UNSIGNED_INT:
-            case INTEGER:
-                long s = (Integer)object;
-                return s;
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-                s = (Byte)object;
-                return s;
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-                s = (Short)object;
-                return s;
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-                Float f = (Float)object;
-                if (f > Long.MAX_VALUE || f < Long.MIN_VALUE) {
-                    throw newIllegalDataException(actualType + " value " + f + " cannot be cast to Long without changing its value");
-                }
-                s = f.longValue();
-                return s;
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                Double de = (Double) object;
-                if (de > Long.MAX_VALUE || de < Long.MIN_VALUE) {
-                    throw newIllegalDataException(actualType + " value " + de + " cannot be cast to Long without changing its value");
-                }
-                s = de.longValue();
-                return s;
-            case DECIMAL:
-                BigDecimal d = (BigDecimal)object;
-                return d.longValueExact();
-            case DATE:
-            case UNSIGNED_DATE:
-            case TIME:
-            case UNSIGNED_TIME:
-                java.util.Date date = (java.util.Date)object;
-                return date.getTime();
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public Long toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case LONG:
-            case UNSIGNED_LONG:
-            case INTEGER:
-            case UNSIGNED_INT:
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-            case DATE:
-            case UNSIGNED_DATE:
-            case TIME:
-            case UNSIGNED_TIME:
-                return actualType.getCodec().decodeLong(b, o, sortOrder);
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return bd.longValueExact();
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            // In general, don't allow conversion of LONG to INTEGER. There are times when
-            // we check isComparableTo for a more relaxed check and then throw a runtime
-            // exception if we overflow
-            return this == targetType || targetType == DECIMAL
-                    || targetType == VARBINARY || targetType == BINARY
-                    || targetType == DOUBLE;
-        }
-
-        @Override
-        public boolean isComparableTo(PDataType targetType) {
-            return DECIMAL.isComparableTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                long l;
-                switch (targetType) {
-                    case UNSIGNED_DOUBLE:
-                    case UNSIGNED_FLOAT:
-                    case UNSIGNED_LONG:
-                        l = (Long) value;
-                        return l >= 0;
-                    case UNSIGNED_INT:
-                        l = (Long) value;
-                        return (l >= 0 && l <= Integer.MAX_VALUE);
-                    case INTEGER:
-                        l = (Long) value;
-                        return (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE);
-                    case UNSIGNED_SMALLINT:
-                        l = (Long) value;
-                        return (l >= 0 && l <= Short.MAX_VALUE);
-                    case SMALLINT:
-                        l = (Long) value;
-                        return (l >=Short.MIN_VALUE && l<=Short.MAX_VALUE);
-                    case TINYINT:
-                        l = (Long)value;
-                        return (l >=Byte.MIN_VALUE && l<Byte.MAX_VALUE);
-                    case UNSIGNED_TINYINT:
-                        l = (Long)value;
-                        return (l >=0 && l<Byte.MAX_VALUE);
-                    default:
-                        break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return super.isCastableTo(targetType) || targetType.isCoercibleTo(TIMESTAMP);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_LONG;
-        }
-
-        @Override
-        public Integer getMaxLength(Object o) {
-            return LONG_PRECISION;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            if (rhsType == DECIMAL) {
-                return -((BigDecimal)rhs).compareTo(BigDecimal.valueOf(((Number)lhs).longValue()));
-            } else if (rhsType == DOUBLE || rhsType == FLOAT || rhsType == UNSIGNED_DOUBLE || rhsType == UNSIGNED_FLOAT) {
-                return Doubles.compare(((Number)lhs).doubleValue(), ((Number)rhs).doubleValue());
-            }
-            return Longs.compare(((Number)lhs).longValue(), ((Number)rhs).longValue());
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            try {
-                return Long.parseLong(value);
-            } catch (NumberFormatException e) {
-                throw newIllegalDataException(e);
-            }
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return RANDOM.get().nextLong();
-        }
-    },
-    INTEGER("INTEGER", Types.INTEGER, Integer.class, new IntCodec()) {
-        @Override
-        public Integer getScale(Object o) {
-            return ZERO;
-        }
-    	
-        @Override
-        public byte[] toBytes(Object object) {
-            byte[] b = new byte[Bytes.SIZEOF_INT];
-            toBytes(object, b, 0);
-            return b;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] b, int o) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            return this.getCodec().encodeInt(((Number)object).intValue(), b, o);
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            Object o = LONG.toObject(object, actualType);
-            if (!(o instanceof Long) || o == null) {
-                return o;
-            }
-            long l = (Long)o;
-            if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
-                throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Integer without changing its value");
-            }
-            int v = (int)l;
-            return v;
-        }
-
-        @Override
-        public Integer toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case LONG:
-            case UNSIGNED_LONG:
-            case INTEGER:
-            case UNSIGNED_INT:
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                return actualType.getCodec().decodeInt(b, o, sortOrder);
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return bd.intValueExact();
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                switch (targetType) {
-                    case UNSIGNED_DOUBLE:
-                    case UNSIGNED_FLOAT:
-                    case UNSIGNED_LONG:
-                    case UNSIGNED_INT:
-                        int i = (Integer) value;
-                        return i >= 0;
-                    case UNSIGNED_SMALLINT:
-                        i = (Integer) value;
-                        return (i >= 0 && i <= Short.MAX_VALUE);
-                    case SMALLINT:
-                        i = (Integer) value;
-                        return (i >=Short.MIN_VALUE && i<=Short.MAX_VALUE);
-                    case TINYINT:
-                        i = (Integer)value;
-                        return (i >=Byte.MIN_VALUE && i<=Byte.MAX_VALUE);
-                    case UNSIGNED_TINYINT:
-                        i = (Integer)value;
-                        return (i >=0 && i<Byte.MAX_VALUE);
-                    default:
-                        break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || targetType == FLOAT || LONG.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_INT;
-        }
-
-        @Override
-        public Integer getMaxLength(Object o) {
-            return INT_PRECISION;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return LONG.compareTo(lhs,rhs,rhsType);
-        }
-
-        @Override
-        public boolean isComparableTo(PDataType targetType) {
-            return DECIMAL.isComparableTo(targetType);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            try {
-                return Integer.parseInt(value);
-            } catch (NumberFormatException e) {
-                throw newIllegalDataException(e);
-            }
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return RANDOM.get().nextInt();
-        }
-    },
-    SMALLINT("SMALLINT", Types.SMALLINT, Short.class, new ShortCodec()){
-        @Override
-        public Integer getScale(Object o) {
-            return ZERO;
-        }
-
-      @Override
-      public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-        return LONG.compareTo(lhs, rhs, rhsType);
-      }
-      
-      @Override
-      public boolean isComparableTo(PDataType targetType) {
-          return DECIMAL.isComparableTo(targetType);
-      }
-
-      @Override
-      public boolean isFixedWidth() {
-        return true;
-      }
-
-      @Override
-      public Integer getByteSize() {
-        return Bytes.SIZEOF_SHORT;
-      }
-
-      @Override
-      public Integer getMaxLength(Object o) {
-          return SHORT_PRECISION;
-      }
-
-      @Override
-      public byte[] toBytes(Object object) {
-        byte[] b = new byte[Bytes.SIZEOF_SHORT];
-        toBytes(object, b, 0);
-        return b;
-      }
-
-      @Override
-      public int toBytes(Object object, byte[] bytes, int offset) {
-        if (object == null) {
-          throw newIllegalDataException(this + " may not be null");
-        }
-        return this.getCodec().encodeShort(((Number)object).shortValue(), bytes, offset);
-      }
-      
-      @Override
-      public Object toObject(Object object, PDataType actualType) {
-          Object o = LONG.toObject(object, actualType);
-          if (!(o instanceof Long) || o == null) {
-              return o;
-          }
-          long l = (Long)o;
-          if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) {
-              throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Short without changing its value");
-          }
-          short s = (short)l;
-          return s;
-      }
-
-      @Override
-      public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-          if (l == 0) {
-              return null;
-          }
-          switch (actualType) {
-          case SMALLINT:
-          case UNSIGNED_SMALLINT:
-          case TINYINT:
-          case UNSIGNED_TINYINT:
-          case LONG:
-          case UNSIGNED_LONG:
-          case INTEGER:
-          case UNSIGNED_INT:
-          case FLOAT:
-          case UNSIGNED_FLOAT:
-          case DOUBLE:
-          case UNSIGNED_DOUBLE:
-              return actualType.getCodec().decodeShort(b, o, sortOrder);
-          case DECIMAL:
-              BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-              return bd.shortValueExact();
-          }
-          throwConstraintViolationException(actualType,this);
-          return null;
-      }
-
-      @Override
-      public Object toObject(String value) {
-        if (value == null || value.length() == 0) {
-          return null;
-        }
-        try {
-            return Short.parseShort(value);
-        } catch (NumberFormatException e) {
-            throw newIllegalDataException(e);
-        }
-      }
-      
-      @Override
-      public boolean isCoercibleTo(PDataType targetType, Object value) {
-          if (value != null) {
-              switch (targetType) {
-                  case UNSIGNED_DOUBLE:
-                  case UNSIGNED_FLOAT:
-                  case UNSIGNED_LONG:
-                  case UNSIGNED_INT:
-                  case UNSIGNED_SMALLINT:
-                      short i = (Short) value;
-                      return i >= 0;
-                  case UNSIGNED_TINYINT:
-                      i = (Short) value;
-                      return (i>=0 && i<= Byte.MAX_VALUE);
-                  case TINYINT:
-                      i = (Short)value;
-                      return (i>=Byte.MIN_VALUE && i<= Byte.MAX_VALUE);
-                  default:
-                      break;
-              }
-          }
-          return super.isCoercibleTo(targetType, value);
-      }
-
-      @Override
-      public boolean isCoercibleTo(PDataType targetType) {
-          return this == targetType || INTEGER.isCoercibleTo(targetType);
-      }
-
-      @Override
-      public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-          return ((Integer) INTEGER.getSampleValue(maxLength, arrayLength)).shortValue();
-      }
-
-    },
-    TINYINT("TINYINT", Types.TINYINT, Byte.class, new ByteCodec()) {
-        @Override
-        public Integer getScale(Object o) {
-            return ZERO;
-        }
-
-      @Override
-      public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-        return LONG.compareTo(lhs, rhs, rhsType);
-      }
-      
-      @Override
-      public boolean isComparableTo(PDataType targetType) {
-          return DECIMAL.isComparableTo(targetType);
-      }
-
-      @Override
-      public boolean isFixedWidth() {
-        return true;
-      }
-
-      @Override
-      public Integer getByteSize() {
-        return Bytes.SIZEOF_BYTE;
-      }
-      
-      @Override
-      public Integer getMaxLength(Object o) {
-          return BYTE_PRECISION;
-      }
-
-      @Override
-      public byte[] toBytes(Object object) {
-        byte[] b = new byte[Bytes.SIZEOF_BYTE];
-        toBytes(object, b, 0);
-        return b;
-      }
-
-      @Override
-      public int toBytes(Object object, byte[] bytes, int offset) {
-        if (object == null) {
-          throw newIllegalDataException(this + " may not be null");
-        }
-        return this.getCodec().encodeByte(((Number)object).byteValue(), bytes, offset);
-      }
-
-      @Override
-      public Object toObject(String value) {
-        if (value == null || value.length() == 0) {
-          return null;
-        }
-        try {
-          Byte b = Byte.parseByte(value);
-          return b;
-        } catch (NumberFormatException e) {
-          throw newIllegalDataException(e);
-        }
-      }
-      
-      @Override
-      public Object toObject(Object object, PDataType actualType) {
-          Object o = LONG.toObject(object, actualType);
-          if(!(o instanceof Long) || o == null) {
-              return o;
-          }
-          long l = (Long)o;
-          if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) {
-              throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Byte without changing its value");
-          }
-          return (byte)l;
-      }
-      
-      @Override
-      public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-          if (l == 0) {
-              return null;
-          }
-          switch (actualType) {
-          case UNSIGNED_DOUBLE:
-          case DOUBLE:
-          case UNSIGNED_FLOAT:
-          case FLOAT:
-          case UNSIGNED_LONG:
-          case LONG:
-          case UNSIGNED_INT:
-          case INTEGER:
-          case UNSIGNED_SMALLINT:
-          case SMALLINT:
-          case UNSIGNED_TINYINT:
-          case TINYINT:
-              return actualType.getCodec().decodeByte(b, o, sortOrder);
-          case DECIMAL:
-              BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-              return bd.byteValueExact();
-          }
-          throwConstraintViolationException(actualType,this);
-          return null;
-      }
-      
-      @Override
-      public boolean isCoercibleTo(PDataType targetType, Object value) {
-          if (value != null) {
-              switch (targetType) {
-                  case UNSIGNED_DOUBLE:
-                  case UNSIGNED_FLOAT:
-                  case UNSIGNED_LONG:
-                  case UNSIGNED_INT:
-                  case UNSIGNED_SMALLINT:
-                  case UNSIGNED_TINYINT:
-                      byte i = (Byte) value;
-                      return i >= 0;
-                  default:
-                      break;
-              }
-          }
-          return super.isCoercibleTo(targetType, value);
-      }
-      
-      @Override
-      public boolean isCoercibleTo(PDataType targetType) {
-          return this == targetType || SMALLINT.isCoercibleTo(targetType);
-      }
-      
-      @Override
-      public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-          return ((Integer) INTEGER.getSampleValue(maxLength, arrayLength)).byteValue();
-      }
-
-    },
-    FLOAT("FLOAT", Types.FLOAT, Float.class, new FloatCodec()) {
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return DOUBLE.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_FLOAT;
-        }
-        
-        @Override
-        public Integer getScale(Object o) {
-            if (o == null) {
-                return null;
-            }
-            Float v = (Float) o;
-            BigDecimal bd = BigDecimal.valueOf(v);
-            return bd.scale() == 0 ? null : bd.scale();
-        }
-        
-        @Override
-        public Integer getMaxLength(Object o) {
-            if (o == null) {
-                return null;
-            }
-            Float v = (Float) o;
-            BigDecimal bd = BigDecimal.valueOf(v);
-            return bd.precision();
-        }
-
-        @Override
-        public byte[] toBytes(Object object) {
-            byte[] b = new byte[Bytes.SIZEOF_FLOAT];
-            toBytes(object, b, 0);
-            return b;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            return this.getCodec().encodeFloat(((Number) object).floatValue(),
-                    bytes, offset);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            try {
-                return Float.parseFloat(value);
-            } catch (NumberFormatException e) {
-                throw newIllegalDataException(e);
-            }
-        }
-        
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-                return object;
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                double d = (Double)object;
-                if (Double.isNaN(d)
-                        || d == Double.POSITIVE_INFINITY
-                        || d == Double.NEGATIVE_INFINITY
-                        || (d >= -Float.MAX_VALUE && d <= Float.MAX_VALUE)) {
-                    return (float) d;
-                } else {
-                    throw newIllegalDataException(actualType + " value " + d + " cannot be cast to Float without changing its value");
-                }
-            case LONG:
-            case UNSIGNED_LONG:
-                float f = (Long)object;
-                return f;
-            case UNSIGNED_INT:
-            case INTEGER:
-                f = (Integer)object;
-                return f;
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-                f = (Byte)object;
-                return f;
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-                f = (Short)object;
-                return f;
-            case DECIMAL:
-                BigDecimal dl = (BigDecimal)object;
-                return dl.floatValue();
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-        
-        @Override
-        public Float toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l <= 0) {
-                return null;
-            }
-            switch (actualType) {
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-            case UNSIGNED_LONG:
-            case LONG:
-            case UNSIGNED_INT:
-            case INTEGER:
-            case UNSIGNED_SMALLINT:
-            case SMALLINT:
-            case UNSIGNED_TINYINT:
-            case TINYINT:
-                return actualType.getCodec().decodeFloat(b, o, sortOrder);
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return bd.floatValue();
-            }
-            
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-        
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                float f = (Float)value;
-                switch (targetType) {
-                case UNSIGNED_FLOAT:
-                    return f >= 0;
-                case UNSIGNED_LONG:
-                    return (f >= 0 && f <= Long.MAX_VALUE);
-                case LONG:
-                    return (f >= Long.MIN_VALUE && f <= Long.MAX_VALUE);
-                case UNSIGNED_INT:
-                    return (f >= 0 && f <= Integer.MAX_VALUE);
-                case INTEGER:
-                    return (f >= Integer.MIN_VALUE && f <= Integer.MAX_VALUE);
-                case UNSIGNED_SMALLINT:
-                    return (f >= 0 && f <= Short.MAX_VALUE);
-                case SMALLINT:
-                    return (f >=Short.MIN_VALUE && f<=Short.MAX_VALUE);
-                case TINYINT:
-                    return (f >=Byte.MIN_VALUE && f<Byte.MAX_VALUE);
-                case UNSIGNED_TINYINT:
-                    return (f >=0 && f<Byte.MAX_VALUE);
-                default:
-                    break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-        
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || DOUBLE.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return RANDOM.get().nextFloat();
-        }
-    },
-    DOUBLE("DOUBLE", Types.DOUBLE, Double.class, new DoubleCodec()) {
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            if (rhsType == DECIMAL) {
-                return -((BigDecimal)rhs).compareTo(BigDecimal.valueOf(((Number)lhs).doubleValue()));
-            }
-            return Doubles.compare(((Number)lhs).doubleValue(), ((Number)rhs).doubleValue());
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_DOUBLE;
-        }
-        
-        @Override
-        public Integer getScale(Object o) {
-            if (o == null) {
-                return null;
-            }
-            Double v = (Double) o;
-            BigDecimal bd = BigDecimal.valueOf(v);
-            return bd.scale() == 0 ? null : bd.scale();
-        }
-        
-        @Override
-        public Integer getMaxLength(Object o) {
-            if (o == null) {
-                return null;
-            }
-            Double v = (Double) o;
-            BigDecimal db = BigDecimal.valueOf(v);
-            return db.precision();
-        }
-
-        @Override
-        public byte[] toBytes(Object object) {
-            byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
-            toBytes(object, b, 0);
-            return b;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            } 
-            return this.getCodec().encodeDouble(((Number) object).doubleValue(),
-                    bytes, offset); 
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            try {
-                return Double.parseDouble(value);
-            } catch (NumberFormatException e) {
-                throw newIllegalDataException(e);
-            }
-        }
-        
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            double de;
-            switch (actualType) {
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                return object; 
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-                de = (Float)object;
-                return de;
-            case LONG:
-            case UNSIGNED_LONG:
-                de = (Long)object;
-                return de;
-            case UNSIGNED_INT:
-            case INTEGER:
-                de = (Integer)object;
-                return de;
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-                de = (Byte)object;
-                return de;
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-                de = (Short)object;
-                return de;
-            case DECIMAL:
-                BigDecimal d = (BigDecimal)object;
-                return d.doubleValue();
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-        
-        @Override
-        public Double toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l <= 0) {
-                return null;
-            }
-            switch (actualType) {
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-            case UNSIGNED_LONG:
-            case LONG:
-            case UNSIGNED_INT:
-            case INTEGER:
-            case UNSIGNED_SMALLINT:
-            case SMALLINT:
-            case UNSIGNED_TINYINT:
-            case TINYINT:
-                return actualType.getCodec().decodeDouble(b, o, sortOrder);
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return bd.doubleValue();
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-        
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                double d = (Double)value;
-                switch (targetType) {
-                case UNSIGNED_DOUBLE:
-                    return d >= 0;
-                case FLOAT:
-                    return Double.isNaN(d)
-                            || d == Double.POSITIVE_INFINITY
-                            || d == Double.NEGATIVE_INFINITY
-                            || (d >= -Float.MAX_VALUE && d <= Float.MAX_VALUE);
-                case UNSIGNED_FLOAT:
-                    return Double.isNaN(d) || d == Double.POSITIVE_INFINITY
-                            || (d >= 0 && d <= Float.MAX_VALUE);
-                case UNSIGNED_LONG:
-                    return (d >= 0 && d <= Long.MAX_VALUE);
-                case LONG:
-                    return (d >= Long.MIN_VALUE && d <= Long.MAX_VALUE);
-                case UNSIGNED_INT:
-                    return (d >= 0 && d <= Integer.MAX_VALUE);
-                case INTEGER:
-                    return (d >= Integer.MIN_VALUE && d <= Integer.MAX_VALUE);
-                case UNSIGNED_SMALLINT:
-                    return (d >= 0 && d <= Short.MAX_VALUE);
-                case SMALLINT:
-                    return (d >=Short.MIN_VALUE && d<=Short.MAX_VALUE);
-                case TINYINT:
-                    return (d >=Byte.MIN_VALUE && d<Byte.MAX_VALUE);
-                case UNSIGNED_TINYINT:
-                    return (d >=0 && d<Byte.MAX_VALUE);
-                default:
-                    break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-        
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || targetType == DECIMAL
-                    || targetType == VARBINARY || targetType == BINARY;
-        }
-        
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return RANDOM.get().nextDouble();
-        }
-    },
-    DECIMAL("DECIMAL", Types.DECIMAL, BigDecimal.class, null) {
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                return ByteUtil.EMPTY_BYTE_ARRAY;
-            }
-            BigDecimal v = (BigDecimal) object;
-            v = NumberUtil.normalize(v);
-            int len = getLength(v);
-            byte[] result = new byte[Math.min(len, MAX_BIG_DECIMAL_BYTES)];
-            PDataType.toBytes(v, result, 0, len);
-            return result;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                return 0;
-            }
-            BigDecimal v = (BigDecimal) object;
-            v = NumberUtil.normalize(v);
-            int len = getLength(v);
-            return PDataType.toBytes(v, bytes, offset, len);
-        }
-
-        private int getLength(BigDecimal v) {
-            int signum = v.signum();
-            if (signum == 0) { // Special case for zero
-                return 1;
-            }
-            /*
-             * Size of DECIMAL includes:
-             * 1) one byte for exponent
-             * 2) one byte for terminal byte if negative
-             * 3) one byte for every two digits with the following caveats:
-             *    a) add one to round up in the case when there is an odd number of digits
-             *    b) add one in the case that the scale is odd to account for 10x of lowest significant digit
-             *       (basically done to increase the range of exponents that can be represented)
-             */
-            return (signum < 0 ? 2 : 1) + (v.precision() +  1 + (v.scale() % 2 == 0 ? 0 : 1)) / 2;
-        }
-
-        @Override
-        public int estimateByteSize(Object o) {
-            if (o == null) {
-                return 1;
-            }
-            BigDecimal v = (BigDecimal) o;
-            // TODO: should we strip zeros and round here too?
-            return Math.min(getLength(v),MAX_BIG_DECIMAL_BYTES);
-        }
-
-        @Override
-        public Integer getMaxLength(Object o) {
-            if (o == null) {
-                return MAX_PRECISION;
-            }
-            BigDecimal v = (BigDecimal) o;
-            return v.precision();
-        }
-
-        @Override
-        public Integer getScale(Object o) {
-            return null;
-        }
-
-        @Override
-        public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            Preconditions.checkNotNull(sortOrder);        	
-            if (l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case DECIMAL:
-                if (sortOrder == SortOrder.DESC) {
-                    b = SortOrder.invert(b, o, new byte[l], 0, l);
-                    o = 0;
-                }
-                return toBigDecimal(b, o, l);
-            case DATE:
-            case TIME:
-            case UNSIGNED_DATE:
-            case UNSIGNED_TIME:
-            case LONG:
-            case UNSIGNED_LONG:
-            case INTEGER:
-            case SMALLINT:
-            case TINYINT:
-            case UNSIGNED_INT:
-            case UNSIGNED_SMALLINT:
-            case UNSIGNED_TINYINT:
-                return BigDecimal.valueOf(actualType.getCodec().decodeLong(b, o, sortOrder));
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-                return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder));
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder));
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                long millisPart = actualType.getCodec().decodeLong(b, o, sortOrder);
-                int nanoPart = UNSIGNED_INT.getCodec().decodeInt(b, o+Bytes.SIZEOF_LONG, sortOrder);
-                BigDecimal nanosPart = BigDecimal.valueOf((nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)/QueryConstants.MILLIS_TO_NANOS_CONVERTOR);
-                BigDecimal value = BigDecimal.valueOf(millisPart).add(nanosPart);
-                return value;
-            case BOOLEAN:
-                return (Boolean)BOOLEAN.toObject(b, o, l, actualType, sortOrder) ? BigDecimal.ONE : BigDecimal.ZERO;
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case INTEGER:
-            case UNSIGNED_INT:
-                return BigDecimal.valueOf((Integer)object);
-            case LONG:
-            case UNSIGNED_LONG:
-                return BigDecimal.valueOf((Long)object);
-            case SMALLINT:
-            case UNSIGNED_SMALLINT:
-                return BigDecimal.valueOf((Short)object);
-            case TINYINT:
-            case UNSIGNED_TINYINT:
-                return BigDecimal.valueOf((Byte)object);
-            case FLOAT:
-            case UNSIGNED_FLOAT:
-                return BigDecimal.valueOf((Float)object);
-            case DOUBLE:
-            case UNSIGNED_DOUBLE:
-                return BigDecimal.valueOf((Double)object);
-            case DECIMAL:
-                return object;
-            case DATE:
-            case UNSIGNED_DATE:
-            case TIME:
-            case UNSIGNED_TIME:
-                java.util.Date d = (java.util.Date)object;
-                return BigDecimal.valueOf(d.getTime());
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                Timestamp ts = (Timestamp)object;
-                long millisPart = ts.getTime();
-                BigDecimal nanosPart = BigDecimal.valueOf((ts.getNanos() % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)/QueryConstants.MILLIS_TO_NANOS_CONVERTOR);
-                BigDecimal value = BigDecimal.valueOf(millisPart).add(nanosPart);
-                return value;
-            case BOOLEAN:
-                return ((Boolean)object) ? BigDecimal.ONE : BigDecimal.ZERO;
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return false;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return MAX_BIG_DECIMAL_BYTES;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            if (rhsType == DECIMAL) {
-                return ((BigDecimal)lhs).compareTo((BigDecimal)rhs);
-            }
-            return -rhsType.compareTo(rhs, lhs, this);
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return super.isCastableTo(targetType) || targetType.isCoercibleTo(TIMESTAMP) || targetType == BOOLEAN;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                BigDecimal bd;
-                switch (targetType) {
-                    case UNSIGNED_LONG:
-                    case UNSIGNED_INT:
-                    case UNSIGNED_SMALLINT:
-                    case UNSIGNED_TINYINT:
-                        bd = (BigDecimal) value;
-                        if (bd.signum() == -1) {
-                            return false;
-                        }
-                    case LONG:
-                        bd = (BigDecimal) value;
-                        try {
-                            bd.longValueExact();
-                            return true;
-                        } catch (ArithmeticException e) {
-                            return false;
-                        }
-                    case INTEGER:
-                        bd = (BigDecimal) value;
-                        try {
-                            bd.intValueExact();
-                            return true;
-                        } catch (ArithmeticException e) {
-                            return false;
-                        }
-                    case SMALLINT:
-                        bd = (BigDecimal) value;
-                        try {
-                            bd.shortValueExact();
-                            return true;
-                        } catch (ArithmeticException e) {
-                            return false;
-                        }
-                    case TINYINT:
-                        bd = (BigDecimal) value;
-                        try {
-                            bd.byteValueExact();
-                            return true;
-                        } catch (ArithmeticException e) {
-                            return false;
-                        }
-                    case UNSIGNED_FLOAT:
-                        bd = (BigDecimal) value;
-                        try {
-                            BigDecimal maxFloat = MAX_FLOAT_AS_BIG_DECIMAL;
-                            boolean isNegtive = (bd.signum() == -1);
-                            return bd.compareTo(maxFloat)<=0 && !isNegtive;
-                        } catch(Exception e) {
-                            return false;
-                        }
-                    case FLOAT:
-                        bd = (BigDecimal) value;
-                        try {
-                            BigDecimal maxFloat = MAX_FLOAT_AS_BIG_DECIMAL;
-                            // Float.MIN_VALUE should not be used here, as this is the
-                            // smallest in terms of closest to zero.
-                            BigDecimal minFloat = MIN_FLOAT_AS_BIG_DECIMAL;
-                            return bd.compareTo(maxFloat)<=0 && bd.compareTo(minFloat)>=0;
-                        } catch(Exception e) {
-                            return false;
-                        }
-                    case UNSIGNED_DOUBLE:
-                        bd = (BigDecimal) value;
-                        try {
-                            BigDecimal maxDouble = MAX_DOUBLE_AS_BIG_DECIMAL;
-                            boolean isNegtive = (bd.signum() == -1);
-                            return bd.compareTo(maxDouble)<=0 && !isNegtive;
-                        } catch(Exception e) {
-                            return false;
-                        }
-                    case DOUBLE:
-                        bd = (BigDecimal) value;
-                        try {
-                            BigDecimal maxDouble = MAX_DOUBLE_AS_BIG_DECIMAL;
-                            BigDecimal minDouble = MIN_DOUBLE_AS_BIG_DECIMAL;
-                            return bd.compareTo(maxDouble)<=0 && bd.compareTo(minDouble)>=0;
-                        } catch(Exception e) {
-                            return false;
-                        }
-                    default:
-                        break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType, Integer maxLength,
-        		Integer scale, Integer desiredMaxLength, Integer desiredScale) {
-            if (ptr.getLength() == 0) {
-                return true;
-            }
-            // Use the scale from the value if provided, as it prevents a deserialization.
-            // The maxLength and scale for the underlying expression are ignored, because they
-            // are not relevant in this case: for example a DECIMAL(10,2) may be assigned to a
-            // DECIMAL(5,0) as long as the value fits.
-            if (value != null) {
-                BigDecimal v = (BigDecimal) value;
-                maxLength = v.precision();
-                scale = v.scale();
-            } else  {
-                int[] v = getDecimalPrecisionAndScale(ptr.get(), ptr.getOffset(), ptr.getLength());
-                maxLength = v[0];
-                scale = v[1];
-            }
-            if (desiredMaxLength != null && desiredScale != null && maxLength != null && scale != null &&
-            		((desiredScale == null && desiredMaxLength < maxLength) || 
-            				(desiredMaxLength - desiredScale) < (maxLength - scale))) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType, 
-                Integer maxLength, Integer scale, SortOrder actualModifier,
-                Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
-            if (desiredScale == null) {
-                // deiredScale not available, or we do not have scale requirement, delegate to parents.
-                super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
-                return;
-            }
-            if (ptr.getLength() == 0) {
-                return;
-            }
-            if (scale == null) {
-                if (object != null) {
-                    BigDecimal v = (BigDecimal) object;
-                    scale = v.scale();
-                } else {
-                    int[] v = getDecimalPrecisionAndScale(ptr.get(), ptr.getOffset(), ptr.getLength());
-                    scale = v[1];
-                }
-            }
-            if (this == actualType && scale <= desiredScale) {
-                // No coerce and rescale necessary
-                return;
-            } else {
-                BigDecimal decimal;
-                // Rescale is necessary.
-                if (object != null) { // value object is passed in.
-                    decimal = (BigDecimal) toObject(object, actualType);
-                } else { // only value bytes is passed in, need to convert to object first.
-                    decimal = (BigDecimal) toObject(ptr);
-                }
-                decimal = decimal.setScale(desiredScale, BigDecimal.ROUND_DOWN);
-                ptr.set(toBytes(decimal));
-            }
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            try {
-                return new BigDecimal(value);
-            } catch (NumberFormatException e) {
-                throw newIllegalDataException(e);
-            }
-        }
-
-        @Override
-        public Integer estimateByteSizeFromLength(Integer length) {
-            // No association of runtime byte size from decimal precision.
-            return null;
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            if (formatter == null) {
-                BigDecimal o = (BigDecimal)toObject(b, offset, length);
-                return o.toPlainString();
-            }
-            return super.toStringLiteral(b,offset, length, formatter);
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new BigDecimal((Long) LONG.getSampleValue(maxLength, arrayLength));
-        }
-    },
-    TIMESTAMP("TIMESTAMP", Types.TIMESTAMP, Timestamp.class, new DateCodec()) {
-
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            byte[] bytes = new byte[getByteSize()];
-            toBytes(object, bytes, 0);
-            return bytes;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            Timestamp value = (Timestamp)object;
-            DATE.getCodec().encodeLong(value.getTime(), bytes, offset);
-            
-            /*
-             * By not getting the stuff that got spilled over from the millis part,
-             * it leaves the timestamp's byte representation saner - 8 bytes of millis | 4 bytes of nanos.
-             * Also, it enables timestamp bytes to be directly compared with date/time bytes.   
-             */
-            Bytes.putInt(bytes, offset + Bytes.SIZEOF_LONG, value.getNanos() % 1000000);  
-            return getByteSize();
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case DATE:
-            case TIME:
-            case UNSIGNED_DATE:
-            case UNSIGNED_TIME:
-                return new Timestamp(((java.util.Date)object).getTime());
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                return object;
-            case LONG:
-            case UNSIGNED_LONG:
-                return new Timestamp((Long)object);
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)object;
-                long ms = bd.longValue();
-                int nanos = (bd.remainder(BigDecimal.ONE).multiply(QueryConstants.BD_MILLIS_NANOS_CONVERSION)).intValue();
-                return DateUtil.getTimestamp(ms, nanos);
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public Timestamp toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (actualType == null || l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                long millisDeserialized = (actualType == TIMESTAMP ? DATE : UNSIGNED_DATE).getCodec().decodeLong(b, o, sortOrder);
-                Timestamp v = new Timestamp(millisDeserialized);
-                int nanosDeserialized = PDataType.UNSIGNED_INT.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder);
-                /*
-                 * There was a bug in serialization of timestamps which was causing the sub-second millis part
-                 * of time stamp to be present both in the LONG and INT bytes. Having the <100000 check
-                 * makes this serialization fix backward compatible.
-                 */
-                v.setNanos(nanosDeserialized < 1000000 ? v.getNanos() + nanosDeserialized : nanosDeserialized);
-                return v;
-            case DATE:
-            case TIME:
-            case LONG:
-            case UNSIGNED_LONG:
-            case UNSIGNED_DATE:
-            case UNSIGNED_TIME:
-                return new Timestamp(actualType.getCodec().decodeLong(b, o, sortOrder));
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
-                long ms = bd.longValue();
-                int nanos = (bd.remainder(BigDecimal.ONE).multiply(QueryConstants.BD_MILLIS_NANOS_CONVERSION)).intValue();
-                v = DateUtil.getTimestamp(ms, nanos);
-                return v;
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-        
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return DATE.isCastableTo(targetType);
-        }
-
-       @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return this == targetType || targetType == VARBINARY || targetType == BINARY;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                switch (targetType) {
-                    case UNSIGNED_TIMESTAMP:
-                        return ((java.util.Date)value).getTime() >= 0;
-                    case UNSIGNED_DATE:
-                    case UNSIGNED_TIME:
-                        return ((java.util.Date)value).getTime() >= 0 && ((Timestamp)value).getNanos() == 0;
-                    case DATE:
-                    case TIME:
-                        return ((Timestamp)value).getNanos() == 0;
-                    default:
-                        break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-        
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return MAX_TIMESTAMP_BYTES;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            if (rhsType == TIMESTAMP || rhsType == UNSIGNED_TIMESTAMP) {
-                return ((Timestamp)lhs).compareTo((Timestamp)rhs);
-            }
-            int c = ((Date)rhs).compareTo((Date)lhs);
-            if (c != 0) return c;
-            return ((Timestamp)lhs).getNanos();
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            return DateUtil.parseTimestamp(value);
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            Timestamp value = (Timestamp)toObject(b,offset,length);
-            if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
-                // If default formatter has not been overridden,
-                // use one that displays milliseconds.
-                formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
-            }
-            return "'" + super.toStringLiteral(b, offset, length, formatter) + "." + value.getNanos() + "'";
-        }
-        
-        @Override
-        public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-            int nanos = PDataType.UNSIGNED_INT.getCodec().decodeInt(ptr.get(), ptr.getOffset() + PDataType.LONG.getByteSize(), sortOrder);
-            return nanos;
-        }
-        
-        @Override
-        public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-            long millis = PDataType.LONG.getCodec().decodeLong(ptr.get(),ptr.getOffset(), sortOrder);
-            return millis;
-        }
-        
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new Timestamp((Long) LONG.getSampleValue(maxLength, arrayLength));
-        }
-
-    },
-    TIME("TIME", Types.TIME, Time.class, new DateCodec()) {
-
-        @Override
-        public byte[] toBytes(Object object) {
-            return DATE.toBytes(object);
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            return DATE.toBytes(object, bytes, offset);
-        }
-
-        @Override
-        public Time toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-            case DATE:
-            case TIME:
-            case LONG:
-            case UNSIGNED_LONG:
-            case UNSIGNED_DATE:
-            case UNSIGNED_TIME:
-                return new Time(actualType.getCodec().decodeLong(b, o, sortOrder));
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return new Time(bd.longValueExact());
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case DATE:
-            case UNSIGNED_DATE:
-                return new Time(((Date)object).getTime());
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                return new Time(((Timestamp)object).getTime());
-            case TIME:
-            case UNSIGNED_TIME:
-                return object;
-            case LONG:
-            case UNSIGNED_LONG:
-                return new Time((Long)object);
-            case DECIMAL:
-                return new Time(((BigDecimal)object).longValueExact());
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return DATE.isCastableTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return DATE.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            return DATE.isCoercibleTo(targetType, value);
-        }
-        
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_LONG;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return DATE.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            return DateUtil.parseTime(value);
-        }
-
-        @Override
-        public boolean isBytesComparableWith(PDataType otherType) {
-            return super.isBytesComparableWith(otherType) ||  this == DATE;
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            // TODO: different default formatter for TIME?
-            return DATE.toStringLiteral(b, offset, length, formatter);
-        }
-        
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new Time((Long) LONG.getSampleValue(maxLength, arrayLength));
-        }
-    },
-    DATE("DATE", Types.DATE, Date.class, new DateCodec()) { // After TIMESTAMP and DATE to ensure toLiteral finds those first
-
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            byte[] bytes = new byte[getByteSize()];
-            toBytes(object, bytes, 0);
-            return bytes;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            getCodec().encodeLong(((java.util.Date)object).getTime(), bytes, offset);
-            return this.getByteSize();
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            if (object == null) {
-                return null;
-            }
-            switch (actualType) {
-            case TIME:
-            case UNSIGNED_TIME:
-                return new Date(((Time)object).getTime());
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-                return new Date(((Timestamp)object).getTime());
-            case DATE:
-            case UNSIGNED_DATE:
-                return object;
-            case LONG:
-            case UNSIGNED_LONG:
-                return new Date((Long)object);
-            case DECIMAL:
-                return new Date(((BigDecimal)object).longValueExact());
-            default:
-                return throwConstraintViolationException(actualType,this);
-            }
-        }
-
-        @Override
-        public Date toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            if (l == 0) {
-                return null;
-            }
-            switch (actualType) {
-            case TIMESTAMP:
-            case UNSIGNED_TIMESTAMP:
-            case DATE:
-            case TIME:
-            case LONG:
-            case UNSIGNED_LONG:
-            case UNSIGNED_DATE:
-            case UNSIGNED_TIME:
-                return new Date(actualType.getCodec().decodeLong(b, o, sortOrder));
-            case DECIMAL:
-                BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
-                return new Date(bd.longValueExact());
-            }
-            throwConstraintViolationException(actualType,this);
-            return null;
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return super.isCastableTo(targetType) || targetType == DECIMAL || targetType == LONG || targetType == UNSIGNED_LONG;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return targetType == DATE || targetType == TIME || targetType == TIMESTAMP
-                    || targetType == VARBINARY || targetType == BINARY;
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            if (value != null) {
-                switch (targetType) {
-                    case UNSIGNED_TIMESTAMP:
-                    case UNSIGNED_DATE:
-                    case UNSIGNED_TIME:
-                        return ((java.util.Date)value).getTime() >= 0;
-                    default:
-                        break;
-                }
-            }
-            return super.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_LONG;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            if (rhsType == TIMESTAMP || rhsType == UNSIGNED_TIMESTAMP) {
-                return -rhsType.compareTo(rhs, lhs, TIME);
-            }
-            return ((java.util.Date)rhs).compareTo((java.util.Date)lhs);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            if (value == null || value.length() == 0) {
-                return null;
-            }
-            return DateUtil.parseDate(value);
-        }
-
-        @Override
-        public boolean isBytesComparableWith(PDataType otherType) {
-            return super.isBytesComparableWith(otherType) || this == TIME;
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
-                // If default formatter has not been overridden,
-                // use one that displays milliseconds.
-                formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
-            }
-            return "'" + super.toStringLiteral(b, offset, length, formatter) + "'";
-        }
-        
-        @Override
-        public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType, 
-                Integer maxLength, Integer scale, SortOrder actualModifier,
-                Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
-            if (ptr.getLength() > 0 && actualType  == PDataType.TIMESTAMP && actualModifier == expectedModifier) {
-                ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
-                return;
-            }
-            super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new Date((Long) LONG.getSampleValue(maxLength, arrayLength));
-        }
-    },
-    UNSIGNED_TIMESTAMP("UNSIGNED_TIMESTAMP", 19, Timestamp.class, null) {
-
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            byte[] bytes = new byte[getByteSize()];
-            toBytes(object, bytes, 0);
-            return bytes;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            Timestamp value = (Timestamp)object;
-            UNSIGNED_DATE.getCodec().encodeLong(value.getTime(), bytes, offset);
-            
-            /*
-             * By not getting the stuff that got spilled over from the millis part,
-             * it leaves the timestamp's byte representation saner - 8 bytes of millis | 4 bytes of nanos.
-             * Also, it enables timestamp bytes to be directly compared with date/time bytes.   
-             */
-            Bytes.putInt(bytes, offset + Bytes.SIZEOF_LONG, value.getNanos() % 1000000);  
-            return getByteSize();
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            Timestamp ts = (Timestamp)TIMESTAMP.toObject(object, actualType);
-            throwIfNonNegativeDate(ts);
-            return ts;
-        }
-
-        @Override
-        public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            Timestamp ts = (Timestamp) TIMESTAMP.toObject(b, o, l, actualType, sortOrder);
-            throwIfNonNegativeDate(ts);
-            return ts;
-        }
-        
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return UNSIGNED_DATE.isCastableTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return targetType == this || UNSIGNED_DATE.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            return super.isCoercibleTo(targetType, value) || TIMESTAMP.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return TIMESTAMP.getByteSize();
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return TIMESTAMP.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            return TIMESTAMP.toObject(value);
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            Timestamp value = (Timestamp)toObject(b,offset,length);
-            if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
-                // If default formatter has not been overridden,
-                // use one that displays milliseconds.
-                formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
-            }
-            return "'" + super.toStringLiteral(b, offset, length, formatter) + "." + value.getNanos() + "'";
-        }
-        
-        @Override
-        public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-            int nanos = PDataType.UNSIGNED_INT.getCodec().decodeInt(ptr.get(), ptr.getOffset() + PDataType.LONG.getByteSize(), sortOrder);
-            return nanos;
-        }
-        
-        @Override
-        public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
-            long millis = PDataType.UNSIGNED_LONG.getCodec().decodeLong(ptr.get(),ptr.getOffset(), sortOrder);
-            return millis;
-        }
-
-        @Override
-        public int getResultSetSqlType() {
-            return Types.TIMESTAMP;
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new Timestamp((Long) UNSIGNED_LONG.getSampleValue(maxLength, arrayLength));
-        }
-    },
-    UNSIGNED_TIME("UNSIGNED_TIME", 18, Time.class, new UnsignedDateCodec()) {
-
-        @Override
-        public byte[] toBytes(Object object) {
-            return UNSIGNED_DATE.toBytes(object);
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            return UNSIGNED_DATE.toBytes(object, bytes, offset);
-        }
-
-        @Override
-        public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            Time t = (Time)TIME.toObject(b, o, l, actualType, sortOrder);
-            throwIfNonNegativeDate(t);
-            return t;
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            Time t = (Time)TIME.toObject(object, actualType);
-            throwIfNonNegativeDate(t);
-            return t;
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return UNSIGNED_DATE.isCastableTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return UNSIGNED_DATE.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            return super.isCoercibleTo(targetType, value) || TIME.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return Bytes.SIZEOF_LONG;
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return TIME.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public Object toObject(String value) {
-            return TIME.toObject(value);
-        }
-
-        @Override
-        public boolean isBytesComparableWith(PDataType otherType) {
-            return super.isBytesComparableWith(otherType) ||  this == UNSIGNED_DATE;
-        }
-        
-        @Override
-        public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
-            return UNSIGNED_DATE.toStringLiteral(b, offset, length, formatter);
-        }
-
-        @Override
-        public int getResultSetSqlType() {
-            return Types.TIME;
-        }
-
-        @Override
-        public Object getSampleValue(Integer maxLength, Integer arrayLength) {
-            return new Time((Long) UNSIGNED_LONG.getSampleValue(maxLength, arrayLength));
-        }
-    },
-    UNSIGNED_DATE("UNSIGNED_DATE", 19, Date.class, new UnsignedDateCodec()) { // After TIMESTAMP and DATE to ensure toLiteral finds those first
-
-        @Override
-        public byte[] toBytes(Object object) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            byte[] bytes = new byte[getByteSize()];
-            toBytes(object, bytes, 0);
-            return bytes;
-        }
-
-        @Override
-        public int toBytes(Object object, byte[] bytes, int offset) {
-            if (object == null) {
-                throw newIllegalDataException(this + " may not be null");
-            }
-            getCodec().encodeLong(((java.util.Date)object).getTime(), bytes, offset);
-            return this.getByteSize();
-        }
-
-        @Override
-        public Object toObject(Object object, PDataType actualType) {
-            Date d = (Date)DATE.toObject(object, actualType);
-            throwIfNonNegativeDate(d);
-            return d;
-        }
-
-        @Override
-        public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
-            Date d = (Date)DATE.toObject(b,o,l,actualType, sortOrder);
-            throwIfNonNegativeDate(d);
-            return d;
-        }
-
-        @Override
-        public boolean isCastableTo(PDataType targetType) {
-            return DATE.isCastableTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType) {
-            return targetType == this || targetType == UNSIGNED_TIME || targetType == UNSIGNED_TIMESTAMP
-                    || DATE.isCoercibleTo(targetType);
-        }
-
-        @Override
-        public boolean isCoercibleTo(PDataType targetType, Object value) {
-            return super.isCoercibleTo(targetType, value) || DATE.isCoercibleTo(targetType, value);
-        }
-
-        @Override
-        public boolean isFixedWidth() {
-            return true;
-        }
-
-        @Override
-        public Integer getByteSize() {
-            return DATE.getByteSize();
-        }
-
-        @Override
-        public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
-            return DATE.compareTo(lhs, rhs, rhsType);
-        }
-
-        @Override
-        public Object toObject(String va

<TRUNCATED>

[10/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
new file mode 100644
index 0000000..77ab263
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallint.java
@@ -0,0 +1,159 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+public class PUnsignedSmallint extends PDataType<Short> {
+
+  public static final PUnsignedSmallint INSTANCE = new PUnsignedSmallint();
+
+  private PUnsignedSmallint() {
+    super("UNSIGNED_SMALLINT", 13, Short.class, new UnsignedShortCodec(), 17);
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_SHORT;
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return SHORT_PRECISION;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    byte[] b = new byte[Bytes.SIZEOF_SHORT];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeShort(((Number) object).shortValue(), bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Short b = Short.parseShort(value);
+      if (b.shortValue() < 0) {
+        throw newIllegalDataException("Value may not be negative(" + b + ")");
+      }
+      return b;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Short v = (Short) PSmallint.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Short v = (Short) PSmallint.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return targetType.equals(this) || PUnsignedInt.INSTANCE.isCoercibleTo(targetType) || PSmallint.INSTANCE
+        .isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PSmallint.INSTANCE
+        .isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PSmallint.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return ((Integer) RANDOM.get().nextInt(Short.MAX_VALUE)).shortValue();
+  }
+
+  static class UnsignedShortCodec extends PSmallint.ShortCodec {
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT);
+      if (sortOrder == SortOrder.DESC) {
+        b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_SHORT], 0, Bytes.SIZEOF_SHORT);
+      }
+      short v = Bytes.toShort(b, o);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putShort(b, o, v);
+      return Bytes.SIZEOF_SHORT;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallintArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallintArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallintArray.java
new file mode 100644
index 0000000..36823c2
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedSmallintArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedSmallintArray extends PArrayDataType<short[]> {
+
+  public static final PUnsignedSmallintArray INSTANCE = new PUnsignedSmallintArray();
+
+  private PUnsignedSmallintArray() {
+    super("UNSIGNED_SMALLINT ARRAY",
+        PDataType.ARRAY_TYPE_BASE + PUnsignedSmallint.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 44);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedSmallint.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedSmallint.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedSmallint.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] shortArr = (Object[]) pArr.array;
+    for (Object i : shortArr) {
+      if (!super.isCoercibleTo(PUnsignedSmallint.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedSmallint.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
new file mode 100644
index 0000000..f738f44
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTime.java
@@ -0,0 +1,115 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Time;
+import java.sql.Types;
+import java.text.Format;
+
+public class PUnsignedTime extends PDataType<Time> {
+
+  public static final PUnsignedTime INSTANCE = new PUnsignedTime();
+
+  private PUnsignedTime() {
+    super("UNSIGNED_TIME", 18, java.sql.Time.class, new PUnsignedDate.UnsignedDateCodec(), 13);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return PUnsignedDate.INSTANCE.toBytes(object);
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    return PUnsignedDate.INSTANCE.toBytes(object, bytes, offset);
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    java.sql.Time t = (java.sql.Time) PTime.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeDate(t);
+    return t;
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    java.sql.Time t = (java.sql.Time) PTime.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeDate(t);
+    return t;
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return PUnsignedDate.INSTANCE.isCastableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return PUnsignedDate.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PTime.INSTANCE.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_LONG;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PTime.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    return PTime.INSTANCE.toObject(value);
+  }
+
+  @Override
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return super.isBytesComparableWith(otherType) || otherType == PUnsignedDate.INSTANCE;
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    return PUnsignedDate.INSTANCE.toStringLiteral(b, offset, length, formatter);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.TIME;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new java.sql.Time(
+        (Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimeArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimeArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimeArray.java
new file mode 100644
index 0000000..9d7584b
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimeArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.*;
+
+public class PUnsignedTimeArray extends PArrayDataType<Time[]> {
+
+  public static final PUnsignedTimeArray INSTANCE = new PUnsignedTimeArray();
+
+  private PUnsignedTimeArray() {
+    super("UNSIGNED_TIME ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedTime.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 39);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedTime.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedTime.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedTime.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] timeArr = (Object[]) pArr.array;
+    for (Object i : timeArr) {
+      if (!super.isCoercibleTo(PUnsignedTime.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedTime.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
new file mode 100644
index 0000000..21e6c50
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestamp.java
@@ -0,0 +1,151 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.DateUtil;
+
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.text.Format;
+
+public class PUnsignedTimestamp extends PDataType<Timestamp> {
+
+  public static final PUnsignedTimestamp INSTANCE = new PUnsignedTimestamp();
+
+  private PUnsignedTimestamp() {
+    super("UNSIGNED_TIMESTAMP", 19, java.sql.Timestamp.class, null, 12);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    byte[] bytes = new byte[getByteSize()];
+    toBytes(object, bytes, 0);
+    return bytes;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    java.sql.Timestamp value = (java.sql.Timestamp) object;
+    PUnsignedDate.INSTANCE.getCodec().encodeLong(value.getTime(), bytes, offset);
+
+            /*
+             * By not getting the stuff that got spilled over from the millis part,
+             * it leaves the timestamp's byte representation saner - 8 bytes of millis | 4 bytes of nanos.
+             * Also, it enables timestamp bytes to be directly compared with date/time bytes.
+             */
+    Bytes.putInt(bytes, offset + Bytes.SIZEOF_LONG, value.getNanos() % 1000000);
+    return getByteSize();
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    java.sql.Timestamp ts = (java.sql.Timestamp) PTimestamp.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeDate(ts);
+    return ts;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    java.sql.Timestamp ts =
+        (java.sql.Timestamp) PTimestamp.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeDate(ts);
+    return ts;
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return PUnsignedDate.INSTANCE.isCastableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return targetType.equals(this) || PUnsignedDate.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PTimestamp.INSTANCE
+        .isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return PTimestamp.INSTANCE.getByteSize();
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PTimestamp.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    return PTimestamp.INSTANCE.toObject(value);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    java.sql.Timestamp value = (java.sql.Timestamp) toObject(b, offset, length);
+    if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
+      // If default formatter has not been overridden,
+      // use one that displays milliseconds.
+      formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
+    }
+    return "'" + super.toStringLiteral(b, offset, length, formatter) + "." + value.getNanos() + "'";
+  }
+
+  @Override
+  public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    int nanos = PUnsignedInt.INSTANCE.getCodec()
+        .decodeInt(ptr.get(), ptr.getOffset() + PLong.INSTANCE.getByteSize(), sortOrder);
+    return nanos;
+  }
+
+  @Override
+  public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    long millis =
+        PUnsignedLong.INSTANCE.getCodec().decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
+    return millis;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.TIMESTAMP;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new java.sql.Timestamp(
+        (Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestampArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestampArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestampArray.java
new file mode 100644
index 0000000..1159b5c
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTimestampArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.*;
+
+public class PUnsignedTimestampArray extends PArrayDataType<Timestamp[]> {
+
+  public static final PUnsignedTimestampArray INSTANCE = new PUnsignedTimestampArray();
+
+  private PUnsignedTimestampArray() {
+    super("UNSIGNED_TIMESTAMP ARRAY",
+        PDataType.ARRAY_TYPE_BASE + PUnsignedTimestamp.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 37);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedTimestamp.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedTimestamp.INSTANCE, sortOrder,
+        maxLength, scale, PUnsignedTimestamp.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] timeStampArr = (Object[]) pArr.array;
+    for (Object i : timeStampArr) {
+      if (!super.isCoercibleTo(PUnsignedTimestamp.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedTimestamp.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyint.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyint.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyint.java
new file mode 100644
index 0000000..4c70c18
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyint.java
@@ -0,0 +1,155 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+public class PUnsignedTinyint extends PDataType<Byte> {
+
+  public static final PUnsignedTinyint INSTANCE = new PUnsignedTinyint();
+
+  private PUnsignedTinyint() {
+    super("UNSIGNED_TINYINT", 11, Byte.class, new UnsignedByteCodec(), 18);
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_BYTE;
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return BYTE_PRECISION;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_BYTE];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeByte(((Number) object).byteValue(), bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Byte b = Byte.parseByte(value);
+      if (b.byteValue() < 0) {
+        throw newIllegalDataException("Value may not be negative(" + b + ")");
+      }
+      return b;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Byte v = (Byte) PTinyint.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Byte v = (Byte) PTinyint.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return targetType.equals(this) || PUnsignedSmallint.INSTANCE.isCoercibleTo(targetType)
+        || PTinyint.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PTinyint.INSTANCE
+        .isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PTinyint.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return ((Integer) RANDOM.get().nextInt(Byte.MAX_VALUE)).byteValue();
+  }
+
+  static class UnsignedByteCodec extends PTinyint.ByteCodec {
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_BYTE);
+      byte v = b[o];
+      if (sortOrder == SortOrder.DESC) {
+        v = SortOrder.invert(v);
+      }
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putByte(b, o, v);
+      return Bytes.SIZEOF_BYTE;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyintArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyintArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyintArray.java
new file mode 100644
index 0000000..a73f284
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedTinyintArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedTinyintArray extends PArrayDataType<byte[]> {
+
+  public static final PUnsignedTinyintArray INSTANCE = new PUnsignedTinyintArray();
+
+  private PUnsignedTinyintArray() {
+    super("UNSIGNED_TINYINT ARRAY",
+        PDataType.ARRAY_TYPE_BASE + PUnsignedTinyint.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 45);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedTinyint.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedTinyint.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedTinyint.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] byteArr = (Object[]) pArr.array;
+    for (Object i : byteArr) {
+      if (!super.isCoercibleTo(PUnsignedTinyint.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedTinyint.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinary.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinary.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinary.java
new file mode 100644
index 0000000..6ba4dc4
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinary.java
@@ -0,0 +1,171 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.sql.Types;
+import java.text.Format;
+
+public class PVarbinary extends PDataType<byte[]> {
+
+  public static final PVarbinary INSTANCE = new PVarbinary();
+
+  private PVarbinary() {
+    super("VARBINARY", Types.VARBINARY, byte[].class, null, 22);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      return ByteUtil.EMPTY_BYTE_ARRAY;
+    }
+    return (byte[]) object;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      return 0;
+    }
+    byte[] o = (byte[]) object;
+    // assumes there's enough room
+    System.arraycopy(bytes, offset, o, 0, o.length);
+    return o.length;
+  }
+
+  /**
+   * Override because we must always create a new byte array
+   */
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    byte[] bytes = toBytes(object);
+    // Override because we need to allocate a new buffer in this case
+    if (sortOrder == SortOrder.DESC) {
+      return SortOrder.invert(bytes, 0, new byte[bytes.length], 0, bytes.length);
+    }
+    return bytes;
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (length == 0) {
+      return null;
+    }
+    if (offset == 0 && bytes.length == length && sortOrder == SortOrder.ASC) {
+      return bytes;
+    }
+    byte[] bytesCopy = new byte[length];
+    System.arraycopy(bytes, offset, bytesCopy, 0, length);
+    if (sortOrder == SortOrder.DESC) {
+      bytesCopy = SortOrder.invert(bytes, offset, bytesCopy, 0, length);
+      offset = 0;
+    }
+    return bytesCopy;
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    return actualType.toBytes(object);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int estimateByteSize(Object o) {
+    byte[] value = (byte[]) o;
+    return value == null ? 1 : value.length;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+      Integer maxLength, Integer scale, Integer desiredMaxLength,
+      Integer desiredScale) {
+    if (ptr.getLength() != 0 && srcType.equals(PBinary.INSTANCE) && maxLength != null
+        && desiredMaxLength != null) {
+      return maxLength <= desiredMaxLength;
+    }
+    return true;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (lhs == null && rhs == null) {
+      return 0;
+    } else if (lhs == null) {
+      return -1;
+    } else if (rhs == null) {
+      return 1;
+    }
+    if (equalsAny(rhsType, this, PBinary.INSTANCE)) {
+      return Bytes.compareTo((byte[]) lhs, (byte[]) rhs);
+    } else {
+      byte[] rhsBytes = rhsType.toBytes(rhs);
+      return Bytes.compareTo((byte[]) lhs, rhsBytes);
+    }
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    return Base64.decode(value);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int o, int length, Format formatter) {
+    if (formatter != null) {
+      return formatter.format(b);
+    }
+    StringBuilder buf = new StringBuilder();
+    buf.append('[');
+    for (int i = 0; i < b.length; i++) {
+      buf.append(0xFF & b[i]);
+      buf.append(',');
+    }
+    buf.setCharAt(buf.length() - 1, ']');
+    return buf.toString();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    int length = maxLength != null && maxLength > 0 ? maxLength : 1;
+    byte[] b = new byte[length];
+    RANDOM.get().nextBytes(b);
+    return b;
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinaryArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinaryArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinaryArray.java
new file mode 100644
index 0000000..10448ac
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarbinaryArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PVarbinaryArray extends PArrayDataType<byte[][]> {
+
+  public static final PVarbinaryArray INSTANCE = new PVarbinaryArray();
+
+  private PVarbinaryArray() {
+    super("VARBINARY ARRAY", PDataType.ARRAY_TYPE_BASE + PVarbinary.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 27);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PVarbinary.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PVarbinary.INSTANCE, sortOrder, maxLength, scale,
+        PVarbinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] charArr = (Object[]) pArr.array;
+    for (Object i : charArr) {
+      if (!super.isCoercibleTo(PVarbinary.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PVarbinary.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
new file mode 100644
index 0000000..9ecfb4e
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarchar.java
@@ -0,0 +1,165 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
+
+import java.sql.Types;
+import java.text.Format;
+
+public class PVarchar extends PDataType<String> {
+
+  public static final PVarchar INSTANCE = new PVarchar();
+
+  private PVarchar() {
+    super("VARCHAR", Types.VARCHAR, String.class, null, 0);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    // TODO: consider using avro UTF8 object instead of String
+    // so that we get get the size easily
+    if (object == null) {
+      return ByteUtil.EMPTY_BYTE_ARRAY;
+    }
+    return Bytes.toBytes((String) object);
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      return 0;
+    }
+    byte[] b = toBytes(object); // TODO: no byte[] allocation: use CharsetEncoder
+    System.arraycopy(b, 0, bytes, offset, b.length);
+    return b.length;
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (!actualType.isCoercibleTo(this)) {
+      throwConstraintViolationException(actualType, this);
+    }
+    if (length == 0) {
+      return null;
+    }
+    if (sortOrder == SortOrder.DESC) {
+      bytes = SortOrder.invert(bytes, offset, length);
+      offset = 0;
+    }
+    return Bytes.toString(bytes, offset, length);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (equalsAny(actualType, this, PChar.INSTANCE)) {
+      String s = (String) object;
+      return s == null || s.length() > 0 ? s : null;
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PChar.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (isCoercibleTo(targetType)) {
+      if (targetType.equals(PChar.INSTANCE)) {
+        return value != null;
+      }
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+      Integer maxLength, Integer scale, Integer desiredMaxLength,
+      Integer desiredScale) {
+    if (ptr.getLength() != 0 && maxLength != null && desiredMaxLength != null) {
+      return maxLength <= desiredMaxLength;
+    }
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int estimateByteSize(Object o) {
+    String value = (String) o;
+    return value == null ? 1 : value.length();
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return ((String) lhs).compareTo((String) rhs);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    return value;
+  }
+
+  @Override
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return super.isBytesComparableWith(otherType) || otherType == PChar.INSTANCE;
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    while (b[length - 1] == 0) {
+      length--;
+    }
+    if (formatter != null) {
+      Object o = toObject(b, offset, length);
+      return "'" + formatter.format(o) + "'";
+    }
+    return "'" + Bytes.toStringBinary(b, offset, length) + "'";
+  }
+
+  private char[] sampleChars = new char[1];
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    Preconditions.checkArgument(maxLength == null || maxLength >= 0);
+    int length = maxLength != null ? maxLength : 1;
+    if (length != sampleChars.length) {
+      sampleChars = new char[length];
+    }
+    for (int i = 0; i < length; i++) {
+      sampleChars[i] = (char) RANDOM.get().nextInt(Byte.MAX_VALUE);
+    }
+    return new String(sampleChars);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarcharArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarcharArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarcharArray.java
new file mode 100644
index 0000000..72561b3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PVarcharArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PVarcharArray extends PArrayDataType<String> {
+
+  public static final PVarcharArray INSTANCE = new PVarcharArray();
+
+  private PVarcharArray() {
+    super("VARCHAR ARRAY", PDataType.ARRAY_TYPE_BASE + PVarchar.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 26);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PVarchar.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PVarchar.INSTANCE, sortOrder, maxLength, scale,
+        PVarchar.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] charArr = (Object[]) pArr.array;
+    for (Object i : charArr) {
+      if (!super.isCoercibleTo(PVarchar.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PVarchar.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java
new file mode 100644
index 0000000..dcfb2c3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PhoenixArray.java
@@ -0,0 +1,644 @@
+/*
+ * 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.schema.types;
+
+import java.sql.Array;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.phoenix.util.SQLCloseable;
+
+/**
+ * java.sql.Array implementation for Phoenix
+ */
+public class PhoenixArray implements Array,SQLCloseable {
+	PDataType baseType;
+	Object array;
+	int numElements;
+	Integer maxLength;
+  protected int hashCode = Integer.MIN_VALUE;
+	public PhoenixArray() {
+		// empty constructor
+	}
+	
+	public Integer getMaxLength() {
+	    return maxLength;
+	}
+
+    public boolean isPrimitiveType() {
+        return this.baseType.getCodec() != null;
+    }
+
+	private static Object[] coerceToNewLength(PDataType baseType, Object[] elements, int maxLength) {
+        Object[] resizedElements = new Object[elements.length];
+        for (int i = 0; i < elements.length; i++) {
+            int length = baseType.getMaxLength(elements[i]);
+            if (length == maxLength) {
+                resizedElements[i] = elements[i];
+            } else {
+                resizedElements[i] = baseType.pad(elements[i],maxLength);
+            }
+        }
+        return resizedElements;
+	}
+	private static Object[] coerceToEqualLength(PDataType baseType, Object[] elements) {
+	    if (elements == null || elements.length == 0) {
+	        return elements;
+	    }
+	    Object element = elements[0];
+	    int maxLength = baseType.getMaxLength(element);
+	    boolean resizeElements = false;
+	    for (int i = 1; i < elements.length; i++) {
+	        int length = baseType.getMaxLength(elements[i]);
+	        if (length > maxLength) {
+	            maxLength = length;
+	            resizeElements = true;
+	        } else if (length < maxLength) {
+	            resizeElements = true;
+	        }
+	    }
+	    if (!resizeElements) {
+	        return elements;
+	    }
+	    return coerceToNewLength(baseType, elements, maxLength);
+	}
+	
+	public PhoenixArray(PDataType baseType, Object[] elements) {
+		// As we are dealing with primitive types and only the Boxed objects
+		this.baseType = baseType;
+		if (baseType.isFixedWidth()) {
+		    if (baseType.getByteSize() == null) {
+    		    elements = coerceToEqualLength(baseType, elements);
+    		    if (elements != null && elements.length > 0) {
+    		        this.maxLength = baseType.getMaxLength(elements[0]);
+    		    }
+		    } else {
+		        maxLength = baseType.getByteSize();
+		    }
+		}
+    this.array = convertObjectArrayToPrimitiveArray(elements);
+		this.numElements = elements.length;
+	}
+	
+	public PhoenixArray(PhoenixArray pArr, Integer desiredMaxLength) {
+	    this.baseType = pArr.baseType;
+	    Object[] elements = (Object[])pArr.array;
+        if (baseType.isFixedWidth()) {
+            if (baseType.getByteSize() == null) {
+                elements = coerceToNewLength(baseType, (Object[])pArr.array, desiredMaxLength);
+                maxLength = desiredMaxLength;
+            } else {
+                maxLength = baseType.getByteSize();
+            }
+        }
+        this.array = convertObjectArrayToPrimitiveArray(elements);
+        this.numElements = elements.length;
+    }
+
+  public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+    return elements;
+	}
+	
+	@Override
+	public void free() throws SQLException {
+	}
+
+	@Override
+	public Object getArray() throws SQLException {
+		return array;
+	}
+	
+	@Override
+	public void close() throws SQLException {
+		this.array = null;
+	}
+
+	@Override
+	public Object getArray(Map<String, Class<?>> map) throws SQLException {
+		throw new UnsupportedOperationException("Currently not supported");
+	}
+
+	@Override
+	public Object getArray(long index, int count) throws SQLException {
+		if(index < 1) {
+			throw new IllegalArgumentException("Index cannot be less than 1");
+		}
+		// Get the set of elements from the given index to the specified count
+		Object[] intArr = (Object[]) array;
+		boundaryCheck(index, count, intArr);
+		Object[] newArr = new Object[count];
+		// Add checks() here.
+		int i = 0;
+		for (int j = (int) index; j < count; j++) {
+			newArr[i] = intArr[j];
+			i++;
+		}
+		return newArr;
+	}
+
+	private void boundaryCheck(long index, int count, Object[] arr) {
+		if ((--index) + count > arr.length) {
+			throw new IllegalArgumentException("The array index is out of range of the total number of elements in the array " + arr.length);
+		}
+	}
+
+	@Override
+	public Object getArray(long index, int count, Map<String, Class<?>> map)
+			throws SQLException {
+		if(map != null && !map.isEmpty()) {
+			throw new UnsupportedOperationException("Currently not supported");
+		}
+		return null;
+	}
+
+	@Override
+	public int getBaseType() throws SQLException {
+		return baseType.getSqlType();
+	}
+
+	@Override
+	public String getBaseTypeName() throws SQLException {
+		return baseType.getSqlTypeName();
+	}
+
+	@Override
+	public ResultSet getResultSet() throws SQLException {
+		throw new UnsupportedOperationException("Currently not supported");
+	}
+
+	@Override
+	public ResultSet getResultSet(Map<String, Class<?>> arg0)
+			throws SQLException {
+		throw new UnsupportedOperationException("Currently not supported");
+	}
+
+	@Override
+	public ResultSet getResultSet(long arg0, int arg1) throws SQLException {
+		throw new UnsupportedOperationException("Currently not supported");
+	}
+
+	@Override
+	public ResultSet getResultSet(long arg0, int arg1,
+			Map<String, Class<?>> arg2) throws SQLException {
+		throw new UnsupportedOperationException("Currently not supported");
+	}
+
+  /**
+   * Return the value in position {@code index} from the underlying array. Used to work around
+   * casting and reflection while enabling primitive arrays.
+   */
+  public Object getElement(int index) {
+    return ((Object[]) array)[index];
+  }
+
+	public int getDimensions() {
+		return this.numElements;
+	}
+	
+	public int estimateByteSize(int pos) {
+	    if(((Object[])array)[pos] == null) {
+	        return 0;
+	    }
+		return this.baseType.estimateByteSize(((Object[])array)[pos]);
+	}
+	
+	public Integer getMaxLength(int pos) {
+	    return this.baseType.getMaxLength(((Object[])array)[pos]);
+	}
+	
+	public byte[] toBytes(int pos) {
+		return this.baseType.toBytes(((Object[])array)[pos]);
+	}
+	
+	public boolean isNull(int pos) {
+	    if(this.baseType.toBytes(((Object[])array)[pos]).length == 0) {
+	        return true;
+	    } else {
+	        return false;
+	    }
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+    if (obj == null) return false;
+    if (this == obj) return true;
+    if (!(obj instanceof PhoenixArray)) return false;
+    PhoenixArray oArray = (PhoenixArray) obj;
+    if (numElements != oArray.numElements) return false;
+    if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+    return Arrays.deepEquals((Object[]) array, (Object[]) oArray.array);
+	}
+
+	@Override
+	public int hashCode() {
+    // implementation based on commons.lang.HashCodeBuilder, except the hashcode is cached and
+    // reused for a given instance.
+    if (hashCode != Integer.MIN_VALUE) return hashCode;
+    hashCode = 17;
+    hashCode = hashCode * 37 + numElements;
+    hashCode = hashCode * 37 + baseType.getSqlType();
+    hashCode = hashCode * 37 + Arrays.deepHashCode((Object[]) array);
+    return hashCode;
+	}
+
+	public static class PrimitiveIntPhoenixArray extends PhoenixArray {
+		private int[] intArr;
+		public PrimitiveIntPhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			intArr = new int[elements.length];
+			int i = 0;
+			for(Object o : elements) {
+			    if (o != null) {
+			        intArr[i] = (Integer)o;
+			    }
+			    i++;
+			}
+      return intArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(intArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(intArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveIntPhoenixArray oArray = (PrimitiveIntPhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((int[]) array, (int[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((int[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((int[]) array)[index];
+    }
+	}
+	
+	public static class PrimitiveShortPhoenixArray extends PhoenixArray {
+		private short[] shortArr;
+		public PrimitiveShortPhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			shortArr = new short[elements.length];
+			int i = 0;
+            for(Object o : elements) {
+                if (o != null) {
+                    shortArr[i] = (Short)o;
+                }
+                i++;
+            }
+      return shortArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(shortArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(shortArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveShortPhoenixArray oArray = (PrimitiveShortPhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((short[]) array, (short[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((short[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((short[]) array)[index];
+    }
+  }
+	
+	public static class PrimitiveLongPhoenixArray extends PhoenixArray {
+		private long[] longArr;
+		public PrimitiveLongPhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			longArr = new long[elements.length];
+			int i = 0;
+            for(Object o : elements) {
+                if (o != null) {
+                    longArr[i] = (Long)o;
+                }
+                i++;
+            }
+      return longArr;
+		}
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(longArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(longArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveLongPhoenixArray oArray = (PrimitiveLongPhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((long[]) array, (long[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((long[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((long[]) array)[index];
+    }
+	}
+	
+	public static class PrimitiveDoublePhoenixArray extends PhoenixArray {
+		private double[] doubleArr;
+		public PrimitiveDoublePhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			doubleArr = new double[elements.length];
+			int i = 0;
+			for (Object o : elements) {
+			    if (o != null) {
+			        doubleArr[i] = (Double) o;
+			    }
+			    i++;
+			}
+      return doubleArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(doubleArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(doubleArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveDoublePhoenixArray oArray = (PrimitiveDoublePhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((double[]) array, (double[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((double[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((double[]) array)[index];
+    }
+	}
+	
+	public static class PrimitiveFloatPhoenixArray extends PhoenixArray {
+		private float[] floatArr;
+		public PrimitiveFloatPhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			floatArr = new float[elements.length];
+			int i = 0;
+            for(Object o : elements) {
+                if (o != null) {
+                    floatArr[i] = (Float)o;
+                }
+                i++;
+            }
+      return floatArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(floatArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(floatArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveFloatPhoenixArray oArray = (PrimitiveFloatPhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((float[]) array, (float[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((float[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((float[]) array)[index];
+    }
+	}
+	
+	public static class PrimitiveBytePhoenixArray extends PhoenixArray {
+		private byte[] byteArr;
+		public PrimitiveBytePhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			byteArr = new byte[elements.length];
+			int i = 0;
+            for(Object o : elements) {
+                if (o != null) {
+                    byteArr[i] = (Byte)o;
+                }
+                i++;
+            }
+      return byteArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(byteArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(byteArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveBytePhoenixArray oArray = (PrimitiveBytePhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((byte[]) array, (byte[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((byte[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((byte[]) array)[index];
+    }
+	}
+	
+	public static class PrimitiveBooleanPhoenixArray extends PhoenixArray {
+		private boolean[] booleanArr;
+		public PrimitiveBooleanPhoenixArray(PDataType dataType, Object[] elements) {
+			super(dataType, elements);
+		}
+		@Override
+		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
+			booleanArr = new boolean[elements.length];
+			int i = 0;
+            for(Object o : elements) {
+                if (o != null) {
+                    booleanArr[i] = (Boolean)o;
+                }
+                i++;
+            }
+      return booleanArr;
+		}
+		
+		@Override
+        public int estimateByteSize(int pos) {
+			return this.baseType.estimateByteSize(booleanArr[pos]);
+		}
+		
+		@Override
+        public byte[] toBytes(int pos) {
+			return this.baseType.toBytes(booleanArr[pos]);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+      if (obj == null) return false;
+      if (this == obj) return true;
+      if (this.getClass() != obj.getClass()) return false;
+      PrimitiveBooleanPhoenixArray oArray = (PrimitiveBooleanPhoenixArray) obj;
+      if (numElements != oArray.numElements) return false;
+      if (baseType.getSqlType() != oArray.baseType.getSqlType()) return false;
+      return Arrays.equals((boolean[]) array, (boolean[]) oArray.array);
+		}
+
+    @Override
+    public int hashCode() {
+      if (hashCode != Integer.MIN_VALUE) return hashCode;
+      hashCode = 17;
+      hashCode = hashCode * 37 + numElements;
+      hashCode = hashCode * 37 + baseType.getSqlType();
+      hashCode = hashCode * 37 + Arrays.hashCode((boolean[]) array);
+      return hashCode;
+    }
+
+    @Override
+    public Object getElement(int index) {
+      return ((boolean[]) array)[index];
+    }
+	}
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/ByteUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ByteUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ByteUtil.java
index 82be510..1e3516d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ByteUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ByteUtil.java
@@ -32,7 +32,7 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 
 import com.google.common.base.Preconditions;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
index 0bf366e..a82dc3c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
@@ -28,7 +28,7 @@ import org.apache.commons.csv.CSVRecord;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.csv.CsvUpsertExecutor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java
index 79eaeb0..55865c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ColumnInfo.java
@@ -13,7 +13,7 @@ package org.apache.phoenix.util;
 import java.util.List;
 
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
index eac396b..6032aec 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java
@@ -19,7 +19,7 @@ import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.function.CurrentDateFunction;
 import org.apache.phoenix.expression.function.CurrentTimeFunction;
 import org.apache.phoenix.expression.function.FunctionExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.collect.Lists;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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 b6d2fce..ae2d2c4 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,11 +67,13 @@ import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ColumnRef;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.KeyValueSchema;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.tuple.ResultTuple;
@@ -106,12 +108,12 @@ public class IndexUtil {
             return dataType;
         }
         // for fixed length numeric types and boolean
-        if (dataType.isCastableTo(PDataType.DECIMAL)) {
-            return PDataType.DECIMAL;
+        if (dataType.isCastableTo(PDecimal.INSTANCE)) {
+            return PDecimal.INSTANCE;
         }
         // for CHAR
-        if (dataType.isCoercibleTo(PDataType.VARCHAR)) {
-            return PDataType.VARCHAR;
+        if (dataType.isCoercibleTo(PVarchar.INSTANCE)) {
+            return PVarchar.INSTANCE;
         }
         throw new IllegalArgumentException("Unsupported non nullable index type " + dataType);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
index d5c7a18..c1aa2cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
@@ -49,8 +49,11 @@ import org.apache.phoenix.hbase.index.util.VersionUtil;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
+import org.apache.phoenix.schema.types.PSmallint;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.SequenceKey;
@@ -159,7 +162,7 @@ public class MetaDataUtil {
         if (kvs != null) {
             for (Cell kv : kvs) { // list is not ordered, so search. TODO: we could potentially assume the position
                 if (Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES, 0, PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES.length) == 0) {
-                    return PDataType.LONG.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
+                    return PLong.INSTANCE.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
                 }
             }
         }
@@ -251,7 +254,7 @@ public class MetaDataUtil {
     
     public static boolean isMultiTenant(Mutation m, KeyValueBuilder builder, ImmutableBytesWritable ptr) {
         if (getMutationValue(m, PhoenixDatabaseMetaData.MULTI_TENANT_BYTES, builder, ptr)) {
-            return Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr));
+            return Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr));
         }
         return false;
     }
@@ -307,7 +310,7 @@ public class MetaDataUtil {
     }
 
     public static PDataType getViewIndexIdDataType() {
-        return PDataType.SMALLINT;
+        return PSmallint.INSTANCE;
     }
 
     public static String getViewIndexIdColumnName() {
@@ -326,7 +329,7 @@ public class MetaDataUtil {
         byte[] physicalIndexName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName);
         try {
             HTableDescriptor desc = connection.getQueryServices().getTableDescriptor(physicalIndexName);
-            return desc != null && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(IS_VIEW_INDEX_TABLE_PROP_BYTES)));
+            return desc != null && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(IS_VIEW_INDEX_TABLE_PROP_BYTES)));
         } catch (TableNotFoundException e) {
             return false;
         }
@@ -344,7 +347,7 @@ public class MetaDataUtil {
         byte[] physicalIndexName = MetaDataUtil.getLocalIndexPhysicalName(physicalTableName);
         try {
             HTableDescriptor desc = connection.getQueryServices().getTableDescriptor(physicalIndexName);
-            return desc != null && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(IS_LOCAL_INDEX_TABLE_PROP_BYTES)));
+            return desc != null && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(IS_LOCAL_INDEX_TABLE_PROP_BYTES)));
         } catch (TableNotFoundException e) {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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 7889a89..56e0137 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
@@ -19,7 +19,7 @@ package org.apache.phoenix.util;
 
 import java.math.BigDecimal;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * Utility methods for numbers like decimal, long, etc.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 0e2bae3..269eda5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -18,7 +18,7 @@
 package org.apache.phoenix.util;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.phoenix.schema.PDataType.ARRAY_TYPE_SUFFIX;
+import static org.apache.phoenix.schema.types.PDataType.ARRAY_TYPE_SUFFIX;
 
 import java.io.File;
 import java.io.FileReader;
@@ -66,7 +66,7 @@ import org.apache.phoenix.schema.KeyValueSchema.KeyValueSchemaBuilder;
 import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.PTableType;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index db1c661..2dfa573 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -45,15 +45,15 @@ import org.apache.phoenix.filter.SkipScanFilter;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.KeyRange.Bound;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PNameFactory;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.ValueSchema.Field;
 
 import com.google.common.collect.Lists;
 
-
 /**
  * 
  * Various utilities for scans
@@ -437,7 +437,7 @@ public class ScanUtil {
     public static ScanRanges newScanRanges(List<Mutation> mutations) throws SQLException {
         List<KeyRange> keys = Lists.newArrayListWithExpectedSize(mutations.size());
         for (Mutation m : mutations) {
-            keys.add(PDataType.VARBINARY.getKeyRange(m.getRow()));
+            keys.add(PVarbinary.INSTANCE.getKeyRange(m.getRow()));
         }
         ScanRanges keyRanges = ScanRanges.create(SchemaUtil.VAR_BINARY_SCHEMA, Collections.singletonList(keys), ScanUtil.SINGLE_COLUMN_SLOT_SPAN);
         return keyRanges;


[21/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
index 3876b8a..a71a963 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java
@@ -101,16 +101,25 @@ import org.apache.phoenix.parse.UnsupportedAllParseNodeVisitor;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ColumnRef;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.DelegateDatum;
 import org.apache.phoenix.schema.LocalIndexDataColumnRef;
-import org.apache.phoenix.schema.PArrayDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.schema.PhoenixArray;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
@@ -228,8 +237,8 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         Determinism determinism = Determinism.ALWAYS;
         while (iterator.hasNext()) {
             Expression child = iterator.next();
-            if (child.getDataType() != PDataType.BOOLEAN) {
-                throw TypeMismatchException.newException(PDataType.BOOLEAN, child.getDataType(), child.toString());
+            if (child.getDataType() != PBoolean.INSTANCE) {
+                throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString());
             }
             if (LiteralExpression.isFalse(child)) {
                 iterator.remove();
@@ -493,7 +502,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                   if (pattern.equals(rhsLiteral)) {
                       return new ComparisonExpression(op, children);
                   } else {
-                      rhs = LiteralExpression.newConstant(rhsLiteral, PDataType.CHAR, rhs.getDeterminism());
+                      rhs = LiteralExpression.newConstant(rhsLiteral, PChar.INSTANCE, rhs.getDeterminism());
                       return new ComparisonExpression(op, Arrays.asList(lhs,rhs));
                   }
                 }
@@ -505,7 +514,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             if (!expression.evaluate(null, ptr)) {
                 return LiteralExpression.newConstant(null, expression.getDeterminism());
             } else {
-                return LiteralExpression.newConstant(Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr)) ^ node.isNegate(), expression.getDeterminism());
+                return LiteralExpression.newConstant(Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr)) ^ node.isNegate(), expression.getDeterminism());
             }
         }
         if (node.isNegate()) {
@@ -524,8 +533,8 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
     public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException {
         ParseNode childNode = node.getChildren().get(0);
         Expression child = children.get(0);
-        if (!PDataType.BOOLEAN.isCoercibleTo(child.getDataType())) {
-            throw TypeMismatchException.newException(PDataType.BOOLEAN, child.getDataType(), node.toString());
+        if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) {
+            throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString());
         }
         if (childNode instanceof BindParseNode) { // TODO: valid/possibe?
             context.getBindManager().addParamMetaData((BindParseNode)childNode, child);
@@ -599,7 +608,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         }
         @Override
         public PDataType getDataType() {
-            return PDataType.DECIMAL;
+            return PDecimal.INSTANCE;
         }
         @Override
         public Integer getMaxLength() {
@@ -635,7 +644,8 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         // If we found an "unknown" child type and the return type is a number
         // make the return type be the most general number type of DECIMAL.
         // TODO: same for TIMESTAMP for DATE/TIME?
-        if (isChildTypeUnknown && datum.getDataType() != null && datum.getDataType().isCoercibleTo(PDataType.DECIMAL)) {
+        if (isChildTypeUnknown && datum.getDataType() != null && datum.getDataType().isCoercibleTo(
+            PDecimal.INSTANCE)) {
             return DECIMAL_DATUM;
         }
         return datum;
@@ -707,7 +717,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             @Override
             public PDatum getBindMetaData(int i, List<Expression> children, final Expression expression) {
                 PDataType type = expression.getDataType();
-                if (type != null && type.isCoercibleTo(PDataType.DATE)) {
+                if (type != null && type.isCoercibleTo(PDate.INSTANCE)) {
                     return new PDatum() {
                         @Override
                         public boolean isNullable() {
@@ -715,7 +725,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                         }
                         @Override
                         public PDataType getDataType() {
-                            return PDataType.DECIMAL;
+                            return PDecimal.INSTANCE;
                         }
                         @Override
                         public Integer getMaxLength() {
@@ -746,41 +756,41 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                     PDataType type = e.getDataType();
                     if (type == null) {
                         continue; 
-                    } else if (type.isCoercibleTo(PDataType.TIMESTAMP)) {
+                    } else if (type.isCoercibleTo(PTimestamp.INSTANCE)) {
                         if (foundDate) {
                             throw TypeMismatchException.newException(type, node.toString());
                         }
-                        if (theType == null || (theType != PDataType.TIMESTAMP && theType != PDataType.UNSIGNED_TIMESTAMP)) {
+                        if (theType == null || (theType != PTimestamp.INSTANCE && theType != PUnsignedTimestamp.INSTANCE)) {
                             theType = type;
                         }
                         foundDate = true;
-                    }else if (type == PDataType.DECIMAL) {
-                        if (theType == null || !theType.isCoercibleTo(PDataType.TIMESTAMP)) {
-                            theType = PDataType.DECIMAL;
+                    }else if (type == PDecimal.INSTANCE) {
+                        if (theType == null || !theType.isCoercibleTo(PTimestamp.INSTANCE)) {
+                            theType = PDecimal.INSTANCE;
                         }
-                    } else if (type.isCoercibleTo(PDataType.LONG)) {
+                    } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.LONG;
+                            theType = PLong.INSTANCE;
                         }
-                    } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+                    } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.DOUBLE;
+                            theType = PDouble.INSTANCE;
                         }
                     } else {
                         throw TypeMismatchException.newException(type, node.toString());
                     }
                 }
-                if (theType == PDataType.DECIMAL) {
+                if (theType == PDecimal.INSTANCE) {
                     return new DecimalAddExpression(children);
-                } else if (theType == PDataType.LONG) {
+                } else if (theType == PLong.INSTANCE) {
                     return new LongAddExpression(children);
-                } else if (theType == PDataType.DOUBLE) {
+                } else if (theType == PDouble.INSTANCE) {
                     return new DoubleAddExpression(children);
                 } else if (theType == null) {
                 	return LiteralExpression.newConstant(null, theType, determinism);
-                } else if (theType == PDataType.TIMESTAMP || theType == PDataType.UNSIGNED_TIMESTAMP) {
+                } else if (theType == PTimestamp.INSTANCE || theType == PUnsignedTimestamp.INSTANCE) {
                     return new TimestampAddExpression(children);
-                } else if (theType.isCoercibleTo(PDataType.DATE)) {
+                } else if (theType.isCoercibleTo(PDate.INSTANCE)) {
                     return new DateAddExpression(children);
                 } else {
                     throw TypeMismatchException.newException(theType, node.toString());
@@ -805,7 +815,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                 // is a date
                 // we know that the first parameter must be a date type too.
                 if (i == 0 && (type = children.get(1).getDataType()) != null
-                        && type.isCoercibleTo(PDataType.DATE)) {
+                        && type.isCoercibleTo(PDate.INSTANCE)) {
                     return new PDatum() {
                         @Override
                         public boolean isNullable() {
@@ -830,7 +840,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                     };
                 } else if (expression.getDataType() != null
                         && expression.getDataType().isCoercibleTo(
-                                PDataType.DATE)) {
+                    PDate.INSTANCE)) {
                     return new PDatum() { // Same as with addition
                         @Override
                         public boolean isNullable() {
@@ -838,7 +848,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                         }
                         @Override
                         public PDataType getDataType() {
-                            return PDataType.DECIMAL;
+                            return PDecimal.INSTANCE;
                         }
                         @Override
                         public Integer getMaxLength() {
@@ -880,22 +890,22 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                  */
                 boolean isType1Date = 
                         type1 != null 
-                        && type1 != PDataType.TIMESTAMP
-                        && type1 != PDataType.UNSIGNED_TIMESTAMP
-                        && type1.isCoercibleTo(PDataType.DATE);
+                        && type1 != PTimestamp.INSTANCE
+                        && type1 != PUnsignedTimestamp.INSTANCE
+                        && type1.isCoercibleTo(PDate.INSTANCE);
                 boolean isType2Date = 
                         type2 != null
-                        && type2 != PDataType.TIMESTAMP
-                        && type2 != PDataType.UNSIGNED_TIMESTAMP
-                        && type2.isCoercibleTo(PDataType.DATE);
+                        && type2 != PTimestamp.INSTANCE
+                        && type2 != PUnsignedTimestamp.INSTANCE
+                        && type2.isCoercibleTo(PDate.INSTANCE);
                 if (isType1Date || isType2Date) {
                     if (isType1Date && isType2Date) {
                         i = 2;
-                        theType = PDataType.DECIMAL;
+                        theType = PDecimal.INSTANCE;
                     } else if (isType1Date && type2 != null
-                            && type2.isCoercibleTo(PDataType.DECIMAL)) {
+                            && type2.isCoercibleTo(PDecimal.INSTANCE)) {
                         i = 2;
-                        theType = PDataType.DATE;
+                        theType = PDate.INSTANCE;
                     } else if (type1 == null || type2 == null) {
                         /*
                          * FIXME: Could be either a Date or BigDecimal, but we
@@ -905,12 +915,12 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                         i = 2;
                         theType = null;
                     }
-                } else if(type1 == PDataType.TIMESTAMP || type2 == PDataType.TIMESTAMP) {
+                } else if(type1 == PTimestamp.INSTANCE || type2 == PTimestamp.INSTANCE) {
                     i = 2;
-                    theType = PDataType.TIMESTAMP;
-                } else if(type1 == PDataType.UNSIGNED_TIMESTAMP || type2 == PDataType.UNSIGNED_TIMESTAMP) {
+                    theType = PTimestamp.INSTANCE;
+                } else if(type1 == PUnsignedTimestamp.INSTANCE || type2 == PUnsignedTimestamp.INSTANCE) {
                     i = 2;
-                    theType = PDataType.UNSIGNED_TIMESTAMP;
+                    theType = PUnsignedTimestamp.INSTANCE;
                 }
                 
                 for (; i < children.size(); i++) {
@@ -921,39 +931,39 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                     PDataType type = e.getDataType();
                     if (type == null) {
                         continue;
-                    } else if (type.isCoercibleTo(PDataType.LONG)) {
+                    } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.LONG;
+                            theType = PLong.INSTANCE;
                         }
-                    } else if (type == PDataType.DECIMAL) {
+                    } else if (type == PDecimal.INSTANCE) {
                         // Coerce return type to DECIMAL from LONG or DOUBLE if DECIMAL child found,
                         // unless we're doing date arithmetic.
                         if (theType == null
-                                || !theType.isCoercibleTo(PDataType.DATE)) {
-                            theType = PDataType.DECIMAL;
+                                || !theType.isCoercibleTo(PDate.INSTANCE)) {
+                            theType = PDecimal.INSTANCE;
                         }
-                    } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+                    } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                         // Coerce return type to DOUBLE from LONG if DOUBLE child found,
                         // unless we're doing date arithmetic or we've found another child of type DECIMAL
                         if (theType == null
-                                || (theType != PDataType.DECIMAL && !theType.isCoercibleTo(PDataType.DATE) )) {
-                            theType = PDataType.DOUBLE;
+                                || (theType != PDecimal.INSTANCE && !theType.isCoercibleTo(PDate.INSTANCE) )) {
+                            theType = PDouble.INSTANCE;
                         }
                     } else {
                         throw TypeMismatchException.newException(type, node.toString());
                     }
                 }
-                if (theType == PDataType.DECIMAL) {
+                if (theType == PDecimal.INSTANCE) {
                     return new DecimalSubtractExpression(children);
-                } else if (theType == PDataType.LONG) {
+                } else if (theType == PLong.INSTANCE) {
                     return new LongSubtractExpression(children);
-                } else if (theType == PDataType.DOUBLE) {
+                } else if (theType == PDouble.INSTANCE) {
                     return new DoubleSubtractExpression(children);
                 } else if (theType == null) {
                 	return LiteralExpression.newConstant(null, theType, determinism);
-                } else if (theType == PDataType.TIMESTAMP || theType == PDataType.UNSIGNED_TIMESTAMP) {
+                } else if (theType == PTimestamp.INSTANCE || theType == PUnsignedTimestamp.INSTANCE) {
                     return new TimestampSubtractExpression(children);
-                } else if (theType.isCoercibleTo(PDataType.DATE)) {
+                } else if (theType.isCoercibleTo(PDate.INSTANCE)) {
                     return new DateSubtractExpression(children);
                 } else {
                     throw TypeMismatchException.newException(theType, node.toString());
@@ -980,29 +990,28 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                     PDataType type = e.getDataType();
                     if (type == null) {
                         continue;
-                    } else if (type == PDataType.DECIMAL) {
-                        theType = PDataType.DECIMAL;
-                    } else if (type.isCoercibleTo(PDataType.LONG)) {
+                    } else if (type == PDecimal.INSTANCE) {
+                        theType = PDecimal.INSTANCE;
+                    } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.LONG;
+                            theType = PLong.INSTANCE;
                         }
-                    } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+                    } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.DOUBLE;
+                            theType = PDouble.INSTANCE;
                         }
                     } else {
                         throw TypeMismatchException.newException(type, node.toString());
                     }
                 }
-                switch (theType) {
-                case DECIMAL:
-                    return new DecimalMultiplyExpression( children);
-                case LONG:
-                    return new LongMultiplyExpression( children);
-                case DOUBLE:
-                    return new DoubleMultiplyExpression( children);
-                default:
-                    return LiteralExpression.newConstant(null, theType, determinism);
+                if (theType == PDecimal.INSTANCE) {
+                  return new DecimalMultiplyExpression( children);
+                } else if (theType == PLong.INSTANCE) {
+                  return new LongMultiplyExpression( children);
+                } else if (theType == PDouble.INSTANCE) {
+                  return new DoubleMultiplyExpression( children);
+                } else {
+                  return LiteralExpression.newConstant(null, theType, determinism);
                 }
             }
         });
@@ -1019,12 +1028,12 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             Expression child = children.get(i);
                 if (child.getDataType() != null && child instanceof LiteralExpression) {
                     LiteralExpression literal = (LiteralExpression)child;
-                    if (literal.getDataType() == PDataType.DECIMAL) {
-                        if (PDataType.DECIMAL.compareTo(literal.getValue(), BigDecimal.ZERO) == 0) {
+                    if (literal.getDataType() == PDecimal.INSTANCE) {
+                        if (PDecimal.INSTANCE.compareTo(literal.getValue(), BigDecimal.ZERO) == 0) {
                             throw new SQLExceptionInfo.Builder(SQLExceptionCode.DIVIDE_BY_ZERO).build().buildException();
                         }
                     } else {
-                        if (literal.getDataType().compareTo(literal.getValue(), 0L, PDataType.LONG) == 0) {
+                        if (literal.getDataType().compareTo(literal.getValue(), 0L, PLong.INSTANCE) == 0) {
                             throw new SQLExceptionInfo.Builder(SQLExceptionCode.DIVIDE_BY_ZERO).build().buildException();
                         }
                     }
@@ -1041,29 +1050,28 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                     PDataType type = e.getDataType();
                     if (type == null) {
                         continue;
-                    } else if (type == PDataType.DECIMAL) {
-                        theType = PDataType.DECIMAL;
-                    } else if (type.isCoercibleTo(PDataType.LONG)) {
+                    } else if (type == PDecimal.INSTANCE) {
+                        theType = PDecimal.INSTANCE;
+                    } else if (type.isCoercibleTo(PLong.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.LONG;
+                            theType = PLong.INSTANCE;
                         }
-                    } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
+                    } else if (type.isCoercibleTo(PDouble.INSTANCE)) {
                         if (theType == null) {
-                            theType = PDataType.DOUBLE;
+                            theType = PDouble.INSTANCE;
                         }
                     } else {
                         throw TypeMismatchException.newException(type, node.toString());
                     }
                 }
-                switch (theType) {
-                case DECIMAL:
-                    return new DecimalDivideExpression( children);
-                case LONG:
-                    return new LongDivideExpression( children);
-                case DOUBLE:
-                    return new DoubleDivideExpression(children);
-                default:
-                    return LiteralExpression.newConstant(null, theType, determinism);
+                if (theType == PDecimal.INSTANCE) {
+                  return new DecimalDivideExpression( children);
+                } else if (theType == PLong.INSTANCE) {
+                  return new LongDivideExpression( children);
+                } else if (theType == PDouble.INSTANCE) {
+                  return new DoubleDivideExpression(children);
+                } else {
+                  return LiteralExpression.newConstant(null, theType, determinism);
                 }
             }
         });
@@ -1082,7 +1090,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                 // ensure integer types
                 for(Expression child : children) {
                     PDataType type = child.getDataType();
-                    if(type != null && !type.isCoercibleTo(PDataType.LONG)) {
+                    if(type != null && !type.isCoercibleTo(PLong.INSTANCE)) {
                         throw TypeMismatchException.newException(type, node.toString());
                     }
                 }
@@ -1136,7 +1144,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
                 context.getBindManager().addParamMetaData((BindParseNode)childNode,expression);
             }
             PDataType type=children.get(i).getDataType();
-            if(type==PDataType.VARBINARY){
+            if(type == PVarbinary.INSTANCE){
                 throw new SQLExceptionInfo.Builder(SQLExceptionCode.TYPE_NOT_SUPPORTED_FOR_OPERATOR)
                 .setMessage("Concatenation does not support "+ type +" in expression" + node).build().buildException();
             }
@@ -1202,8 +1210,9 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         }
         // If we found an "unknown" child type and the return type is a number
         // make the return type be the most general number type of DECIMAL.
-        if (isChildTypeUnknown && arrayElemDataType != null && arrayElemDataType.isCoercibleTo(PDataType.DECIMAL)) {
-            arrayElemDataType = PDataType.DECIMAL;
+        if (isChildTypeUnknown && arrayElemDataType != null && arrayElemDataType.isCoercibleTo(
+            PDecimal.INSTANCE)) {
+            arrayElemDataType = PDecimal.INSTANCE;
         }
         final PDataType theArrayElemDataType = arrayElemDataType;
         for (int i = 0; i < node.getChildren().size(); i++) {
@@ -1220,8 +1229,9 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
             }
         }
         ImmutableBytesWritable ptr = context.getTempPtr();
-        Object[] elements = new Object[children.size()];
-        
+        // the value object array type should match the java known type
+        Object[] elements = (Object[]) java.lang.reflect.Array.newInstance(theArrayElemDataType.getJavaClass(), children.size());
+
         ArrayConstructorExpression arrayExpression = new ArrayConstructorExpression(children, arrayElemDataType);
         if (ExpressionUtil.isConstant(arrayExpression)) {
             for (int i = 0; i < children.size(); i++) {
@@ -1252,7 +1262,7 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
     public Expression visitLeave(ExistsParseNode node, List<Expression> l) throws SQLException {
         LiteralExpression child = (LiteralExpression) l.get(0);
         PhoenixArray array = (PhoenixArray) child.getValue();
-        return LiteralExpression.newConstant(array.getDimensions() > 0 ^ node.isNegate(), PDataType.BOOLEAN);
+        return LiteralExpression.newConstant(array.getDimensions() > 0 ^ node.isNegate(), PBoolean.INSTANCE);
     }
 
     @Override
@@ -1260,4 +1270,4 @@ public class ExpressionCompiler extends UnsupportedAllParseNodeVisitor<Expressio
         Object result = context.getSubqueryResult(node.getSelectNode());
         return LiteralExpression.newConstant(result);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionProjector.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionProjector.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionProjector.java
index db58332..b333ac6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionProjector.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionProjector.java
@@ -22,7 +22,7 @@ import java.sql.SQLException;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/GroupByCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/GroupByCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/GroupByCompiler.java
index 016cd52..ecb238a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/GroupByCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/GroupByCompiler.java
@@ -38,11 +38,12 @@ import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.schema.AmbiguousColumnException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
-
+import org.apache.phoenix.schema.types.PVarchar;
 
 /**
  * 
@@ -268,11 +269,11 @@ public class GroupByCompiler {
         if (!expression.isNullable() || !type.isFixedWidth()) {
             return type;
         }
-        if (type.isCastableTo(PDataType.DECIMAL)) {
-            return PDataType.DECIMAL;
+        if (type.isCastableTo(PDecimal.INSTANCE)) {
+            return PDecimal.INSTANCE;
         }
-        if (type.isCastableTo(PDataType.VARCHAR)) {
-            return PDataType.VARCHAR;
+        if (type.isCastableTo(PVarchar.INSTANCE)) {
+            return PVarchar.INSTANCE;
         }
         // This might happen if someone tries to group by an array
         throw new IllegalStateException("Multiple occurrences of type " + type + " may not occur in a GROUP BY clause");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/HavingCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/HavingCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/HavingCompiler.java
index a9f2f71..0cd6ecf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/HavingCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/HavingCompiler.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.SelectStatementRewriter;
 import org.apache.phoenix.schema.ColumnRef;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 
@@ -51,8 +51,8 @@ public class HavingCompiler {
         }
         ExpressionCompiler expressionBuilder = new ExpressionCompiler(context, groupBy);
         Expression expression = having.accept(expressionBuilder);
-        if (expression.getDataType() != PDataType.BOOLEAN) {
-            throw TypeMismatchException.newException(PDataType.BOOLEAN, expression.getDataType(), expression.toString());
+        if (expression.getDataType() != PBoolean.INSTANCE) {
+            throw TypeMismatchException.newException(PBoolean.INSTANCE, expression.getDataType(), expression.toString());
         }
         if (LiteralExpression.isFalse(expression)) {
             context.setScanRanges(ScanRanges.NOTHING);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/IndexStatementRewriter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/IndexStatementRewriter.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/IndexStatementRewriter.java
index c9349ec..17b1574 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/IndexStatementRewriter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/IndexStatementRewriter.java
@@ -34,7 +34,7 @@ import org.apache.phoenix.parse.TableWildcardParseNode;
 import org.apache.phoenix.parse.WildcardParseNode;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.util.IndexUtil;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 45b6603..f90cef8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -69,14 +69,25 @@ import org.apache.phoenix.parse.WildcardParseNode;
 import org.apache.phoenix.schema.AmbiguousColumnException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ColumnRef;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnImpl;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PNameFactory;
+import org.apache.phoenix.schema.types.PSmallint;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableImpl;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PTinyint;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -541,57 +552,57 @@ public class JoinCompiler {
                     .setMessage("On-clause LHS expression and RHS expression must be comparable. LHS type: " + lType + ", RHS type: " + rType)
                     .build().buildException();
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.TINYINT))
-                    && (rType == null || rType.isCoercibleTo(PDataType.TINYINT))) {
+            if ((lType == null || lType.isCoercibleTo(PTinyint.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PTinyint.INSTANCE))) {
                 return lType == null ? rType : lType; // to preserve UNSIGNED type
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.SMALLINT))
-                    && (rType == null || rType.isCoercibleTo(PDataType.SMALLINT))) {
+            if ((lType == null || lType.isCoercibleTo(PSmallint.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PSmallint.INSTANCE))) {
                 return lType == null ? rType : lType; // to preserve UNSIGNED type
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.INTEGER))
-                    && (rType == null || rType.isCoercibleTo(PDataType.INTEGER))) {
+            if ((lType == null || lType.isCoercibleTo(PInteger.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PInteger.INSTANCE))) {
                 return lType == null ? rType : lType; // to preserve UNSIGNED type
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.LONG))
-                    && (rType == null || rType.isCoercibleTo(PDataType.LONG))) {
+            if ((lType == null || lType.isCoercibleTo(PLong.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PLong.INSTANCE))) {
                 return lType == null ? rType : lType; // to preserve UNSIGNED type
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.DOUBLE))
-                    && (rType == null || rType.isCoercibleTo(PDataType.DOUBLE))) {
+            if ((lType == null || lType.isCoercibleTo(PDouble.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PDouble.INSTANCE))) {
                 return lType == null ? rType : lType; // to preserve UNSIGNED type
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.DECIMAL))
-                    && (rType == null || rType.isCoercibleTo(PDataType.DECIMAL))) {
-                return PDataType.DECIMAL;
+            if ((lType == null || lType.isCoercibleTo(PDecimal.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PDecimal.INSTANCE))) {
+                return PDecimal.INSTANCE;
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.DATE))
-                    && (rType == null || rType.isCoercibleTo(PDataType.DATE))) {
+            if ((lType == null || lType.isCoercibleTo(PDate.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PDate.INSTANCE))) {
                 return lType == null ? rType : lType;
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.TIMESTAMP))
-                    && (rType == null || rType.isCoercibleTo(PDataType.TIMESTAMP))) {
+            if ((lType == null || lType.isCoercibleTo(PTimestamp.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PTimestamp.INSTANCE))) {
                 return lType == null ? rType : lType;
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.VARCHAR))
-                    && (rType == null || rType.isCoercibleTo(PDataType.VARCHAR))) {
-                return PDataType.VARCHAR;
+            if ((lType == null || lType.isCoercibleTo(PVarchar.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PVarchar.INSTANCE))) {
+                return PVarchar.INSTANCE;
             }
 
-            if ((lType == null || lType.isCoercibleTo(PDataType.BOOLEAN))
-                    && (rType == null || rType.isCoercibleTo(PDataType.BOOLEAN))) {
-                return PDataType.BOOLEAN;
+            if ((lType == null || lType.isCoercibleTo(PBoolean.INSTANCE))
+                    && (rType == null || rType.isCoercibleTo(PBoolean.INSTANCE))) {
+                return PBoolean.INSTANCE;
             }
 
-            return PDataType.VARBINARY;
+            return PVarbinary.INSTANCE;
         }
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
index 4f31107..06caad9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/LimitCompiler.java
@@ -25,11 +25,11 @@ import org.apache.phoenix.parse.LimitNode;
 import org.apache.phoenix.parse.LiteralParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
 import org.apache.phoenix.parse.TraverseNoParseNodeVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.SortOrder;
 
-
 public class LimitCompiler {
     private static final ParseNodeFactory NODE_FACTORY = new ParseNodeFactory();
     
@@ -40,7 +40,7 @@ public class LimitCompiler {
         }
         @Override
         public PDataType getDataType() {
-            return PDataType.INTEGER;
+            return PInteger.INSTANCE;
         }
         @Override
         public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/MutatingParallelIteratorFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/MutatingParallelIteratorFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/MutatingParallelIteratorFactory.java
index ba601ef..bcac17d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/MutatingParallelIteratorFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/MutatingParallelIteratorFactory.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.KeyValueUtil;
@@ -68,7 +68,7 @@ public abstract class MutatingParallelIteratorFactory implements ParallelIterato
             state = new MutationState(maxSize, connection, totalRowCount);
         }
         final MutationState finalState = state;
-        byte[] value = PDataType.LONG.toBytes(totalRowCount);
+        byte[] value = PLong.INSTANCE.toBytes(totalRowCount);
         KeyValue keyValue = KeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, AGG_TIMESTAMP, value, 0, value.length);
         final Tuple tuple = new SingleKeyValueTuple(keyValue);
         return new PeekingResultIterator() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
index 033995e..0c586f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/PostDDLCompiler.java
@@ -42,7 +42,7 @@ import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -210,7 +210,7 @@ public class PostDDLCompiler {
                                 try {
                                     Tuple row = iterator.next();
                                     ImmutableBytesWritable ptr = context.getTempPtr();
-                                    totalMutationCount += (Long)projector.getColumnProjector(0).getValue(row, PDataType.LONG, ptr);
+                                    totalMutationCount += (Long)projector.getColumnProjector(0).getValue(row, PLong.INSTANCE, ptr);
                                 } catch (SQLException e) {
                                     sqlE = e;
                                 } finally {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index 3204e03..c6ab7ec 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -70,7 +70,7 @@ import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.LocalIndexDataColumnRef;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
index 9ea4245..e62f87d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/SequenceManager.java
@@ -32,7 +32,8 @@ import org.apache.phoenix.parse.SequenceValueParseNode;
 import org.apache.phoenix.parse.SequenceValueParseNode.Op;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.ConnectionQueryServices;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.Sequence;
 import org.apache.phoenix.schema.SequenceKey;
@@ -191,15 +192,15 @@ public class SequenceManager {
         
         @Override
         public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
-        		byte[] valueBuffer = new byte[PDataType.LONG.getByteSize()];
-            PDataType.LONG.getCodec().encodeLong(tuple.getSequenceValue(index), valueBuffer, 0);
+        		byte[] valueBuffer = new byte[PLong.INSTANCE.getByteSize()];
+            PLong.INSTANCE.getCodec().encodeLong(tuple.getSequenceValue(index), valueBuffer, 0);
             ptr.set(valueBuffer);
             return true;
         }
 
         @Override
         public PDataType getDataType() {
-            return PDataType.LONG;
+            return PLong.INSTANCE;
         }
         
         @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 796f368..5395210 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -73,7 +73,7 @@ import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.MetaDataEntityNotFoundException;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnImpl;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.ViewType;
@@ -613,7 +613,7 @@ public class UpsertCompiler {
                                 ResultIterator iterator = aggPlan.iterator();
                                 try {
                                     Tuple row = iterator.next();
-                                    final long mutationCount = (Long)aggProjector.getColumnProjector(0).getValue(row, PDataType.LONG, ptr);
+                                    final long mutationCount = (Long)aggProjector.getColumnProjector(0).getValue(row, PLong.INSTANCE, ptr);
                                     return new MutationState(maxSize, connection) {
                                         @Override
                                         public long getUpdateCount() {
@@ -675,7 +675,7 @@ public class UpsertCompiler {
                     long totalRowCount = 0;
                     while ((tuple=iterator.next()) != null) {// Runs query
                         Cell kv = tuple.getValue(0);
-                        totalRowCount += PDataType.LONG.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
+                        totalRowCount += PLong.INSTANCE.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
                     }
                     // Return total number of rows that have been updated. In the case of auto commit being off
                     // the mutations will all be in the mutation state of the current connection.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index b3a9c2d..1360178 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -49,7 +49,7 @@ import org.apache.phoenix.parse.SubqueryParseNode;
 import org.apache.phoenix.schema.AmbiguousColumnException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ColumnRef;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
@@ -127,12 +127,12 @@ public class WhereCompiler {
         
         Set<Expression> extractedNodes = Sets.<Expression>newHashSet();
         WhereExpressionCompiler whereCompiler = new WhereExpressionCompiler(context);
-        Expression expression = where == null ? LiteralExpression.newConstant(true,PDataType.BOOLEAN,Determinism.ALWAYS) : where.accept(whereCompiler);
+        Expression expression = where == null ? LiteralExpression.newConstant(true, PBoolean.INSTANCE,Determinism.ALWAYS) : where.accept(whereCompiler);
         if (whereCompiler.isAggregate()) {
             throw new SQLExceptionInfo.Builder(SQLExceptionCode.AGGREGATE_IN_WHERE).build().buildException();
         }
-        if (expression.getDataType() != PDataType.BOOLEAN) {
-            throw TypeMismatchException.newException(PDataType.BOOLEAN, expression.getDataType(), expression.toString());
+        if (expression.getDataType() != PBoolean.INSTANCE) {
+            throw TypeMismatchException.newException(PBoolean.INSTANCE, expression.getDataType(), expression.toString());
         }
         if (viewWhere != null) {
             WhereExpressionCompiler viewWhereCompiler = new WhereExpressionCompiler(context, true);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
index 58e0bee..5edd38c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
@@ -54,10 +54,12 @@ import org.apache.phoenix.parse.HintNode.Hint;
 import org.apache.phoenix.parse.LikeParseNode.LikeType;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.schema.SortOrder;
@@ -84,7 +86,7 @@ import com.google.common.collect.Sets;
  */
 public class WhereOptimizer {
     private static final List<KeyRange> EVERYTHING_RANGES = Collections.<KeyRange>singletonList(KeyRange.EVERYTHING_RANGE);
-    private static final List<KeyRange> SALT_PLACEHOLDER = Collections.singletonList(PDataType.CHAR.getKeyRange(QueryConstants.SEPARATOR_BYTE_ARRAY));
+    private static final List<KeyRange> SALT_PLACEHOLDER = Collections.singletonList(PChar.INSTANCE.getKeyRange(QueryConstants.SEPARATOR_BYTE_ARRAY));
     
     private WhereOptimizer() {
     }
@@ -939,7 +941,7 @@ public class WhereOptimizer {
             KeySlots childSlots = childParts.get(0);
             KeySlot childSlot = childSlots.iterator().next();
             final String startsWith = node.getLiteralPrefix();
-            byte[] key = PDataType.CHAR.toBytes(startsWith, node.getChildren().get(0).getSortOrder());
+            byte[] key = PChar.INSTANCE.toBytes(startsWith, node.getChildren().get(0).getSortOrder());
             // If the expression is an equality expression against a fixed length column
             // and the key length doesn't match the column length, the expression can
             // never be true.
@@ -1379,7 +1381,7 @@ public class WhereOptimizer {
                     return null; 
                 }
                 byte[] key = ByteUtil.copyKeyBytesIfNecessary(ptr);
-                return ByteUtil.getKeyRange(key, op, PDataType.VARBINARY);
+                return ByteUtil.getKeyRange(key, op, PVarbinary.INSTANCE);
             }
 
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
index 91a9bdd..ca21742 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/GroupedAggregateRegionObserver.java
@@ -63,7 +63,7 @@ import org.apache.phoenix.index.IndexMaintainer;
 import org.apache.phoenix.join.HashJoinInfo;
 import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.MultiKeyValueTuple;
 import org.apache.phoenix.util.Closeables;
@@ -128,7 +128,7 @@ public class GroupedAggregateRegionObserver extends BaseScannerRegionObserver {
         long limit = Long.MAX_VALUE;
         byte[] limitBytes = scan.getAttribute(GROUP_BY_LIMIT);
         if (limitBytes != null) {
-            limit = PDataType.INTEGER.getCodec().decodeInt(limitBytes, 0, SortOrder.getDefault());
+            limit = PInteger.INSTANCE.getCodec().decodeInt(limitBytes, 0, SortOrder.getDefault());
         }
 
         RegionScanner innerScanner = s;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 6f247c7..ebd9355 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -112,13 +112,17 @@ import org.apache.phoenix.metrics.Metrics;
 import org.apache.phoenix.protobuf.ProtobufUtil;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.AmbiguousColumnException;
+import org.apache.phoenix.schema.types.PBinary;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
 import org.apache.phoenix.schema.PColumnImpl;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTable;
@@ -127,6 +131,8 @@ import org.apache.phoenix.schema.PTable.LinkType;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableImpl;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.stats.PTableStats;
@@ -415,41 +421,41 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
 
         Cell columnSizeKv = colKeyValues[COLUMN_SIZE_INDEX];
         Integer maxLength =
-                columnSizeKv == null ? null : PDataType.INTEGER.getCodec().decodeInt(
+                columnSizeKv == null ? null : PInteger.INSTANCE.getCodec().decodeInt(
                     columnSizeKv.getValueArray(), columnSizeKv.getValueOffset(), SortOrder.getDefault());
         Cell decimalDigitKv = colKeyValues[DECIMAL_DIGITS_INDEX];
         Integer scale =
-                decimalDigitKv == null ? null : PDataType.INTEGER.getCodec().decodeInt(
+                decimalDigitKv == null ? null : PInteger.INSTANCE.getCodec().decodeInt(
                     decimalDigitKv.getValueArray(), decimalDigitKv.getValueOffset(), SortOrder.getDefault());
         Cell ordinalPositionKv = colKeyValues[ORDINAL_POSITION_INDEX];
         int position =
-                PDataType.INTEGER.getCodec().decodeInt(ordinalPositionKv.getValueArray(),
+            PInteger.INSTANCE.getCodec().decodeInt(ordinalPositionKv.getValueArray(),
                     ordinalPositionKv.getValueOffset(), SortOrder.getDefault()) + (isSalted ? 1 : 0);
         Cell nullableKv = colKeyValues[NULLABLE_INDEX];
         boolean isNullable =
-                PDataType.INTEGER.getCodec().decodeInt(nullableKv.getValueArray(),
+            PInteger.INSTANCE.getCodec().decodeInt(nullableKv.getValueArray(),
                     nullableKv.getValueOffset(), SortOrder.getDefault()) != ResultSetMetaData.columnNoNulls;
         Cell dataTypeKv = colKeyValues[DATA_TYPE_INDEX];
         PDataType dataType =
-                PDataType.fromTypeId(PDataType.INTEGER.getCodec().decodeInt(
+                PDataType.fromTypeId(PInteger.INSTANCE.getCodec().decodeInt(
                   dataTypeKv.getValueArray(), dataTypeKv.getValueOffset(), SortOrder.getDefault()));
-        if (maxLength == null && dataType == PDataType.BINARY) dataType = PDataType.VARBINARY; // For
+        if (maxLength == null && dataType == PBinary.INSTANCE) dataType = PVarbinary.INSTANCE;   // For
                                                                                                // backward
                                                                                                // compatibility.
         Cell sortOrderKv = colKeyValues[SORT_ORDER_INDEX];
         SortOrder sortOrder =
-        		sortOrderKv == null ? SortOrder.getDefault() : SortOrder.fromSystemValue(PDataType.INTEGER
+        		sortOrderKv == null ? SortOrder.getDefault() : SortOrder.fromSystemValue(PInteger.INSTANCE
                         .getCodec().decodeInt(sortOrderKv.getValueArray(),
                         		sortOrderKv.getValueOffset(), SortOrder.getDefault()));
         
         Cell arraySizeKv = colKeyValues[ARRAY_SIZE_INDEX];
-        Integer arraySize = arraySizeKv == null ? null : 
-          PDataType.INTEGER.getCodec().decodeInt(arraySizeKv.getValueArray(), arraySizeKv.getValueOffset(), SortOrder.getDefault());
+        Integer arraySize = arraySizeKv == null ? null :
+            PInteger.INSTANCE.getCodec().decodeInt(arraySizeKv.getValueArray(), arraySizeKv.getValueOffset(), SortOrder.getDefault());
  
         Cell viewConstantKv = colKeyValues[VIEW_CONSTANT_INDEX];
         byte[] viewConstant = viewConstantKv == null ? null : viewConstantKv.getValue();
         Cell isViewReferencedKv = colKeyValues[IS_VIEW_REFERENCED_INDEX];
-        boolean isViewReferenced = isViewReferencedKv != null && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(isViewReferencedKv.getValueArray(), isViewReferencedKv.getValueOffset(), isViewReferencedKv.getValueLength()));
+        boolean isViewReferenced = isViewReferencedKv != null && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isViewReferencedKv.getValueArray(), isViewReferencedKv.getValueOffset(), isViewReferencedKv.getValueLength()));
         PColumn column = new PColumnImpl(colName, famName, dataType, maxLength, scale, isNullable, position-1, sortOrder, arraySize, viewConstant, isViewReferenced);
         columns.add(column);
     }
@@ -530,11 +536,11 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                         .fromSerializedValue(tableTypeKv.getValueArray()[tableTypeKv.getValueOffset()]);
         Cell tableSeqNumKv = tableKeyValues[TABLE_SEQ_NUM_INDEX];
         long tableSeqNum =
-                PDataType.LONG.getCodec().decodeLong(tableSeqNumKv.getValueArray(),
+            PLong.INSTANCE.getCodec().decodeLong(tableSeqNumKv.getValueArray(),
                     tableSeqNumKv.getValueOffset(), SortOrder.getDefault());
         Cell columnCountKv = tableKeyValues[COLUMN_COUNT_INDEX];
         int columnCount =
-                PDataType.INTEGER.getCodec().decodeInt(columnCountKv.getValueArray(),
+            PInteger.INSTANCE.getCodec().decodeInt(columnCountKv.getValueArray(),
                     columnCountKv.getValueOffset(), SortOrder.getDefault());
         Cell pkNameKv = tableKeyValues[PK_NAME_INDEX];
         PName pkName =
@@ -542,7 +548,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                     pkNameKv.getValueLength()) : null;
         Cell saltBucketNumKv = tableKeyValues[SALT_BUCKETS_INDEX];
         Integer saltBucketNum =
-                saltBucketNumKv != null ? (Integer) PDataType.INTEGER.getCodec().decodeInt(
+                saltBucketNumKv != null ? (Integer) PInteger.INSTANCE.getCodec().decodeInt(
                     saltBucketNumKv.getValueArray(), saltBucketNumKv.getValueOffset(), SortOrder.getDefault()) : null;
         if (saltBucketNum != null && saltBucketNum.intValue() == 0) {
             saltBucketNum = null; // Zero salt buckets means not salted
@@ -557,17 +563,19 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                         .getValueArray()[indexStateKv.getValueOffset()]);
         Cell immutableRowsKv = tableKeyValues[IMMUTABLE_ROWS_INDEX];
         boolean isImmutableRows =
-                immutableRowsKv == null ? false : (Boolean) PDataType.BOOLEAN.toObject(
+                immutableRowsKv == null ? false : (Boolean) PBoolean.INSTANCE.toObject(
                     immutableRowsKv.getValueArray(), immutableRowsKv.getValueOffset(),
                     immutableRowsKv.getValueLength());
         Cell defaultFamilyNameKv = tableKeyValues[DEFAULT_COLUMN_FAMILY_INDEX];
         PName defaultFamilyName = defaultFamilyNameKv != null ? newPName(defaultFamilyNameKv.getValueArray(), defaultFamilyNameKv.getValueOffset(), defaultFamilyNameKv.getValueLength()) : null;
         Cell viewStatementKv = tableKeyValues[VIEW_STATEMENT_INDEX];
-        String viewStatement = viewStatementKv != null ? (String)PDataType.VARCHAR.toObject(viewStatementKv.getValueArray(), viewStatementKv.getValueOffset(), viewStatementKv.getValueLength()) : null;
+        String viewStatement = viewStatementKv != null ? (String) PVarchar.INSTANCE.toObject(viewStatementKv.getValueArray(), viewStatementKv.getValueOffset(),
+                viewStatementKv.getValueLength()) : null;
         Cell disableWALKv = tableKeyValues[DISABLE_WAL_INDEX];
-        boolean disableWAL = disableWALKv == null ? PTable.DEFAULT_DISABLE_WAL : Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(disableWALKv.getValueArray(), disableWALKv.getValueOffset(), disableWALKv.getValueLength()));
+        boolean disableWAL = disableWALKv == null ? PTable.DEFAULT_DISABLE_WAL : Boolean.TRUE.equals(
+            PBoolean.INSTANCE.toObject(disableWALKv.getValueArray(), disableWALKv.getValueOffset(), disableWALKv.getValueLength()));
         Cell multiTenantKv = tableKeyValues[MULTI_TENANT_INDEX];
-        boolean multiTenant = multiTenantKv == null ? false : Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(multiTenantKv.getValueArray(), multiTenantKv.getValueOffset(), multiTenantKv.getValueLength()));
+        boolean multiTenant = multiTenantKv == null ? false : Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(multiTenantKv.getValueArray(), multiTenantKv.getValueOffset(), multiTenantKv.getValueLength()));
         Cell viewTypeKv = tableKeyValues[VIEW_TYPE_INDEX];
         ViewType viewType = viewTypeKv == null ? null : ViewType.fromSerializedValue(viewTypeKv.getValueArray()[viewTypeKv.getValueOffset()]);
         Cell viewIndexIdKv = tableKeyValues[VIEW_INDEX_ID_INDEX];
@@ -1542,11 +1550,11 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
                     (currentState == PIndexState.DISABLE || currentState == PIndexState.INACTIVE) && 
                     (currentDisableTimeStamp != null && currentDisableTimeStamp.getValueLength() > 0) &&
                     (disableTimeStampKVIndex >= 0)) {
-                    Long curTimeStampVal = (Long)PDataType.LONG.toObject(currentDisableTimeStamp.getValueArray(), 
+                    Long curTimeStampVal = (Long) PLong.INSTANCE.toObject(currentDisableTimeStamp.getValueArray(),
                       currentDisableTimeStamp.getValueOffset(), currentDisableTimeStamp.getValueLength());
                     // new DisableTimeStamp is passed in
                     Cell newDisableTimeStampCell = newKVs.get(disableTimeStampKVIndex);
-                    Long newDisableTimeStamp = (Long)PDataType.LONG.toObject(newDisableTimeStampCell.getValueArray(),
+                    Long newDisableTimeStamp = (Long) PLong.INSTANCE.toObject(newDisableTimeStampCell.getValueArray(),
                       newDisableTimeStampCell.getValueOffset(), newDisableTimeStampCell.getValueLength());
                     if(curTimeStampVal > 0 && curTimeStampVal < newDisableTimeStamp){
                         // not reset disable timestamp

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index 822ced8..6f1d5ac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -26,9 +26,7 @@ import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -53,8 +51,8 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.MetaDataClient;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.util.MetaDataUtil;
@@ -159,7 +157,7 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                 Scan scan = new Scan();
                 SingleColumnValueFilter filter = new SingleColumnValueFilter(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
                     PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP_BYTES,
-                    CompareFilter.CompareOp.NOT_EQUAL, PDataType.LONG.toBytes(0L));
+                    CompareFilter.CompareOp.NOT_EQUAL, PLong.INSTANCE.toBytes(0L));
                 filter.setFilterIfMissing(true);
                 scan.setFilter(filter);
                 scan.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
@@ -190,7 +188,7 @@ public class MetaDataRegionObserver extends BaseRegionObserver {
                     }
 
                     // disableTimeStamp has to be a positive value
-                    disabledTimeStampVal = (Long) PDataType.LONG.toObject(disabledTimeStamp);
+                    disabledTimeStampVal = (Long) PLong.INSTANCE.toObject(disabledTimeStamp);
                     if (disabledTimeStampVal <= 0) {
                         continue;
                     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
index 9754d00..c1cf2df 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SequenceRegionObserver.java
@@ -19,12 +19,9 @@
 package org.apache.phoenix.coprocessor;
 
 import java.io.IOException;
-import java.sql.SQLException;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.NavigableMap;
-import java.util.Set;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellUtil;
@@ -48,7 +45,10 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.Sequence;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.ByteUtil;
@@ -56,8 +56,6 @@ import org.apache.phoenix.util.KeyValueUtil;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.SequenceUtil;
 import org.apache.phoenix.util.ServerUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 
@@ -79,11 +77,11 @@ public class SequenceRegionObserver extends BaseRegionObserver {
     public static final String OPERATION_ATTRIB = "SEQUENCE_OPERATION";
     public static final String MAX_TIMERANGE_ATTRIB = "MAX_TIMERANGE";
     public static final String CURRENT_VALUE_ATTRIB = "CURRENT_VALUE";
-    private static final byte[] SUCCESS_VALUE = PDataType.INTEGER.toBytes(Integer.valueOf(Sequence.SUCCESS));
+    private static final byte[] SUCCESS_VALUE = PInteger.INSTANCE.toBytes(Integer.valueOf(Sequence.SUCCESS));
     
     private static Result getErrorResult(byte[] row, long timestamp, int errorCode) {
-        byte[] errorCodeBuf = new byte[PDataType.INTEGER.getByteSize()];
-        PDataType.INTEGER.getCodec().encodeInt(errorCode, errorCodeBuf, 0);
+        byte[] errorCodeBuf = new byte[PInteger.INSTANCE.getByteSize()];
+        PInteger.INSTANCE.getCodec().encodeInt(errorCode, errorCodeBuf, 0);
         return  Result.create(Collections.singletonList(
                 (Cell)KeyValueUtil.newKeyValue(row, 
                         PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, 
@@ -148,9 +146,9 @@ public class SequenceRegionObserver extends BaseRegionObserver {
                 KeyValue incrementByKV = Sequence.getIncrementByKV(result);
                 KeyValue cacheSizeKV = Sequence.getCacheSizeKV(result);
                 
-                long currentValue = PDataType.LONG.getCodec().decodeLong(currentValueKV.getValueArray(), currentValueKV.getValueOffset(), SortOrder.getDefault());
-                long incrementBy = PDataType.LONG.getCodec().decodeLong(incrementByKV.getValueArray(), incrementByKV.getValueOffset(), SortOrder.getDefault());
-                long cacheSize = PDataType.LONG.getCodec().decodeLong(cacheSizeKV.getValueArray(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
+                long currentValue = PLong.INSTANCE.getCodec().decodeLong(currentValueKV.getValueArray(), currentValueKV.getValueOffset(), SortOrder.getDefault());
+                long incrementBy = PLong.INSTANCE.getCodec().decodeLong(incrementByKV.getValueArray(), incrementByKV.getValueOffset(), SortOrder.getDefault());
+                long cacheSize = PLong.INSTANCE.getCodec().decodeLong(cacheSizeKV.getValueArray(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
                 
                 // Hold timestamp constant for sequences, so that clients always only see the latest
                 // value regardless of when they connect.
@@ -189,7 +187,7 @@ public class SequenceRegionObserver extends BaseRegionObserver {
 	                	Sequence.replaceLimitReachedKV(cells, newLimitReachedKV);
 	                }
 	                else {
-	                	limitReached = (Boolean) PDataType.BOOLEAN.toObject(limitReachedKV.getValueArray(),
+	                	limitReached = (Boolean) PBoolean.INSTANCE.toObject(limitReachedKV.getValueArray(),
 	                			limitReachedKV.getValueOffset(), limitReachedKV.getValueLength());
 	                }
 	                long minValue;
@@ -200,7 +198,7 @@ public class SequenceRegionObserver extends BaseRegionObserver {
 	                    Sequence.replaceMinValueKV(cells, newMinValueKV);
 	                }
 	                else {
-	                    minValue = PDataType.LONG.getCodec().decodeLong(minValueKV.getValueArray(),
+	                    minValue = PLong.INSTANCE.getCodec().decodeLong(minValueKV.getValueArray(),
 	                                minValueKV.getValueOffset(), SortOrder.getDefault());
 	                }           
 	                long maxValue;
@@ -211,7 +209,7 @@ public class SequenceRegionObserver extends BaseRegionObserver {
 	                    Sequence.replaceMaxValueKV(cells, newMaxValueKV);
 	                }
 	                else {
-	                    maxValue =  PDataType.LONG.getCodec().decodeLong(maxValueKV.getValueArray(),
+	                    maxValue =  PLong.INSTANCE.getCodec().decodeLong(maxValueKV.getValueArray(),
 	                            maxValueKV.getValueOffset(), SortOrder.getDefault());
 	                }
 	                boolean cycle;
@@ -222,7 +220,7 @@ public class SequenceRegionObserver extends BaseRegionObserver {
 	                    Sequence.replaceCycleValueKV(cells, newCycleKV);
 	                }
 	                else {
-	                    cycle = (Boolean) PDataType.BOOLEAN.toObject(cycleKV.getValueArray(),
+	                    cycle = (Boolean) PBoolean.INSTANCE.toObject(cycleKV.getValueArray(),
 	                            cycleKV.getValueOffset(), cycleKV.getValueLength());
 	                }
 	                
@@ -277,8 +275,8 @@ public class SequenceRegionObserver extends BaseRegionObserver {
 	 * @return return the KeyValue that was created
 	 */
 	KeyValue createKeyValue(byte[] key, byte[] cqBytes, long value, long timestamp) {
-		byte[] valueBuffer = new byte[PDataType.LONG.getByteSize()];
-		PDataType.LONG.getCodec().encodeLong(value, valueBuffer, 0);
+		byte[] valueBuffer = new byte[PLong.INSTANCE.getByteSize()];
+    PLong.INSTANCE.getCodec().encodeLong(value, valueBuffer, 0);
 		return KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, cqBytes, timestamp, valueBuffer);
 	}
     
@@ -374,8 +372,8 @@ public class SequenceRegionObserver extends BaseRegionObserver {
                 switch (op) {
                 case RETURN_SEQUENCE:
                     KeyValue currentValueKV = result.raw()[0];
-                    long expectedValue = PDataType.LONG.getCodec().decodeLong(append.getAttribute(CURRENT_VALUE_ATTRIB), 0, SortOrder.getDefault());
-                    long value = PDataType.LONG.getCodec().decodeLong(currentValueKV.getValueArray(), 
+                    long expectedValue = PLong.INSTANCE.getCodec().decodeLong(append.getAttribute(CURRENT_VALUE_ATTRIB), 0, SortOrder.getDefault());
+                    long value = PLong.INSTANCE.getCodec().decodeLong(currentValueKV.getValueArray(),
                       currentValueKV.getValueOffset(), SortOrder.getDefault());
                     // Timestamp should match exactly, or we may have the wrong sequence
                     if (expectedValue != value || currentValueKV.getTimestamp() != clientTimestamp) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SuffixFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SuffixFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SuffixFilter.java
index e6bf9ac..083a01e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SuffixFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/SuffixFilter.java
@@ -1,3 +1,20 @@
+/*
+ * 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.coprocessor;
 
 import java.io.IOException;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index ff05dad..9bf9d86 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -49,7 +49,6 @@ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.InternalScanner;
-import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
 import org.apache.hadoop.hbase.regionserver.RegionScanner;
 import org.apache.hadoop.hbase.regionserver.ScanType;
 import org.apache.hadoop.hbase.regionserver.Store;
@@ -69,14 +68,13 @@ import org.apache.phoenix.hbase.index.util.GenericKeyValueBuilder;
 import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
 import org.apache.phoenix.index.IndexMaintainer;
 import org.apache.phoenix.index.PhoenixIndexCodec;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.join.HashJoinInfo;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.ConstraintViolationException;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PRow;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableImpl;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 0be1c28..d23acc0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -28,7 +28,7 @@ import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.ConcurrentTableMutationException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.ReadOnlyTableException;
 import org.apache.phoenix.schema.SequenceAlreadyExistsException;
 import org.apache.phoenix.schema.SequenceNotFoundException;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/exception/ValueTypeIncompatibleException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/ValueTypeIncompatibleException.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/ValueTypeIncompatibleException.java
index 470d5b9..f8be85d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/ValueTypeIncompatibleException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/ValueTypeIncompatibleException.java
@@ -18,7 +18,7 @@
 package org.apache.phoenix.exception;
 
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 
 public class ValueTypeIncompatibleException extends IllegalDataException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
index 2ebfa41..8627bfb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
@@ -53,7 +53,7 @@ import org.apache.phoenix.parse.FilterableStatement;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.TableRef;
 
 
@@ -168,7 +168,7 @@ public class AggregatePlan extends BaseQueryPlan {
              *    order, so we can early exit, even when aggregate functions are used, as
              *    the rows in the group are contiguous.
              */
-            context.getScan().setAttribute(BaseScannerRegionObserver.GROUP_BY_LIMIT, PDataType.INTEGER.toBytes(limit));
+            context.getScan().setAttribute(BaseScannerRegionObserver.GROUP_BY_LIMIT, PInteger.INSTANCE.toBytes(limit));
         }
         ParallelIterators parallelIterators = new ParallelIterators(this, null, wrapParallelIteratorFactory());
         splits = parallelIterators.getSplits();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
index c6ed0ac..df5c72d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
@@ -65,8 +65,9 @@ import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SQLCloseable;
@@ -202,7 +203,7 @@ public class HashJoinPlan extends DelegateQueryPlan {
             Expression rhsExpression, List<ImmutableBytesWritable> rhsValues, 
             ImmutableBytesWritable ptr, boolean hasFilters) throws SQLException {
         if (rhsValues.isEmpty())
-            return LiteralExpression.newConstant(null, PDataType.BOOLEAN, Determinism.ALWAYS);
+            return LiteralExpression.newConstant(null, PBoolean.INSTANCE, Determinism.ALWAYS);
         
         PDataType type = rhsExpression.getDataType();
         if (!useInClause(hasFilters)) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
index bb2dc7e..70e94ca 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/AndExpression.java
@@ -22,7 +22,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 
@@ -41,8 +41,8 @@ public class AndExpression extends AndOrExpression {
         Iterator<Expression> iterator = children.iterator();
         while (iterator.hasNext()) {
             Expression child = iterator.next();
-            if (child.getDataType() != PDataType.BOOLEAN) {
-                throw TypeMismatchException.newException(PDataType.BOOLEAN, child.getDataType(), child.toString());
+            if (child.getDataType() != PBoolean.INSTANCE) {
+                throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), child.toString());
             }
             if (LiteralExpression.isFalse(child)) {
                 return child;


[02/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
new file mode 100644
index 0000000..a34709a
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
@@ -0,0 +1,1710 @@
+/*
+ * 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.schema.types;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.schema.ConstraintViolationException;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PBinaryArray;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PCharArray;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PSmallint;
+import org.apache.phoenix.schema.types.PTime;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PTinyint;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedDouble;
+import org.apache.phoenix.schema.types.PUnsignedFloat;
+import org.apache.phoenix.schema.types.PUnsignedInt;
+import org.apache.phoenix.schema.types.PUnsignedLong;
+import org.apache.phoenix.schema.types.PUnsignedSmallint;
+import org.apache.phoenix.schema.types.PUnsignedTime;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PhoenixArray;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Test;
+
+
+public class PDataTypeTest {
+    @Test
+    public void testFloatToLongComparison() {
+        // Basic tests
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(1e100), 0, PFloat.INSTANCE.getByteSize(), SortOrder
+            .getDefault(),
+                PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(0.001), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+
+        // Edge tests
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MAX_VALUE), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MAX_VALUE - 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MIN_VALUE + 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MAX_VALUE + 1.0F), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MAX_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0); // Passes due to rounding
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MAX_VALUE + 129.0F), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MAX_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MIN_VALUE - 128.0F), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(Integer.MIN_VALUE - 129.0F), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+
+        float f1 = 9111111111111111.0F;
+        float f2 = 9111111111111112.0F;
+        assertTrue(f1 == f2);
+        long la = 9111111111111111L;
+        assertTrue(f1 > Integer.MAX_VALUE);
+        assertTrue(la == f1);
+        assertTrue(la == f2);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(f1), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PLong.INSTANCE.toBytes(la), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PFloat.INSTANCE.compareTo(PFloat.INSTANCE.toBytes(f2), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PLong.INSTANCE.toBytes(la), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+
+        // Same as above, but reversing LHS and RHS
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE.toBytes(1e100), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) < 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE.toBytes(0.001), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) > 0);
+
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MAX_VALUE - 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MAX_VALUE), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) < 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MIN_VALUE + 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MIN_VALUE), 0,
+                PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) > 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MIN_VALUE), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MAX_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MAX_VALUE + 1.0F), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE) < 0); // Passes due to rounding
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MAX_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MAX_VALUE + 129.0F), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE) < 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MIN_VALUE - 128.0F), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Integer.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PFloat.INSTANCE.toBytes(Integer.MIN_VALUE - 129.0F), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE) > 0);
+
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(la), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE.toBytes(f1), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(la), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PFloat.INSTANCE.toBytes(f2), 0, PFloat.INSTANCE.getByteSize(), SortOrder.getDefault(), PFloat.INSTANCE) == 0);
+    }        
+        
+    @Test
+    public void testDoubleToDecimalComparison() {
+        // Basic tests
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(1.23), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                   PDecimal.INSTANCE.toBytes(BigDecimal.valueOf(1.24)), 0, PDecimal.INSTANCE.getByteSize(), SortOrder.getDefault(), PDecimal.INSTANCE) < 0);
+    }
+    
+    @Test
+    public void testDoubleToLongComparison() {
+        // Basic tests
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(-1e100), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(0.001), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MAX_VALUE), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MAX_VALUE - 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MIN_VALUE + 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MAX_VALUE + 1024.0), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MAX_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MAX_VALUE + 1025.0), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MAX_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) > 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MIN_VALUE - 1024.0), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) == 0);
+        assertTrue(PDouble.INSTANCE.compareTo(PDouble.INSTANCE.toBytes(Long.MIN_VALUE - 1025.0), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PLong.INSTANCE) < 0);
+
+        // Same as above, but reversing LHS and RHS
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE.toBytes(-1e100), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE) > 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(1), 0, PLong.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE.toBytes(0.001), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE) > 0);
+
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MAX_VALUE - 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MAX_VALUE), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE) < 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MIN_VALUE + 1), 0,
+                PLong.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MIN_VALUE), 0,
+                PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(), PDouble.INSTANCE) > 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MIN_VALUE), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MAX_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MAX_VALUE + 1024.0), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MAX_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MAX_VALUE + 1025.0), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE) < 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MIN_VALUE - 1024.0), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE) == 0);
+        assertTrue(PLong.INSTANCE.compareTo(PLong.INSTANCE.toBytes(Long.MIN_VALUE), 0, PLong.INSTANCE.getByteSize(),
+        		SortOrder.getDefault(), PDouble.INSTANCE.toBytes(Long.MIN_VALUE - 1025.0), 0, PDouble.INSTANCE.getByteSize(), SortOrder.getDefault(),
+                PDouble.INSTANCE) > 0);
+
+        long i = 10;
+        long maxl = (1L << 62);
+        try {
+            for (; i < 100; i++) {
+                double d = Math.pow(2, i);
+                if ((long)d > maxl) {
+                    assertTrue(i > 62);
+                    continue;
+                }
+                long l = (1L << i) - 1;
+                assertTrue(l + 1L == (long)d);
+                assertTrue(l < (long)d);
+            }
+        } catch (AssertionError t) {
+            throw t;
+        }
+        double d = 0.0;
+        try {
+            while (d <= 1024) {
+                double d1 = Long.MAX_VALUE;
+                double d2 = Long.MAX_VALUE + d;
+                assertTrue(d2 == d1);
+                d++;
+            }
+        } catch (AssertionError t) {
+            throw t;
+        }
+        d = 0.0;
+        try {
+            while (d >= -1024) {
+                double d1 = Long.MIN_VALUE;
+                double d2 = Long.MIN_VALUE + d;
+                assertTrue(d2 == d1);
+                d--;
+            }
+        } catch (AssertionError t) {
+            throw t;
+        }
+        double d1 = Long.MAX_VALUE;
+        double d2 = Long.MAX_VALUE + 1024.0;
+        double d3 = Long.MAX_VALUE + 1025.0;
+        assertTrue(d1 == d2);
+        assertTrue(d3 > d1);
+        long l1 = Long.MAX_VALUE - 1;
+        assertTrue((long)d1 > l1);
+    }
+        
+    @Test
+    public void testLong() {
+        Long la = 4L;
+        byte[] b = PLong.INSTANCE.toBytes(la);
+        Long lb = (Long) PLong.INSTANCE.toObject(b);
+        assertEquals(la,lb);
+
+        Long na = 1L;
+        Long nb = -1L;
+        byte[] ba = PLong.INSTANCE.toBytes(na);
+        byte[] bb = PLong.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Integer value = 100;
+        Object obj = PLong.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Long);
+        assertEquals(100, ((Long)obj).longValue());
+        
+        Long longValue = 100l;
+        Object longObj = PLong.INSTANCE.toObject(longValue, PLong.INSTANCE);
+        assertTrue(longObj instanceof Long);
+        assertEquals(100, ((Long)longObj).longValue());
+        
+        assertEquals(0, PLong.INSTANCE.compareTo(Long.MAX_VALUE, Float.valueOf(Long.MAX_VALUE), PFloat.INSTANCE));
+        assertEquals(0, PLong.INSTANCE.compareTo(Long.MAX_VALUE, Double.valueOf(Long.MAX_VALUE), PDouble.INSTANCE));
+        assertEquals(-1, PLong.INSTANCE.compareTo(99, Float.valueOf(100), PFloat.INSTANCE));
+        assertEquals(1, PLong.INSTANCE.compareTo(101, Float.valueOf(100), PFloat.INSTANCE));
+        
+        Double d = -2.0;
+        Object lo = PLong.INSTANCE.toObject(d, PDouble.INSTANCE);
+        assertEquals(-2L, ((Long)lo).longValue());
+        
+        byte[] bytes = PDouble.INSTANCE.toBytes(d);
+        lo = PLong.INSTANCE.toObject(bytes,0, bytes.length, PDouble.INSTANCE);
+        assertEquals(-2L, ((Long)lo).longValue());
+        
+        Float f = -2.0f;
+        lo = PLong.INSTANCE.toObject(f, PFloat.INSTANCE);
+        assertEquals(-2L, ((Long)lo).longValue());
+        
+        bytes = PFloat.INSTANCE.toBytes(f);
+        lo = PLong.INSTANCE.toObject(bytes,0, bytes.length, PFloat.INSTANCE);
+        assertEquals(-2L, ((Long)lo).longValue());
+        
+        // Checks for unsignedlong
+        d = 2.0;
+        lo = PUnsignedLong.INSTANCE.toObject(d, PDouble.INSTANCE);
+        assertEquals(2L, ((Long)lo).longValue());
+        
+        bytes = PDouble.INSTANCE.toBytes(d);
+        lo = PUnsignedLong.INSTANCE.toObject(bytes,0, bytes.length, PDouble.INSTANCE);
+        assertEquals(2L, ((Long)lo).longValue());
+        
+        f = 2.0f;
+        lo = PUnsignedLong.INSTANCE.toObject(f, PFloat.INSTANCE);
+        assertEquals(2L, ((Long)lo).longValue());
+        
+        bytes = PFloat.INSTANCE.toBytes(f);
+        lo = PUnsignedLong.INSTANCE.toObject(bytes,0, bytes.length, PFloat.INSTANCE);
+        assertEquals(2L, ((Long)lo).longValue());
+        
+    }
+
+    @Test
+    public void testInt() {
+        Integer na = 4;
+        byte[] b = PInteger.INSTANCE.toBytes(na);
+        Integer nb = (Integer) PInteger.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+
+        na = 1;
+        nb = -1;
+        byte[] ba = PInteger.INSTANCE.toBytes(na);
+        byte[] bb = PInteger.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -1;
+        nb = -3;
+        ba = PInteger.INSTANCE.toBytes(na);
+        bb = PInteger.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -3;
+        nb = -100000000;
+        ba = PInteger.INSTANCE.toBytes(na);
+        bb = PInteger.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Long value = 100l;
+        Object obj = PInteger.INSTANCE.toObject(value, PLong.INSTANCE);
+        assertTrue(obj instanceof Integer);
+        assertEquals(100, ((Integer)obj).intValue());
+        
+        Float unsignedFloatValue = 100f;
+        Object unsignedFloatObj = PInteger.INSTANCE.toObject(unsignedFloatValue, PUnsignedFloat.INSTANCE);
+        assertTrue(unsignedFloatObj instanceof Integer);
+        assertEquals(100, ((Integer)unsignedFloatObj).intValue());
+        
+        Double unsignedDoubleValue = 100d;
+        Object unsignedDoubleObj = PInteger.INSTANCE.toObject(unsignedDoubleValue, PUnsignedDouble.INSTANCE);
+        assertTrue(unsignedDoubleObj instanceof Integer);
+        assertEquals(100, ((Integer)unsignedDoubleObj).intValue());
+        
+        Float floatValue = 100f;
+        Object floatObj = PInteger.INSTANCE.toObject(floatValue, PFloat.INSTANCE);
+        assertTrue(floatObj instanceof Integer);
+        assertEquals(100, ((Integer)floatObj).intValue());
+        
+        Double doubleValue = 100d;
+        Object doubleObj = PInteger.INSTANCE.toObject(doubleValue, PDouble.INSTANCE);
+        assertTrue(doubleObj instanceof Integer);
+        assertEquals(100, ((Integer)doubleObj).intValue());
+        
+        Short shortValue = 100;
+        Object shortObj = PInteger.INSTANCE.toObject(shortValue, PSmallint.INSTANCE);
+        assertTrue(shortObj instanceof Integer);
+        assertEquals(100, ((Integer)shortObj).intValue());
+    }
+    
+    @Test
+    public void testSmallInt() {
+        Short na = 4;
+        byte[] b = PSmallint.INSTANCE.toBytes(na);
+        Short nb = (Short) PSmallint.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+        
+        na = 4;
+        b = PSmallint.INSTANCE.toBytes(na, SortOrder.DESC);
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        ptr.set(b);
+        nb = PSmallint.INSTANCE.getCodec().decodeShort(ptr, SortOrder.DESC);
+        assertEquals(na,nb);
+
+        na = 1;
+        nb = -1;
+        byte[] ba = PSmallint.INSTANCE.toBytes(na);
+        byte[] bb = PSmallint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -1;
+        nb = -3;
+        ba = PSmallint.INSTANCE.toBytes(na);
+        bb = PSmallint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -3;
+        nb = -10000;
+        ba = PSmallint.INSTANCE.toBytes(na);
+        bb = PSmallint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Integer value = 100;
+        Object obj = PSmallint.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Short);
+        assertEquals(100, ((Short)obj).shortValue());
+        
+        Float unsignedFloatValue = 100f;
+        Object unsignedFloatObj = PSmallint.INSTANCE.toObject(unsignedFloatValue, PUnsignedFloat.INSTANCE);
+        assertTrue(unsignedFloatObj instanceof Short);
+        assertEquals(100, ((Short)unsignedFloatObj).shortValue());
+        
+        Double unsignedDoubleValue = 100d;
+        Object unsignedDoubleObj = PSmallint.INSTANCE.toObject(unsignedDoubleValue, PUnsignedDouble.INSTANCE);
+        assertTrue(unsignedDoubleObj instanceof Short);
+        assertEquals(100, ((Short)unsignedDoubleObj).shortValue());
+        
+        Float floatValue = 100f;
+        Object floatObj = PSmallint.INSTANCE.toObject(floatValue, PFloat.INSTANCE);
+        assertTrue(floatObj instanceof Short);
+        assertEquals(100, ((Short)floatObj).shortValue());
+        
+        Double doubleValue = 100d;
+        Object doubleObj = PSmallint.INSTANCE.toObject(doubleValue, PDouble.INSTANCE);
+        assertTrue(doubleObj instanceof Short);
+        assertEquals(100, ((Short)doubleObj).shortValue());
+    }
+    
+    @Test
+    public void testTinyInt() {
+        Byte na = 4;
+        byte[] b = PTinyint.INSTANCE.toBytes(na);
+        Byte nb = (Byte) PTinyint.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+
+        na = 1;
+        nb = -1;
+        byte[] ba = PTinyint.INSTANCE.toBytes(na);
+        byte[] bb = PTinyint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -1;
+        nb = -3;
+        ba = PTinyint.INSTANCE.toBytes(na);
+        bb = PTinyint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -3;
+        nb = -100;
+        ba = PTinyint.INSTANCE.toBytes(na);
+        bb = PTinyint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Integer value = 100;
+        Object obj = PTinyint.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Byte);
+        assertEquals(100, ((Byte)obj).byteValue());
+        
+        Float floatValue = 100f;
+        Object floatObj = PTinyint.INSTANCE.toObject(floatValue, PFloat.INSTANCE);
+        assertTrue(floatObj instanceof Byte);
+        assertEquals(100, ((Byte)floatObj).byteValue());
+        
+        Float unsignedFloatValue = 100f;
+        Object unsignedFloatObj = PTinyint.INSTANCE.toObject(unsignedFloatValue, PUnsignedFloat.INSTANCE);
+        assertTrue(unsignedFloatObj instanceof Byte);
+        assertEquals(100, ((Byte)unsignedFloatObj).byteValue());
+        
+        Double unsignedDoubleValue = 100d;
+        Object unsignedDoubleObj = PTinyint.INSTANCE.toObject(unsignedDoubleValue, PUnsignedDouble.INSTANCE);
+        assertTrue(unsignedDoubleObj instanceof Byte);
+        assertEquals(100, ((Byte)unsignedDoubleObj).byteValue());
+        
+        Double doubleValue = 100d;
+        Object doubleObj = PTinyint.INSTANCE.toObject(doubleValue, PDouble.INSTANCE);
+        assertTrue(doubleObj instanceof Byte);
+        assertEquals(100, ((Byte)doubleObj).byteValue());
+    }
+    
+    @Test
+    public void testUnsignedSmallInt() {
+        Short na = 4;
+        byte[] b = PUnsignedSmallint.INSTANCE.toBytes(na);
+        Short nb = (Short) PUnsignedSmallint.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+
+        na = 10;
+        nb = 8;
+        byte[] ba = PUnsignedSmallint.INSTANCE.toBytes(na);
+        byte[] bb = PUnsignedSmallint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Integer value = 100;
+        Object obj = PUnsignedSmallint.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Short);
+        assertEquals(100, ((Short)obj).shortValue());
+        
+        Float floatValue = 100f;
+        Object floatObj = PUnsignedSmallint.INSTANCE.toObject(floatValue, PFloat.INSTANCE);
+        assertTrue(floatObj instanceof Short);
+        assertEquals(100, ((Short)floatObj).shortValue());
+        
+        Float unsignedFloatValue = 100f;
+        Object unsignedFloatObj = PUnsignedSmallint.INSTANCE.toObject(unsignedFloatValue, PUnsignedFloat.INSTANCE);
+        assertTrue(unsignedFloatObj instanceof Short);
+        assertEquals(100, ((Short)unsignedFloatObj).shortValue());
+        
+        Double unsignedDoubleValue = 100d;
+        Object unsignedDoubleObj = PUnsignedSmallint.INSTANCE.toObject(unsignedDoubleValue, PUnsignedDouble.INSTANCE);
+        assertTrue(unsignedDoubleObj instanceof Short);
+        assertEquals(100, ((Short)unsignedDoubleObj).shortValue());
+        
+        Double doubleValue = 100d;
+        Object doubleObj = PUnsignedSmallint.INSTANCE.toObject(doubleValue, PDouble.INSTANCE);
+        assertTrue(doubleObj instanceof Short);
+        assertEquals(100, ((Short)doubleObj).shortValue());
+    }
+    
+    @Test
+    public void testUnsignedTinyInt() {
+        Byte na = 4;
+        byte[] b = PUnsignedTinyint.INSTANCE.toBytes(na);
+        Byte nb = (Byte) PUnsignedTinyint.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+
+        na = 10;
+        nb = 8;
+        byte[] ba = PUnsignedTinyint.INSTANCE.toBytes(na);
+        byte[] bb = PUnsignedTinyint.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        Integer value = 100;
+        Object obj = PUnsignedTinyint.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Byte);
+        assertEquals(100, ((Byte)obj).byteValue());
+        
+        Float floatValue = 100f;
+        Object floatObj = PUnsignedTinyint.INSTANCE.toObject(floatValue, PFloat.INSTANCE);
+        assertTrue(floatObj instanceof Byte);
+        assertEquals(100, ((Byte)floatObj).byteValue());
+        
+        Float unsignedFloatValue = 100f;
+        Object unsignedFloatObj = PUnsignedTinyint.INSTANCE.toObject(unsignedFloatValue, PUnsignedFloat.INSTANCE);
+        assertTrue(unsignedFloatObj instanceof Byte);
+        assertEquals(100, ((Byte)unsignedFloatObj).byteValue());
+        
+        Double unsignedDoubleValue = 100d;
+        Object unsignedDoubleObj = PUnsignedTinyint.INSTANCE.toObject(unsignedDoubleValue, PUnsignedDouble.INSTANCE);
+        assertTrue(unsignedDoubleObj instanceof Byte);
+        assertEquals(100, ((Byte)unsignedDoubleObj).byteValue());
+        
+        Double doubleValue = 100d;
+        Object doubleObj = PUnsignedTinyint.INSTANCE.toObject(doubleValue, PDouble.INSTANCE);
+        assertTrue(doubleObj instanceof Byte);
+        assertEquals(100, ((Byte)doubleObj).byteValue());
+    }
+    
+    @Test
+    public void testUnsignedFloat() {
+        Float na = 0.005f;
+        byte[] b = PUnsignedFloat.INSTANCE.toBytes(na);
+        Float nb = (Float) PUnsignedFloat.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+        
+        na = 10.0f;
+        b = PUnsignedFloat.INSTANCE.toBytes(na, SortOrder.DESC);
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        ptr.set(b);
+        nb = PUnsignedFloat.INSTANCE.getCodec().decodeFloat(ptr, SortOrder.DESC);
+        assertEquals(na,nb);
+        
+        na = 2.0f;
+        nb = 1.0f;
+        byte[] ba = PUnsignedFloat.INSTANCE.toBytes(na);
+        byte[] bb = PUnsignedFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        na = 0.0f;
+        nb = Float.MIN_VALUE;
+        ba = PUnsignedFloat.INSTANCE.toBytes(na);
+        bb = PUnsignedFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.MIN_VALUE;
+        nb = Float.MAX_VALUE;
+        ba = PUnsignedFloat.INSTANCE.toBytes(na);
+        bb = PUnsignedFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.MAX_VALUE;
+        nb = Float.POSITIVE_INFINITY;
+        ba = PUnsignedFloat.INSTANCE.toBytes(na);
+        bb = PUnsignedFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.POSITIVE_INFINITY;
+        nb = Float.NaN;
+        ba = PUnsignedFloat.INSTANCE.toBytes(na);
+        bb = PUnsignedFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        Integer value = 100;
+        Object obj = PUnsignedFloat.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Float);
+    }
+    
+    @Test
+    public void testUnsignedDouble() {
+        Double na = 0.005;
+        byte[] b = PUnsignedDouble.INSTANCE.toBytes(na);
+        Double nb = (Double) PUnsignedDouble.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+        
+        na = 10.0;
+        b = PUnsignedDouble.INSTANCE.toBytes(na, SortOrder.DESC);
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        ptr.set(b);
+        nb = PUnsignedDouble.INSTANCE.getCodec().decodeDouble(ptr, SortOrder.DESC);
+        assertEquals(na,nb);
+
+        na = 2.0;
+        nb = 1.0;
+        byte[] ba = PUnsignedDouble.INSTANCE.toBytes(na);
+        byte[] bb = PUnsignedDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        na = 0.0;
+        nb = Double.MIN_VALUE;
+        ba = PUnsignedDouble.INSTANCE.toBytes(na);
+        bb = PUnsignedDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.MIN_VALUE;
+        nb = Double.MAX_VALUE;
+        ba = PUnsignedDouble.INSTANCE.toBytes(na);
+        bb = PUnsignedDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.MAX_VALUE;
+        nb = Double.POSITIVE_INFINITY;
+        ba = PUnsignedDouble.INSTANCE.toBytes(na);
+        bb = PUnsignedDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.POSITIVE_INFINITY;
+        nb = Double.NaN;
+        ba = PUnsignedDouble.INSTANCE.toBytes(na);
+        bb = PUnsignedDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        Integer value = 100;
+        Object obj = PUnsignedDouble.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Double);
+        
+        assertEquals(1, PUnsignedDouble.INSTANCE.compareTo(Double.valueOf(101), Long.valueOf(100), PLong.INSTANCE));
+        assertEquals(0, PUnsignedDouble.INSTANCE.compareTo(Double.valueOf(Long.MAX_VALUE), Long.MAX_VALUE, PLong.INSTANCE));
+        assertEquals(-1, PUnsignedDouble.INSTANCE.compareTo(Double.valueOf(1), Long.valueOf(100), PLong.INSTANCE));
+        
+        assertEquals(0, PUnsignedDouble.INSTANCE.compareTo(Double.valueOf(101), BigDecimal.valueOf(101.0), PDecimal.INSTANCE));
+    }
+    
+    @Test
+    public void testFloat() {
+        Float na = 0.005f;
+        byte[] b = PFloat.INSTANCE.toBytes(na);
+        Float nb = (Float) PFloat.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+        
+        na = 10.0f;
+        b = PFloat.INSTANCE.toBytes(na, SortOrder.DESC);
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        ptr.set(b);
+        nb = PFloat.INSTANCE.getCodec().decodeFloat(ptr, SortOrder.DESC);
+        assertEquals(na,nb);
+        
+        na = 1.0f;
+        nb = -1.0f;
+        byte[] ba = PFloat.INSTANCE.toBytes(na);
+        byte[] bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -1f;
+        nb = -3f;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        na = Float.NEGATIVE_INFINITY;
+        nb = -Float.MAX_VALUE;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -Float.MAX_VALUE;
+        nb = -Float.MIN_VALUE;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -Float.MIN_VALUE;
+        nb = -0.0f;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -0.0f;
+        nb = 0.0f;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = 0.0f;
+        nb = Float.MIN_VALUE;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.MIN_VALUE;
+        nb = Float.MAX_VALUE;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.MAX_VALUE;
+        nb = Float.POSITIVE_INFINITY;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Float.POSITIVE_INFINITY;
+        nb = Float.NaN;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        Integer value = 100;
+        Object obj = PFloat.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Float);
+        
+        Double dvalue = Double.NEGATIVE_INFINITY;
+        obj = PFloat.INSTANCE.toObject(dvalue, PDouble.INSTANCE);
+        assertTrue(obj instanceof Float);
+        assertEquals(Float.NEGATIVE_INFINITY, obj);
+        
+        na = 1.0f;
+        nb = -1.0f;
+        ba = PFloat.INSTANCE.toBytes(na);
+        bb = PFloat.INSTANCE.toBytes(nb);
+        float nna = PFloat.INSTANCE.getCodec().decodeFloat(ba, 0, SortOrder.DESC);
+        float nnb = PFloat.INSTANCE.getCodec().decodeFloat(bb, 0, SortOrder.DESC);
+        assertTrue(Float.compare(nna, nnb) < 0);
+    }
+    
+    @Test
+    public void testDouble() {
+        Double na = 0.005;
+        byte[] b = PDouble.INSTANCE.toBytes(na);
+        Double nb = (Double) PDouble.INSTANCE.toObject(b);
+        assertEquals(na,nb);
+        
+        na = 10.0;
+        b = PDouble.INSTANCE.toBytes(na, SortOrder.DESC);
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        ptr.set(b);
+        nb = PDouble.INSTANCE.getCodec().decodeDouble(ptr, SortOrder.DESC);
+        assertEquals(na,nb);
+
+        na = 1.0;
+        nb = -1.0;
+        byte[] ba = PDouble.INSTANCE.toBytes(na);
+        byte[] bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+
+        na = -1.0;
+        nb = -3.0;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        
+        na = Double.NEGATIVE_INFINITY;
+        nb = -Double.MAX_VALUE;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -Double.MAX_VALUE;
+        nb = -Double.MIN_VALUE;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -Double.MIN_VALUE;
+        nb = -0.0;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = -0.0;
+        nb = 0.0;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = 0.0;
+        nb = Double.MIN_VALUE;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.MIN_VALUE;
+        nb = Double.MAX_VALUE;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.MAX_VALUE;
+        nb = Double.POSITIVE_INFINITY;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        na = Double.POSITIVE_INFINITY;
+        nb = Double.NaN;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) < 0);
+        
+        Integer value = 100;
+        Object obj = PDouble.INSTANCE.toObject(value, PInteger.INSTANCE);
+        assertTrue(obj instanceof Double);
+        
+        na = 1.0;
+        nb = -1.0;
+        ba = PDouble.INSTANCE.toBytes(na);
+        bb = PDouble.INSTANCE.toBytes(nb);
+        double nna = PDouble.INSTANCE.getCodec().decodeDouble(ba, 0, SortOrder.DESC);
+        double nnb = PDouble.INSTANCE.getCodec().decodeDouble(bb, 0, SortOrder.DESC);
+        assertTrue(Double.compare(nna, nnb) < 0);
+        
+        assertEquals(1, PDouble.INSTANCE.compareTo(Double.valueOf(101), Long.valueOf(100), PLong.INSTANCE));
+        assertEquals(0, PDouble.INSTANCE.compareTo(Double.valueOf(Long.MAX_VALUE), Long.MAX_VALUE, PLong.INSTANCE));
+        assertEquals(-1, PDouble.INSTANCE.compareTo(Double.valueOf(1), Long.valueOf(100), PLong.INSTANCE));
+        
+        assertEquals(0, PDouble.INSTANCE.compareTo(Double.valueOf(101), BigDecimal.valueOf(101.0), PDecimal.INSTANCE));
+    }
+
+    @Test
+    public void testBigDecimal() {
+        byte[] b;
+        BigDecimal na, nb;
+
+        b = new byte[] {
+                (byte)0xc2,0x02,0x10,0x36,0x22,0x22,0x22,0x22,0x22,0x22,0x0f,0x27,0x38,0x1c,0x05,0x40,0x62,0x21,0x54,0x4d,0x4e,0x01,0x14,0x36,0x0d,0x33
+        };
+        BigDecimal decodedBytes = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(decodedBytes.compareTo(BigDecimal.ZERO) > 0);
+
+        na = new BigDecimal(new BigInteger("12345678901239998123456789"), 2);
+        //[-52, 13, 35, 57, 79, 91, 13, 40, 100, 82, 24, 46, 68, 90]
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        TestUtil.assertRoundEquals(na,nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = new BigDecimal("115.533333333333331438552704639732837677001953125");
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        TestUtil.assertRoundEquals(na,nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        
+        // test for negative serialization using biginteger
+        na = new BigDecimal("-5.00000000000000000000000001");
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        TestUtil.assertRoundEquals(na,nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        
+        // test for serialization of 38 digits
+        na = new BigDecimal("-2.4999999999999999999999999999999999999");
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        TestUtil.assertRoundEquals(na,nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        
+        // test for serialization of 39 digits, should round to -2.5
+        na = new BigDecimal("-2.499999999999999999999999999999999999999");
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(nb.compareTo(new BigDecimal("-2.5")) == 0);
+        assertEquals(new BigDecimal("-2.5"), nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = new BigDecimal(2.5);
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(na.compareTo(nb) == 0);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        // If we don't remove trailing zeros, this fails
+        na = new BigDecimal(Double.parseDouble("96.45238095238095"));
+        String naStr = na.toString();
+        assertTrue(naStr != null);
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        TestUtil.assertRoundEquals(na,nb);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        // If we don't remove trailing zeros, this fails
+        na = new BigDecimal(-1000);
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(na.compareTo(nb) == 0);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = new BigDecimal("1000.5829999999999913");
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(na.compareTo(nb) == 0);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = TestUtil.computeAverage(11000, 3);
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(na.compareTo(nb) == 0);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = new BigDecimal(new BigInteger("12345678901239999"), 2);
+        b = PDecimal.INSTANCE.toBytes(na);
+        nb = (BigDecimal) PDecimal.INSTANCE.toObject(b);
+        assertTrue(na.compareTo(nb) == 0);
+        assertTrue(b.length <= PDecimal.INSTANCE.estimateByteSize(na));
+
+        na = new BigDecimal(1);
+        nb = new BigDecimal(-1);
+        byte[] ba = PDecimal.INSTANCE.toBytes(na);
+        byte[] bb = PDecimal.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        assertTrue(ba.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        assertTrue(bb.length <= PDecimal.INSTANCE.estimateByteSize(nb));
+
+        na = new BigDecimal(-1);
+        nb = new BigDecimal(-2);
+        ba = PDecimal.INSTANCE.toBytes(na);
+        bb = PDecimal.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        assertTrue(ba.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        assertTrue(bb.length <= PDecimal.INSTANCE.estimateByteSize(nb));
+
+        na = new BigDecimal(-3);
+        nb = new BigDecimal(-1000);
+        assertTrue(na.compareTo(nb) > 0);
+        ba = PDecimal.INSTANCE.toBytes(na);
+        bb = PDecimal.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        assertTrue(ba.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        assertTrue(bb.length <= PDecimal.INSTANCE.estimateByteSize(nb));
+
+        na = new BigDecimal(BigInteger.valueOf(12345678901239998L), 2);
+        nb = new BigDecimal(97);
+        assertTrue(na.compareTo(nb) > 0);
+        ba = PDecimal.INSTANCE.toBytes(na);
+        bb = PDecimal.INSTANCE.toBytes(nb);
+        assertTrue(Bytes.compareTo(ba, bb) > 0);
+        assertTrue(ba.length <= PDecimal.INSTANCE.estimateByteSize(na));
+        assertTrue(bb.length <= PDecimal.INSTANCE.estimateByteSize(nb));
+
+        List<BigDecimal> values = Arrays.asList(new BigDecimal[] {
+            new BigDecimal(-1000),
+            new BigDecimal(-100000000),
+            new BigDecimal(1000),
+            new BigDecimal("-0.001"),
+            new BigDecimal("0.001"),
+            new BigDecimal(new BigInteger("12345678901239999"), 2),
+            new BigDecimal(new BigInteger("12345678901239998"), 2),
+            new BigDecimal(new BigInteger("12345678901239998123456789"), 2), // bigger than long
+            new BigDecimal(new BigInteger("-1000"),3),
+            new BigDecimal(new BigInteger("-1000"),10),
+            new BigDecimal(99),
+            new BigDecimal(97),
+            new BigDecimal(-3)
+        });
+
+        List<byte[]> byteValues = new ArrayList<byte[]>();
+        for (int i = 0; i < values.size(); i++) {
+            byteValues.add(PDecimal.INSTANCE.toBytes(values.get(i)));
+        }
+
+        for (int i = 0; i < values.size(); i++) {
+            BigDecimal expected = values.get(i);
+            BigDecimal actual = (BigDecimal) PDecimal.INSTANCE.toObject(byteValues.get(i));
+            assertTrue("For " + i + " expected " + expected + " but got " + actual,expected.round(
+                PDataType.DEFAULT_MATH_CONTEXT).compareTo(actual.round(
+                PDataType.DEFAULT_MATH_CONTEXT)) == 0);
+            assertTrue(byteValues.get(i).length <= PDecimal.INSTANCE.estimateByteSize(expected));
+        }
+
+        Collections.sort(values);
+        Collections.sort(byteValues, Bytes.BYTES_COMPARATOR);
+
+        for (int i = 0; i < values.size(); i++) {
+            BigDecimal expected = values.get(i);
+            byte[] bytes = PDecimal.INSTANCE.toBytes(values.get(i));
+            assertNotNull("bytes converted from values should not be null!", bytes);
+            BigDecimal actual = (BigDecimal) PDecimal.INSTANCE.toObject(byteValues.get(i));
+            assertTrue("For " + i + " expected " + expected + " but got " + actual,expected.round(PDataType.DEFAULT_MATH_CONTEXT).compareTo(actual.round(PDataType.DEFAULT_MATH_CONTEXT))==0);
+        }
+
+
+        {
+            String[] strs ={
+                    "\\xC2\\x03\\x0C\\x10\\x01\\x01\\x01\\x01\\x01\\x019U#\\x13W\\x09\\x09"
+                    ,"\\xC2\\x03<,ddddddN\\x1B\\x1B!.9N"
+                    ,"\\xC2\\x039"
+                    ,"\\xC2\\x03\\x16,\\x01\\x01\\x01\\x01\\x01\\x01E\\x16\\x16\\x03@\\x1EG"
+                    ,"\\xC2\\x02d6dddddd\\x15*]\\x0E<1F"
+                    ,"\\xC2\\x04 3"
+                    ,"\\xC2\\x03$Ldddddd\\x0A\\x06\\x06\\x1ES\\x1C\\x08"
+                    ,"\\xC2\\x03\\x1E\\x0A\\x01\\x01\\x01\\x01\\x01\\x01#\\x0B=4 AV"
+                    ,"\\xC2\\x02\\\\x04dddddd\\x15*]\\x0E<1F"
+                    ,"\\xC2\\x02V\"\\x01\\x01\\x01\\x01\\x01\\x02\\x1A\\x068\\x162&O"
+            };
+            for (String str : strs) {
+                byte[] bytes = Bytes.toBytesBinary(str);
+                Object o = PDecimal.INSTANCE.toObject(bytes);
+                assertNotNull(o);
+                //System.out.println(o.getClass() +" " + bytesToHex(bytes)+" " + o+" ");
+            }
+        }
+    }
+    public static String bytesToHex(byte[] bytes) {
+        final char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+        char[] hexChars = new char[bytes.length * 2];
+        int v;
+        for ( int j = 0; j < bytes.length; j++ ) {
+            v = bytes[j] & 0xFF;
+            hexChars[j * 2] = hexArray[v >>> 4];
+            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+        }
+        return new String(hexChars);
+    }
+
+    @Test
+    public void testEmptyString() throws Throwable {
+        byte[] b1 = PVarchar.INSTANCE.toBytes("");
+        byte[] b2 = PVarchar.INSTANCE.toBytes(null);
+        assert (b1.length == 0 && Bytes.compareTo(b1, b2) == 0);
+    }
+
+    @Test
+    public void testNull() throws Throwable {
+        byte[] b = new byte[8];
+        for (PDataType type : PDataType.values()) {
+            try {
+				type.toBytes(null);
+				type.toBytes(null, b, 0);
+				type.toObject(new byte[0], 0, 0);
+				type.toObject(new byte[0], 0, 0, type);
+                if (type.isArrayType()) {
+					type.toBytes(new PhoenixArray());
+					type.toBytes(new PhoenixArray(), b, 0);
+                }
+            } catch (ConstraintViolationException e) {
+            	if (!type.isArrayType() && ! ( type.isFixedWidth() && e.getMessage().contains("may not be null"))) {
+            		// Fixed width types do not support the concept of a "null" value.
+                    fail(type + ":" + e);
+                }
+            }
+        }
+    }
+
+    @Test
+    public void testValueCoersion() throws Exception {
+        // Testing coercing integer to other values.
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, 0.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, Double.valueOf(Float.MAX_VALUE) + Double.valueOf(Float.MAX_VALUE)));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, Double.valueOf(Long.MAX_VALUE) + Double.valueOf(Long.MAX_VALUE)));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -100000.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -1000.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -100000.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -1000.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 10.0));
+        assertTrue(PDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 0.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, -10.0));
+        assertFalse(PDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, Double.MAX_VALUE));
+        
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, Float.valueOf(Long.MAX_VALUE) + Float.valueOf(Long.MAX_VALUE)));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -100000.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -1000.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -100000.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -10.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -1000.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 10.0f));
+        assertTrue(PFloat.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 0.0f));
+        assertFalse(PFloat.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, -10.0f));
+        
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PFloat.INSTANCE, Double.MAX_VALUE));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PLong.INSTANCE, Double.MAX_VALUE));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 10.0));
+        assertTrue(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 0.0));
+        assertFalse(PUnsignedDouble.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, Double.MAX_VALUE));
+        
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PLong.INSTANCE, Float.MAX_VALUE));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0.0f));
+        assertFalse(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0.0f));
+        assertTrue(PUnsignedFloat.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        
+        // Testing coercing integer to other values.
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PLong.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -100000));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -1000));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -100000));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -10));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -1000));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, -10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 0));
+        assertFalse(PInteger.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, -10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 10));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 0));
+        assertTrue(PInteger.INSTANCE.isCoercibleTo(PVarbinary.INSTANCE, 0));
+
+        // Testing coercing long to other values.
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Long.MAX_VALUE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Integer.MAX_VALUE + 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (long)Integer.MAX_VALUE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Integer.MAX_VALUE - 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 0L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, -10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Integer.MIN_VALUE + 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (long)Integer.MIN_VALUE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Integer.MIN_VALUE - 10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, Long.MIN_VALUE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, 0L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, -10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, Long.MAX_VALUE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, -10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, Long.MIN_VALUE));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, -100000L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, -1000L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, -100000L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10L));
+        assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -10L));
+        assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, -1000L));
+		assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 10L));
+		assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, 0L));
+		assertFalse(PLong.INSTANCE
+				.isCoercibleTo(PUnsignedDouble.INSTANCE, -1L));
+		assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 10L));
+		assertTrue(PLong.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, 0L));
+		assertFalse(PLong.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, -1L));
+        
+        // Testing coercing smallint to other values.
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (short)0));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (short)-10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (short)0));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)0));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)1000));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)-10));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)1000));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (short)-1));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (short)10));
+        assertTrue(PSmallint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (short)0));
+        assertFalse(PSmallint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (short)-1));
+        
+        // Testing coercing tinyint to other values.
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (byte)0));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (byte)-10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (byte)0));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (byte)-10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (byte)100));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (byte)0));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (byte)-10));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (byte)-10));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (byte)-10));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (byte)-10));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (byte)-10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE, (byte)-1));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (byte)10));
+        assertTrue(PTinyint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (byte)0));
+        assertFalse(PTinyint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE, (byte)-1));
+
+        // Testing coercing unsigned_int to other values.
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 0));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PLong.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PLong.INSTANCE, 0));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, 0));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 100000));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 1000));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        assertTrue(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+
+        // Testing coercing unsigned_long to other values.
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 10L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PInteger.INSTANCE, 0L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 10L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, 0L));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 10L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, 0L));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 10L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 0L));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, 100000L));
+        assertFalse(PUnsignedInt.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 10L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 0L));
+        assertFalse(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, 1000L));
+        assertTrue(PUnsignedLong.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        
+        // Testing coercing unsigned_smallint to other values.
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (short)0));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (short)0));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (short)0));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (short)0));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (short)0));
+        assertFalse(PUnsignedSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)0));
+        assertFalse(PUnsignedSmallint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (short)1000));
+        assertFalse(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)10));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)0));
+        assertFalse(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedTinyint.INSTANCE, (short)1000));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        assertTrue(PUnsignedSmallint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+        
+        // Testing coercing unsigned_tinyint to other values.
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PDouble.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PFloat.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PInteger.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PLong.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedLong.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedInt.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PSmallint.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PTinyint.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (byte)10));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedSmallint.INSTANCE, (byte)0));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedDouble.INSTANCE));
+        assertTrue(PUnsignedTinyint.INSTANCE.isCoercibleTo(PUnsignedFloat.INSTANCE));
+        
+        // Testing coercing Date types
+        assertTrue(PDate.INSTANCE.isCoercibleTo(PTimestamp.INSTANCE));
+        assertTrue(PDate.INSTANCE.isCoercibleTo(PTime.INSTANCE));
+        assertFalse(PTimestamp.INSTANCE.isCoercibleTo(PDate.INSTANCE));
+        assertFalse(PTimestamp.INSTANCE.isCoercibleTo(PTime.INSTANCE));
+        assertTrue(PTime.INSTANCE.isCoercibleTo(PTimestamp.INSTANCE));
+        assertTrue(PTime.INSTANCE.isCoercibleTo(PDate.INSTANCE));
+    }
+
+    @Test
+    public void testGetDeicmalPrecisionAndScaleFromRawBytes() throws Exception {
+        // Special case for 0.
+        BigDecimal bd = new BigDecimal("0");
+        byte[] b = PDecimal.INSTANCE.toBytes(bd);
+        int[] v = PDataType.getDecimalPrecisionAndScale(b, 0, b.length);
+        assertEquals(0, v[0]);
+        assertEquals(0, v[1]);
+
+        BigDecimal[] bds = new BigDecimal[] {
+                new BigDecimal("1"),
+                new BigDecimal("0.11"),
+                new BigDecimal("1.1"),
+                new BigDecimal("11"),
+                new BigDecimal("101"),
+                new BigDecimal("10.1"),
+                new BigDecimal("1.01"),
+                new BigDecimal("0.101"),
+                new BigDecimal("1001"),
+                new BigDecimal("100.1"),
+                new BigDecimal("10.01"),
+                new BigDecimal("1.001"),
+                new BigDecimal("0.1001"),
+                new BigDecimal("10001"),
+                new BigDecimal("1000.1"),
+                new BigDecimal("100.01"),
+                new BigDecimal("10.001"),
+                new BigDecimal("1.0001"),
+                new BigDecimal("0.10001"),
+                new BigDecimal("100000000000000000000000000000"),
+                new BigDecimal("1000000000000000000000000000000"),
+                new BigDecimal("0.000000000000000000000000000001"),
+                new BigDecimal("0.0000000000000000000000000000001"),
+                new BigDecimal("111111111111111111111111111111"),
+                new BigDecimal("1111111111111111111111111111111"),
+                new BigDecimal("0.111111111111111111111111111111"),
+                new BigDecimal("0.1111111111111111111111111111111"),
+        };
+
+        for (int i=0; i<bds.length; i++) {
+            testReadDecimalPrecisionAndScaleFromRawBytes(bds[i]);
+            testReadDecimalPrecisionAndScaleFromRawBytes(bds[i].negate());
+        }
+        
+        assertTrue(new BigDecimal("5").remainder(BigDecimal.ONE).equals(BigDecimal.ZERO));
+    

<TRUNCATED>

[11/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallintArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallintArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallintArray.java
new file mode 100644
index 0000000..98da723
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallintArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PSmallintArray extends PArrayDataType<short[]> {
+
+  public static final PSmallintArray INSTANCE = new PSmallintArray();
+
+  private PSmallintArray() {
+    super("SMALLINT ARRAY", PDataType.ARRAY_TYPE_BASE + PSmallint.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 31);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PSmallint.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PSmallint.INSTANCE, sortOrder, maxLength, scale,
+        PSmallint.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveShortPhoenixArray pArr = (PhoenixArray.PrimitiveShortPhoenixArray) value;
+    short[] shortArr = (short[]) pArr.array;
+    for (short i : shortArr) {
+      if (!super.isCoercibleTo(PSmallint.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PSmallint.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
new file mode 100644
index 0000000..319f801
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTime.java
@@ -0,0 +1,137 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.DateUtil;
+
+import java.math.BigDecimal;
+import java.sql.Time;
+import java.sql.Types;
+import java.text.Format;
+
+public class PTime extends PDataType<Time> {
+
+  public static final PTime INSTANCE = new PTime();
+
+  private PTime() {
+    super("TIME", Types.TIME, java.sql.Time.class, new PDate.DateCodec(), 10);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return PDate.INSTANCE.toBytes(object);
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    return PDate.INSTANCE.toBytes(object, bytes, offset);
+  }
+
+  @Override
+  public java.sql.Time toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    if (l == 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE, PDate.INSTANCE,
+        PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE, PLong.INSTANCE,
+        PUnsignedLong.INSTANCE)) {
+      return new java.sql.Time(actualType.getCodec().decodeLong(b, o, sortOrder));
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return new java.sql.Time(bd.longValueExact());
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE)) {
+      return new java.sql.Time(((java.util.Date) object).getTime());
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      return new java.sql.Time(((java.sql.Timestamp) object).getTime());
+    } else if (equalsAny(actualType, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return new java.sql.Time((Long) object);
+    } else if (actualType == PDecimal.INSTANCE) {
+      return new java.sql.Time(((BigDecimal) object).longValueExact());
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return PDate.INSTANCE.isCastableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return PDate.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return PDate.INSTANCE.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_LONG;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PDate.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    return DateUtil.parseTime(value);
+  }
+
+  @Override
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return super.isBytesComparableWith(otherType) || otherType.equals(PDate.INSTANCE);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    // TODO: different default formatter for TIME?
+    return PDate.INSTANCE.toStringLiteral(b, offset, length, formatter);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new java.sql.Time((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimeArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimeArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimeArray.java
new file mode 100644
index 0000000..e0a7655
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimeArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Time;
+import java.sql.Types;
+
+public class PTimeArray extends PArrayDataType<Time[]> {
+
+  public static final PTimeArray INSTANCE = new PTimeArray();
+
+  private PTimeArray() {
+    super("TIME ARRAY", PDataType.ARRAY_TYPE_BASE + PTime.INSTANCE.getSqlType(), PhoenixArray.class,
+        null, 38);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PTime.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PTime.INSTANCE, sortOrder, maxLength, scale,
+        PTime.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] timeArr = (Object[]) pArr.array;
+    for (Object i : timeArr) {
+      if (!super.isCoercibleTo(PTime.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PTime.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
new file mode 100644
index 0000000..2b95611
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestamp.java
@@ -0,0 +1,209 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.DateUtil;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.text.Format;
+
+public class PTimestamp extends PDataType<Timestamp> {
+
+  public static final PTimestamp INSTANCE = new PTimestamp();
+
+  private PTimestamp() {
+    super("TIMESTAMP", Types.TIMESTAMP, java.sql.Timestamp.class,
+        new PDate.DateCodec(), 9);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    byte[] bytes = new byte[getByteSize()];
+    toBytes(object, bytes, 0);
+    return bytes;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    java.sql.Timestamp value = (java.sql.Timestamp) object;
+    PDate.INSTANCE.getCodec().encodeLong(value.getTime(), bytes, offset);
+
+            /*
+             * By not getting the stuff that got spilled over from the millis part,
+             * it leaves the timestamp's byte representation saner - 8 bytes of millis | 4 bytes of nanos.
+             * Also, it enables timestamp bytes to be directly compared with date/time bytes.
+             */
+    Bytes.putInt(bytes, offset + Bytes.SIZEOF_LONG, value.getNanos() % 1000000);
+    return getByteSize();
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
+        PUnsignedTime.INSTANCE)) {
+      return new java.sql.Timestamp(((java.util.Date) object).getTime());
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return new java.sql.Timestamp((Long) object);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) object;
+      long ms = bd.longValue();
+      int nanos =
+          (bd.remainder(BigDecimal.ONE).multiply(QueryConstants.BD_MILLIS_NANOS_CONVERSION))
+              .intValue();
+      return DateUtil.getTimestamp(ms, nanos);
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public java.sql.Timestamp toObject(byte[] b, int o, int l, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (actualType == null || l == 0) {
+      return null;
+    }
+    java.sql.Timestamp v;
+    if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      long millisDeserialized =
+          (actualType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE).getCodec()
+              .decodeLong(b, o, sortOrder);
+      v = new java.sql.Timestamp(millisDeserialized);
+      int nanosDeserialized =
+          PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder);
+                /*
+                 * There was a bug in serialization of timestamps which was causing the sub-second millis part
+                 * of time stamp to be present both in the LONG and INT bytes. Having the <100000 check
+                 * makes this serialization fix backward compatible.
+                 */
+      v.setNanos(
+          nanosDeserialized < 1000000 ? v.getNanos() + nanosDeserialized : nanosDeserialized);
+      return v;
+    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
+        PUnsignedTime.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return new java.sql.Timestamp(actualType.getCodec().decodeLong(b, o, sortOrder));
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      long ms = bd.longValue();
+      int nanos = (bd.remainder(BigDecimal.ONE).multiply(QueryConstants.BD_MILLIS_NANOS_CONVERSION))
+          .intValue();
+      v = DateUtil.getTimestamp(ms, nanos);
+      return v;
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return PDate.INSTANCE.isCastableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PVarbinary.INSTANCE, PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      if (targetType.equals(PUnsignedTimestamp.INSTANCE)) {
+        return ((java.util.Date) value).getTime() >= 0;
+      } else if (equalsAny(targetType, PUnsignedDate.INSTANCE, PUnsignedTime.INSTANCE)) {
+        return ((java.util.Date) value).getTime() >= 0
+            && ((java.sql.Timestamp) value).getNanos() == 0;
+      } else if (equalsAny(targetType, PDate.INSTANCE, PTime.INSTANCE)) {
+        return ((java.sql.Timestamp) value).getNanos() == 0;
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return MAX_TIMESTAMP_BYTES;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (equalsAny(rhsType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) {
+      return ((java.sql.Timestamp) lhs).compareTo((java.sql.Timestamp) rhs);
+    }
+    int c = ((java.util.Date) rhs).compareTo((java.util.Date) lhs);
+    if (c != 0) return c;
+    return ((java.sql.Timestamp) lhs).getNanos();
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    return DateUtil.parseTimestamp(value);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    java.sql.Timestamp value = (java.sql.Timestamp) toObject(b, offset, length);
+    if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
+      // If default formatter has not been overridden,
+      // use one that displays milliseconds.
+      formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
+    }
+    return "'" + super.toStringLiteral(b, offset, length, formatter) + "." + value.getNanos() + "'";
+  }
+
+  @Override
+  public int getNanos(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    int nanos = PUnsignedInt.INSTANCE.getCodec()
+        .decodeInt(ptr.get(), ptr.getOffset() + PLong.INSTANCE.getByteSize(), sortOrder);
+    return nanos;
+  }
+
+  @Override
+  public long getMillis(ImmutableBytesWritable ptr, SortOrder sortOrder) {
+    long millis = PLong.INSTANCE.getCodec().decodeLong(ptr.get(), ptr.getOffset(), sortOrder);
+    return millis;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new java.sql.Timestamp(
+        (Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestampArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestampArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestampArray.java
new file mode 100644
index 0000000..d44bda9
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTimestampArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.*;
+
+public class PTimestampArray extends PArrayDataType<Timestamp[]> {
+
+  public static final PTimestampArray INSTANCE = new PTimestampArray();
+
+  private PTimestampArray() {
+    super("TIMESTAMP ARRAY", PDataType.ARRAY_TYPE_BASE + PTimestamp.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 36);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PTimestamp.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PTimestamp.INSTANCE, sortOrder, maxLength, scale,
+        PTimestamp.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] timeStampArr = (Object[]) pArr.array;
+    for (Object i : timeStampArr) {
+      if (!super.isCoercibleTo(PTimestamp.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PTimestamp.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyint.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyint.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyint.java
new file mode 100644
index 0000000..681b41b
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyint.java
@@ -0,0 +1,253 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PTinyint extends PDataType<Byte> {
+
+  public static final PTinyint INSTANCE = new PTinyint();
+
+  private PTinyint() {
+    super("TINYINT", Types.TINYINT, Byte.class, new ByteCodec(), 5);
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_BYTE;
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return BYTE_PRECISION;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_BYTE];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeByte(((Number) object).byteValue(), bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Byte b = Byte.parseByte(value);
+      return b;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Object o = PLong.INSTANCE.toObject(object, actualType);
+    if (!(o instanceof Long) || o == null) {
+      return o;
+    }
+    long l = (Long) o;
+    if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) {
+      throw newIllegalDataException(
+          actualType + " value " + l + " cannot be cast to Byte without changing its value");
+    }
+    return (byte) l;
+  }
+
+  @Override
+  public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    if (l == 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE,
+        PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+        PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+        PUnsignedTinyint.INSTANCE)) {
+      return actualType.getCodec().decodeByte(b, o, sortOrder);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return bd.byteValueExact();
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      if (equalsAny(targetType, this, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
+          PUnsignedLong.INSTANCE, PUnsignedInt.INSTANCE, PUnsignedSmallint.INSTANCE,
+          PUnsignedTinyint.INSTANCE)) {
+        byte i = (Byte) value;
+        return i >= 0;
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return this.equals(targetType) || PSmallint.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return ((Integer) PInteger.INSTANCE.getSampleValue(maxLength, arrayLength))
+        .byteValue();
+  }
+
+  static class ByteCodec extends BaseCodec {
+
+    @Override
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+      return decodeByte(b, o, sortOrder);
+    }
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      return decodeByte(b, o, sortOrder);
+    }
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_BYTE);
+      int v;
+      if (sortOrder == SortOrder.ASC) {
+        v = b[o] ^ 0x80; // Flip sign bit back
+      } else {
+        v = b[o] ^ 0xff ^ 0x80; // Flip sign bit back
+      }
+      return (byte) v;
+    }
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      return decodeByte(b, o, sortOrder);
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_BYTE);
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Byte without changing its value");
+      }
+      return encodeByte((byte) v, b, o);
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Byte without changing its value");
+      }
+      return encodeByte((byte) v, b, o);
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Byte without changing its value");
+      }
+      return encodeByte((byte) v, b, o);
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_BYTE);
+      b[o] = (byte) (v ^ 0x80); // Flip sign bit so that Short is binary comparable
+      return Bytes.SIZEOF_BYTE;
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+      return decodeByte(b, o, sortOrder);
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      return decodeByte(b, o, sortOrder);
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Byte without changing its value");
+      }
+      return encodeByte((byte) v, b, o);
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Byte without changing its value");
+      }
+      return encodeByte((byte) v, b, o);
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray.PrimitiveBytePhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyintArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyintArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyintArray.java
new file mode 100644
index 0000000..e0b300d
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PTinyintArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PTinyintArray extends PArrayDataType<byte[]> {
+
+  public static final PTinyintArray INSTANCE = new PTinyintArray();
+
+  private PTinyintArray() {
+    super("TINYINT ARRAY", PDataType.ARRAY_TYPE_BASE + PTinyint.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 32);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PTinyint.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PTinyint.INSTANCE, sortOrder, maxLength, scale,
+        PTinyint.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveBytePhoenixArray pArr = (PhoenixArray.PrimitiveBytePhoenixArray) value;
+    byte[] byteArr = (byte[]) pArr.array;
+    for (byte i : byteArr) {
+      if (!super.isCoercibleTo(PTinyint.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PTinyint.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
new file mode 100644
index 0000000..8b63fbb
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDate.java
@@ -0,0 +1,164 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.DateUtil;
+
+import java.sql.Types;
+import java.sql.Date;
+import java.text.Format;
+
+public class PUnsignedDate extends PDataType<Date> {
+
+  public static final PUnsignedDate INSTANCE = new PUnsignedDate();
+
+  private PUnsignedDate() {
+    super("UNSIGNED_DATE", 19, Date.class,
+        new UnsignedDateCodec(), 14); // After TIMESTAMP and DATE to ensure toLiteral finds those first
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    byte[] bytes = new byte[getByteSize()];
+    toBytes(object, bytes, 0);
+    return bytes;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    getCodec().encodeLong(((java.util.Date) object).getTime(), bytes, offset);
+    return this.getByteSize();
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Date d = (Date) PDate.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeDate(d);
+    return d;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    Date d = (Date) PDate.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeDate(d);
+    return d;
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return PDate.INSTANCE.isCastableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PUnsignedTime.INSTANCE, PUnsignedTimestamp.INSTANCE)
+        || PDate.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PDate.INSTANCE.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return PDate.INSTANCE.getByteSize();
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PDate.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    return PDate.INSTANCE.toObject(value);
+  }
+
+  @Override
+  public boolean isBytesComparableWith(PDataType otherType) {
+    return super.isBytesComparableWith(otherType) || otherType.equals(PUnsignedTime.INSTANCE);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    // Can't delegate, as the super.toStringLiteral calls this.toBytes
+    if (formatter == null || formatter == DateUtil.DEFAULT_DATE_FORMATTER) {
+      // If default formatter has not been overridden,
+      // use one that displays milliseconds.
+      formatter = DateUtil.DEFAULT_MS_DATE_FORMATTER;
+    }
+    return "'" + super.toStringLiteral(b, offset, length, formatter) + "'";
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifier,
+      Integer desiredMaxLength, Integer desiredScale,
+      SortOrder expectedModifier) {
+    if (ptr.getLength() > 0 && actualType == PUnsignedTimestamp.INSTANCE
+        && actualModifier == expectedModifier) {
+      ptr.set(ptr.get(), ptr.getOffset(), getByteSize());
+      return;
+    }
+    super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+        desiredScale, expectedModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.DATE;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new Date((Long) PUnsignedLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class UnsignedDateCodec extends PUnsignedLong.UnsignedLongCodec {
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDateArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDateArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDateArray.java
new file mode 100644
index 0000000..859c93b
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDateArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+import java.util.Date;
+
+public class PUnsignedDateArray extends PArrayDataType<Date> {
+
+  public static final PUnsignedDateArray INSTANCE = new PUnsignedDateArray();
+
+  private PUnsignedDateArray() {
+    super("UNSIGNED_DATE ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedDate.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 41);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedDate.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedDate.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedDate.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] dateArr = (Object[]) pArr.array;
+    for (Object i : dateArr) {
+      if (!super.isCoercibleTo(PUnsignedDate.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedDate.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
new file mode 100644
index 0000000..c1fd7ba
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDouble.java
@@ -0,0 +1,158 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Doubles;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+
+public class PUnsignedDouble extends PDataType<PDouble> {
+
+  public static final PUnsignedDouble INSTANCE = new PUnsignedDouble();
+
+  private PUnsignedDouble() {
+    super("UNSIGNED_DOUBLE", 15, Double.class, new UnsignedDoubleCodec(), 20);
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PDecimal.INSTANCE) {
+      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue()));
+    }
+    return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_DOUBLE;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return PDouble.INSTANCE.getScale(o);
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return PDouble.INSTANCE.getMaxLength(o);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeDouble(((Number) object).doubleValue(),
+        bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Double d = Double.parseDouble(value);
+      if (d.doubleValue() < 0) {
+        throw newIllegalDataException("Value may not be negative("
+            + d + ")");
+      }
+      return d;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Double v = (Double) PDouble.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Double v = (Double) PDouble.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PDouble.INSTANCE
+        .isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return this.equals(targetType) || PDouble.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PDouble.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return Math.abs((Double) PDouble.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class UnsignedDoubleCodec extends PDouble.DoubleCodec {
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putDouble(b, o, v);
+      return Bytes.SIZEOF_DOUBLE;
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_DOUBLE);
+      if (sortOrder == SortOrder.DESC) {
+        b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_DOUBLE], 0, Bytes.SIZEOF_DOUBLE);
+      }
+      double v = Bytes.toDouble(b, o);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDoubleArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDoubleArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDoubleArray.java
new file mode 100644
index 0000000..50c69bf
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedDoubleArray.java
@@ -0,0 +1,112 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedDoubleArray extends PArrayDataType<double[]> {
+
+  public static final PUnsignedDoubleArray INSTANCE = new PUnsignedDoubleArray();
+
+  private PUnsignedDoubleArray() {
+    super("UNSIGNED_DOUBLE ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedDouble.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 47);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedDouble.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedDouble.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedDouble.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] doubleArr = (Object[]) pArr.array;
+    for (Object i : doubleArr) {
+      if (!super.isCoercibleTo(PUnsignedDouble.INSTANCE, i) && (!super.isCoercibleTo(
+          PUnsignedTimestamp.INSTANCE, i))
+          && (!super.isCoercibleTo(PUnsignedTime.INSTANCE, i)) && (!super
+          .isCoercibleTo(PUnsignedDate.INSTANCE, i))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedDouble.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
new file mode 100644
index 0000000..c04b9c7
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloat.java
@@ -0,0 +1,152 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+public class PUnsignedFloat extends PDataType<PFloat> {
+
+  public static final PUnsignedFloat INSTANCE = new PUnsignedFloat();
+
+  private PUnsignedFloat() {
+    super("UNSIGNED_FLOAT", 14, Float.class, new UnsignedFloatCodec(), 19);
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PFloat.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_FLOAT;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return PFloat.INSTANCE.getScale(o);
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return PFloat.INSTANCE.getMaxLength(o);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_FLOAT];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeFloat(((Number) object).floatValue(),
+        bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Float f = Float.parseFloat(value);
+      if (f.floatValue() < 0) {
+        throw newIllegalDataException("Value may not be negative("
+            + f + ")");
+      }
+      return f;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Float v = (Float) PFloat.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Float v = (Float) PFloat.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType) || PFloat.INSTANCE.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return this.equals(targetType) || PUnsignedDouble.INSTANCE.isCoercibleTo(targetType) || PFloat.INSTANCE
+        .isCoercibleTo(targetType);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PFloat.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return Math.abs((Float) PFloat.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class UnsignedFloatCodec extends PFloat.FloatCodec {
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putFloat(b, o, v);
+      return Bytes.SIZEOF_FLOAT;
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
+      if (sortOrder == SortOrder.DESC) {
+        b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_FLOAT], 0, Bytes.SIZEOF_FLOAT);
+      }
+      float v = Bytes.toFloat(b, o);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloatArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloatArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloatArray.java
new file mode 100644
index 0000000..db9d075
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedFloatArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedFloatArray extends PArrayDataType<float[]> {
+
+  public static final PUnsignedFloatArray INSTANCE = new PUnsignedFloatArray();
+
+  private PUnsignedFloatArray() {
+    super("UNSIGNED_FLOAT ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedFloat.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 46);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedFloat.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedFloat.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedFloat.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] floatArr = (Object[]) pArr.array;
+    for (Object i : floatArr) {
+      if (!super.isCoercibleTo(PUnsignedFloat.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedFloat.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
new file mode 100644
index 0000000..8bd5e6d
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedInt.java
@@ -0,0 +1,178 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.phoenix.schema.SortOrder;
+
+/**
+ * Unsigned integer type that restricts values to be from 0 to {@link Integer#MAX_VALUE}
+ * inclusive. May be used to map to existing HTable values created through
+ * {@link org.apache.hadoop.hbase.util.Bytes#toBytes(int)}
+ * as long as all values are non negative (the leading sign bit of negative numbers would cause
+ * them to sort ahead of positive numbers when they're used as part of the row key when using the
+ * HBase utility methods).
+ */
+public class PUnsignedInt extends PDataType<Integer> {
+
+  public static final PUnsignedInt INSTANCE = new PUnsignedInt();
+
+  private PUnsignedInt() {
+    super("UNSIGNED_INT", 9 /* no constant available in Types */, Integer.class,
+        new UnsignedIntCodec(), 16);
+  }
+
+  @Override
+  public boolean isOrderPreserving() {
+    return true;
+  }
+
+  @Override
+  public Order getOrder() {
+    return Order.ASCENDING;
+  }
+
+  @Override
+  public boolean isSkippable() {
+    return true;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_INT];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] b, int o) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeInt(((Number) object).intValue(), b, o);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Integer v = (Integer) PInteger.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Integer v =
+        (Integer) PInteger.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return targetType.equals(this) || targetType.equals(PUnsignedFloat.INSTANCE)
+        || PUnsignedLong.INSTANCE.isCoercibleTo(targetType)
+        || PInteger.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PInteger.INSTANCE
+        .isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_INT;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Integer i = Integer.parseInt(value);
+      if (i.intValue() < 0) {
+        throw newIllegalDataException("Value may not be negative(" + i + ")");
+      }
+      return i;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PInteger.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return Math.abs((Integer) PInteger.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class UnsignedIntCodec extends PInteger.IntCodec {
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_INT);
+      if (sortOrder == SortOrder.DESC) {
+        b = SortOrder.invert(b, o, new byte[Bytes.SIZEOF_INT], 0, Bytes.SIZEOF_INT);
+      }
+      int v = Bytes.toInt(b, o);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_INT);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putInt(b, o, v);
+      return Bytes.SIZEOF_INT;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedIntArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedIntArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedIntArray.java
new file mode 100644
index 0000000..11e5f10
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedIntArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedIntArray extends PArrayDataType<int[]> {
+
+  public static final PUnsignedIntArray INSTANCE = new PUnsignedIntArray();
+
+  private PUnsignedIntArray() {
+    super("UNSIGNED_INT ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedInt.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 43);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedInt.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedInt.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedInt.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] intArr = (Object[]) pArr.array;
+    for (Object i : intArr) {
+      if (!super.isCoercibleTo(PUnsignedInt.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedInt.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
new file mode 100644
index 0000000..a0ead11
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLong.java
@@ -0,0 +1,193 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Doubles;
+import com.google.common.primitives.Longs;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Order;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+
+/**
+ * Unsigned long type that restricts values to be from 0 to {@link Long#MAX_VALUE}
+ * inclusive. May be used to map to existing HTable values created through
+ * {@link org.apache.hadoop.hbase.util.Bytes#toBytes(long)}
+ * as long as all values are non negative (the leading sign bit of negative numbers would cause
+ * them to sort ahead of positive numbers when they're used as part of the row key when using the
+ * HBase utility methods).
+ */
+public class PUnsignedLong extends PDataType<Long> {
+
+  public static final PUnsignedLong INSTANCE = new PUnsignedLong();
+
+  private PUnsignedLong() {
+    super("UNSIGNED_LONG", 10 /* no constant available in Types */, Long.class,
+        new UnsignedLongCodec(), 15);
+  }
+
+  @Override
+  public boolean isOrderPreserving() {
+    return true;
+  }
+
+  @Override
+  public Order getOrder() {
+    return Order.ASCENDING;
+  }
+
+  @Override
+  public boolean isSkippable() {
+    return true;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_LONG];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] b, int o) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Long v = (Long) PLong.INSTANCE.toObject(object, actualType);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder);
+    throwIfNonNegativeNumber(v);
+    return v;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return targetType == this || targetType == PUnsignedDouble.INSTANCE || PLong.INSTANCE
+        .isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    return super.isCoercibleTo(targetType, value) || PLong.INSTANCE.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_LONG;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PDecimal.INSTANCE) {
+      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
+    } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE,
+        PUnsignedFloat.INSTANCE)) {
+      return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+    }
+    return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      Long l = Long.parseLong(value);
+      if (l.longValue() < 0) {
+        throw newIllegalDataException("Value may not be negative(" + l + ")");
+      }
+      return l;
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return PLong.INSTANCE.getResultSetSqlType();
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return Math.abs((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+
+  static class UnsignedLongCodec extends PLong.LongCodec {
+
+    @Override
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+      long v = 0;
+      if (sortOrder == SortOrder.ASC) {
+        for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
+          v <<= 8;
+          v ^= b[i] & 0xFF;
+        }
+      } else {
+        for (int i = o; i < o + Bytes.SIZEOF_LONG; i++) {
+          v <<= 8;
+          v ^= (b[i] & 0xFF) ^ 0xFF;
+        }
+      }
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      return v;
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+      if (v < 0) {
+        throw newIllegalDataException();
+      }
+      Bytes.putLong(b, o, v);
+      return Bytes.SIZEOF_LONG;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLongArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLongArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLongArray.java
new file mode 100644
index 0000000..dcbe210
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PUnsignedLongArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PUnsignedLongArray extends PArrayDataType<long[]> {
+
+  public static final PUnsignedLongArray INSTANCE = new PUnsignedLongArray();
+
+  private PUnsignedLongArray() {
+    super("UNSIGNED_LONG ARRAY", PDataType.ARRAY_TYPE_BASE + PUnsignedLong.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 42);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PUnsignedLong.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PUnsignedLong.INSTANCE, sortOrder, maxLength,
+        scale, PUnsignedLong.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] longArr = (Object[]) pArr.array;
+    for (Object i : longArr) {
+      if (!super.isCoercibleTo(PUnsignedLong.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PUnsignedLong.INSTANCE, arrayLength, maxLength);
+  }
+}


[08/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
index 1ce6c02..ad8e5f5 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
@@ -54,8 +54,11 @@ import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.schema.ColumnNotFoundException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PUnsignedLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -96,8 +99,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
 
     @Test
@@ -107,7 +110,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] key = StringUtil.padChar(PDataType.CHAR.toBytes(tenantId), 15);
+        byte[] key = StringUtil.padChar(PChar.INSTANCE.toBytes(tenantId), 15);
         assertArrayEquals(key, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(key), scan.getStopRow());
     }
@@ -121,7 +124,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] key = ByteUtil.fillKey(PDataType.VARCHAR.toBytes(tenantId), 15);
+        byte[] key = ByteUtil.fillKey(PVarchar.INSTANCE.toBytes(tenantId), 15);
         assertArrayEquals(key, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(key), scan.getStopRow());
     }
@@ -133,8 +136,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         assertNull(scan.getFilter());
 
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
 
     @Test
@@ -147,8 +150,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes("EA"), scan.getStartRow());
-        assertArrayEquals(PDataType.VARCHAR.toBytes("EZ"), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes("EA"), scan.getStartRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes("EZ"), scan.getStopRow());
     }
 
     @Test
@@ -194,9 +197,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)), 15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)), 15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -209,9 +214,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -226,13 +233,13 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(startDate));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(startDate));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -258,12 +265,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
+        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -278,12 +285,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
+        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -298,12 +305,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
+        byte[] stopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -318,12 +325,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -338,12 +345,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -358,12 +365,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -378,12 +385,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query, binds).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.VARCHAR.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
-                PDataType.DATE.toBytes(endDate));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(inst),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PVarchar.INSTANCE.toBytes(host),QueryConstants.SEPARATOR_BYTE_ARRAY,
+                PDate.INSTANCE.toBytes(endDate));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -396,7 +403,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),PDataType.VARCHAR.toBytes(entityId));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(startRow, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(startRow), scan.getStopRow());
     }
@@ -409,14 +416,16 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         assertNotNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(StringUtil.padChar(PDataType.VARCHAR.toBytes(tenantId.substring(0,3)),15),PDataType.VARCHAR.toBytes(entityId));
+        byte[] startRow = ByteUtil.concat(StringUtil.padChar(PVarchar.INSTANCE.toBytes(tenantId.substring(0,3)),15),
+            PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(startRow, scan.getStartRow());
         // Even though the first slot is a non inclusive range, we need to do a next key
         // on the second slot because of the algorithm we use to seek to and terminate the
         // loop during skip scan. We could end up having a first slot just under the upper
         // limit of slot one and a value equal to the value in slot two and we need this to
         // be less than the upper range that would get formed.
-        byte[] stopRow = ByteUtil.concat(StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId.substring(0,3))),15),ByteUtil.nextKey(PDataType.VARCHAR.toBytes(entityId)));
+        byte[] stopRow = ByteUtil.concat(StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId.substring(0,3))),15),ByteUtil.nextKey(
+            PVarchar.INSTANCE.toBytes(entityId)));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -428,7 +437,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         assertNull(scan.getFilter());
 
         assertTrue(scan.getStartRow().length == 0);
-        byte[] stopRow = ByteUtil.concat(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)));
+        byte[] stopRow = ByteUtil.concat(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -441,9 +450,9 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(PDataType.CHAR.toBytes(keyPrefix1),15));
+        byte[] startRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PChar.INSTANCE.toBytes(keyPrefix1),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(PDataType.CHAR.toBytes(keyPrefix2),15));
+        byte[] stopRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PChar.INSTANCE.toBytes(keyPrefix2),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -456,9 +465,10 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(PDataType.CHAR.toBytes(keyPrefix1),15));
+        byte[] startRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PChar.INSTANCE.toBytes(keyPrefix1),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.CHAR.toBytes(keyPrefix2)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes(keyPrefix2)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -471,9 +481,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix1)),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix1)),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix2)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix2)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -496,9 +508,9 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),PDataType.VARCHAR.toBytes(entityId));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),PDataType.VARCHAR.toBytes(entityId));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
     }
 
@@ -521,9 +533,9 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
         assertNull(scan.getFilter());
 
-        byte[] startRow = PDataType.CHAR.toBytes(tenantId);
+        byte[] startRow = PChar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(PDataType.CHAR.toBytes(keyPrefix1),entityId.length()));
+        byte[] stopRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PChar.INSTANCE.toBytes(keyPrefix1),entityId.length()));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -536,9 +548,9 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),PDataType.VARCHAR.toBytes(entityId));
+        byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),PDataType.VARCHAR.toBytes(entityId));
+        byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId));
         assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
     }
 
@@ -551,9 +563,10 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(PDataType.CHAR.toBytes(keyPrefix1),15)); // extra byte is due to implicit internal padding
+        byte[] startRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PChar.INSTANCE.toBytes(keyPrefix1),15)); // extra byte is due to implicit internal padding
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.CHAR.toBytes(keyPrefix2)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PChar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes(keyPrefix2)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -589,8 +602,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = compileStatement(query).getScan();
 
         assertNotNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
 
     @Test
@@ -626,7 +639,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
 
         assertNotNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
 
@@ -638,8 +651,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
 
         assertNotNull(scan.getFilter());
-        assertArrayEquals(PDataType.VARCHAR.toBytes(tenantId), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(PVarchar.INSTANCE.toBytes(tenantId), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
 
 
@@ -664,9 +677,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -680,9 +695,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
 
         assertNull(scan.getFilter());
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -715,9 +732,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg)),
                 filter);
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -739,9 +758,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg)),
                 filter);
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
         assertArrayEquals(startRow, scan.getStartRow());
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(stopRow, scan.getStopRow());
     }
 
@@ -763,8 +784,10 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg)),
                 filter);
 
-        byte[] startRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15));
-        byte[] stopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15));
+        byte[] startRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15));
+        byte[] stopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId),StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15));
         assertArrayEquals(startRow, scan.getStartRow());
         assertArrayEquals(stopRow, scan.getStopRow());
     }
@@ -787,7 +810,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg)),
                 filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(startRow), scan.getStopRow());
     }
@@ -810,7 +833,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg)),
                 filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(startRow), scan.getStopRow());
     }
@@ -833,7 +856,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
                     likeArg))),
                 filter);
 
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
         assertArrayEquals(startRow, scan.getStartRow());
         assertArrayEquals(ByteUtil.nextKey(startRow), scan.getStopRow());
     }
@@ -1030,12 +1053,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         List<List<KeyRange>> ranges = scanRanges.getRanges();
         assertEquals(1,ranges.size());
         List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList(
-                PDataType.CHAR.getKeyRange(PDataType.CHAR.toBytes(tenantId1), true, PDataType.CHAR.toBytes(tenantId1), true), 
-                PDataType.CHAR.getKeyRange(PDataType.CHAR.toBytes(tenantId2), true, PDataType.CHAR.toBytes(tenantId2), true)));
+                PChar.INSTANCE.getKeyRange(PChar.INSTANCE.toBytes(tenantId1), true, PChar.INSTANCE.toBytes(tenantId1), true),
+                PChar.INSTANCE.getKeyRange(PChar.INSTANCE.toBytes(tenantId2), true, PChar.INSTANCE.toBytes(tenantId2), true)));
         assertEquals(expectedRanges, ranges);
-        byte[] startRow = PDataType.VARCHAR.toBytes(tenantId1);
+        byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
         assertArrayEquals(startRow, scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId2)), scan.getStopRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId2)), scan.getStopRow());
     }
     
     @Test
@@ -1092,12 +1115,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         List<List<KeyRange>> ranges = scanRanges.getRanges();
         assertEquals(1,ranges.size());
         List<List<KeyRange>> expectedRanges = Collections.singletonList(Arrays.asList(
-                PDataType.CHAR.getKeyRange(
-                        StringUtil.padChar(PDataType.CHAR.toBytes("00D"),15), true, 
-                        StringUtil.padChar(ByteUtil.nextKey(PDataType.CHAR.toBytes("00D")),15), false), 
-                PDataType.CHAR.getKeyRange(
-                        StringUtil.padChar(PDataType.CHAR.toBytes("foo"),15), true, 
-                        StringUtil.padChar(ByteUtil.nextKey(PDataType.CHAR.toBytes("foo")),15), false)));
+                PChar.INSTANCE.getKeyRange(
+                        StringUtil.padChar(PChar.INSTANCE.toBytes("00D"),15), true,
+                        StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("00D")),15), false),
+                PChar.INSTANCE.getKeyRange(
+                        StringUtil.padChar(PChar.INSTANCE.toBytes("foo"),15), true,
+                        StringUtil.padChar(ByteUtil.nextKey(PChar.INSTANCE.toBytes("foo")),15), false)));
         assertEquals(expectedRanges, ranges);
     }
     
@@ -1135,7 +1158,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         assertEquals(KeyRange.EVERYTHING_RANGE,scanRanges.getRanges().get(1).get(0));
         assertEquals(1,scanRanges.getRanges().get(2).size());
         assertTrue(scanRanges.getRanges().get(2).get(0).isSingleKey());
-        assertEquals(Long.valueOf(5399179882L), PDataType.UNSIGNED_LONG.toObject(scanRanges.getRanges().get(2).get(0).getLowerRange()));
+        assertEquals(Long.valueOf(5399179882L), PUnsignedLong.INSTANCE.toObject(scanRanges.getRanges().get(2).get(0).getLowerRange()));
     }
     
     @Test
@@ -1154,9 +1177,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         assertNotNull(filter);
         assertTrue(filter instanceof RowKeyComparisonFilter);
 
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), StringUtil.padChar(PDataType.VARCHAR.toBytes(keyPrefix),15), PDataType.DATE.toBytes(startTime));
+        byte[] expectedStartRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15), PDate.INSTANCE.toBytes(startTime));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
-        byte[] expectedStopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), StringUtil.padChar(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(keyPrefix)),15), PDataType.DATE.toBytes(stopTime));
+        byte[] expectedStopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15), PDate.INSTANCE.toBytes(stopTime));
         assertArrayEquals(expectedStopRow, scan.getStopRow());
     }
 
@@ -1169,7 +1194,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         StatementContext context = compileStatement(query, binds);
         Scan scan = context.getScan();
         assertNull(scan.getFilter());
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId), PDataType.CHAR.toBytes(entityId));
+        byte[] expectedStartRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId), PChar.INSTANCE.toBytes(entityId));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1187,8 +1212,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), PDataType.VARCHAR.toBytes(entityId2));
-        byte[] expectedStopRow = ByteUtil.concat(ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), PDataType.VARCHAR.toBytes(entityId2)), QueryConstants.SEPARATOR_BYTE_ARRAY);
+        byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId2));
+        byte[] expectedStopRow = ByteUtil.concat(ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(entityId2)), QueryConstants.SEPARATOR_BYTE_ARRAY);
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(expectedStopRow, scan.getStopRow());
     }
@@ -1216,7 +1241,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNotNull(filter);
         assertTrue(filter instanceof RowKeyComparisonFilter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), PDataType.VARCHAR.toBytes(parentId));
+        byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(parentId));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1261,8 +1286,9 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(lowerTenantId), PDataType.VARCHAR.toBytes(lowerParentId), PDataType.DATE.toBytes(lowerCreatedDate));
-        byte[] expectedStopRow = ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes(upperTenantId), PDataType.VARCHAR.toBytes(upperParentId)));
+        byte[] expectedStartRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(lowerTenantId), PVarchar.INSTANCE.toBytes(lowerParentId), PDate.INSTANCE.toBytes(lowerCreatedDate));
+        byte[] expectedStopRow = ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(upperTenantId), PVarchar.INSTANCE.toBytes(upperParentId)));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(expectedStopRow, scan.getStopRow());
     }
@@ -1279,8 +1305,10 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(lowerTenantId), PDataType.VARCHAR.toBytes(lowerParentId), PDataType.DATE.toBytes(lowerCreatedDate));
-        byte[] expectedStopRow = ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PDataType.VARCHAR.toBytes("7"),15), StringUtil.padChar(PDataType.VARCHAR.toBytes("7"), 15)));
+        byte[] expectedStartRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(lowerTenantId), PVarchar.INSTANCE.toBytes(lowerParentId), PDate.INSTANCE.toBytes(lowerCreatedDate));
+        byte[] expectedStopRow = ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PVarchar.INSTANCE.toBytes("7"),15), StringUtil.padChar(
+            PVarchar.INSTANCE.toBytes("7"), 15)));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(expectedStopRow, scan.getStopRow());
     }
@@ -1299,7 +1327,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNotNull(filter);
         assertTrue(filter instanceof RowKeyComparisonFilter);
-        byte[] expectedStartRow = PDataType.VARCHAR.toBytes(subStringTenantId);
+        byte[] expectedStartRow = PVarchar.INSTANCE.toBytes(subStringTenantId);
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1318,7 +1346,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNotNull(filter);
         assertTrue(filter instanceof RowKeyComparisonFilter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), PDataType.VARCHAR.toBytes(subStringParentId));
+        byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(subStringParentId));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1337,7 +1365,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNotNull(filter);
         assertTrue(filter instanceof RowKeyComparisonFilter);
-        byte[] expectedStopRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), ByteUtil.nextKey(PDataType.VARCHAR.toBytes(subStringParentId)));
+        byte[] expectedStopRow = ByteUtil.concat(
+            PVarchar.INSTANCE.toBytes(tenantId), ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(subStringParentId)));
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
         assertArrayEquals(expectedStopRow, scan.getStopRow());
     }
@@ -1354,7 +1383,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.VARCHAR.toBytes(tenantId), PDataType.VARCHAR.toBytes(parentId));
+        byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(parentId));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1371,7 +1400,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(PDataType.CHAR.toBytes(tenantId), new byte[15], ByteUtil.previousKey(PDataType.DATE.toBytes(createdDate)));
+        byte[] expectedStartRow = ByteUtil.concat(PChar.INSTANCE.toBytes(tenantId), new byte[15], ByteUtil.previousKey(
+            PDate.INSTANCE.toBytes(createdDate)));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1388,7 +1418,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        byte[] expectedStartRow = ByteUtil.concat(new byte[15], ByteUtil.previousKey(PDataType.CHAR.toBytes(parentId)), PDataType.DATE.toBytes(createdDate));
+        byte[] expectedStartRow = ByteUtil.concat(new byte[15], ByteUtil.previousKey(PChar.INSTANCE.toBytes(parentId)), PDate.INSTANCE.toBytes(createdDate));
         assertArrayEquals(expectedStartRow, scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
@@ -1407,8 +1437,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.concat(PDataType.VARCHAR.toBytes(firstOrgId), PDataType.VARCHAR.toBytes(parentId), PDataType.DATE.toBytes(createdDate)), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(secondOrgId)), scan.getStopRow());
+        assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstOrgId), PVarchar.INSTANCE.toBytes(parentId), PDate.INSTANCE.toBytes(createdDate)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(secondOrgId)), scan.getStopRow());
     }
     
     @Test
@@ -1422,7 +1452,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
     
@@ -1437,7 +1467,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
     
@@ -1451,7 +1481,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
     
@@ -1467,7 +1497,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNull(filter);
         assertArrayEquals(HConstants.EMPTY_START_ROW, scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
     
     @Test
@@ -1482,7 +1512,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertNull(filter);
         assertArrayEquals(HConstants.EMPTY_START_ROW, scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(PDataType.VARCHAR.toBytes(tenantId)), scan.getStopRow());
+        assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), scan.getStopRow());
     }
     
     @Test
@@ -1515,7 +1545,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.concat(PDataType.VARCHAR.toBytes(firstTenantId), PDataType.VARCHAR.toBytes(firstParentId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstTenantId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
     
@@ -1531,7 +1561,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.concat(PDataType.VARCHAR.toBytes(firstTenantId), PDataType.VARCHAR.toBytes(firstParentId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstTenantId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
     }
     
@@ -1578,8 +1608,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertTrue(filter instanceof SkipScanFilter);
-        assertArrayEquals(ByteUtil.concat(PDataType.VARCHAR.toBytes(firstOrgId), PDataType.VARCHAR.toBytes(firstParentId)), scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(PDataType.VARCHAR.toBytes(secondOrgId), PDataType.VARCHAR.toBytes(secondParentId))), scan.getStopRow());
+        assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstOrgId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(secondOrgId), PVarchar.INSTANCE.toBytes(secondParentId))), scan.getStopRow());
     }
     
     @Test
@@ -1595,11 +1625,11 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Filter filter = scan.getFilter();
         assertTrue(filter instanceof SkipScanFilter);
         List<List<KeyRange>> skipScanRanges = Collections.singletonList(Arrays.asList(
-                KeyRange.getKeyRange(ByteUtil.concat(PDataType.CHAR.toBytes(firstOrgId), PDataType.CHAR.toBytes(firstParentId))), 
-                KeyRange.getKeyRange(ByteUtil.concat(PDataType.CHAR.toBytes(secondOrgId), PDataType.CHAR.toBytes(secondParentId)))));
+                KeyRange.getKeyRange(ByteUtil.concat(PChar.INSTANCE.toBytes(firstOrgId), PChar.INSTANCE.toBytes(firstParentId))),
+                KeyRange.getKeyRange(ByteUtil.concat(PChar.INSTANCE.toBytes(secondOrgId), PChar.INSTANCE.toBytes(secondParentId)))));
         assertEquals(skipScanRanges, context.getScanRanges().getRanges());
-        assertArrayEquals(ByteUtil.concat(PDataType.CHAR.toBytes(firstOrgId), PDataType.CHAR.toBytes(firstParentId)), scan.getStartRow());
-        assertArrayEquals(ByteUtil.concat(PDataType.CHAR.toBytes(secondOrgId), PDataType.CHAR.toBytes(secondParentId), QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
+        assertArrayEquals(ByteUtil.concat(PChar.INSTANCE.toBytes(firstOrgId), PChar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.concat(PChar.INSTANCE.toBytes(secondOrgId), PChar.INSTANCE.toBytes(secondParentId), QueryConstants.SEPARATOR_BYTE_ARRAY), scan.getStopRow());
     }
     
     @Test
@@ -1668,7 +1698,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Scan scan = context.getScan();
         Filter filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId), 15)), scan.getStartRow());
+        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId), 15)), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
         
         // CASE 2: >
@@ -1678,7 +1709,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         scan = context.getScan();
         filter = scan.getFilter();
         assertNull(filter);
-        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId), 15))), scan.getStartRow());
+        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId), 15))), scan.getStartRow());
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
         
         // CASE 3: <=
@@ -1689,7 +1721,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         filter = scan.getFilter();
         assertNull(filter);
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
-        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId), 15))), scan.getStopRow());
+        assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId), 15))), scan.getStopRow());
         
         // CASE 4: <
         query = "select * from atable where (organization_id, entity_id) < (?,?)";
@@ -1699,7 +1732,8 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         filter = scan.getFilter();
         assertNull(filter);
         assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
-        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId), 15)), scan.getStopRow());
+        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId), 15)), scan.getStopRow());
         
         // CASE 5: =
         // For RVC, this will only occur if there's more than one key in the IN
@@ -1714,10 +1748,12 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
         Iterator<KeyRange> iterator = scanRanges.getPointLookupKeyIterator();
         KeyRange k1 = iterator.next();
         assertTrue(k1.isSingleKey());
-        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId), 15)), k1.getLowerRange());
+        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId), 15)), k1.getLowerRange());
         KeyRange k2 = iterator.next();
         assertTrue(k2.isSingleKey());
-        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PDataType.CHAR.toBytes(orgId2), 15), StringUtil.padChar(PDataType.CHAR.toBytes(entityId2), 15)), k2.getLowerRange());
+        assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId2), 15), StringUtil.padChar(
+            PChar.INSTANCE.toBytes(entityId2), 15)), k2.getLowerRange());
     }
     
     private static StatementContext compileStatementTenantSpecific(String tenantId, String query, List<Object> binds) throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/expression/CoerceExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/CoerceExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/CoerceExpressionTest.java
index 387c2e5..b7baa97 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/CoerceExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/CoerceExpressionTest.java
@@ -26,9 +26,16 @@ import java.sql.Timestamp;
 import java.util.HashMap;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.junit.Test;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * Test class for unit-testing {@link CoerceExpression}
@@ -59,8 +66,8 @@ public class CoerceExpressionTest {
 	
 	@Test
     public void testCoerceExpressionSupportsCoercingIntToDecimal() throws Exception {
-        LiteralExpression v = LiteralExpression.newConstant(1, PDataType.INTEGER);
-        CoerceExpression e = new CoerceExpression(v, PDataType.DECIMAL);
+        LiteralExpression v = LiteralExpression.newConstant(1, PInteger.INSTANCE);
+        CoerceExpression e = new CoerceExpression(v, PDecimal.INSTANCE);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         e.evaluate(null, ptr);
         Object obj = e.getDataType().toObject(ptr);
@@ -71,8 +78,8 @@ public class CoerceExpressionTest {
 	
 	@Test
     public void testCoerceExpressionSupportsCoercingCharToVarchar() throws Exception {
-        LiteralExpression v = LiteralExpression.newConstant("a", PDataType.CHAR);
-        CoerceExpression e = new CoerceExpression(v, PDataType.VARCHAR);
+        LiteralExpression v = LiteralExpression.newConstant("a", PChar.INSTANCE);
+        CoerceExpression e = new CoerceExpression(v, PVarchar.INSTANCE);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         e.evaluate(null, ptr);
         Object obj = e.getDataType().toObject(ptr);
@@ -83,8 +90,8 @@ public class CoerceExpressionTest {
 	
 	@Test
     public void testCoerceExpressionSupportsCoercingIntToLong() throws Exception {
-        LiteralExpression v = LiteralExpression.newConstant(1, PDataType.INTEGER);
-        CoerceExpression e = new CoerceExpression(v, PDataType.LONG);
+        LiteralExpression v = LiteralExpression.newConstant(1, PInteger.INSTANCE);
+        CoerceExpression e = new CoerceExpression(v, PLong.INSTANCE);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         e.evaluate(null, ptr);
         Object obj = e.getDataType().toObject(ptr);
@@ -100,7 +107,7 @@ public class CoerceExpressionTest {
 				LiteralExpression v = LiteralExpression.newConstant(
 						map.get(p.getJavaClass()), p);
 				CoerceExpression e = new CoerceExpression(v,
-						PDataType.VARBINARY);
+            PVarbinary.INSTANCE);
 				ImmutableBytesWritable ptr = new ImmutableBytesWritable();
 				e.evaluate(null, ptr);
 				Object obj = e.getDataType().toObject(ptr);
@@ -117,7 +124,7 @@ public class CoerceExpressionTest {
 			if (!p.isArrayType()) {
 				LiteralExpression v = LiteralExpression.newConstant(
 						map.get(p.getJavaClass()), p);
-				CoerceExpression e = new CoerceExpression(v, PDataType.BINARY);
+				CoerceExpression e = new CoerceExpression(v, PBinary.INSTANCE);
 				ImmutableBytesWritable ptr = new ImmutableBytesWritable();
 				e.evaluate(null, ptr);
 				Object obj = e.getDataType().toObject(ptr);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
index d63fc0e..b91d8ca 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/ColumnExpressionTest.java
@@ -25,10 +25,12 @@ import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnImpl;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PNameFactory;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.junit.Test;
 
@@ -38,7 +40,7 @@ public class ColumnExpressionTest {
     public void testSerialization() throws Exception {
         int maxLen = 30;
         int scale = 5;
-        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDataType.DECIMAL, maxLen, scale,
+        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, maxLen, scale,
                 true, 20, SortOrder.getDefault(), 0, null, false);
         ColumnExpression colExp = new KeyValueColumnExpression(column);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -52,13 +54,13 @@ public class ColumnExpressionTest {
         colExp2.readFields(dIn);
         assertEquals(maxLen, colExp2.getMaxLength().intValue());
         assertEquals(scale, colExp2.getScale().intValue());
-        assertEquals(PDataType.DECIMAL, colExp2.getDataType());
+        assertEquals(PDecimal.INSTANCE, colExp2.getDataType());
     }
 
     @Test
     public void testSerializationWithNullScale() throws Exception {
         int maxLen = 30;
-        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDataType.BINARY, maxLen, null,
+        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PBinary.INSTANCE, maxLen, null,
                 true, 20, SortOrder.getDefault(), 0, null, false);
         ColumnExpression colExp = new KeyValueColumnExpression(column);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -72,13 +74,13 @@ public class ColumnExpressionTest {
         colExp2.readFields(dIn);
         assertEquals(maxLen, colExp2.getMaxLength().intValue());
         assertNull(colExp2.getScale());
-        assertEquals(PDataType.BINARY, colExp2.getDataType());
+        assertEquals(PBinary.INSTANCE, colExp2.getDataType());
     }
 
     @Test
     public void testSerializationWithNullMaxLength() throws Exception {
         int scale = 5;
-        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDataType.VARCHAR, null, scale,
+        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PVarchar.INSTANCE, null, scale,
                 true, 20, SortOrder.getDefault(), 0, null, false);
         ColumnExpression colExp = new KeyValueColumnExpression(column);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -92,12 +94,12 @@ public class ColumnExpressionTest {
         colExp2.readFields(dIn);
         assertNull(colExp2.getMaxLength());
         assertEquals(scale, colExp2.getScale().intValue());
-        assertEquals(PDataType.VARCHAR, colExp2.getDataType());
+        assertEquals(PVarchar.INSTANCE, colExp2.getDataType());
     }
 
     @Test
     public void testSerializationWithNullScaleAndMaxLength() throws Exception {
-        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDataType.DECIMAL, null, null, true,
+        PColumn column = new PColumnImpl(PNameFactory.newName("c1"), PNameFactory.newName("f1"), PDecimal.INSTANCE, null, null, true,
                 20, SortOrder.getDefault(), 0, null, false);
         ColumnExpression colExp = new KeyValueColumnExpression(column);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();


[14/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDateColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDateColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDateColumn.java
index 90cc520..339c9b4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDateColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDateColumn.java
@@ -17,9 +17,12 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+
 abstract public class PDateColumn extends PBaseColumn {
     @Override
     public PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
index 792ba92..915473a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDatum.java
@@ -17,6 +17,7 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
 
 public interface PDatum {
     /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIndexState.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PIndexState.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIndexState.java
index e41c11f..cf9db4c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PIndexState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIndexState.java
@@ -17,6 +17,7 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PVarchar;
 
 public enum PIndexState {
     BUILDING("b"),
@@ -33,8 +34,8 @@ public enum PIndexState {
 
     private PIndexState(String value) {
         this.serializedValue = value;
-        this.serializedBytes = PDataType.VARCHAR.toBytes(value);
-        this.nameBytesValue = PDataType.VARCHAR.toBytes(this.toString());
+        this.serializedBytes = PVarchar.INSTANCE.toBytes(value);
+        this.nameBytesValue = PVarchar.INSTANCE.toBytes(this.toString());
     }
 
     public String getSerializedValue() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIntegerColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PIntegerColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIntegerColumn.java
index c854d2f..7a8ab2f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PIntegerColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PIntegerColumn.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
 
 /**
  * 
@@ -28,6 +30,6 @@ package org.apache.phoenix.schema;
 public abstract class PIntegerColumn extends PBaseColumn {
     @Override
     public final PDataType getDataType() {
-        return PDataType.INTEGER;
+        return PInteger.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PLongColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PLongColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PLongColumn.java
index 1129e04..ff3578f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PLongColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PLongColumn.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 
 /**
  * 
@@ -28,6 +30,6 @@ package org.apache.phoenix.schema;
 public abstract class PLongColumn extends PBaseColumn {
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PStringColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PStringColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PStringColumn.java
index dc8e590..8901aa2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PStringColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PStringColumn.java
@@ -17,9 +17,12 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
+
 /**
  * 
- * Abstract class for columns of type {@link org.apache.phoenix.schema.PDataType#VARCHAR}
+ * Abstract class for columns of type {@link org.apache.phoenix.schema.types.PVarchar}
  *
  * 
  * @since 0.1
@@ -28,7 +31,7 @@ public abstract class PStringColumn extends PBaseColumn {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index a877175..06f3a9c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -50,6 +50,8 @@ import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.stats.GuidePostsInfo;
 import org.apache.phoenix.schema.stats.PTableStats;
 import org.apache.phoenix.schema.stats.PTableStatsImpl;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.SizedUtil;
@@ -661,7 +663,7 @@ public class PTableImpl implements PTable {
                         .getFamilyName().getBytesPtr(), column.getName().getBytesPtr(), ts));
             } else {
                 ImmutableBytesWritable ptr = new ImmutableBytesWritable(byteValue);
-            	Integer	maxLength = column.getMaxLength();
+              Integer	maxLength = column.getMaxLength();
             	if (type.isFixedWidth() && maxLength != null) {
     				if (ptr.getLength() <= maxLength) {
                         type.pad(ptr, maxLength);
@@ -908,7 +910,7 @@ public class PTableImpl implements PTable {
       if (tableType == PTableType.VIEW) {
         viewType = ViewType.fromSerializedValue(table.getViewType().toByteArray()[0]);
         if(table.hasViewStatement()){
-          viewStatement = (String)PDataType.VARCHAR.toObject(table.getViewStatement().toByteArray());
+          viewStatement = (String) PVarchar.INSTANCE.toObject(table.getViewStatement().toByteArray());
         }
       }
       if (tableType == PTableType.VIEW || viewIndexId != null) {
@@ -996,7 +998,7 @@ public class PTableImpl implements PTable {
       builder.setMultiTenant(table.isMultiTenant());
       if(table.getType() == PTableType.VIEW){
         builder.setViewType(HBaseZeroCopyByteString.wrap(new byte[]{table.getViewType().getSerializedValue()}));
-        builder.setViewStatement(HBaseZeroCopyByteString.wrap(PDataType.VARCHAR.toBytes(table.getViewStatement())));
+        builder.setViewStatement(HBaseZeroCopyByteString.wrap(PVarchar.INSTANCE.toBytes(table.getViewStatement())));
       }
       if(table.getType() == PTableType.VIEW || table.getViewIndexId() != null){
         for (int i = 0; i < table.getPhysicalNames().size(); i++) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java
deleted file mode 100644
index 59d0aff..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java
+++ /dev/null
@@ -1,551 +0,0 @@
-/*
- * 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.schema;
-
-import java.sql.Array;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Map;
-
-import org.apache.phoenix.util.SQLCloseable;
-
-/**
- * java.sql.Array implementation for Phoenix
- */
-public class PhoenixArray implements Array,SQLCloseable {
-	PDataType baseType;
-	Object array;
-	int numElements;
-	Integer maxLength;
-	public PhoenixArray() {
-		// empty constructor
-	}
-	
-	public Integer getMaxLength() {
-	    return maxLength;
-	}
-
-    public boolean isPrimitiveType() {
-        return this.baseType.getCodec() != null;
-    }
-
-	private static Object[] coerceToNewLength(PDataType baseType, Object[] elements, int maxLength) {
-        Object[] resizedElements = new Object[elements.length];
-        for (int i = 0; i < elements.length; i++) {
-            int length = baseType.getMaxLength(elements[i]);
-            if (length == maxLength) {
-                resizedElements[i] = elements[i];
-            } else {
-                resizedElements[i] = baseType.pad(elements[i],maxLength);
-            }
-        }
-        return resizedElements;
-	}
-	private static Object[] coerceToEqualLength(PDataType baseType, Object[] elements) {
-	    if (elements == null || elements.length == 0) {
-	        return elements;
-	    }
-	    Object element = elements[0];
-	    int maxLength = baseType.getMaxLength(element);
-	    boolean resizeElements = false;
-	    for (int i = 1; i < elements.length; i++) {
-	        int length = baseType.getMaxLength(elements[i]);
-	        if (length > maxLength) {
-	            maxLength = length;
-	            resizeElements = true;
-	        } else if (length < maxLength) {
-	            resizeElements = true;
-	        }
-	    }
-	    if (!resizeElements) {
-	        return elements;
-	    }
-	    return coerceToNewLength(baseType, elements, maxLength);
-	}
-	
-	public PhoenixArray(PDataType baseType, Object[] elements) {
-		// As we are dealing with primitive types and only the Boxed objects
-		this.baseType = baseType;
-		if (baseType.isFixedWidth()) {
-		    if (baseType.getByteSize() == null) {
-    		    elements = coerceToEqualLength(baseType, elements);
-    		    if (elements != null && elements.length > 0) {
-    		        this.maxLength = baseType.getMaxLength(elements[0]);
-    		    }
-		    } else {
-		        maxLength = baseType.getByteSize();
-		    }
-		}
-        this.array = convertObjectArrayToPrimitiveArray(elements);
-		this.numElements = elements.length;
-	}
-	
-	public PhoenixArray(PhoenixArray pArr, Integer desiredMaxLength) {
-	    this.baseType = pArr.baseType;
-	    Object[] elements = (Object[])pArr.array;
-        if (baseType.isFixedWidth()) {
-            if (baseType.getByteSize() == null) {
-                elements = coerceToNewLength(baseType, (Object[])pArr.array, desiredMaxLength);
-                maxLength = desiredMaxLength;
-            } else {
-                maxLength = baseType.getByteSize();
-            }
-        }
-        this.array = convertObjectArrayToPrimitiveArray(elements);
-        this.numElements = elements.length;
-    }
-
-    public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-	    return elements; 
-	}
-	
-	@Override
-	public void free() throws SQLException {
-	}
-
-	@Override
-	public Object getArray() throws SQLException {
-		return array;
-	}
-	
-	@Override
-	public void close() throws SQLException {
-		this.array = null;
-	}
-
-	@Override
-	public Object getArray(Map<String, Class<?>> map) throws SQLException {
-		throw new UnsupportedOperationException("Currently not supported");
-	}
-
-	@Override
-	public Object getArray(long index, int count) throws SQLException {
-		if(index < 1) {
-			throw new IllegalArgumentException("Index cannot be less than 1");
-		}
-		// Get the set of elements from the given index to the specified count
-		Object[] intArr = (Object[]) array;
-		boundaryCheck(index, count, intArr);
-		Object[] newArr = new Object[count];
-		// Add checks() here.
-		int i = 0;
-		for (int j = (int) index; j < count; j++) {
-			newArr[i] = intArr[j];
-			i++;
-		}
-		return newArr;
-	}
-
-	private void boundaryCheck(long index, int count, Object[] arr) {
-		if ((--index) + count > arr.length) {
-			throw new IllegalArgumentException("The array index is out of range of the total number of elements in the array " + arr.length);
-		}
-	}
-
-	@Override
-	public Object getArray(long index, int count, Map<String, Class<?>> map)
-			throws SQLException {
-		if(map != null && !map.isEmpty()) {
-			throw new UnsupportedOperationException("Currently not supported");
-		}
-		return null;
-	}
-
-	@Override
-	public int getBaseType() throws SQLException {
-		return baseType.getSqlType();
-	}
-
-	@Override
-	public String getBaseTypeName() throws SQLException {
-		return baseType.getSqlTypeName();
-	}
-
-	@Override
-	public ResultSet getResultSet() throws SQLException {
-		throw new UnsupportedOperationException("Currently not supported");
-	}
-
-	@Override
-	public ResultSet getResultSet(Map<String, Class<?>> arg0)
-			throws SQLException {
-		throw new UnsupportedOperationException("Currently not supported");
-	}
-
-	@Override
-	public ResultSet getResultSet(long arg0, int arg1) throws SQLException {
-		throw new UnsupportedOperationException("Currently not supported");
-	}
-
-	@Override
-	public ResultSet getResultSet(long arg0, int arg1,
-			Map<String, Class<?>> arg2) throws SQLException {
-		throw new UnsupportedOperationException("Currently not supported");
-	}
-
-	public int getDimensions() {
-		return this.numElements;
-	}
-	
-	public int estimateByteSize(int pos) {
-	    if(((Object[])array)[pos] == null) {
-	        return 0;
-	    }
-		return this.baseType.estimateByteSize(((Object[])array)[pos]);
-	}
-	
-	public Integer getMaxLength(int pos) {
-	    return this.baseType.getMaxLength(((Object[])array)[pos]);
-	}
-	
-	public byte[] toBytes(int pos) {
-		return this.baseType.toBytes(((Object[])array)[pos]);
-	}
-	
-	public boolean isNull(int pos) {
-	    if(this.baseType.toBytes(((Object[])array)[pos]).length == 0) {
-	        return true;
-	    } else {
-	        return false;
-	    }
-	}
-	
-	@Override
-	public boolean equals(Object obj) {
-		if (this.numElements != ((PhoenixArray) obj).numElements) {
-			return false;
-		}
-		if (this.baseType != ((PhoenixArray) obj).baseType) {
-			return false;
-		}
-		return Arrays.deepEquals((Object[]) this.array,
-				(Object[]) ((PhoenixArray) obj).array);
-	}
-
-	@Override
-	public int hashCode() {
-		// TODO : Revisit
-		final int prime = 31;
-		int result = 1;
-		result = prime * result
-				+ ((array == null) ? 0 : array.hashCode());
-		return result;
-	}
-	
-	public static class PrimitiveIntPhoenixArray extends PhoenixArray {
-		private int[] intArr;
-		public PrimitiveIntPhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(int.class,
-					elements.length);
-			intArr = (int[]) object;
-			int i = 0;
-			for(Object o : elements) {
-			    if (o != null) {
-			        intArr[i] = (Integer)o;
-			    }
-			    i++;
-			}
-			return intArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(intArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(intArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((int[]) this.array,
-					(int[]) ((PhoenixArray) obj).array);
-		}
-	}
-	
-	public static class PrimitiveShortPhoenixArray extends PhoenixArray {
-		private short[] shortArr;
-		public PrimitiveShortPhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(short.class,
-					elements.length);
-			shortArr = (short[]) object;
-			int i = 0;
-            for(Object o : elements) {
-                if (o != null) {
-                    shortArr[i] = (Short)o;
-                }
-                i++;
-            }
-			return shortArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(shortArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(shortArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((short[]) this.array,
-					(short[]) ((PhoenixArray) obj).array);
-		}
-	}
-	
-	public static class PrimitiveLongPhoenixArray extends PhoenixArray {
-		private long[] longArr;
-		public PrimitiveLongPhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(long.class,
-					elements.length);
-			longArr = (long[]) object;
-			int i = 0;
-            for(Object o : elements) {
-                if (o != null) {
-                    longArr[i] = (Long)o;
-                }
-                i++;
-            }
-			return longArr;
-		}
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(longArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(longArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((long[]) this.array,
-					(long[]) ((PhoenixArray) obj).array);
-		}
-
-	}
-	
-	public static class PrimitiveDoublePhoenixArray extends PhoenixArray {
-		private double[] doubleArr;
-		public PrimitiveDoublePhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(double.class,
-					elements.length);
-			doubleArr = (double[]) object;
-			int i = 0;
-			for (Object o : elements) {
-			    if (o != null) {
-			        doubleArr[i] = (Double) o;
-			    }
-			    i++;
-			}
-			return doubleArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(doubleArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(doubleArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((double[]) this.array,
-					(double[]) ((PhoenixArray) obj).array);
-		}
-	}
-	
-	public static class PrimitiveFloatPhoenixArray extends PhoenixArray {
-		private float[] floatArr;
-		public PrimitiveFloatPhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(float.class,
-					elements.length);
-			floatArr = (float[]) object;
-			int i = 0;
-            for(Object o : elements) {
-                if (o != null) {
-                    floatArr[i] = (Float)o;
-                }
-                i++;
-            }
-			return floatArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(floatArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(floatArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((float[]) this.array,
-					(float[]) ((PhoenixArray) obj).array);
-		}
-	}
-	
-	public static class PrimitiveBytePhoenixArray extends PhoenixArray {
-		private byte[] byteArr;
-		public PrimitiveBytePhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(byte.class,
-					elements.length);
-			byteArr = (byte[]) object;
-			int i = 0;
-            for(Object o : elements) {
-                if (o != null) {
-                    byteArr[i] = (Byte)o;
-                }
-                i++;
-            }
-			return byteArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(byteArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(byteArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((byte[]) this.array,
-					(byte[]) ((PhoenixArray) obj).array);
-		}
-	}
-	
-	public static class PrimitiveBooleanPhoenixArray extends PhoenixArray {
-		private boolean[] booleanArr;
-		public PrimitiveBooleanPhoenixArray(PDataType dataType, Object[] elements) {
-			super(dataType, elements);
-		}
-		@Override
-		public Object convertObjectArrayToPrimitiveArray(Object[] elements) {
-			Object object = java.lang.reflect.Array.newInstance(boolean.class,
-					elements.length);
-			booleanArr = (boolean[]) object;
-			int i = 0;
-            for(Object o : elements) {
-                if (o != null) {
-                    booleanArr[i] = (Boolean)o;
-                }
-                i++;
-            }
-			return booleanArr;
-		}
-		
-		@Override
-        public int estimateByteSize(int pos) {
-			return this.baseType.estimateByteSize(booleanArr[pos]);
-		}
-		
-		@Override
-        public byte[] toBytes(int pos) {
-			return this.baseType.toBytes(booleanArr[pos]);
-		}
-		
-		@Override
-		public boolean equals(Object obj) {
-			if (this.numElements != ((PhoenixArray) obj).numElements) {
-				return false;
-			}
-			if (this.baseType != ((PhoenixArray) obj).baseType) {
-				return false;
-			}
-			return Arrays.equals((boolean[]) this.array,
-					(boolean[]) ((PhoenixArray) obj).array);
-		}
-	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeySchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeySchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeySchema.java
index 510d11b..7c36e41 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeySchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeySchema.java
@@ -167,7 +167,7 @@ public class RowKeySchema extends ValueSchema {
      * set, and null if the value is null and there are no more values
      */
     public Boolean next(ImmutableBytesWritable ptr, int position, int maxOffset, int extraSpan) {
-        Boolean returnValue = next(ptr, position, maxOffset);
+      Boolean returnValue = next(ptr, position, maxOffset);
         readExtraFields(ptr, position + 1, maxOffset, extraSpan);
         return returnValue;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
index 527f4a6..91e4f36 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/SaltingUtil.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
+import org.apache.phoenix.schema.types.PBinary;
 import org.apache.phoenix.util.SchemaUtil;
 
 import com.google.common.collect.Lists;
@@ -37,7 +38,7 @@ public class SaltingUtil {
     public static final String SALTING_COLUMN_NAME = "_SALT";
     public static final String SALTED_ROW_KEY_NAME = "_SALTED_KEY";
     public static final PColumnImpl SALTING_COLUMN = new PColumnImpl(
-            PNameFactory.newName(SALTING_COLUMN_NAME), null, PDataType.BINARY, 1, 0, false, 0, SortOrder.getDefault(), 0, null, false);
+            PNameFactory.newName(SALTING_COLUMN_NAME), null, PBinary.INSTANCE, 1, 0, false, 0, SortOrder.getDefault(), 0, null, false);
     public static final RowKeySchema VAR_BINARY_SALTED_SCHEMA = new RowKeySchemaBuilder(2)
         .addField(SALTING_COLUMN, false, SortOrder.getDefault())
         .addField(SchemaUtil.VAR_BINARY_DATUM, false, SortOrder.getDefault()).build();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
index 21445e7..aeba58b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/Sequence.java
@@ -48,6 +48,10 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.KeyValueUtil;
 import org.apache.phoenix.util.SequenceUtil;
@@ -219,10 +223,10 @@ public class Sequence {
         Append append = new Append(key);
         byte[] opBuf = new byte[] {(byte)MetaOp.RETURN_SEQUENCE.ordinal()};
         append.setAttribute(SequenceRegionObserver.OPERATION_ATTRIB, opBuf);
-        append.setAttribute(SequenceRegionObserver.CURRENT_VALUE_ATTRIB, PDataType.LONG.toBytes(value.nextValue));
+        append.setAttribute(SequenceRegionObserver.CURRENT_VALUE_ATTRIB, PLong.INSTANCE.toBytes(value.nextValue));
         Map<byte[], List<Cell>> familyMap = append.getFamilyCellMap();
         familyMap.put(PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, Arrays.<Cell>asList(
-        		(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CURRENT_VALUE_BYTES, value.timestamp, PDataType.LONG.toBytes(value.currentValue)),
+        		(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CURRENT_VALUE_BYTES, value.timestamp, PLong.INSTANCE.toBytes(value.currentValue)),
         		// set LIMIT_REACHED flag to false since we are returning unused sequence values
         		(Cell)KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG_BYTES, value.timestamp, PDataType.FALSE_BYTES)
                 ));
@@ -253,7 +257,7 @@ public class Sequence {
         // before a next val was. Not sure how to prevent that.
         if (result.rawCells().length == 1) {
             Cell errorKV = result.rawCells()[0];
-            int errorCode = PDataType.INTEGER.getCodec().decodeInt(errorKV.getValueArray(), errorKV.getValueOffset(), SortOrder.getDefault());
+            int errorCode = PInteger.INSTANCE.getCodec().decodeInt(errorKV.getValueArray(), errorKV.getValueOffset(), SortOrder.getDefault());
             SQLExceptionCode code = SQLExceptionCode.fromErrorCode(errorCode);
             // TODO: We could have the server return the timestamps of the
             // delete markers and we could insert them here, but this seems
@@ -417,12 +421,12 @@ public class Sequence {
             KeyValue maxValueKV = getMaxValueKV(r);
             KeyValue cycleKV = getCycleKV(r);
             this.timestamp = currentValueKV.getTimestamp();
-            this.nextValue = PDataType.LONG.getCodec().decodeLong(currentValueKV.getValueArray(), currentValueKV.getValueOffset(), SortOrder.getDefault());
-            this.incrementBy = PDataType.LONG.getCodec().decodeLong(incrementByKV.getValueArray(), incrementByKV.getValueOffset(), SortOrder.getDefault());
-            this.cacheSize = PDataType.LONG.getCodec().decodeLong(cacheSizeKV.getValueArray(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
-            this.minValue = PDataType.LONG.getCodec().decodeLong(minValueKV.getValueArray(), minValueKV.getValueOffset(), SortOrder.getDefault());
-            this.maxValue = PDataType.LONG.getCodec().decodeLong(maxValueKV.getValueArray(), maxValueKV.getValueOffset(), SortOrder.getDefault());
-            this.cycle = (Boolean)PDataType.BOOLEAN.toObject(cycleKV.getValueArray(), cycleKV.getValueOffset(), cycleKV.getValueLength());
+            this.nextValue = PLong.INSTANCE.getCodec().decodeLong(currentValueKV.getValueArray(), currentValueKV.getValueOffset(), SortOrder.getDefault());
+            this.incrementBy = PLong.INSTANCE.getCodec().decodeLong(incrementByKV.getValueArray(), incrementByKV.getValueOffset(), SortOrder.getDefault());
+            this.cacheSize = PLong.INSTANCE.getCodec().decodeLong(cacheSizeKV.getValueArray(), cacheSizeKV.getValueOffset(), SortOrder.getDefault());
+            this.minValue = PLong.INSTANCE.getCodec().decodeLong(minValueKV.getValueArray(), minValueKV.getValueOffset(), SortOrder.getDefault());
+            this.maxValue = PLong.INSTANCE.getCodec().decodeLong(maxValueKV.getValueArray(), maxValueKV.getValueOffset(), SortOrder.getDefault());
+            this.cycle = (Boolean) PBoolean.INSTANCE.toObject(cycleKV.getValueArray(), cycleKV.getValueOffset(), cycleKV.getValueLength());
             this.limitReached = false;
             currentValue = nextValue;
             if (op != ValueOp.VALIDATE_SEQUENCE) {
@@ -437,7 +441,7 @@ public class Sequence {
             return false;
         }
         long timestamp = statusKV.getTimestamp();
-        int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
+        int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
         if (statusCode == SUCCESS) {  // Success - update nextValue down to currentValue
             SequenceValue value = findSequenceValue(timestamp);
             if (value == null) {
@@ -465,16 +469,16 @@ public class Sequence {
             append.setAttribute(SequenceRegionObserver.MAX_TIMERANGE_ATTRIB, Bytes.toBytes(timestamp));
         }
         Map<byte[], List<Cell>> familyMap = append.getFamilyCellMap();
-        byte[] startWithBuf = PDataType.LONG.toBytes(startWith);
+        byte[] startWithBuf = PLong.INSTANCE.toBytes(startWith);
         familyMap.put(PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, Arrays.<Cell>asList(
                 KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, timestamp, ByteUtil.EMPTY_BYTE_ARRAY),
                 KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CURRENT_VALUE_BYTES, timestamp, startWithBuf),
                 KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.START_WITH_BYTES, timestamp, startWithBuf),
-                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.INCREMENT_BY_BYTES, timestamp, PDataType.LONG.toBytes(incrementBy)),
-                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CACHE_SIZE_BYTES, timestamp, PDataType.LONG.toBytes(cacheSize)),
-                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.MIN_VALUE_BYTES, timestamp, PDataType.LONG.toBytes(minValue)),
-                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.MAX_VALUE_BYTES, timestamp, PDataType.LONG.toBytes(maxValue)),
-                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CYCLE_FLAG_BYTES, timestamp, PDataType.BOOLEAN.toBytes(cycle)),
+                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.INCREMENT_BY_BYTES, timestamp, PLong.INSTANCE.toBytes(incrementBy)),
+                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CACHE_SIZE_BYTES, timestamp, PLong.INSTANCE.toBytes(cacheSize)),
+                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.MIN_VALUE_BYTES, timestamp, PLong.INSTANCE.toBytes(minValue)),
+                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.MAX_VALUE_BYTES, timestamp, PLong.INSTANCE.toBytes(maxValue)),
+                KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.CYCLE_FLAG_BYTES, timestamp, PBoolean.INSTANCE.toBytes(cycle)),
                 KeyValueUtil.newKeyValue(key, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, PhoenixDatabaseMetaData.LIMIT_REACHED_FLAG_BYTES, timestamp, PDataType.FALSE_BYTES)
                 ));
         return append;
@@ -483,7 +487,7 @@ public class Sequence {
     public long createSequence(Result result, long minValue, long maxValue, boolean cycle) throws SQLException {
         Cell statusKV = result.rawCells()[0];
         long timestamp = statusKV.getTimestamp();
-        int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
+        int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
         if (statusCode == 0) {  // Success - add sequence value and return timestamp
             SequenceValue value = new SequenceValue(timestamp, minValue, maxValue, cycle);
             insertSequenceValue(value);
@@ -512,7 +516,7 @@ public class Sequence {
     public long dropSequence(Result result) throws SQLException {
         Cell statusKV = result.rawCells()[0];
         long timestamp = statusKV.getTimestamp();
-        int statusCode = PDataType.INTEGER.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
+        int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
         SQLExceptionCode code = statusCode == 0 ? null : SQLExceptionCode.fromErrorCode(statusCode);
         if (code == null) {
             // Insert delete marker so that point-in-time sequences work

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/TypeMismatchException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/TypeMismatchException.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/TypeMismatchException.java
index 7f00267..0cd15b0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/TypeMismatchException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/TypeMismatchException.java
@@ -21,6 +21,7 @@ import java.sql.SQLException;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * Exception thrown when we try to convert one type into a different incompatible type.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
index 12e30ab..7660ffe 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
@@ -26,6 +26,7 @@ import java.util.List;
 
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.SizedUtil;
 
 import com.google.common.base.Preconditions;
@@ -34,7 +35,7 @@ import com.google.common.collect.Lists;
 
 /**
  * 
- * Simple flat schema over a byte array where fields may be any of {@link PDataType}.
+ * Simple flat schema over a byte array where fields may be any of {@link org.apache.phoenix.schema.types.PDataType}.
  * Optimized for positional access by index.
  *
  * 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsWriter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsWriter.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsWriter.java
index 9b6efc9..bb624f8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsWriter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsWriter.java
@@ -43,7 +43,9 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.ServerUtil;
@@ -58,11 +60,6 @@ public class StatisticsWriter implements Closeable {
     /**
      * @param tableName TODO
      * @param clientTimeStamp TODO
-     * @param guidepostDepth 
-     * @param Configuration
-     *            Configruation to update the stats table.
-     * @param primaryTableName
-     *            name of the primary table on which we should collect stats
      * @return the {@link StatisticsWriter} for the given primary table.
      * @throws IOException
      *             if the table cannot be created due to an underlying HTable creation error
@@ -124,7 +121,7 @@ public class StatisticsWriter implements Closeable {
 	        	long byteSize = 0;
 	        	Cell byteSizeCell = result.getColumnLatestCell(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
 	        	if (byteSizeCell != null) {
-	        		byteSize = PDataType.LONG.getCodec().decodeLong(byteSizeCell.getValueArray(), byteSizeCell.getValueOffset(), SortOrder.getDefault()) / 2;
+	        		byteSize = PLong.INSTANCE.getCodec().decodeLong(byteSizeCell.getValueArray(), byteSizeCell.getValueOffset(), SortOrder.getDefault()) / 2;
 	        	}
 	        	int midEndIndex, midStartIndex;
 	            int index = Collections.binarySearch(guidePosts.getGuidePosts(), r.getStartKey(), Bytes.BYTES_COMPARATOR);
@@ -159,10 +156,6 @@ public class StatisticsWriter implements Closeable {
      * @param tracker - the statistics tracker
      * @param cfKey -  the family for which the stats is getting collected.
      * @param mutations - list of mutations that collects all the mutations to commit in a batch
-     * @param tablekey - The table name
-     * @param schemaName - the schema name associated with the table          
-     * @param region name -  the region of the table for which the stats are collected
-     * @param split - if the updation is caused due to a split
      * @throws IOException
      *             if we fail to do any of the puts. Any single failure will prevent any future attempts for the remaining list of stats to
      *             update
@@ -180,11 +173,11 @@ public class StatisticsWriter implements Closeable {
         GuidePostsInfo gp = tracker.getGuidePosts(cfKey);
         if (gp != null) {
             put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_COUNT_BYTES,
-                    timeStamp, PDataType.LONG.toBytes((gp.getGuidePosts().size())));
+                    timeStamp, PLong.INSTANCE.toBytes((gp.getGuidePosts().size())));
             put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_BYTES,
-                    timeStamp, PDataType.VARBINARY.toBytes(gp.toBytes()));
+                    timeStamp, PVarbinary.INSTANCE.toBytes(gp.toBytes()));
             put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES,
-                    timeStamp, PDataType.LONG.toBytes(gp.getByteCount()));
+                    timeStamp, PLong.INSTANCE.toBytes(gp.getByteCount()));
         }
         // Add our empty column value so queries behave correctly
         put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES,
@@ -225,8 +218,9 @@ public class StatisticsWriter implements Closeable {
         long currentTime = TimeKeeper.SYSTEM.getCurrentTime();
         byte[] prefix = tableName;
         Put put = new Put(prefix);
-        put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.LAST_STATS_UPDATE_TIME_BYTES, timeStamp,
-                PDataType.DATE.toBytes(new Date(currentTime)));
+        put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES,
+            PhoenixDatabaseMetaData.LAST_STATS_UPDATE_TIME_BYTES, timeStamp,
+            PDate.INSTANCE.toBytes(new Date(currentTime)));
         return put;
     }
 
@@ -243,4 +237,4 @@ public class StatisticsWriter implements Closeable {
         byte[] prefix = StatisticsUtil.getRowKey(tableName, fam, regionName);
         mutations.add(new Delete(prefix, timeStamp - 1));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
new file mode 100644
index 0000000..47cc7d6
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PArrayDataType.java
@@ -0,0 +1,656 @@
+/*
+ * 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.schema.types;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.ConstraintViolationException;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.schema.ValueSchema;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.TrustedByteArrayOutputStream;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+/**
+ * The datatype for PColummns that are Arrays. Any variable length array would follow the below order. 
+ * Every element would be seperated by a seperator byte '0'. Null elements are counted and once a first 
+ * non null element appears we write the count of the nulls prefixed with a seperator byte.
+ * Trailing nulls are not taken into account. The last non null element is followed by two seperator bytes. 
+ * For eg a, b, null, null, c, null -> 65 0 66 0 0 2 67 0 0 0 
+ * a null null null b c null d -> 65 0 0 3 66 0 67 0 0 1 68 0 0 0.
+ * The reason we use this serialization format is to allow the
+ * byte array of arrays of the same type to be directly comparable against each other. 
+ * This prevents a costly deserialization on compare and allows an array column to be used as the last column in a primary key constraint.
+ */
+public abstract class PArrayDataType<T> extends PDataType<T> {
+
+    public static final byte ARRAY_SERIALIZATION_VERSION = 1;
+
+  protected PArrayDataType(String sqlTypeName, int sqlType, Class clazz, PDataCodec codec, int ordinal) {
+    super(sqlTypeName, sqlType, clazz, codec, ordinal);
+  }
+
+  public byte[] toBytes(Object object, PDataType baseType, SortOrder sortOrder) {
+		if(object == null) {
+			throw new ConstraintViolationException(this + " may not be null");
+		}
+		PhoenixArray arr = ((PhoenixArray)object);
+        int noOfElements = arr.numElements;
+        if(noOfElements == 0) {
+        	return ByteUtil.EMPTY_BYTE_ARRAY;
+        }
+        TrustedByteArrayOutputStream byteStream = null;
+		if (!baseType.isFixedWidth()) {
+	        Pair<Integer, Integer> nullsVsNullRepeationCounter = new Pair<>();
+	        int size = estimateByteSize(object, nullsVsNullRepeationCounter,
+	                PDataType.fromTypeId((baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE)));
+		    size += ((2 * Bytes.SIZEOF_BYTE) + (noOfElements - nullsVsNullRepeationCounter.getFirst()) * Bytes.SIZEOF_BYTE)
+		                                + (nullsVsNullRepeationCounter.getSecond() * 2 * Bytes.SIZEOF_BYTE);
+		    // Assume an offset array that fit into Short.MAX_VALUE.  Also not considering nulls that could be > 255
+		    // In both of these cases, finally an array copy would happen
+		    int capacity = noOfElements * Bytes.SIZEOF_SHORT;
+		    // Here the int for noofelements, byte for the version, int for the offsetarray position and 2 bytes for the end seperator
+            byteStream = new TrustedByteArrayOutputStream(size + capacity + Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE +  Bytes.SIZEOF_INT);
+		} else {
+		    int size = arr.getMaxLength() * noOfElements;
+		    // Here the int for noofelements, byte for the version
+		    byteStream = new TrustedByteArrayOutputStream(size);
+		}
+		DataOutputStream oStream = new DataOutputStream(byteStream);
+		// Handles bit inversion also
+		return createArrayBytes(byteStream, oStream, (PhoenixArray)object, noOfElements, baseType, sortOrder);
+	}
+	
+    public static int serializeNulls(DataOutputStream oStream, int nulls) throws IOException {
+        // We need to handle 3 different cases here
+        // 1) Arrays with repeating nulls in the middle which is less than 255
+        // 2) Arrays with repeating nulls in the middle which is less than 255 but greater than bytes.MAX_VALUE
+        // 3) Arrays with repeating nulls in the middle greaterh than 255
+        // Take a case where we have two arrays that has the following elements
+        // Array 1 - size : 240, elements = abc, bcd, null, null, bcd,null,null......,null, abc
+        // Array 2 - size : 16 : elements = abc, bcd, null, null, bcd, null, null...null, abc
+        // In both case the elements and the value array will be the same but the Array 1 is actually smaller because it has more nulls.
+        // Now we should have mechanism to show that we treat arrays with more nulls as lesser.  Hence in the above case as 
+        // 240 > Bytes.MAX_VALUE, by always inverting the number of nulls we would get a +ve value
+        // For Array 2, by inverting we would get a -ve value.  On comparison Array 2 > Array 1.
+        // Now for cases where the number of nulls is greater than 255, we would write an those many (byte)1, it is bigger than 255.
+        // This would ensure that we don't compare with triple zero which is used as an end  byte
+        if (nulls > 0) {
+            oStream.write(QueryConstants.SEPARATOR_BYTE);
+            int nMultiplesOver255 = nulls / 255;
+            while (nMultiplesOver255-- > 0) {
+                // Don't write a zero byte, as we need to ensure that the only triple zero
+                // byte occurs at the end of the array (i.e. the terminator byte for the
+                // element plus the double zero byte at the end of the array).
+                oStream.write((byte)1); 
+            }
+            int nRemainingNulls = nulls % 255; // From 0 to 254
+            // Write a byte for the remaining null elements
+            if (nRemainingNulls > 0) {
+                // Remaining null elements is from 1 to 254.
+                // Subtract one and invert so that more remaining nulls becomes smaller than less 
+                // remaining nulls and min byte value is always greater than 1, the repeating value  
+                // used for arrays with more than 255 repeating null elements.
+                // The reason we invert is that  an array with less null elements has a non
+                // null element sooner than an array with more null elements. Thus, the more
+                // null elements you have, the smaller the array becomes.
+                byte nNullByte = SortOrder.invert((byte)(nRemainingNulls-1));
+                oStream.write(nNullByte); // Single byte for repeating nulls
+            }
+        }
+        return 0;
+    }
+ 
+    public static void writeEndSeperatorForVarLengthArray(DataOutputStream oStream) throws IOException {
+        oStream.write(QueryConstants.SEPARATOR_BYTE);
+        oStream.write(QueryConstants.SEPARATOR_BYTE);
+    }
+
+	public static boolean useShortForOffsetArray(int maxOffset) {
+		// If the max offset is less than Short.MAX_VALUE then offset array can use short
+		if (maxOffset <= (2 * Short.MAX_VALUE)) {
+			return true;
+		}
+		// else offset array can use Int
+		return false;
+	}
+
+	public int toBytes(Object object, byte[] bytes, int offset) {
+	    PhoenixArray array = (PhoenixArray)object;
+        if (array == null || array.baseType == null) {
+            return 0;
+        }
+        return estimateByteSize(object, null, PDataType.fromTypeId((array.baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE)));
+	}
+
+	// Estimates the size of the given array and also calculates the number of nulls and its repetition factor
+    public int estimateByteSize(Object o, Pair<Integer, Integer> nullsVsNullRepeationCounter, PDataType baseType) {
+        if (baseType.isFixedWidth()) { return baseType.getByteSize(); }
+        if (baseType.isArrayType()) {
+            PhoenixArray array = (PhoenixArray)o;
+            int noOfElements = array.numElements;
+            int totalVarSize = 0;
+            int nullsRepeationCounter = 0;
+            int nulls = 0;
+            int totalNulls = 0;
+            for (int i = 0; i < noOfElements; i++) {
+                totalVarSize += array.estimateByteSize(i);
+                if (!PDataType.fromTypeId((baseType.getSqlType() - PDataType.ARRAY_TYPE_BASE)).isFixedWidth()) {
+                    if (array.isNull(i)) {
+                        nulls++;
+                    } else {
+                        if (nulls > 0) {
+                            totalNulls += nulls;
+                            nulls = 0;
+                            nullsRepeationCounter++;
+                        }
+                    }
+                }
+            }
+            if (nullsVsNullRepeationCounter != null) {
+                if (nulls > 0) {
+                    totalNulls += nulls;
+                    // do not increment nullsRepeationCounter to identify trailing nulls
+                }
+                nullsVsNullRepeationCounter.setFirst(totalNulls);
+                nullsVsNullRepeationCounter.setSecond(nullsRepeationCounter);
+            }
+            return totalVarSize;
+        }
+        // Non fixed width types must override this
+        throw new UnsupportedOperationException();
+    }
+    
+	public boolean isCoercibleTo(PDataType targetType, Object value) {
+	    return targetType.isCoercibleTo(targetType, value);
+	}
+	
+	public boolean isCoercibleTo(PDataType targetType, PDataType expectedTargetType) {
+		if(!targetType.isArrayType()) {
+			return false;
+		} else {
+			PDataType targetElementType = PDataType.fromTypeId(targetType.getSqlType()
+					- PDataType.ARRAY_TYPE_BASE);
+			PDataType expectedTargetElementType = PDataType.fromTypeId(expectedTargetType
+					.getSqlType() - PDataType.ARRAY_TYPE_BASE);
+			return expectedTargetElementType.isCoercibleTo(targetElementType);
+		}
+    }
+
+  @Override
+	public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value,
+      PDataType srcType, Integer maxLength, Integer scale,
+      Integer desiredMaxLength, Integer desiredScale) {
+    if (value == null) return true;
+		PhoenixArray pArr = (PhoenixArray) value;
+    PDataType baseType = PDataType.fromTypeId(srcType.getSqlType() - PDataType.ARRAY_TYPE_BASE);
+    for (int i = 0 ; i < pArr.numElements; i++) {
+      Object val = pArr.getElement(i);
+      if (!baseType.isSizeCompatible(ptr, val, baseType, srcType.getMaxLength(val),
+          scale, desiredMaxLength, desiredScale)) {
+        return false;
+      }
+		}
+		return true;
+	}
+
+    public void coerceBytes(ImmutableBytesWritable ptr, Object value, PDataType actualType, Integer maxLength,
+        Integer scale, Integer desiredMaxLength, Integer desiredScale, PDataType desiredType,
+            SortOrder actualModifer, SortOrder expectedModifier) {
+        if (ptr.getLength() == 0) { // a zero length ptr means null which will not be coerced to anything different
+            return;
+        }
+        PDataType baseType = PDataType.fromTypeId(actualType.getSqlType() - PDataType.ARRAY_TYPE_BASE);
+        PDataType desiredBaseType = PDataType.fromTypeId(desiredType.getSqlType() - PDataType.ARRAY_TYPE_BASE);
+        if ((Objects.equal(maxLength, desiredMaxLength) || maxLength == null || desiredMaxLength == null)
+                && actualType.isBytesComparableWith(desiredType)
+                && baseType.isFixedWidth() == desiredBaseType.isFixedWidth() && actualModifer == expectedModifier) { 
+            return; 
+        }
+        if (value == null || actualType != desiredType) {
+            value = toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), baseType, actualModifer, maxLength,
+                    desiredScale, desiredBaseType);
+            PhoenixArray pArr = (PhoenixArray)value;
+            // VARCHAR <=> CHAR
+            if(baseType.isFixedWidth() != desiredBaseType.isFixedWidth()) {
+                if (!pArr.isPrimitiveType()) {
+                    pArr = new PhoenixArray(pArr, desiredMaxLength);
+                }
+            }
+            baseType = desiredBaseType;
+            ptr.set(toBytes(pArr, baseType, expectedModifier));
+        } else {
+            PhoenixArray pArr = (PhoenixArray)value;
+            pArr = new PhoenixArray(pArr, desiredMaxLength);
+            ptr.set(toBytes(pArr, baseType, expectedModifier));
+        }
+    }
+
+
+    public Object toObject(String value) {
+		throw new IllegalArgumentException("This operation is not suppported");
+	}
+
+	public Object toObject(byte[] bytes, int offset, int length, PDataType baseType, 
+			SortOrder sortOrder, Integer maxLength, Integer scale, PDataType desiredDataType) {
+		return createPhoenixArray(bytes, offset, length, sortOrder,
+				baseType, maxLength, desiredDataType);
+	}
+
+    public static boolean positionAtArrayElement(Tuple tuple, ImmutableBytesWritable ptr, int index,
+            Expression arrayExpr, PDataType pDataType, Integer maxLen) {
+        if (!arrayExpr.evaluate(tuple, ptr)) {
+            return false;
+        } else if (ptr.getLength() == 0) { return true; }
+
+        // Given a ptr to the entire array, set ptr to point to a particular element within that array
+        // given the type of an array element (see comments in PDataTypeForArray)
+        positionAtArrayElement(ptr, index - 1, pDataType, maxLen);
+        return true;
+    }
+    public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
+        Integer byteSize) {
+        byte[] bytes = ptr.get();
+        int initPos = ptr.getOffset();
+        if (!baseDataType.isFixedWidth()) {
+            int noOfElements = Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)),
+                    Bytes.SIZEOF_INT);
+            boolean useShort = true;
+            if (noOfElements < 0) {
+                noOfElements = -noOfElements;
+                useShort = false;
+            }
+            if (arrayIndex >= noOfElements) {
+                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+                return;
+            }
+
+            int indexOffset = Bytes.toInt(bytes,
+                    (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT))) + ptr.getOffset();
+            if(arrayIndex >= noOfElements) {
+                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+            } else {
+                // Skip those many offsets as given in the arrayIndex
+                // If suppose there are 5 elements in the array and the arrayIndex = 3
+                // This means we need to read the 4th element of the array
+                // So inorder to know the length of the 4th element we will read the offset of 4th element and the
+                // offset of 5th element.
+                // Subtracting the offset of 5th element and 4th element will give the length of 4th element
+                // So we could just skip reading the other elements.
+                int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
+                int elementLength = 0;
+                if (arrayIndex == (noOfElements - 1)) {
+                    elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE ? 0 : indexOffset
+                            - (currOffset + initPos) - 3;
+                } else {
+                    elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE ? 0 : getOffset(bytes,
+                            arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
+                }
+                ptr.set(bytes, currOffset + initPos, elementLength);
+            }
+        } else {
+            int elemByteSize = (byteSize == null ? baseDataType.getByteSize() : byteSize);
+            int offset = arrayIndex * elemByteSize;
+            if (offset >= ptr.getLength()) {
+                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+            } else {
+                ptr.set(bytes, ptr.getOffset() + offset, elemByteSize);
+            }
+        }
+    }
+    
+    public static void positionAtArrayElement(ImmutableBytesWritable ptr, int arrayIndex, PDataType baseDataType,
+        Integer byteSize, int offset, int length, int noOfElements, boolean first) {
+        byte[] bytes = ptr.get();
+        if (!baseDataType.isFixedWidth()) {
+            int indexOffset = Bytes.toInt(bytes, (offset + length - (Bytes.SIZEOF_BYTE + 2 * Bytes.SIZEOF_INT)))
+                    + offset;
+            boolean useShort = true;
+            if (first) {
+                int count = Bytes.toInt(bytes,
+                        (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)), Bytes.SIZEOF_INT);
+                if (count < 0) {
+                    count = -count;
+                    useShort = false;
+                }
+            }
+            if (arrayIndex >= noOfElements) {
+                return;
+            } else {
+                // Skip those many offsets as given in the arrayIndex
+                // If suppose there are 5 elements in the array and the arrayIndex = 3
+                // This means we need to read the 4th element of the array
+                // So inorder to know the length of the 4th element we will read the offset of 4th element and the
+                // offset of 5th element.
+                // Subtracting the offset of 5th element and 4th element will give the length of 4th element
+                // So we could just skip reading the other elements.
+                int currOffset = getOffset(bytes, arrayIndex, useShort, indexOffset);
+                int elementLength = 0;
+                if (arrayIndex == (noOfElements - 1)) {
+                    elementLength = bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE ? 0 : indexOffset
+                            - (currOffset + offset) - 3;
+                } else {
+                    elementLength = bytes[currOffset + offset] == QueryConstants.SEPARATOR_BYTE ? 0 : getOffset(bytes,
+                            arrayIndex + 1, useShort, indexOffset) - currOffset - 1;
+                }
+                ptr.set(bytes, currOffset + offset, elementLength);
+            }
+        } else {
+            int elemByteSize = (byteSize == null ? baseDataType.getByteSize() : byteSize);
+            offset += arrayIndex * elemByteSize;
+            if (offset >= offset + length) {
+                return;
+            } else {
+                ptr.set(bytes, offset, elemByteSize);
+            }
+        }
+    }
+
+    private static int getOffset(byte[] bytes, int arrayIndex, boolean useShort, int indexOffset) {
+        int offset;
+        if (useShort) {
+            offset = indexOffset + (Bytes.SIZEOF_SHORT * arrayIndex);
+            return Bytes.toShort(bytes, offset, Bytes.SIZEOF_SHORT) + Short.MAX_VALUE;
+        } else {
+            offset = indexOffset + (Bytes.SIZEOF_INT * arrayIndex);
+            return Bytes.toInt(bytes, offset, Bytes.SIZEOF_INT);
+        }
+    }
+    
+    private static int getOffset(ByteBuffer indexBuffer, int arrayIndex, boolean useShort, int indexOffset ) {
+        int offset;
+        if(useShort) {
+            offset = indexBuffer.getShort() + Short.MAX_VALUE;
+        } else {
+            offset = indexBuffer.getInt();
+        }
+        return offset;
+    }
+
+	public Object toObject(Object object, PDataType actualType) {
+		return object;
+	}
+
+	public Object toObject(Object object, PDataType actualType, SortOrder sortOrder) {
+		// How to use the sortOrder ? Just reverse the elements
+		return toObject(object, actualType);
+	}
+	
+	/**
+	 * creates array bytes
+	 */
+    private byte[] createArrayBytes(TrustedByteArrayOutputStream byteStream, DataOutputStream oStream,
+            PhoenixArray array, int noOfElements, PDataType baseType, SortOrder sortOrder) {
+        try {
+            if (!baseType.isFixedWidth()) {
+                int[] offsetPos = new int[noOfElements];
+                int nulls = 0;
+                for (int i = 0; i < noOfElements; i++) {
+                    byte[] bytes = array.toBytes(i);
+                    if (bytes.length == 0) {
+                        offsetPos[i] = byteStream.size();
+                        nulls++;
+                    } else {
+                        nulls = serializeNulls(oStream, nulls);
+                        offsetPos[i] = byteStream.size();
+                        if (sortOrder == SortOrder.DESC) {
+                            SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
+                        }
+                        oStream.write(bytes, 0, bytes.length);
+                        oStream.write(QueryConstants.SEPARATOR_BYTE);
+                    }
+                }
+                // Double seperator byte to show end of the non null array
+                PArrayDataType.writeEndSeperatorForVarLengthArray(oStream);
+                noOfElements = PArrayDataType.serailizeOffsetArrayIntoStream(oStream, byteStream, noOfElements,
+                        offsetPos[offsetPos.length - 1], offsetPos);
+                serializeHeaderInfoIntoStream(oStream, noOfElements);
+            } else {
+                for (int i = 0; i < noOfElements; i++) {
+                    byte[] bytes = array.toBytes(i);
+                    int length = bytes.length;
+                    if (sortOrder == SortOrder.DESC) {
+                        SortOrder.invert(bytes, 0, bytes, 0, bytes.length);
+                    }
+                    oStream.write(bytes, 0, length);
+                }
+            }
+            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+            ptr.set(byteStream.getBuffer(), 0, byteStream.size());
+            return ByteUtil.copyKeyBytesIfNecessary(ptr);
+        } catch (IOException e) {
+            try {
+                byteStream.close();
+                oStream.close();
+            } catch (IOException ioe) {
+
+            }
+        }
+        // This should not happen
+        return null;
+    }
+
+    public static int serailizeOffsetArrayIntoStream(DataOutputStream oStream, TrustedByteArrayOutputStream byteStream,
+            int noOfElements, int maxOffset, int[] offsetPos) throws IOException {
+        int offsetPosition = (byteStream.size());
+        byte[] offsetArr = null;
+        boolean useInt = true;
+        if (PArrayDataType.useShortForOffsetArray(maxOffset)) {
+            offsetArr = new byte[PArrayDataType.initOffsetArray(noOfElements, Bytes.SIZEOF_SHORT)];
+            useInt = false;
+        } else {
+            offsetArr = new byte[PArrayDataType.initOffsetArray(noOfElements, Bytes.SIZEOF_INT)];
+            noOfElements = -noOfElements;
+        }
+        int off = 0;
+        if(useInt) {
+            for (int pos : offsetPos) {
+                Bytes.putInt(offsetArr, off, pos);
+                off += Bytes.SIZEOF_INT;
+            }
+        } else {
+            for (int pos : offsetPos) {
+                Bytes.putShort(offsetArr, off, (short)(pos - Short.MAX_VALUE));
+                off += Bytes.SIZEOF_SHORT;
+            }
+        }
+        oStream.write(offsetArr);
+        oStream.writeInt(offsetPosition);
+        return noOfElements;
+    }
+
+    public static void serializeHeaderInfoIntoBuffer(ByteBuffer buffer, int noOfElements) {
+        // No of elements
+        buffer.putInt(noOfElements);
+        // Version of the array
+        buffer.put(ARRAY_SERIALIZATION_VERSION);
+    }
+
+    public static void serializeHeaderInfoIntoStream(DataOutputStream oStream, int noOfElements) throws IOException {
+        // No of elements
+        oStream.writeInt(noOfElements);
+        // Version of the array
+        oStream.write(ARRAY_SERIALIZATION_VERSION);
+    }
+
+	public static int initOffsetArray(int noOfElements, int baseSize) {
+		// for now create an offset array equal to the noofelements
+		return noOfElements * baseSize;
+    }
+
+    // Any variable length array would follow the below order
+    // Every element would be seperated by a seperator byte '0'
+    // Null elements are counted and once a first non null element appears we
+    // write the count of the nulls prefixed with a seperator byte
+    // Trailing nulls are not taken into account
+    // The last non null element is followed by two seperator bytes
+    // For eg
+    // a, b, null, null, c, null would be 
+    // 65 0 66 0 0 2 67 0 0 0
+    // a null null null b c null d would be
+    // 65 0 0 3 66 0 67 0 0 1 68 0 0 0
+	// Follow the above example to understand how this works
+    private Object createPhoenixArray(byte[] bytes, int offset, int length, SortOrder sortOrder,
+            PDataType baseDataType, Integer maxLength, PDataType desiredDataType) {
+        if (bytes == null || bytes.length == 0) { return null; }
+        Object[] elements;
+        if (!baseDataType.isFixedWidth()) {
+            ByteBuffer buffer = ByteBuffer.wrap(bytes, offset, length);
+            int initPos = buffer.position();
+            buffer.position((buffer.limit() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)));
+            int noOfElements = buffer.getInt();
+            boolean useShort = true;
+            int baseSize = Bytes.SIZEOF_SHORT;
+            if (noOfElements < 0) {
+                noOfElements = -noOfElements;
+                baseSize = Bytes.SIZEOF_INT;
+                useShort = false;
+            }
+            if (baseDataType == desiredDataType) {
+                elements = (Object[])java.lang.reflect.Array.newInstance(baseDataType.getJavaClass(), noOfElements);
+            } else {
+                elements = (Object[])java.lang.reflect.Array.newInstance(desiredDataType.getJavaClass(), noOfElements);
+            }
+            buffer.position(buffer.limit() - (Bytes.SIZEOF_BYTE + (2 * Bytes.SIZEOF_INT)));
+            int indexOffset = buffer.getInt();
+            buffer.position(initPos);
+            buffer.position(indexOffset + initPos);
+            ByteBuffer indexArr = ByteBuffer.allocate(initOffsetArray(noOfElements, baseSize));
+            byte[] array = indexArr.array();
+            buffer.get(array);
+            int countOfElementsRead = 0;
+            int i = 0;
+            int currOffset = -1;
+            int nextOff = -1;
+            boolean foundNull = false;
+            if (noOfElements != 0) {
+                while (countOfElementsRead <= noOfElements) {
+                    if (countOfElementsRead == 0) {
+                        currOffset = getOffset(indexArr, countOfElementsRead, useShort, indexOffset);
+                        countOfElementsRead++;
+                    } else {
+                        currOffset = nextOff;
+                    }
+                    if (countOfElementsRead == noOfElements) {
+                        nextOff = indexOffset - 2;
+                    } else {
+                        nextOff = getOffset(indexArr, countOfElementsRead + 1, useShort, indexOffset);
+                    }
+                    countOfElementsRead++;
+                    if ((bytes[currOffset + initPos] != QueryConstants.SEPARATOR_BYTE) && foundNull) {
+                        // Found a non null element
+                        foundNull = false;
+                    }
+                    if (bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE) {
+                        // Null element
+                        foundNull = true;
+                        i++;
+                        continue;
+                    }
+                    int elementLength = nextOff - currOffset;
+                    buffer.position(currOffset + initPos);
+                    // Subtract the seperator from the element length
+                    byte[] val = new byte[elementLength - 1];
+                    buffer.get(val);
+                    if (baseDataType == desiredDataType) {
+                        elements[i++] = baseDataType.toObject(val, sortOrder);
+                    } else {
+                        elements[i++] = desiredDataType.toObject(val, sortOrder, baseDataType);
+                    }
+                }
+            }
+        } else {
+            int elemLength = (maxLength == null ? baseDataType.getByteSize() : maxLength);
+            int noOfElements = length / elemLength;
+            if (baseDataType == desiredDataType) {
+                elements = (Object[])java.lang.reflect.Array.newInstance(baseDataType.getJavaClass(), noOfElements);
+            } else {
+                elements = (Object[])java.lang.reflect.Array.newInstance(desiredDataType.getJavaClass(), noOfElements);
+            }
+            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+            for (int i = 0; i < noOfElements; i++) {
+                ptr.set(bytes, offset + i * elemLength, elemLength);
+                if (baseDataType == desiredDataType) {
+                    elements[i] = baseDataType.toObject(ptr, sortOrder);
+                } else {
+                    elements[i] = desiredDataType.toObject(ptr, baseDataType, sortOrder);
+                }
+            }
+        }
+        if(baseDataType == desiredDataType) {
+            return PArrayDataType.instantiatePhoenixArray(baseDataType, elements);
+        } else {
+            return PArrayDataType.instantiatePhoenixArray(desiredDataType, elements);
+        }
+    }
+	
+    public static PhoenixArray instantiatePhoenixArray(PDataType actualType, Object[] elements) {
+        return PDataType.instantiatePhoenixArray(actualType, elements);
+    }
+	
+	public int compareTo(Object lhs, Object rhs) {
+		PhoenixArray lhsArr = (PhoenixArray) lhs;
+		PhoenixArray rhsArr = (PhoenixArray) rhs;
+		if(lhsArr.equals(rhsArr)) {
+			return 0;
+		}
+		return 1;
+	}
+
+	public static int getArrayLength(ImmutableBytesWritable ptr,
+			PDataType baseType, Integer maxLength) {
+		byte[] bytes = ptr.get();
+		if(baseType.isFixedWidth()) {
+		    int elemLength = maxLength == null ? baseType.getByteSize() : maxLength;
+			return (ptr.getLength() / elemLength);
+		}
+		return Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)));
+	}
+
+    public static int estimateSize(int size, PDataType baseType) {
+        if(baseType.isFixedWidth()) {
+            return baseType.getByteSize() * size;
+        } else {
+            return size * ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE;
+        }
+        
+    }
+    
+    public Object getSampleValue(PDataType baseType, Integer arrayLength, Integer elemLength) {
+        Preconditions.checkArgument(arrayLength == null || arrayLength >= 0);
+        if (arrayLength == null) {
+            arrayLength = 1;
+        }
+        Object[] array = new Object[arrayLength];
+        for (int i = 0; i < arrayLength; i++) {
+            array[i] = baseType.getSampleValue(elemLength, arrayLength);
+        }
+        return instantiatePhoenixArray(baseType, array);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
new file mode 100644
index 0000000..d188387
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
@@ -0,0 +1,189 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Base64;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.exception.ValueTypeIncompatibleException;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+import java.text.Format;
+
+public class PBinary extends PDataType<byte[]> {
+
+  public static final PBinary INSTANCE = new PBinary();
+
+  private PBinary() {
+    super("BINARY", Types.BINARY, byte[].class, null, 23);
+  }
+
+  @Override
+  public void pad(ImmutableBytesWritable ptr, Integer maxLength) {
+    if (ptr.getLength() >= maxLength) {
+      return;
+    }
+    byte[] newBytes = new byte[maxLength];
+    System.arraycopy(ptr.get(), ptr.getOffset(), newBytes, 0, ptr.getLength());
+    ptr.set(newBytes);
+  }
+
+  @Override
+  public Object pad(Object object, Integer maxLength) {
+    byte[] b = (byte[]) object;
+    if (b == null) {
+      return null;
+    }
+    if (b.length == maxLength) {
+      return object;
+    }
+    if (b.length > maxLength) {
+      throw new ValueTypeIncompatibleException(this, maxLength, null);
+    }
+    byte[] newBytes = new byte[maxLength];
+    System.arraycopy(b, 0, newBytes, 0, b.length);
+
+    return newBytes;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) { // Delegate to VARBINARY
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return PVarbinary.INSTANCE.toBytes(object);
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return PVarbinary.INSTANCE.toBytes(object, bytes, offset);
+
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    byte[] bytes = toBytes(object);
+    if (sortOrder == SortOrder.DESC) {
+      return SortOrder.invert(bytes, 0, new byte[bytes.length], 0, bytes.length);
+    }
+    return bytes;
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (!actualType.isCoercibleTo(this)) {
+      throwConstraintViolationException(actualType, this);
+    }
+    return PVarbinary.INSTANCE.toObject(bytes, offset, length, actualType, sortOrder);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    return actualType.toBytes(object);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public int estimateByteSize(Object o) {
+    byte[] value = (byte[]) o;
+    return value == null ? 1 : value.length;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PVarbinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+      Integer maxLength, Integer scale, Integer desiredMaxLength,
+      Integer desiredScale) {
+    if (ptr.getLength() != 0 && (
+        (srcType.equals(PVarbinary.INSTANCE) && ((String) value).length() != ptr.getLength()) ||
+            (maxLength != null && desiredMaxLength != null && maxLength > desiredMaxLength))) {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public Integer estimateByteSizeFromLength(Integer length) {
+    return length;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (lhs == null && rhs == null) {
+      return 0;
+    } else if (lhs == null) {
+      return -1;
+    } else if (rhs == null) {
+      return 1;
+    }
+    if (equalsAny(rhsType, PVarbinary.INSTANCE, PBinary.INSTANCE)) {
+      return Bytes.compareTo((byte[]) lhs, (byte[]) rhs);
+    } else {
+      byte[] rhsBytes = rhsType.toBytes(rhs);
+      return Bytes.compareTo((byte[]) lhs, rhsBytes);
+    }
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    if (o == null) {
+      return null;
+    }
+    byte[] value = (byte[]) o;
+    return value.length;
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    return Base64.decode(value);
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    if (formatter == null && b.length == 1) {
+      return Integer.toString(0xFF & b[0]);
+    }
+    return PVarbinary.INSTANCE.toStringLiteral(b, offset, length, formatter);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return PVarbinary.INSTANCE.getSampleValue(maxLength, arrayLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinaryArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinaryArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinaryArray.java
new file mode 100644
index 0000000..16c6485
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinaryArray.java
@@ -0,0 +1,108 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PBinaryArray extends PArrayDataType<byte[][]> {
+
+  public static final PBinaryArray INSTANCE = new PBinaryArray();
+
+  private PBinaryArray() {
+    super("BINARY ARRAY", PDataType.ARRAY_TYPE_BASE + PBinary.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 28);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PBinary.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return toObject(bytes, offset, length, PBinary.INSTANCE, sortOrder, maxLength, scale,
+        PBinary.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] charArr = (Object[]) pArr.array;
+    for (Object i : charArr) {
+      if (!super.isCoercibleTo(PBinary.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PBinary.INSTANCE, arrayLength, maxLength);
+  }
+}


[05/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeUnionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeUnionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeUnionTest.java
index f280bbd..520e7ee 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeUnionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeUnionTest.java
@@ -27,13 +27,12 @@ import java.util.Collection;
 
 import junit.framework.TestCase;
 
+import org.apache.phoenix.schema.types.PChar;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import org.apache.phoenix.schema.PDataType;
-
 @RunWith(Parameterized.class)
 public class KeyRangeUnionTest extends TestCase {
     private final KeyRange a, b, union;
@@ -48,33 +47,33 @@ public class KeyRangeUnionTest extends TestCase {
     public static Collection<?> data() {
         return Arrays.asList(new Object[][] {
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("F"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("F"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), false, toBytes("E"), false),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("C"), false, toBytes("F"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), false, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), false, toBytes("F"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), false, toBytes("E"), false),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("E"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("C"), false, toBytes("E"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), false, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), false, toBytes("E"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), false, toBytes("E"), false),
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), false, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), false),
                     EMPTY_RANGE,
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), false),
                 },
                 {
                     EVERYTHING_RANGE,
-                    PDataType.CHAR.getKeyRange(toBytes("E"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
                     EVERYTHING_RANGE,
                 },
                 {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
index d314e72..f929eb4 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
@@ -51,8 +51,9 @@ import org.apache.phoenix.jdbc.PhoenixParameterMetaData;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.FilterableStatement;
 import org.apache.phoenix.parse.SelectStatement;
+import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.schema.ColumnRef;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
@@ -113,19 +114,19 @@ public class ParallelIteratorsSplitTest extends BaseConnectionlessQueryTest {
     }
 
     private static KeyRange getKeyRange(byte[] lowerRange, boolean lowerInclusive, byte[] upperRange, boolean upperInclusive) {
-        return PDataType.CHAR.getKeyRange(lowerRange, lowerInclusive, upperRange, upperInclusive);
+        return PChar.INSTANCE.getKeyRange(lowerRange, lowerInclusive, upperRange, upperInclusive);
     }
 
     private static KeyRange getKeyRange(String lowerRange, boolean lowerInclusive, String upperRange, boolean upperInclusive) {
-        return PDataType.CHAR.getKeyRange(Bytes.toBytes(lowerRange), lowerInclusive, Bytes.toBytes(upperRange), upperInclusive);
+        return PChar.INSTANCE.getKeyRange(Bytes.toBytes(lowerRange), lowerInclusive, Bytes.toBytes(upperRange), upperInclusive);
     }
     
     private static KeyRange getKeyRange(String lowerRange, boolean lowerInclusive, byte[] upperRange, boolean upperInclusive) {
-        return PDataType.CHAR.getKeyRange(Bytes.toBytes(lowerRange), lowerInclusive, upperRange, upperInclusive);
+        return PChar.INSTANCE.getKeyRange(Bytes.toBytes(lowerRange), lowerInclusive, upperRange, upperInclusive);
     }
     
     private static KeyRange getKeyRange(byte[] lowerRange, boolean lowerInclusive, String upperRange, boolean upperInclusive) {
-        return PDataType.CHAR.getKeyRange(lowerRange, lowerInclusive, Bytes.toBytes(upperRange), upperInclusive);
+        return PChar.INSTANCE.getKeyRange(lowerRange, lowerInclusive, Bytes.toBytes(upperRange), upperInclusive);
     }
     
     private static String nextKey(String s) {
@@ -260,7 +261,7 @@ public class ParallelIteratorsSplitTest extends BaseConnectionlessQueryTest {
                 }
                 @Override
                 public PDataType getDataType() {
-                    return PDataType.CHAR;
+                    return PChar.INSTANCE;
                 }
                 @Override
                 public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java
index 29732f3..d5e5b5b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java
@@ -27,6 +27,52 @@ import java.sql.Timestamp;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PBooleanArray;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PCharArray;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDateArray;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDecimalArray;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PDoubleArray;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PFloatArray;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PIntegerArray;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PLongArray;
+import org.apache.phoenix.schema.types.PSmallint;
+import org.apache.phoenix.schema.types.PSmallintArray;
+import org.apache.phoenix.schema.types.PTime;
+import org.apache.phoenix.schema.types.PTimeArray;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PTimestampArray;
+import org.apache.phoenix.schema.types.PTinyint;
+import org.apache.phoenix.schema.types.PTinyintArray;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedDateArray;
+import org.apache.phoenix.schema.types.PUnsignedDouble;
+import org.apache.phoenix.schema.types.PUnsignedDoubleArray;
+import org.apache.phoenix.schema.types.PUnsignedFloat;
+import org.apache.phoenix.schema.types.PUnsignedFloatArray;
+import org.apache.phoenix.schema.types.PUnsignedInt;
+import org.apache.phoenix.schema.types.PUnsignedIntArray;
+import org.apache.phoenix.schema.types.PUnsignedLong;
+import org.apache.phoenix.schema.types.PUnsignedLongArray;
+import org.apache.phoenix.schema.types.PUnsignedSmallint;
+import org.apache.phoenix.schema.types.PUnsignedSmallintArray;
+import org.apache.phoenix.schema.types.PUnsignedTime;
+import org.apache.phoenix.schema.types.PUnsignedTimeArray;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestampArray;
+import org.apache.phoenix.schema.types.PUnsignedTinyint;
+import org.apache.phoenix.schema.types.PUnsignedTinyintArray;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarcharArray;
+import org.apache.phoenix.schema.types.PhoenixArray;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -37,10 +83,10 @@ public class PDataTypeForArraysTest {
 		intArr[0] = 1;
 		intArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.INTEGER, intArr);
-		PDataType.INTEGER_ARRAY.toObject(arr, PDataType.INTEGER_ARRAY);
-		byte[] bytes = PDataType.INTEGER_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.INTEGER_ARRAY
+        PInteger.INSTANCE, intArr);
+		PIntegerArray.INSTANCE.toObject(arr, PIntegerArray.INSTANCE);
+		byte[] bytes = PIntegerArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PIntegerArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -51,10 +97,10 @@ public class PDataTypeForArraysTest {
 		boolArr[0] = true;
 		boolArr[1] = false;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.BOOLEAN, boolArr);
-		PDataType.BOOLEAN_ARRAY.toObject(arr, PDataType.BOOLEAN_ARRAY);
-		byte[] bytes = PDataType.BOOLEAN_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.BOOLEAN_ARRAY
+				PBoolean.INSTANCE, boolArr);
+		PBooleanArray.INSTANCE.toObject(arr, PBooleanArray.INSTANCE);
+		byte[] bytes = PBooleanArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PBooleanArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -65,9 +111,9 @@ public class PDataTypeForArraysTest {
 		strArr[0] = "abc";
 		strArr[1] = "klmnop";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -82,9 +128,9 @@ public class PDataTypeForArraysTest {
         strArr[4] = null;
         strArr[5] = "b";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
                 .toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
 	}
@@ -98,9 +144,9 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "cde";
         strArr[5] = null;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -113,9 +159,9 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = null;
         strArr[5] = null;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -129,9 +175,9 @@ public class PDataTypeForArraysTest {
         strArr[4] = null;
         strArr[5] = null;
         strArr[6] = "xys";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -145,9 +191,9 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = null;
         strArr[5] = null;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -160,9 +206,9 @@ public class PDataTypeForArraysTest {
         strArr[3] = "bcd";
         strArr[4] = null;
         strArr[5] = null;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -175,9 +221,9 @@ public class PDataTypeForArraysTest {
         strArr[3] = "bcd";
         strArr[4] = null;
         strArr[5] = "cde";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(bytes, 0, bytes.length);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
 
@@ -187,10 +233,10 @@ public class PDataTypeForArraysTest {
 		strArr[0] = "a";
 		strArr[1] = "d";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.CHAR, strArr);
-		byte[] bytes = PDataType.CHAR_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.CHAR_ARRAY.toObject(
-				bytes, 0, bytes.length, PDataType.CHAR_ARRAY, null, 1, null);
+				PChar.INSTANCE, strArr);
+		byte[] bytes = PCharArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PCharArray.INSTANCE.toObject(
+				bytes, 0, bytes.length, PCharArray.INSTANCE, null, 1, null);
 		assertEquals(arr, resultArr);
 	}
 
@@ -200,10 +246,10 @@ public class PDataTypeForArraysTest {
 		longArr[0] = 1l;
 		longArr[1] = 2l;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.LONG, longArr);
-		PDataType.LONG_ARRAY.toObject(arr, PDataType.LONG_ARRAY);
-		byte[] bytes = PDataType.LONG_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.LONG_ARRAY.toObject(
+				PLong.INSTANCE, longArr);
+		PLongArray.INSTANCE.toObject(arr, PLongArray.INSTANCE);
+		byte[] bytes = PLongArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PLongArray.INSTANCE.toObject(
 				bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -214,10 +260,10 @@ public class PDataTypeForArraysTest {
 		shortArr[0] = 1;
 		shortArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.SMALLINT, shortArr);
-		PDataType.SMALLINT_ARRAY.toObject(arr, PDataType.SMALLINT_ARRAY);
-		byte[] bytes = PDataType.SMALLINT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.SMALLINT_ARRAY
+				PSmallint.INSTANCE, shortArr);
+		PSmallintArray.INSTANCE.toObject(arr, PSmallintArray.INSTANCE);
+		byte[] bytes = PSmallintArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PSmallintArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -229,9 +275,9 @@ public class PDataTypeForArraysTest {
 		strArr[1] = "ereref";
 		strArr[2] = "random";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -241,9 +287,9 @@ public class PDataTypeForArraysTest {
         String[] strArr = new String[1];
         strArr[0] = "ereref";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
                 .toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
@@ -252,15 +298,15 @@ public class PDataTypeForArraysTest {
     public void testForVarcharArrayWith1ElementInLargerBuffer() {
         String[] strArr = new String[1];
         strArr[0] = "abx";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         byte[] moreBytes = new byte[bytes.length + 20];
         // Generate some garbage
         for (int i = 0; i < moreBytes.length; i++) {
             moreBytes[i] = (byte)-i;
         }
         System.arraycopy(bytes, 0, moreBytes, 10, bytes.length);
-        PhoenixArray resultArr = (PhoenixArray)PDataType.VARCHAR_ARRAY.toObject(moreBytes, 10, bytes.length);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(moreBytes, 10, bytes.length);
         assertEquals(arr, resultArr);
     }
     
@@ -274,10 +320,10 @@ public class PDataTypeForArraysTest {
 		strArr[3] = "random12";
 		strArr[4] = "ranzzz";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
 		int offset = ptr.getOffset();
 		int length = ptr.getLength();
 		byte[] bs = ptr.get();
@@ -292,10 +338,10 @@ public class PDataTypeForArraysTest {
         String[] strArr = new String[1];
         strArr[0] = "abx";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 0, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 0, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -315,10 +361,10 @@ public class PDataTypeForArraysTest {
 	        strArr[i] = str;
 	    }
 	    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 3, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -336,10 +382,10 @@ public class PDataTypeForArraysTest {
 		strArr[3] = "random12";
 		strArr[4] = "ranzzz";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		int result = PArrayDataType.getArrayLength(ptr, PDataType.VARCHAR, null);
+		int result = PArrayDataType.getArrayLength(ptr, PVarchar.INSTANCE, null);
 		assertEquals(5, result);
 	}
 
@@ -352,10 +398,10 @@ public class PDataTypeForArraysTest {
 		strArr[3] = "random12";
 		strArr[4] = "ran";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+		PArrayDataType.positionAtArrayElement(ptr, 3, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
 		int offset = ptr.getOffset();
 		int length = ptr.getLength();
 		byte[] bs = ptr.get();
@@ -373,10 +419,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 2, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 2, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -394,10 +440,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = "random12";
         strArr[4] = null;
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 2, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 2, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -414,10 +460,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = "random12";
         strArr[4] = null;
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -435,10 +481,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = null;
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 3, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -456,10 +502,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "random12";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -478,10 +524,10 @@ public class PDataTypeForArraysTest {
         strArr[4] = "random12";
         strArr[5] = "random17";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -498,10 +544,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 3, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -519,10 +565,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 3, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -540,10 +586,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 0, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 0, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -561,10 +607,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -582,10 +628,10 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = null;
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
         ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-        PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+        PArrayDataType.positionAtArrayElement(ptr, 4, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
         int offset = ptr.getOffset();
         int length = ptr.getLength();
         byte[] bs = ptr.get();
@@ -599,10 +645,10 @@ public class PDataTypeForArraysTest {
 		String[] strArr = new String[1];
 		strArr[0] = "abx";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		PArrayDataType.positionAtArrayElement(ptr, 0, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+		PArrayDataType.positionAtArrayElement(ptr, 0, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
 		int offset = ptr.getOffset();
 		int length = ptr.getLength();
 		byte[] bs = ptr.get();
@@ -617,10 +663,10 @@ public class PDataTypeForArraysTest {
 		strArr[0] = "abx";
 		strArr[1] = "ereref";
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		PArrayDataType.positionAtArrayElement(ptr, 1, PDataType.VARCHAR, PDataType.VARCHAR.getByteSize());
+		PArrayDataType.positionAtArrayElement(ptr, 1, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
 		int offset = ptr.getOffset();
 		int length = ptr.getLength();
 		byte[] bs = ptr.get();
@@ -637,17 +683,17 @@ public class PDataTypeForArraysTest {
 		longArr[2] = 4l;
 		longArr[3] = 5l;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.LONG, longArr);
-		PDataType.LONG_ARRAY.toObject(arr, PDataType.LONG_ARRAY);
-		byte[] bytes = PDataType.LONG_ARRAY.toBytes(arr);
+				PLong.INSTANCE, longArr);
+		PLongArray.INSTANCE.toObject(arr, PLongArray.INSTANCE);
+		byte[] bytes = PLongArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		PArrayDataType.positionAtArrayElement(ptr, 2, PDataType.LONG, PDataType.LONG.getByteSize());
+		PArrayDataType.positionAtArrayElement(ptr, 2, PLong.INSTANCE, PLong.INSTANCE.getByteSize());
 		int offset = ptr.getOffset();
 		int length = ptr.getLength();
 		byte[] bs = ptr.get();
 		byte[] res = new byte[length];
 		System.arraycopy(bs, offset, res, 0, length);
-		long result = (Long) PDataType.LONG.toObject(res);
+		long result = (Long) PLong.INSTANCE.toObject(res);
 		assertEquals(4l, result);
 	}
 	
@@ -659,11 +705,11 @@ public class PDataTypeForArraysTest {
 		longArr[2] = 4l;
 		longArr[3] = 5l;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.LONG, longArr);
-		PDataType.LONG_ARRAY.toObject(arr, PDataType.LONG_ARRAY);
-		byte[] bytes = PDataType.LONG_ARRAY.toBytes(arr);
+				PLong.INSTANCE, longArr);
+		PLongArray.INSTANCE.toObject(arr, PLongArray.INSTANCE);
+		byte[] bytes = PLongArray.INSTANCE.toBytes(arr);
 		ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
-		int length = PArrayDataType.getArrayLength(ptr, PDataType.LONG, null);
+		int length = PArrayDataType.getArrayLength(ptr, PLong.INSTANCE, null);
 		assertEquals(4, length);
 	}
 
@@ -674,9 +720,9 @@ public class PDataTypeForArraysTest {
 			strArr[i] = "abc" + i;
 		}
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.VARCHAR, strArr);
-		byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+				PVarchar.INSTANCE, strArr);
+		byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -687,10 +733,10 @@ public class PDataTypeForArraysTest {
 		byteArr[0] = 1;
 		byteArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.TINYINT, byteArr);
-		PDataType.TINYINT_ARRAY.toObject(arr, PDataType.TINYINT_ARRAY);
-		byte[] bytes = PDataType.TINYINT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.TINYINT_ARRAY
+				PTinyint.INSTANCE, byteArr);
+		PTinyintArray.INSTANCE.toObject(arr, PTinyintArray.INSTANCE);
+		byte[] bytes = PTinyintArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PTinyintArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -701,10 +747,10 @@ public class PDataTypeForArraysTest {
 		floatArr[0] = 1.06f;
 		floatArr[1] = 2.89f;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.FLOAT, floatArr);
-		PDataType.FLOAT_ARRAY.toObject(arr, PDataType.FLOAT_ARRAY);
-		byte[] bytes = PDataType.FLOAT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.FLOAT_ARRAY.toObject(
+				PFloat.INSTANCE, floatArr);
+		PFloatArray.INSTANCE.toObject(arr, PFloatArray.INSTANCE);
+		byte[] bytes = PFloatArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PFloatArray.INSTANCE.toObject(
 				bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -715,10 +761,10 @@ public class PDataTypeForArraysTest {
 		doubleArr[0] = 1.06;
 		doubleArr[1] = 2.89;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.DOUBLE, doubleArr);
-		PDataType.DOUBLE_ARRAY.toObject(arr, PDataType.DOUBLE_ARRAY);
-		byte[] bytes = PDataType.DOUBLE_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.DOUBLE_ARRAY
+				PDouble.INSTANCE, doubleArr);
+		PDoubleArray.INSTANCE.toObject(arr, PDoubleArray.INSTANCE);
+		byte[] bytes = PDoubleArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PDoubleArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -729,10 +775,10 @@ public class PDataTypeForArraysTest {
 		bigDecimalArr[0] = new BigDecimal(89997);
 		bigDecimalArr[1] = new BigDecimal(8999.995f);
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.DECIMAL, bigDecimalArr);
-		PDataType.DECIMAL_ARRAY.toObject(arr, PDataType.DECIMAL_ARRAY);
-		byte[] bytes = PDataType.DECIMAL_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.DECIMAL_ARRAY
+				PDecimal.INSTANCE, bigDecimalArr);
+		PDecimalArray.INSTANCE.toObject(arr, PDecimalArray.INSTANCE);
+		byte[] bytes = PDecimalArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PDecimalArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -743,10 +789,10 @@ public class PDataTypeForArraysTest {
 		timeStampArr[0] = new Timestamp(System.currentTimeMillis());
 		timeStampArr[1] = new Timestamp(900000l);
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.TIMESTAMP, timeStampArr);
-		PDataType.TIMESTAMP_ARRAY.toObject(arr, PDataType.TIMESTAMP_ARRAY);
-		byte[] bytes = PDataType.TIMESTAMP_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.TIMESTAMP_ARRAY
+				PTimestamp.INSTANCE, timeStampArr);
+		PTimestampArray.INSTANCE.toObject(arr, PTimestampArray.INSTANCE);
+		byte[] bytes = PTimestampArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PTimestampArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -757,11 +803,11 @@ public class PDataTypeForArraysTest {
 		timeStampArr[0] = new Timestamp(System.currentTimeMillis());
 		timeStampArr[1] = new Timestamp(900000l);
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_TIMESTAMP, timeStampArr);
-		PDataType.UNSIGNED_TIMESTAMP_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_TIMESTAMP_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_TIMESTAMP_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_TIMESTAMP_ARRAY
+				PUnsignedTimestamp.INSTANCE, timeStampArr);
+		PUnsignedTimestampArray.INSTANCE.toObject(arr,
+				PUnsignedTimestampArray.INSTANCE);
+		byte[] bytes = PUnsignedTimestampArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedTimestampArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -772,10 +818,10 @@ public class PDataTypeForArraysTest {
 		timeArr[0] = new Time(System.currentTimeMillis());
 		timeArr[1] = new Time(900000l);
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.TIME, timeArr);
-		PDataType.TIME_ARRAY.toObject(arr, PDataType.TIME_ARRAY);
-		byte[] bytes = PDataType.TIME_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.TIME_ARRAY.toObject(
+        PTime.INSTANCE, timeArr);
+		PTimeArray.INSTANCE.toObject(arr, PTimeArray.INSTANCE);
+		byte[] bytes = PTimeArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PTimeArray.INSTANCE.toObject(
 				bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -786,11 +832,11 @@ public class PDataTypeForArraysTest {
 		timeArr[0] = new Time(System.currentTimeMillis());
 		timeArr[1] = new Time(900000l);
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_TIME, timeArr);
-		PDataType.UNSIGNED_TIME_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_TIME_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_TIME_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_TIME_ARRAY
+				PUnsignedTime.INSTANCE, timeArr);
+		PUnsignedTimeArray.INSTANCE.toObject(arr,
+				PUnsignedTimeArray.INSTANCE);
+		byte[] bytes = PUnsignedTimeArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedTimeArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -802,10 +848,10 @@ public class PDataTypeForArraysTest {
 		dateArr[1] = new Date(System.currentTimeMillis()
 				+ System.currentTimeMillis());
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.DATE, dateArr);
-		PDataType.DATE_ARRAY.toObject(arr, PDataType.DATE_ARRAY);
-		byte[] bytes = PDataType.DATE_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.DATE_ARRAY.toObject(
+        PDate.INSTANCE, dateArr);
+		PDateArray.INSTANCE.toObject(arr, PDateArray.INSTANCE);
+		byte[] bytes = PDateArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PDateArray.INSTANCE.toObject(
 				bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -817,11 +863,11 @@ public class PDataTypeForArraysTest {
 		dateArr[1] = new Date(System.currentTimeMillis()
 				+ System.currentTimeMillis());
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_DATE, dateArr);
-		PDataType.UNSIGNED_DATE_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_DATE_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_DATE_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_DATE_ARRAY
+				PUnsignedDate.INSTANCE, dateArr);
+		PUnsignedDateArray.INSTANCE.toObject(arr,
+				PUnsignedDateArray.INSTANCE);
+		byte[] bytes = PUnsignedDateArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedDateArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -832,11 +878,11 @@ public class PDataTypeForArraysTest {
 		longArr[0] = 1l;
 		longArr[1] = 2l;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_LONG, longArr);
-		PDataType.UNSIGNED_LONG_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_LONG_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_LONG_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_LONG_ARRAY
+				PUnsignedLong.INSTANCE, longArr);
+		PUnsignedLongArray.INSTANCE.toObject(arr,
+				PUnsignedLongArray.INSTANCE);
+		byte[] bytes = PUnsignedLongArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedLongArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -847,11 +893,11 @@ public class PDataTypeForArraysTest {
 		intArr[0] = 1;
 		intArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_INT, intArr);
-		PDataType.UNSIGNED_INT_ARRAY
-				.toObject(arr, PDataType.UNSIGNED_INT_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_INT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_INT_ARRAY
+				PUnsignedInt.INSTANCE, intArr);
+		PUnsignedIntArray.INSTANCE
+				.toObject(arr, PUnsignedIntArray.INSTANCE);
+		byte[] bytes = PUnsignedIntArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedIntArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -862,11 +908,11 @@ public class PDataTypeForArraysTest {
 		shortArr[0] = 1;
 		shortArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_SMALLINT, shortArr);
-		PDataType.UNSIGNED_SMALLINT_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_SMALLINT_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_SMALLINT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_SMALLINT_ARRAY
+				PUnsignedSmallint.INSTANCE, shortArr);
+		PUnsignedSmallintArray.INSTANCE.toObject(arr,
+				PUnsignedSmallintArray.INSTANCE);
+		byte[] bytes = PUnsignedSmallintArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedSmallintArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -877,11 +923,11 @@ public class PDataTypeForArraysTest {
 		byteArr[0] = 1;
 		byteArr[1] = 2;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_TINYINT, byteArr);
-		PDataType.UNSIGNED_TINYINT_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_TINYINT_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_TINYINT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_TINYINT_ARRAY
+				PUnsignedTinyint.INSTANCE, byteArr);
+		PUnsignedTinyintArray.INSTANCE.toObject(arr,
+				PUnsignedTinyintArray.INSTANCE);
+		byte[] bytes = PUnsignedTinyintArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedTinyintArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -892,11 +938,11 @@ public class PDataTypeForArraysTest {
 		floatArr[0] = 1.9993f;
 		floatArr[1] = 2.786f;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_FLOAT, floatArr);
-		PDataType.UNSIGNED_FLOAT_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_FLOAT_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_FLOAT_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_FLOAT_ARRAY
+				PUnsignedFloat.INSTANCE, floatArr);
+		PUnsignedFloatArray.INSTANCE.toObject(arr,
+				PUnsignedFloatArray.INSTANCE);
+		byte[] bytes = PUnsignedFloatArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedFloatArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -907,11 +953,11 @@ public class PDataTypeForArraysTest {
 		doubleArr[0] = 1.9993;
 		doubleArr[1] = 2.786;
 		PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-				PDataType.UNSIGNED_DOUBLE, doubleArr);
-		PDataType.UNSIGNED_DOUBLE_ARRAY.toObject(arr,
-				PDataType.UNSIGNED_DOUBLE_ARRAY);
-		byte[] bytes = PDataType.UNSIGNED_DOUBLE_ARRAY.toBytes(arr);
-		PhoenixArray resultArr = (PhoenixArray) PDataType.UNSIGNED_DOUBLE_ARRAY
+				PUnsignedDouble.INSTANCE, doubleArr);
+		PUnsignedDoubleArray.INSTANCE.toObject(arr,
+				PUnsignedDoubleArray.INSTANCE);
+		byte[] bytes = PUnsignedDoubleArray.INSTANCE.toBytes(arr);
+		PhoenixArray resultArr = (PhoenixArray) PUnsignedDoubleArray.INSTANCE
 				.toObject(bytes, 0, bytes.length);
 		assertEquals(arr, resultArr);
 	}
@@ -921,16 +967,16 @@ public class PDataTypeForArraysTest {
         Double[] doubleArr = new Double[2];
         doubleArr[0] = 1.9993;
         doubleArr[1] = 2.786;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.UNSIGNED_DOUBLE, doubleArr);
-        PDataType.UNSIGNED_DOUBLE_ARRAY.toObject(arr, PDataType.UNSIGNED_DOUBLE_ARRAY);
-        byte[] bytes1 = PDataType.UNSIGNED_DOUBLE_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PUnsignedDouble.INSTANCE, doubleArr);
+        PUnsignedDoubleArray.INSTANCE.toObject(arr, PUnsignedDoubleArray.INSTANCE);
+        byte[] bytes1 = PUnsignedDoubleArray.INSTANCE.toBytes(arr);
 
         doubleArr = new Double[2];
         doubleArr[0] = 1.9993;
         doubleArr[1] = 2.786;
-        arr = PArrayDataType.instantiatePhoenixArray(PDataType.UNSIGNED_DOUBLE, doubleArr);
-        PDataType.UNSIGNED_DOUBLE_ARRAY.toObject(arr, PDataType.UNSIGNED_DOUBLE_ARRAY);
-        byte[] bytes2 = PDataType.UNSIGNED_DOUBLE_ARRAY.toBytes(arr);
+        arr = PArrayDataType.instantiatePhoenixArray(PUnsignedDouble.INSTANCE, doubleArr);
+        PUnsignedDoubleArray.INSTANCE.toObject(arr, PUnsignedDoubleArray.INSTANCE);
+        byte[] bytes2 = PUnsignedDoubleArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.equals(bytes1, bytes2));
     }
 
@@ -939,17 +985,17 @@ public class PDataTypeForArraysTest {
         Double[] doubleArr = new Double[2];
         doubleArr[0] = 1.9993;
         doubleArr[1] = 2.786;
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.UNSIGNED_DOUBLE, doubleArr);
-        PDataType.UNSIGNED_DOUBLE_ARRAY.toObject(arr, PDataType.UNSIGNED_DOUBLE_ARRAY);
-        byte[] bytes1 = PDataType.UNSIGNED_DOUBLE_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PUnsignedDouble.INSTANCE, doubleArr);
+        PUnsignedDoubleArray.INSTANCE.toObject(arr, PUnsignedDoubleArray.INSTANCE);
+        byte[] bytes1 = PUnsignedDoubleArray.INSTANCE.toBytes(arr);
 
         doubleArr = new Double[3];
         doubleArr[0] = 1.9993;
         doubleArr[1] = 2.786;
         doubleArr[2] = 6.3;
-        arr = PArrayDataType.instantiatePhoenixArray(PDataType.UNSIGNED_DOUBLE, doubleArr);
-        PDataType.UNSIGNED_DOUBLE_ARRAY.toObject(arr, PDataType.UNSIGNED_DOUBLE_ARRAY);
-        byte[] bytes2 = PDataType.UNSIGNED_DOUBLE_ARRAY.toBytes(arr);
+        arr = PArrayDataType.instantiatePhoenixArray(PUnsignedDouble.INSTANCE, doubleArr);
+        PUnsignedDoubleArray.INSTANCE.toObject(arr, PUnsignedDoubleArray.INSTANCE);
+        byte[] bytes2 = PUnsignedDoubleArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.compareTo(bytes1, bytes2) < 0);
     }
 
@@ -961,8 +1007,8 @@ public class PDataTypeForArraysTest {
         strArr[2] = "random";
         strArr[3] = "random1";
         strArr[4] = "ran";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes1 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
 
         strArr = new String[5];
         strArr[0] = "abc";
@@ -970,8 +1016,8 @@ public class PDataTypeForArraysTest {
         strArr[2] = "random";
         strArr[3] = "random1";
         strArr[4] = "ran";
-        arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes2 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.equals(bytes1, bytes2));
     }
 
@@ -983,16 +1029,16 @@ public class PDataTypeForArraysTest {
         strArr[2] = "random";
         strArr[3] = "random1";
         strArr[4] = "ran";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes1 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
 
         strArr = new String[5];
         strArr[0] = "abc";
         strArr[1] = "ereref";
         strArr[2] = "random";
         strArr[3] = "random1";
-        arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes2 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.compareTo(bytes1, bytes2) > 0);
     }
 
@@ -1005,8 +1051,8 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = "ran";
         strArr[5] = "ran";
-        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes1 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
 
         strArr = new String[6];
         strArr[0] = null;
@@ -1015,8 +1061,8 @@ public class PDataTypeForArraysTest {
         strArr[3] = null;
         strArr[4] = null;
         strArr[5] = "ran";
-        arr = PArrayDataType.instantiatePhoenixArray(PDataType.VARCHAR, strArr);
-        byte[] bytes2 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+        arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
+        byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.compareTo(bytes1, bytes2) > 0);
     }
     
@@ -1033,9 +1079,9 @@ public class PDataTypeForArraysTest {
         }
         strArr[strArr.length - 1] = "abc";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
-        PhoenixArray resultArr = (PhoenixArray) PDataType.VARCHAR_ARRAY
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
+        PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE
                 .toObject(bytes, 0, bytes.length);
         assertEquals(arr, resultArr);
     }
@@ -1050,8 +1096,8 @@ public class PDataTypeForArraysTest {
         strArr[4] = "bcd";
         strArr[strArr.length - 1] = "abc";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes1 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
         
         strArr = new String[16];
         strArr[0] = "abc";
@@ -1061,8 +1107,8 @@ public class PDataTypeForArraysTest {
         strArr[4] = "bcd";
         strArr[strArr.length - 1] = "abc";
         arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes2 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.compareTo(bytes1, bytes2) < 0);
     }
     
@@ -1076,8 +1122,8 @@ public class PDataTypeForArraysTest {
         strArr[4] = "bcd";
         strArr[strArr.length - 1] = "abc";
         PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes1 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
         
         strArr = new String[500];
         strArr[0] = "abc";
@@ -1087,8 +1133,8 @@ public class PDataTypeForArraysTest {
         strArr[4] = "bcd";
         strArr[strArr.length - 1] = "abc";
         arr = PArrayDataType.instantiatePhoenixArray(
-                PDataType.VARCHAR, strArr);
-        byte[] bytes2 = PDataType.VARCHAR_ARRAY.toBytes(arr);
+                PVarchar.INSTANCE, strArr);
+        byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
         assertTrue(Bytes.compareTo(bytes1, bytes2) == 0);
     }
     


[07/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
index f8a7391..c9f81fe 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/RoundFloorCeilExpressionsTest.java
@@ -17,7 +17,6 @@
  */
 package org.apache.phoenix.expression;
 
-import static org.apache.phoenix.schema.PDataType.DECIMAL;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -44,98 +43,102 @@ import org.apache.phoenix.expression.function.ScalarFunction;
 import org.apache.phoenix.expression.function.TimeUnit;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.DateUtil;
 import org.junit.Test;
 
 /**
- * 
+ *
  * Unit tests for {@link RoundDecimalExpression}, {@link FloorDecimalExpression}
  * and {@link CeilDecimalExpression}.
  *
- * 
+ *
  * @since 3.0.0
  */
 public class RoundFloorCeilExpressionsTest {
 
     // Decimal Expression Tests
-    
+
     @Test
     public void testRoundDecimalExpression() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDataType.DECIMAL);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
         Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);
-        
+
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         roundDecimalExpression.evaluate(null, ptr);
         Object result = roundDecimalExpression.getDataType().toObject(ptr);
-        
+
         assertTrue(result instanceof BigDecimal);
         BigDecimal resultDecimal = (BigDecimal)result;
         assertEquals(BigDecimal.valueOf(1.239), resultDecimal);
     }
-    
+
     @Test
     public void testRoundDecimalExpressionNoop() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PDataType.INTEGER);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
         Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);
-        
+
         assertEquals(roundDecimalExpression, decimalLiteral);
     }
-    
+
     @Test
     public void testFloorDecimalExpression() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDataType.DECIMAL);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
         Expression floorDecimalExpression = FloorDecimalExpression.create(decimalLiteral, 3);
-        
+
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         floorDecimalExpression.evaluate(null, ptr);
         Object result = floorDecimalExpression.getDataType().toObject(ptr);
-        
+
         assertTrue(result instanceof BigDecimal);
         BigDecimal resultDecimal = (BigDecimal)result;
         assertEquals(BigDecimal.valueOf(1.238), resultDecimal);
     }
-    
+
     @Test
     public void testFloorDecimalExpressionNoop() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PDataType.INTEGER);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
         Expression floorDecimalExpression = FloorDecimalExpression.create(decimalLiteral, 3);
-        
+
         assertEquals(floorDecimalExpression, decimalLiteral);
     }
-    
+
     @Test
     public void testCeilDecimalExpression() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDataType.DECIMAL);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
         Expression ceilDecimalExpression = CeilDecimalExpression.create(decimalLiteral, 3);
-        
+
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         ceilDecimalExpression.evaluate(null, ptr);
         Object result = ceilDecimalExpression.getDataType().toObject(ptr);
-        
+
         assertTrue(result instanceof BigDecimal);
         BigDecimal resultDecimal = (BigDecimal)result;
         assertEquals(BigDecimal.valueOf(1.239), resultDecimal);
     }
-    
+
     @Test
     public void testCeilDecimalExpressionNoop() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PDataType.INTEGER);
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
         Expression ceilDecimalExpression = CeilDecimalExpression.create(decimalLiteral, 3);
-        
+
         assertEquals(ceilDecimalExpression, decimalLiteral);
     }
-    
+
     @Test
     public void testRoundDecimalExpressionScaleParamValidation() throws Exception {
-        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDataType.DECIMAL);
-        LiteralExpression scale = LiteralExpression.newConstant("3", PDataType.VARCHAR);
-        
+        LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
+        LiteralExpression scale = LiteralExpression.newConstant("3", PVarchar.INSTANCE);
+
         List<Expression> childExpressions = new ArrayList<Expression>(2);
         childExpressions.add(decimalLiteral);
         childExpressions.add(scale);
-        
+
         try {
             RoundDecimalExpression.create(childExpressions);
             fail("Evaluation should have failed because only an INTEGER is allowed for second param in a RoundDecimalExpression");
@@ -143,47 +146,47 @@ public class RoundFloorCeilExpressionsTest {
 
         }
     }
-    
+
     // KeyRange explicit simple / sanity tests
-    
+
     @Test
     public void testRoundDecimalExpressionKeyRangeSimple() throws Exception {
         ScalarFunction roundDecimalExpression = (ScalarFunction)RoundDecimalExpression.create(DUMMY_DECIMAL, 3);
-        
-        byte[] upperBound = DECIMAL.toBytes(new BigDecimal("1.2385"));
-        byte[] lowerBound = DECIMAL.toBytes(new BigDecimal("1.2375"));
+
+        byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2385"));
+        byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2375"));
         KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, upperBound);
-        
+
         KeyPart keyPart = roundDecimalExpression.newKeyPart(null);
-        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), DECIMAL)));
+        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
     }
-    
+
     @Test
     public void testFloorDecimalExpressionKeyRangeSimple() throws Exception {
         ScalarFunction floorDecimalExpression = (ScalarFunction)FloorDecimalExpression.create(DUMMY_DECIMAL, 3);
-        
-        byte[] upperBound = DECIMAL.toBytes(new BigDecimal("1.239"));
-        byte[] lowerBound = DECIMAL.toBytes(new BigDecimal("1.238"));
+
+        byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.239"));
+        byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238"));
         KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, true, upperBound, false);
-        
+
         KeyPart keyPart = floorDecimalExpression.newKeyPart(null);
-        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), DECIMAL)));
+        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
     }
-    
+
     @Test
     public void testCeilDecimalExpressionKeyRangeSimple() throws Exception {
         ScalarFunction ceilDecimalExpression = (ScalarFunction)CeilDecimalExpression.create(DUMMY_DECIMAL, 3);
-        
-        byte[] upperBound = DECIMAL.toBytes(new BigDecimal("1.238"));
-        byte[] lowerBound = DECIMAL.toBytes(new BigDecimal("1.237"));
+
+        byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238"));
+        byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.237"));
         KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, false, upperBound, true);
-        
+
         KeyPart keyPart = ceilDecimalExpression.newKeyPart(null);
-        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), DECIMAL)));
+        assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
     }
-    
+
     // KeyRange complex / generated tests
-    
+
     @Test
     public void testRoundDecimalExpressionKeyRangeCoverage() throws Exception {
         for(int scale : SCALES) {
@@ -192,7 +195,7 @@ public class RoundFloorCeilExpressionsTest {
             verifyKeyPart(RoundingType.ROUND, scale, keyPart);
         }
     }
-    
+
     @Test
     public void testFloorDecimalExpressionKeyRangeCoverage() throws Exception {
         for(int scale : SCALES) {
@@ -201,7 +204,7 @@ public class RoundFloorCeilExpressionsTest {
             verifyKeyPart(RoundingType.FLOOR, scale, keyPart);
         }
     }
-    
+
     @Test
     public void testCeilDecimalExpressionKeyRangeCoverage() throws Exception {
         for(int scale : SCALES) {
@@ -210,31 +213,31 @@ public class RoundFloorCeilExpressionsTest {
             verifyKeyPart(RoundingType.CEIL, scale, keyPart);
         }
     }
-    
+
     /**
      * Represents the three different types of rounding expression and produces
      * expressions of their type when given a Decimal key and scale.
      */
     private static enum RoundingType {
-        ROUND("ROUND"), 
-        FLOOR("FLOOR"), 
+        ROUND("ROUND"),
+        FLOOR("FLOOR"),
         CEIL("CEIL");
-        
+
         public final String name;
-        
+
         RoundingType(String name) {
             this.name = name;
         }
-        
+
         /**
          * Returns a rounding expression of this type that will round the given decimal key at the
-         * given scale. 
+         * given scale.
          * @param key  the byte key for the Decimal to round
          * @param scale  the scale to round the decimal to
          * @return  the expression containing the above parameters
          */
         public Expression getExpression(byte[] key, int scale) throws SQLException {
-            LiteralExpression decimalLiteral = LiteralExpression.newConstant(DECIMAL.toObject(key), DECIMAL);
+            LiteralExpression decimalLiteral = LiteralExpression.newConstant(PDecimal.INSTANCE.toObject(key), PDecimal.INSTANCE);
             switch(this) {
                 case ROUND:
                     return RoundDecimalExpression.create(decimalLiteral, scale);
@@ -247,7 +250,7 @@ public class RoundFloorCeilExpressionsTest {
             }
         }
     }
-    
+
     /**
      * Represents a possible relational operator used in rounding expression where clauses.
      * Includes information not kept by CompareFilter.CompareOp, including a string symbol
@@ -259,15 +262,15 @@ public class RoundFloorCeilExpressionsTest {
         GREATER_OR_EQUAL(CompareOp.GREATER_OR_EQUAL, ">="),
         LESS(CompareOp.LESS, "<"),
         LESS_OR_EQUAL(CompareOp.LESS_OR_EQUAL, "<=");
-        
+
         public final CompareOp compareOp;
         public final String symbol;
-        
+
         Relation(CompareOp compareOp, String symbol) {
             this.compareOp = compareOp;
             this.symbol = symbol;
         }
-        
+
         public <E extends Comparable<? super E>> boolean compare(E lhs, E rhs) {
             int comparison = lhs.compareTo(rhs);
             switch(this) {
@@ -286,7 +289,7 @@ public class RoundFloorCeilExpressionsTest {
             }
         }
     }
-    
+
     /**
      * Produces a string error message containing the given information, formatted like a where
      * clause. <br>
@@ -297,53 +300,53 @@ public class RoundFloorCeilExpressionsTest {
      * @param relation
      * @param rhs
      * @param range
-     * @return 
+     * @return
      */
     private static String getMessage(RoundingType exprType, int scale, Relation relation, BigDecimal rhs, KeyRange range) {
         String where = exprType.name + "(?, " + scale + ") " + relation.symbol + " " + rhs;
         return "'where " + where + "' (produced range: " + formatDecimalKeyRange(range) + " )";
     }
-    
+
     /**
      * Interpreting the KeyRange as a range of decimal, produces a nicely formatted string
-     * representation. 
+     * representation.
      * @param range  the KeyRange to format
      * @return  the string representation, e.g. [2.45, 2.55)
      */
     private static String formatDecimalKeyRange(KeyRange range) {
-        return (range.isLowerInclusive() ? "[" : "(") 
-            + (range.lowerUnbound() ? "*" : DECIMAL.toObject(range.getLowerRange())) 
-            + ", " 
-            + (range.upperUnbound() ? "*" : DECIMAL.toObject(range.getUpperRange())) 
+        return (range.isLowerInclusive() ? "[" : "(")
+            + (range.lowerUnbound() ? "*" : PDecimal.INSTANCE.toObject(range.getLowerRange()))
+            + ", "
+            + (range.upperUnbound() ? "*" : PDecimal.INSTANCE.toObject(range.getUpperRange()))
             + (range.isUpperInclusive() ? "]" : ")");
     }
-    
+
     // create methods need a dummy expression that is not coercible to to a long
     // value doesn't matter because we only use those expressions to produce a keypart
     private static final LiteralExpression DUMMY_DECIMAL = LiteralExpression.newConstant(new BigDecimal("2.5"));
-    
+
     private static final List<BigDecimal> DECIMALS = Collections.unmodifiableList(
         Arrays.asList(
             BigDecimal.valueOf(Long.MIN_VALUE * 17L - 13L, 9),
             BigDecimal.valueOf(Long.MIN_VALUE, 8),
-            new BigDecimal("-200300"), 
-            new BigDecimal("-8.44"), 
-            new BigDecimal("-2.00"), 
-            new BigDecimal("-0.6"), 
-            new BigDecimal("-0.00032"), 
-            BigDecimal.ZERO, 
-            BigDecimal.ONE, 
-            new BigDecimal("0.00000984"), 
-            new BigDecimal("0.74"), 
-            new BigDecimal("2.00"), 
-            new BigDecimal("7.09"), 
+            new BigDecimal("-200300"),
+            new BigDecimal("-8.44"),
+            new BigDecimal("-2.00"),
+            new BigDecimal("-0.6"),
+            new BigDecimal("-0.00032"),
+            BigDecimal.ZERO,
+            BigDecimal.ONE,
+            new BigDecimal("0.00000984"),
+            new BigDecimal("0.74"),
+            new BigDecimal("2.00"),
+            new BigDecimal("7.09"),
             new BigDecimal("84900800"),
             BigDecimal.valueOf(Long.MAX_VALUE, 8),
             BigDecimal.valueOf(Long.MAX_VALUE * 31L + 17L, 7)
         ));
-    
+
     private static final List<Integer> SCALES = Collections.unmodifiableList(Arrays.asList(0, 1, 2, 3, 8));
-    
+
     /**
      * Checks that a given KeyPart produces the right key ranges for each relational operator and
      * a variety of right-hand-side decimals.
@@ -353,19 +356,19 @@ public class RoundFloorCeilExpressionsTest {
      */
     private void verifyKeyPart(RoundingType exprType, int scale, KeyPart keyPart) throws SQLException {
         for(BigDecimal rhsDecimal : DECIMALS) {
-            LiteralExpression rhsExpression = LiteralExpression.newConstant(rhsDecimal, DECIMAL);
+            LiteralExpression rhsExpression = LiteralExpression.newConstant(rhsDecimal, PDecimal.INSTANCE);
             for(Relation relation : Relation.values()) {
                 KeyRange keyRange = keyPart.getKeyRange(relation.compareOp, rhsExpression);
                 verifyKeyRange(exprType, scale, relation, rhsDecimal, keyRange);
             }
         }
     }
-    
+
     /**
      * Checks that a given KeyRange's boundaries match with the given rounding expression type,
      * rounding scale, relational operator, and right hand side decimal.
      * Does so by checking the decimal values immediately on either side of the KeyRange border and
-     * verifying that they either match or do not match the "where clause" formed by the 
+     * verifying that they either match or do not match the "where clause" formed by the
      * rounding type, scale, relation, and rhs decimal. If a relation should produce an unbounded
      * upper or lower range, verifies that that end of the range is unbounded. Finally, if the
      * range is empty, verifies that the rhs decimal required more precision than could be
@@ -379,19 +382,19 @@ public class RoundFloorCeilExpressionsTest {
     private void verifyKeyRange(RoundingType exprType, int scale, Relation relation, BigDecimal rhs, KeyRange range) throws SQLException {
         // dump of values for debugging
         final String dump = getMessage(exprType, scale, relation, rhs, range);
-        
+
         ImmutableBytesPtr rhsPtr = new ImmutableBytesPtr();
-        LiteralExpression.newConstant(rhs, DECIMAL).evaluate(null, rhsPtr);
-        
+        LiteralExpression.newConstant(rhs, PDecimal.INSTANCE).evaluate(null, rhsPtr);
+
         ImmutableBytesPtr lhsPtr = new ImmutableBytesPtr();
-        
+
         // we should only get an empty range if we can verify that precision makes a match impossible
         if(range == KeyRange.EMPTY_RANGE) {
             assertTrue("should only get empty key range for unmatchable rhs precision (" + dump + ")", rhs.scale() > scale);
             assertEquals("should only get empty key range for equals checks (" + dump + ")", Relation.EQUAL, relation);
             return;
         }
-        
+
         // if it should have an upper bound
         if(relation != Relation.GREATER && relation != Relation.GREATER_OR_EQUAL) {
             // figure out what the upper bound is
@@ -405,20 +408,20 @@ public class RoundFloorCeilExpressionsTest {
                 highestHighIncluded = prevDecimalKey(range.getUpperRange());
                 lowestHighExcluded = range.getUpperRange();
             }
-            
+
             // check on either side of the boundary to validate that it is in fact the boundary
             exprType.getExpression(highestHighIncluded, scale).evaluate(null, lhsPtr);
-            assertTrue("incorrectly excluding " + DECIMAL.toObject(highestHighIncluded) 
+            assertTrue("incorrectly excluding " + PDecimal.INSTANCE.toObject(highestHighIncluded)
                 + " in upper bound for " + dump, relation.compare(lhsPtr, rhsPtr));
             exprType.getExpression(lowestHighExcluded, scale).evaluate(null, lhsPtr);
-            assertFalse("incorrectly including " + DECIMAL.toObject(lowestHighExcluded) 
+            assertFalse("incorrectly including " + PDecimal.INSTANCE.toObject(lowestHighExcluded)
                 + " in upper bound for " + dump, relation.compare(lhsPtr, rhsPtr));
         }
         else {
             // otherwise verify that it does not have an upper bound
             assertTrue("should not have a upper bound for " + dump, range.upperUnbound());
         }
-        
+
         // if it should have a lower bound
         if(relation != Relation.LESS && relation != Relation.LESS_OR_EQUAL) {
             // figure out what the lower bound is
@@ -432,13 +435,13 @@ public class RoundFloorCeilExpressionsTest {
                 lowestLowIncluded = nextDecimalKey(range.getLowerRange());
                 highestLowExcluded = range.getLowerRange();
             }
-            
+
             // check on either side of the boundary to validate that it is in fact the boundary
             exprType.getExpression(lowestLowIncluded, scale).evaluate(null, lhsPtr);
-            assertTrue("incorrectly excluding " + DECIMAL.toObject(lowestLowIncluded) 
+            assertTrue("incorrectly excluding " + PDecimal.INSTANCE.toObject(lowestLowIncluded)
                 + " in lower bound for " + dump, relation.compare(lhsPtr, rhsPtr));
             exprType.getExpression(highestLowExcluded, scale).evaluate(null, lhsPtr);
-            assertFalse("incorrectly including " + DECIMAL.toObject(highestLowExcluded) 
+            assertFalse("incorrectly including " + PDecimal.INSTANCE.toObject(highestLowExcluded)
                 + " in lower bound for " + dump, relation.compare(lhsPtr, rhsPtr));
         }
         else {
@@ -446,7 +449,7 @@ public class RoundFloorCeilExpressionsTest {
             assertTrue("should not have a lower bound for " + dump, range.lowerUnbound());
         }
     }
-    
+
     /**
      * Produces the previous Decimal key relative to the given key. The new key will differ from
      * the old key in as small a unit as possible while still maintaining accurate serialization.
@@ -454,11 +457,11 @@ public class RoundFloorCeilExpressionsTest {
      * @return  bytes for the new Decimal key, a single unit previous to the old one
      */
     private static byte[] prevDecimalKey(byte[] key) {
-        BigDecimal decimal = (BigDecimal) DECIMAL.toObject(key);
+        BigDecimal decimal = (BigDecimal) PDecimal.INSTANCE.toObject(key);
         BigDecimal prev = decimal.subtract(getSmallestUnit(decimal));
-        return DECIMAL.toBytes(prev);
+        return PDecimal.INSTANCE.toBytes(prev);
     }
-    
+
     /**
      * Produces the next Decimal key relative to the given key. The new key will differ from the
      * old key in as small a unit as possible while still maintaining accurate serialization.
@@ -466,14 +469,14 @@ public class RoundFloorCeilExpressionsTest {
      * @return  bytes for the new Decimal key, a single unit next from the old one
      */
     private static byte[] nextDecimalKey(byte[] key) {
-        BigDecimal decimal = (BigDecimal) DECIMAL.toObject(key);
+        BigDecimal decimal = (BigDecimal) PDecimal.INSTANCE.toObject(key);
         BigDecimal next = decimal.add(getSmallestUnit(decimal));
-        return DECIMAL.toBytes(next);
+        return PDecimal.INSTANCE.toBytes(next);
     }
-    
+
     /**
      * Produces the smallest unit of difference possible for the given decimal that will still
-     * be serialized accurately. For example, if the MAXIMUM_RELIABLE_PRECISION were 4, then 
+     * be serialized accurately. For example, if the MAXIMUM_RELIABLE_PRECISION were 4, then
      * getSmallestUnit(2.3) would produce 0.001, as 2.301 could be serialized accurately but
      * 2.3001 could not.
      * @param decimal  the decimal to find the smallest unit in relation to
@@ -493,7 +496,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testRoundDateExpression() throws Exception {
-        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.DAY);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -507,7 +510,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testRoundDateExpressionWithMultiplier() throws Exception {
-        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.MINUTE, 10);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -521,7 +524,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testFloorDateExpression() throws Exception {
-        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.DAY);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -535,7 +538,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testFloorDateExpressionWithMultiplier() throws Exception {
-        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.SECOND, 10);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -549,7 +552,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testCeilDateExpression() throws Exception {
-        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.DAY);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -563,7 +566,7 @@ public class RoundFloorCeilExpressionsTest {
     
     @Test
     public void testCeilDateExpressionWithMultiplier() throws Exception {
-        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.SECOND, 10);
         
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
@@ -580,7 +583,7 @@ public class RoundFloorCeilExpressionsTest {
      */
     @Test
     public void testRoundDateExpressionValidation_1() throws Exception {
-        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
+        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
         
         List<Expression> childExpressions = new ArrayList<Expression>(1);
         childExpressions.add(dateLiteral);
@@ -598,8 +601,8 @@ public class RoundFloorCeilExpressionsTest {
      */
     @Test
     public void testRoundDateExpressionValidation_2() throws Exception {
-        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDataType.DATE);
-        LiteralExpression timeUnitLiteral = LiteralExpression.newConstant("millis", PDataType.VARCHAR);
+        LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
+        LiteralExpression timeUnitLiteral = LiteralExpression.newConstant("millis", PVarchar.INSTANCE);
         
         List<Expression> childExpressions = new ArrayList<Expression>(1);
         childExpressions.add(dateLiteral);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
index d7f4172..464153d 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
@@ -30,6 +30,19 @@ import java.util.TimeZone;
 
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PUnsignedDouble;
+import org.apache.phoenix.schema.types.PUnsignedFloat;
+import org.apache.phoenix.schema.types.PUnsignedInt;
+import org.apache.phoenix.schema.types.PUnsignedLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.junit.Test;
 
 import com.google.common.collect.Lists;
@@ -50,7 +63,7 @@ import org.apache.phoenix.expression.function.ToNumberFunction;
 import org.apache.phoenix.expression.function.TrimFunction;
 import org.apache.phoenix.expression.function.UpperFunction;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.DateUtil;
 
 /**
@@ -60,31 +73,31 @@ public class SortOrderExpressionTest {
     
     @Test
     public void substr() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.CHAR), getLiteral(3), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE), getLiteral(3), getLiteral(2));
         evaluateAndAssertResult(new SubstrFunction(args), "ah");
     }
     
     @Test
     public void regexpSubstr() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.CHAR), getLiteral("l.h"), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE), getLiteral("l.h"), getLiteral(2));
         evaluateAndAssertResult(new RegexpSubstrFunction(args), "lah");
     }
     
     @Test
     public void regexpReplace() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.CHAR), getLiteral("l.h"), getLiteral("foo"));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE), getLiteral("l.h"), getLiteral("foo"));
         evaluateAndAssertResult(new RegexpReplaceFunction(args), "bfoo");
     }
     
     @Test
     public void ltrim() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("   blah", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("   blah", PChar.INSTANCE));
         evaluateAndAssertResult(new LTrimFunction(args), "blah");
     }
     
     @Test
     public void substrLtrim() throws Exception {
-        List<Expression> ltrimArgs = Lists.newArrayList(getInvertedLiteral("   blah", PDataType.CHAR));
+        List<Expression> ltrimArgs = Lists.newArrayList(getInvertedLiteral("   blah", PChar.INSTANCE));
         Expression ltrim = new LTrimFunction(ltrimArgs);
         List<Expression> substrArgs = Lists.newArrayList(ltrim, getLiteral(3), getLiteral(2));
         evaluateAndAssertResult(new SubstrFunction(substrArgs), "ah");
@@ -92,157 +105,157 @@ public class SortOrderExpressionTest {
     
     @Test
     public void rtrim() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah    ", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah    ", PChar.INSTANCE));
         evaluateAndAssertResult(new RTrimFunction(args), "blah");
     }
     
     @Test
     public void lower() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("BLAH", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("BLAH", PChar.INSTANCE));
         evaluateAndAssertResult(new LowerFunction(args), "blah");        
     }
     
     @Test
     public void upper() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE));
         evaluateAndAssertResult(new UpperFunction(args), "BLAH");        
     }
     
     @Test
     public void length() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PChar.INSTANCE));
         evaluateAndAssertResult(new LengthFunction(args), 4);
     }
     
     @Test
     public void round() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(date(12, 11, 2001), PDataType.DATE), getLiteral("hour"), getLiteral(1));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(date(12, 11, 2001), PDate.INSTANCE), getLiteral("hour"), getLiteral(1));
         evaluateAndAssertResult(RoundDateExpression.create(args), date(12, 11, 2001));
     }
     
     @Test
     public void sqlTypeName() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(12, PDataType.INTEGER));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(12, PInteger.INSTANCE));
         evaluateAndAssertResult(new SqlTypeNameFunction(args), "VARCHAR");        
     }
     
     @Test
     public void toChar() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(date(12, 11, 2001), PDataType.DATE));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(date(12, 11, 2001), PDate.INSTANCE));
         evaluateAndAssertResult(new ToCharFunction(args, FunctionArgumentType.TEMPORAL, "", DateUtil.getDateFormatter("MM/dd/yy hh:mm a")), "12/11/01 12:00 AM");
     }
     
     @Test
     public void toDate() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("2001-11-30 00:00:00:0", PDataType.VARCHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("2001-11-30 00:00:00:0", PVarchar.INSTANCE));
         evaluateAndAssertResult(new ToDateFunction(args, null, DateUtil.getDateParser("yyyy-MM-dd HH:mm:ss:S")), date(11, 30, 2001));
     }
     
     @Test
     public void toNumber() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("10", PDataType.VARCHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("10", PVarchar.INSTANCE));
         evaluateAndAssertResult(new ToNumberFunction(args, FunctionArgumentType.CHAR, "", null), new BigDecimal(BigInteger.valueOf(1), -1));
     }
     
     @Test
     public void trim() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("   blah    ", PDataType.CHAR));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("   blah    ", PChar.INSTANCE));
         evaluateAndAssertResult(new TrimFunction(args), "blah");
     }
     
     @Test
     public void lpad() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("ABCD", PDataType.CHAR), getLiteral(7), getLiteral("12"));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("ABCD", PChar.INSTANCE), getLiteral(7), getLiteral("12"));
         evaluateAndAssertResult(new LpadFunction(args), "121ABCD");
     }
     
     @Test
     public void add() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DecimalAddExpression(args), BigDecimal.valueOf(12));
         
-        args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new LongAddExpression(args), 12l);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleAddExpression(args), 12.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleAddExpression(args), 12.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleAddExpression(args), 12.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleAddExpression(args), 12.0);
     }
 
     @Test
     public void subtract() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DecimalSubtractExpression(args), BigDecimal.valueOf(8));
         
-        args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new LongSubtractExpression(args), 8l);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleSubtractExpression(args), 8.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleSubtractExpression(args), 8.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleSubtractExpression(args), 8.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleSubtractExpression(args), 8.0);
     }
     
     @Test
     public void divide() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DecimalDivideExpression(args), BigDecimal.valueOf(5));
         
-        args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new LongDivideExpression(args), 5l);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleDivideExpression(args), 5.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleDivideExpression(args), 5.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleDivideExpression(args), 5.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleDivideExpression(args), 5.0);
     }
     
     @Test
     public void multiply() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DecimalMultiplyExpression(args), new BigDecimal(BigInteger.valueOf(2), -1));
         
-        args = Lists.newArrayList(getInvertedLiteral(10, PDataType.INTEGER), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10, PInteger.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new LongMultiplyExpression(args), 20l);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleMultiplyExpression(args), 20.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_FLOAT), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedFloat.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleMultiplyExpression(args), 20.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.UNSIGNED_DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PUnsignedDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleMultiplyExpression(args), 20.0);
         
-        args = Lists.newArrayList(getInvertedLiteral(10.0, PDataType.DOUBLE), getLiteral(2));
+        args = Lists.newArrayList(getInvertedLiteral(10.0, PDouble.INSTANCE), getLiteral(2));
         evaluateAndAssertResult(new DoubleMultiplyExpression(args), 20.0);
     }
         
     @Test
     public void compareNumbers() throws Exception {
-        PDataType[] numberDataTypes = new PDataType[]{PDataType.INTEGER, PDataType.LONG, PDataType.DECIMAL, PDataType.UNSIGNED_INT, PDataType.UNSIGNED_LONG};
+        PDataType[] numberDataTypes = new PDataType[]{ PInteger.INSTANCE, PLong.INSTANCE, PDecimal.INSTANCE, PUnsignedInt.INSTANCE, PUnsignedLong.INSTANCE};
         for (PDataType lhsDataType : numberDataTypes) {
             for (PDataType rhsDataType : numberDataTypes) {
                 runCompareTest(CompareOp.GREATER, true, 10, lhsDataType, 2, rhsDataType);
@@ -252,7 +265,7 @@ public class SortOrderExpressionTest {
     
     @Test
     public void compareCharacters() throws Exception {
-        PDataType[] textDataTypes = new PDataType[]{PDataType.CHAR, PDataType.VARCHAR};
+        PDataType[] textDataTypes = new PDataType[]{ PChar.INSTANCE, PVarchar.INSTANCE};
         for (PDataType lhsDataType : textDataTypes) {
             for (PDataType rhsDataType : textDataTypes) {
                 runCompareTest(CompareOp.GREATER, true, "xxx", lhsDataType, "bbb", rhsDataType);
@@ -262,15 +275,15 @@ public class SortOrderExpressionTest {
     
     @Test
     public void compareBooleans() throws Exception {
-        runCompareTest(CompareOp.GREATER, true, true, PDataType.BOOLEAN, false, PDataType.BOOLEAN);        
+        runCompareTest(CompareOp.GREATER, true, true, PBoolean.INSTANCE, false, PBoolean.INSTANCE);
     }
     
     @Test
     public void stringConcat() throws Exception {
-        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.VARCHAR), getInvertedLiteral("foo", PDataType.VARCHAR)); 
+        List<Expression> args = Lists.newArrayList(getInvertedLiteral("blah", PVarchar.INSTANCE), getInvertedLiteral("foo", PVarchar.INSTANCE));
         evaluateAndAssertResult(new StringConcatExpression(args), "blahfoo");
         
-        args = Lists.newArrayList(getInvertedLiteral("blah", PDataType.VARCHAR), getInvertedLiteral(10, PDataType.INTEGER)); 
+        args = Lists.newArrayList(getInvertedLiteral("blah", PVarchar.INSTANCE), getInvertedLiteral(10, PInteger.INSTANCE));
         evaluateAndAssertResult(new StringConcatExpression(args), "blah10");        
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
index bc32414..7f9cc9b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
@@ -21,7 +21,8 @@ import com.google.common.collect.Lists;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PIntegerArray;
 import org.junit.Test;
 
 import java.sql.SQLException;
@@ -35,7 +36,7 @@ public class ExternalSqlTypeIdFunctionTest {
     @Test
     public void testEvaluate() throws SQLException {
         Expression inputArg = LiteralExpression.newConstant(
-                PDataType.INTEGER.getSqlType(), PDataType.INTEGER);
+                PInteger.INSTANCE.getSqlType(), PInteger.INSTANCE);
 
         Object returnValue = executeFunction(inputArg);
 
@@ -45,7 +46,7 @@ public class ExternalSqlTypeIdFunctionTest {
     @Test
     public void testEvaluateArrayType() throws SQLException {
         Expression inputArg = LiteralExpression.newConstant(
-                PDataType.INTEGER_ARRAY.getSqlType(), PDataType.INTEGER);
+                PIntegerArray.INSTANCE.getSqlType(), PInteger.INSTANCE);
 
         Object returnValue = executeFunction(inputArg);
 
@@ -59,7 +60,7 @@ public class ExternalSqlTypeIdFunctionTest {
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         assertTrue(externalIdFunction.evaluate(null, ptr));
 
-        return PDataType.INTEGER.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(),
-                PDataType.INTEGER, inputArg.getSortOrder());
+        return PInteger.INSTANCE.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(),
+            PInteger.INSTANCE, inputArg.getSortOrder());
     }
 }


[04/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/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
deleted file mode 100644
index 7c84928..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeTest.java
+++ /dev/null
@@ -1,1678 +0,0 @@
-/*
- * 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.schema;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Date;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.Test;
-
-
-public class PDataTypeTest {
-    @Test
-    public void testFloatToLongComparison() {
-        // Basic tests
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(1e100), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(0.001), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-
-        // Edge tests
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MAX_VALUE), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MAX_VALUE - 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MIN_VALUE + 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MAX_VALUE + 1.0F), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MAX_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0); // Passes due to rounding
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MAX_VALUE + 129.0F), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MAX_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MIN_VALUE - 128.0F), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(Integer.MIN_VALUE - 129.0F), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-
-        float f1 = 9111111111111111.0F;
-        float f2 = 9111111111111112.0F;
-        assertTrue(f1 == f2);
-        long la = 9111111111111111L;
-        assertTrue(f1 > Integer.MAX_VALUE);
-        assertTrue(la == f1);
-        assertTrue(la == f2);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(f1), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(la), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.FLOAT.compareTo(PDataType.FLOAT.toBytes(f2), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(la), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-
-        // Same as above, but reversing LHS and RHS
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT.toBytes(1e100), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) < 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT.toBytes(0.001), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) > 0);
-
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MAX_VALUE - 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MAX_VALUE), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) < 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MIN_VALUE + 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MIN_VALUE), 0,
-                PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) > 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MIN_VALUE), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MAX_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MAX_VALUE + 1.0F), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT) < 0); // Passes due to rounding
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MAX_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MAX_VALUE + 129.0F), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT) < 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MIN_VALUE - 128.0F), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Integer.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.FLOAT.toBytes(Integer.MIN_VALUE - 129.0F), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT) > 0);
-
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(la), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT.toBytes(f1), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(la), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.FLOAT.toBytes(f2), 0, PDataType.FLOAT.getByteSize(), SortOrder.getDefault(), PDataType.FLOAT) == 0);
-    }        
-        
-    @Test
-    public void testDoubleToDecimalComparison() {
-        // Basic tests
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(1.23), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                   PDataType.DECIMAL.toBytes(BigDecimal.valueOf(1.24)), 0, PDataType.DECIMAL.getByteSize(), SortOrder.getDefault(), PDataType.DECIMAL) < 0);
-    }
-    
-    @Test
-    public void testDoubleToLongComparison() {
-        // Basic tests
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(-1e100), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(0.001), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MAX_VALUE), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MAX_VALUE - 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MIN_VALUE), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MIN_VALUE + 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MIN_VALUE), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MAX_VALUE + 1024.0), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MAX_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MAX_VALUE + 1025.0), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MAX_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) > 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MIN_VALUE - 1024.0), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) == 0);
-        assertTrue(PDataType.DOUBLE.compareTo(PDataType.DOUBLE.toBytes(Long.MIN_VALUE - 1025.0), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.LONG.toBytes(Long.MIN_VALUE), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.LONG) < 0);
-
-        // Same as above, but reversing LHS and RHS
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE.toBytes(-1e100), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE) > 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(1), 0, PDataType.LONG.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE.toBytes(0.001), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE) > 0);
-
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MAX_VALUE - 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MAX_VALUE), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE) < 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MIN_VALUE + 1), 0,
-                PDataType.LONG.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MIN_VALUE), 0,
-                PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(), PDataType.DOUBLE) > 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MIN_VALUE), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MAX_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MAX_VALUE + 1024.0), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MAX_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MAX_VALUE + 1025.0), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE) < 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MIN_VALUE - 1024.0), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE) == 0);
-        assertTrue(PDataType.LONG.compareTo(PDataType.LONG.toBytes(Long.MIN_VALUE), 0, PDataType.LONG.getByteSize(),
-        		SortOrder.getDefault(), PDataType.DOUBLE.toBytes(Long.MIN_VALUE - 1025.0), 0, PDataType.DOUBLE.getByteSize(), SortOrder.getDefault(),
-                PDataType.DOUBLE) > 0);
-
-        long i = 10;
-        long maxl = (1L << 62);
-        try {
-            for (; i < 100; i++) {
-                double d = Math.pow(2, i);
-                if ((long)d > maxl) {
-                    assertTrue(i > 62);
-                    continue;
-                }
-                long l = (1L << i) - 1;
-                assertTrue(l + 1L == (long)d);
-                assertTrue(l < (long)d);
-            }
-        } catch (AssertionError t) {
-            throw t;
-        }
-        double d = 0.0;
-        try {
-            while (d <= 1024) {
-                double d1 = Long.MAX_VALUE;
-                double d2 = Long.MAX_VALUE + d;
-                assertTrue(d2 == d1);
-                d++;
-            }
-        } catch (AssertionError t) {
-            throw t;
-        }
-        d = 0.0;
-        try {
-            while (d >= -1024) {
-                double d1 = Long.MIN_VALUE;
-                double d2 = Long.MIN_VALUE + d;
-                assertTrue(d2 == d1);
-                d--;
-            }
-        } catch (AssertionError t) {
-            throw t;
-        }
-        double d1 = Long.MAX_VALUE;
-        double d2 = Long.MAX_VALUE + 1024.0;
-        double d3 = Long.MAX_VALUE + 1025.0;
-        assertTrue(d1 == d2);
-        assertTrue(d3 > d1);
-        long l1 = Long.MAX_VALUE - 1;
-        assertTrue((long)d1 > l1);
-    }
-        
-    @Test
-    public void testLong() {
-        Long la = 4L;
-        byte[] b = PDataType.LONG.toBytes(la);
-        Long lb = (Long)PDataType.LONG.toObject(b);
-        assertEquals(la,lb);
-
-        Long na = 1L;
-        Long nb = -1L;
-        byte[] ba = PDataType.LONG.toBytes(na);
-        byte[] bb = PDataType.LONG.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.LONG.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Long);
-        assertEquals(100, ((Long)obj).longValue());
-        
-        Long longValue = 100l;
-        Object longObj = PDataType.LONG.toObject(longValue, PDataType.LONG);
-        assertTrue(longObj instanceof Long);
-        assertEquals(100, ((Long)longObj).longValue());
-        
-        assertEquals(0, PDataType.LONG.compareTo(Long.MAX_VALUE, Float.valueOf(Long.MAX_VALUE), PDataType.FLOAT));
-        assertEquals(0, PDataType.LONG.compareTo(Long.MAX_VALUE, Double.valueOf(Long.MAX_VALUE), PDataType.DOUBLE));
-        assertEquals(-1, PDataType.LONG.compareTo(99, Float.valueOf(100), PDataType.FLOAT));
-        assertEquals(1, PDataType.LONG.compareTo(101, Float.valueOf(100), PDataType.FLOAT));
-        
-        Double d = -2.0;
-        Object lo = PDataType.LONG.toObject(d, PDataType.DOUBLE);
-        assertEquals(-2L, ((Long)lo).longValue());
-        
-        byte[] bytes = PDataType.DOUBLE.toBytes(d);
-        lo = PDataType.LONG.toObject(bytes,0, bytes.length, PDataType.DOUBLE);
-        assertEquals(-2L, ((Long)lo).longValue());
-        
-        Float f = -2.0f;
-        lo = PDataType.LONG.toObject(f, PDataType.FLOAT);
-        assertEquals(-2L, ((Long)lo).longValue());
-        
-        bytes = PDataType.FLOAT.toBytes(f);
-        lo = PDataType.LONG.toObject(bytes,0, bytes.length, PDataType.FLOAT);
-        assertEquals(-2L, ((Long)lo).longValue());
-        
-        // Checks for unsignedlong
-        d = 2.0;
-        lo = PDataType.UNSIGNED_LONG.toObject(d, PDataType.DOUBLE);
-        assertEquals(2L, ((Long)lo).longValue());
-        
-        bytes = PDataType.DOUBLE.toBytes(d);
-        lo = PDataType.UNSIGNED_LONG.toObject(bytes,0, bytes.length, PDataType.DOUBLE);
-        assertEquals(2L, ((Long)lo).longValue());
-        
-        f = 2.0f;
-        lo = PDataType.UNSIGNED_LONG.toObject(f, PDataType.FLOAT);
-        assertEquals(2L, ((Long)lo).longValue());
-        
-        bytes = PDataType.FLOAT.toBytes(f);
-        lo = PDataType.UNSIGNED_LONG.toObject(bytes,0, bytes.length, PDataType.FLOAT);
-        assertEquals(2L, ((Long)lo).longValue());
-        
-    }
-
-    @Test
-    public void testInt() {
-        Integer na = 4;
-        byte[] b = PDataType.INTEGER.toBytes(na);
-        Integer nb = (Integer)PDataType.INTEGER.toObject(b);
-        assertEquals(na,nb);
-
-        na = 1;
-        nb = -1;
-        byte[] ba = PDataType.INTEGER.toBytes(na);
-        byte[] bb = PDataType.INTEGER.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -1;
-        nb = -3;
-        ba = PDataType.INTEGER.toBytes(na);
-        bb = PDataType.INTEGER.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -3;
-        nb = -100000000;
-        ba = PDataType.INTEGER.toBytes(na);
-        bb = PDataType.INTEGER.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Long value = 100l;
-        Object obj = PDataType.INTEGER.toObject(value, PDataType.LONG);
-        assertTrue(obj instanceof Integer);
-        assertEquals(100, ((Integer)obj).intValue());
-        
-        Float unsignedFloatValue = 100f;
-        Object unsignedFloatObj = PDataType.INTEGER.toObject(unsignedFloatValue, PDataType.UNSIGNED_FLOAT);
-        assertTrue(unsignedFloatObj instanceof Integer);
-        assertEquals(100, ((Integer)unsignedFloatObj).intValue());
-        
-        Double unsignedDoubleValue = 100d;
-        Object unsignedDoubleObj = PDataType.INTEGER.toObject(unsignedDoubleValue, PDataType.UNSIGNED_DOUBLE);
-        assertTrue(unsignedDoubleObj instanceof Integer);
-        assertEquals(100, ((Integer)unsignedDoubleObj).intValue());
-        
-        Float floatValue = 100f;
-        Object floatObj = PDataType.INTEGER.toObject(floatValue, PDataType.FLOAT);
-        assertTrue(floatObj instanceof Integer);
-        assertEquals(100, ((Integer)floatObj).intValue());
-        
-        Double doubleValue = 100d;
-        Object doubleObj = PDataType.INTEGER.toObject(doubleValue, PDataType.DOUBLE);
-        assertTrue(doubleObj instanceof Integer);
-        assertEquals(100, ((Integer)doubleObj).intValue());
-        
-        Short shortValue = 100;
-        Object shortObj = PDataType.INTEGER.toObject(shortValue, PDataType.SMALLINT);
-        assertTrue(shortObj instanceof Integer);
-        assertEquals(100, ((Integer)shortObj).intValue());
-    }
-    
-    @Test
-    public void testSmallInt() {
-        Short na = 4;
-        byte[] b = PDataType.SMALLINT.toBytes(na);
-        Short nb = (Short)PDataType.SMALLINT.toObject(b);
-        assertEquals(na,nb);
-        
-        na = 4;
-        b = PDataType.SMALLINT.toBytes(na, SortOrder.DESC);
-        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-        ptr.set(b);
-        nb = PDataType.SMALLINT.getCodec().decodeShort(ptr, SortOrder.DESC);
-        assertEquals(na,nb);
-
-        na = 1;
-        nb = -1;
-        byte[] ba = PDataType.SMALLINT.toBytes(na);
-        byte[] bb = PDataType.SMALLINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -1;
-        nb = -3;
-        ba = PDataType.SMALLINT.toBytes(na);
-        bb = PDataType.SMALLINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -3;
-        nb = -10000;
-        ba = PDataType.SMALLINT.toBytes(na);
-        bb = PDataType.SMALLINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.SMALLINT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Short);
-        assertEquals(100, ((Short)obj).shortValue());
-        
-        Float unsignedFloatValue = 100f;
-        Object unsignedFloatObj = PDataType.SMALLINT.toObject(unsignedFloatValue, PDataType.UNSIGNED_FLOAT);
-        assertTrue(unsignedFloatObj instanceof Short);
-        assertEquals(100, ((Short)unsignedFloatObj).shortValue());
-        
-        Double unsignedDoubleValue = 100d;
-        Object unsignedDoubleObj = PDataType.SMALLINT.toObject(unsignedDoubleValue, PDataType.UNSIGNED_DOUBLE);
-        assertTrue(unsignedDoubleObj instanceof Short);
-        assertEquals(100, ((Short)unsignedDoubleObj).shortValue());
-        
-        Float floatValue = 100f;
-        Object floatObj = PDataType.SMALLINT.toObject(floatValue, PDataType.FLOAT);
-        assertTrue(floatObj instanceof Short);
-        assertEquals(100, ((Short)floatObj).shortValue());
-        
-        Double doubleValue = 100d;
-        Object doubleObj = PDataType.SMALLINT.toObject(doubleValue, PDataType.DOUBLE);
-        assertTrue(doubleObj instanceof Short);
-        assertEquals(100, ((Short)doubleObj).shortValue());
-    }
-    
-    @Test
-    public void testTinyInt() {
-        Byte na = 4;
-        byte[] b = PDataType.TINYINT.toBytes(na);
-        Byte nb = (Byte)PDataType.TINYINT.toObject(b);
-        assertEquals(na,nb);
-
-        na = 1;
-        nb = -1;
-        byte[] ba = PDataType.TINYINT.toBytes(na);
-        byte[] bb = PDataType.TINYINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -1;
-        nb = -3;
-        ba = PDataType.TINYINT.toBytes(na);
-        bb = PDataType.TINYINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -3;
-        nb = -100;
-        ba = PDataType.TINYINT.toBytes(na);
-        bb = PDataType.TINYINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.TINYINT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Byte);
-        assertEquals(100, ((Byte)obj).byteValue());
-        
-        Float floatValue = 100f;
-        Object floatObj = PDataType.TINYINT.toObject(floatValue, PDataType.FLOAT);
-        assertTrue(floatObj instanceof Byte);
-        assertEquals(100, ((Byte)floatObj).byteValue());
-        
-        Float unsignedFloatValue = 100f;
-        Object unsignedFloatObj = PDataType.TINYINT.toObject(unsignedFloatValue, PDataType.UNSIGNED_FLOAT);
-        assertTrue(unsignedFloatObj instanceof Byte);
-        assertEquals(100, ((Byte)unsignedFloatObj).byteValue());
-        
-        Double unsignedDoubleValue = 100d;
-        Object unsignedDoubleObj = PDataType.TINYINT.toObject(unsignedDoubleValue, PDataType.UNSIGNED_DOUBLE);
-        assertTrue(unsignedDoubleObj instanceof Byte);
-        assertEquals(100, ((Byte)unsignedDoubleObj).byteValue());
-        
-        Double doubleValue = 100d;
-        Object doubleObj = PDataType.TINYINT.toObject(doubleValue, PDataType.DOUBLE);
-        assertTrue(doubleObj instanceof Byte);
-        assertEquals(100, ((Byte)doubleObj).byteValue());
-    }
-    
-    @Test
-    public void testUnsignedSmallInt() {
-        Short na = 4;
-        byte[] b = PDataType.UNSIGNED_SMALLINT.toBytes(na);
-        Short nb = (Short)PDataType.UNSIGNED_SMALLINT.toObject(b);
-        assertEquals(na,nb);
-
-        na = 10;
-        nb = 8;
-        byte[] ba = PDataType.UNSIGNED_SMALLINT.toBytes(na);
-        byte[] bb = PDataType.UNSIGNED_SMALLINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.UNSIGNED_SMALLINT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Short);
-        assertEquals(100, ((Short)obj).shortValue());
-        
-        Float floatValue = 100f;
-        Object floatObj = PDataType.UNSIGNED_SMALLINT.toObject(floatValue, PDataType.FLOAT);
-        assertTrue(floatObj instanceof Short);
-        assertEquals(100, ((Short)floatObj).shortValue());
-        
-        Float unsignedFloatValue = 100f;
-        Object unsignedFloatObj = PDataType.UNSIGNED_SMALLINT.toObject(unsignedFloatValue, PDataType.UNSIGNED_FLOAT);
-        assertTrue(unsignedFloatObj instanceof Short);
-        assertEquals(100, ((Short)unsignedFloatObj).shortValue());
-        
-        Double unsignedDoubleValue = 100d;
-        Object unsignedDoubleObj = PDataType.UNSIGNED_SMALLINT.toObject(unsignedDoubleValue, PDataType.UNSIGNED_DOUBLE);
-        assertTrue(unsignedDoubleObj instanceof Short);
-        assertEquals(100, ((Short)unsignedDoubleObj).shortValue());
-        
-        Double doubleValue = 100d;
-        Object doubleObj = PDataType.UNSIGNED_SMALLINT.toObject(doubleValue, PDataType.DOUBLE);
-        assertTrue(doubleObj instanceof Short);
-        assertEquals(100, ((Short)doubleObj).shortValue());
-    }
-    
-    @Test
-    public void testUnsignedTinyInt() {
-        Byte na = 4;
-        byte[] b = PDataType.UNSIGNED_TINYINT.toBytes(na);
-        Byte nb = (Byte)PDataType.UNSIGNED_TINYINT.toObject(b);
-        assertEquals(na,nb);
-
-        na = 10;
-        nb = 8;
-        byte[] ba = PDataType.UNSIGNED_TINYINT.toBytes(na);
-        byte[] bb = PDataType.UNSIGNED_TINYINT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.UNSIGNED_TINYINT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Byte);
-        assertEquals(100, ((Byte)obj).byteValue());
-        
-        Float floatValue = 100f;
-        Object floatObj = PDataType.UNSIGNED_TINYINT.toObject(floatValue, PDataType.FLOAT);
-        assertTrue(floatObj instanceof Byte);
-        assertEquals(100, ((Byte)floatObj).byteValue());
-        
-        Float unsignedFloatValue = 100f;
-        Object unsignedFloatObj = PDataType.UNSIGNED_TINYINT.toObject(unsignedFloatValue, PDataType.UNSIGNED_FLOAT);
-        assertTrue(unsignedFloatObj instanceof Byte);
-        assertEquals(100, ((Byte)unsignedFloatObj).byteValue());
-        
-        Double unsignedDoubleValue = 100d;
-        Object unsignedDoubleObj = PDataType.UNSIGNED_TINYINT.toObject(unsignedDoubleValue, PDataType.UNSIGNED_DOUBLE);
-        assertTrue(unsignedDoubleObj instanceof Byte);
-        assertEquals(100, ((Byte)unsignedDoubleObj).byteValue());
-        
-        Double doubleValue = 100d;
-        Object doubleObj = PDataType.UNSIGNED_TINYINT.toObject(doubleValue, PDataType.DOUBLE);
-        assertTrue(doubleObj instanceof Byte);
-        assertEquals(100, ((Byte)doubleObj).byteValue());
-    }
-    
-    @Test
-    public void testUnsignedFloat() {
-        Float na = 0.005f;
-        byte[] b = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        Float nb = (Float)PDataType.UNSIGNED_FLOAT.toObject(b);
-        assertEquals(na,nb);
-        
-        na = 10.0f;
-        b = PDataType.UNSIGNED_FLOAT.toBytes(na, SortOrder.DESC);
-        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-        ptr.set(b);
-        nb = PDataType.UNSIGNED_FLOAT.getCodec().decodeFloat(ptr, SortOrder.DESC);
-        assertEquals(na,nb);
-        
-        na = 2.0f;
-        nb = 1.0f;
-        byte[] ba = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        byte[] bb = PDataType.UNSIGNED_FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        na = 0.0f;
-        nb = Float.MIN_VALUE;
-        ba = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        bb = PDataType.UNSIGNED_FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.MIN_VALUE;
-        nb = Float.MAX_VALUE;
-        ba = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        bb = PDataType.UNSIGNED_FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.MAX_VALUE;
-        nb = Float.POSITIVE_INFINITY;
-        ba = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        bb = PDataType.UNSIGNED_FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.POSITIVE_INFINITY;
-        nb = Float.NaN;
-        ba = PDataType.UNSIGNED_FLOAT.toBytes(na);
-        bb = PDataType.UNSIGNED_FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.UNSIGNED_FLOAT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Float);
-    }
-    
-    @Test
-    public void testUnsignedDouble() {
-        Double na = 0.005;
-        byte[] b = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        Double nb = (Double)PDataType.UNSIGNED_DOUBLE.toObject(b);
-        assertEquals(na,nb);
-        
-        na = 10.0;
-        b = PDataType.UNSIGNED_DOUBLE.toBytes(na, SortOrder.DESC);
-        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-        ptr.set(b);
-        nb = PDataType.UNSIGNED_DOUBLE.getCodec().decodeDouble(ptr, SortOrder.DESC);
-        assertEquals(na,nb);
-
-        na = 2.0;
-        nb = 1.0;
-        byte[] ba = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        byte[] bb = PDataType.UNSIGNED_DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        na = 0.0;
-        nb = Double.MIN_VALUE;
-        ba = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        bb = PDataType.UNSIGNED_DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.MIN_VALUE;
-        nb = Double.MAX_VALUE;
-        ba = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        bb = PDataType.UNSIGNED_DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.MAX_VALUE;
-        nb = Double.POSITIVE_INFINITY;
-        ba = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        bb = PDataType.UNSIGNED_DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.POSITIVE_INFINITY;
-        nb = Double.NaN;
-        ba = PDataType.UNSIGNED_DOUBLE.toBytes(na);
-        bb = PDataType.UNSIGNED_DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.UNSIGNED_DOUBLE.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Double);
-        
-        assertEquals(1, PDataType.UNSIGNED_DOUBLE.compareTo(Double.valueOf(101), Long.valueOf(100), PDataType.LONG));
-        assertEquals(0, PDataType.UNSIGNED_DOUBLE.compareTo(Double.valueOf(Long.MAX_VALUE), Long.MAX_VALUE, PDataType.LONG));
-        assertEquals(-1, PDataType.UNSIGNED_DOUBLE.compareTo(Double.valueOf(1), Long.valueOf(100), PDataType.LONG));
-        
-        assertEquals(0, PDataType.UNSIGNED_DOUBLE.compareTo(Double.valueOf(101), BigDecimal.valueOf(101.0), PDataType.DECIMAL));
-    }
-    
-    @Test
-    public void testFloat() {
-        Float na = 0.005f;
-        byte[] b = PDataType.FLOAT.toBytes(na);
-        Float nb = (Float)PDataType.FLOAT.toObject(b);
-        assertEquals(na,nb);
-        
-        na = 10.0f;
-        b = PDataType.FLOAT.toBytes(na, SortOrder.DESC);
-        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-        ptr.set(b);
-        nb = PDataType.FLOAT.getCodec().decodeFloat(ptr, SortOrder.DESC);
-        assertEquals(na,nb);
-        
-        na = 1.0f;
-        nb = -1.0f;
-        byte[] ba = PDataType.FLOAT.toBytes(na);
-        byte[] bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -1f;
-        nb = -3f;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        na = Float.NEGATIVE_INFINITY;
-        nb = -Float.MAX_VALUE;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -Float.MAX_VALUE;
-        nb = -Float.MIN_VALUE;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -Float.MIN_VALUE;
-        nb = -0.0f;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -0.0f;
-        nb = 0.0f;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = 0.0f;
-        nb = Float.MIN_VALUE;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.MIN_VALUE;
-        nb = Float.MAX_VALUE;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.MAX_VALUE;
-        nb = Float.POSITIVE_INFINITY;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Float.POSITIVE_INFINITY;
-        nb = Float.NaN;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.FLOAT.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Float);
-        
-        Double dvalue = Double.NEGATIVE_INFINITY;
-        obj = PDataType.FLOAT.toObject(dvalue, PDataType.DOUBLE);
-        assertTrue(obj instanceof Float);
-        assertEquals(Float.NEGATIVE_INFINITY, obj);
-        
-        na = 1.0f;
-        nb = -1.0f;
-        ba = PDataType.FLOAT.toBytes(na);
-        bb = PDataType.FLOAT.toBytes(nb);
-        float nna = PDataType.FLOAT.getCodec().decodeFloat(ba, 0, SortOrder.DESC);
-        float nnb = PDataType.FLOAT.getCodec().decodeFloat(bb, 0, SortOrder.DESC);
-        assertTrue(Float.compare(nna, nnb) < 0);
-    }
-    
-    @Test
-    public void testDouble() {
-        Double na = 0.005;
-        byte[] b = PDataType.DOUBLE.toBytes(na);
-        Double nb = (Double)PDataType.DOUBLE.toObject(b);
-        assertEquals(na,nb);
-        
-        na = 10.0;
-        b = PDataType.DOUBLE.toBytes(na, SortOrder.DESC);
-        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-        ptr.set(b);
-        nb = PDataType.DOUBLE.getCodec().decodeDouble(ptr, SortOrder.DESC);
-        assertEquals(na,nb);
-
-        na = 1.0;
-        nb = -1.0;
-        byte[] ba = PDataType.DOUBLE.toBytes(na);
-        byte[] bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-
-        na = -1.0;
-        nb = -3.0;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        
-        na = Double.NEGATIVE_INFINITY;
-        nb = -Double.MAX_VALUE;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -Double.MAX_VALUE;
-        nb = -Double.MIN_VALUE;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -Double.MIN_VALUE;
-        nb = -0.0;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = -0.0;
-        nb = 0.0;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = 0.0;
-        nb = Double.MIN_VALUE;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.MIN_VALUE;
-        nb = Double.MAX_VALUE;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.MAX_VALUE;
-        nb = Double.POSITIVE_INFINITY;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        na = Double.POSITIVE_INFINITY;
-        nb = Double.NaN;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) < 0);
-        
-        Integer value = 100;
-        Object obj = PDataType.DOUBLE.toObject(value, PDataType.INTEGER);
-        assertTrue(obj instanceof Double);
-        
-        na = 1.0;
-        nb = -1.0;
-        ba = PDataType.DOUBLE.toBytes(na);
-        bb = PDataType.DOUBLE.toBytes(nb);
-        double nna = PDataType.DOUBLE.getCodec().decodeDouble(ba, 0, SortOrder.DESC);
-        double nnb = PDataType.DOUBLE.getCodec().decodeDouble(bb, 0, SortOrder.DESC);
-        assertTrue(Double.compare(nna, nnb) < 0);
-        
-        assertEquals(1, PDataType.DOUBLE.compareTo(Double.valueOf(101), Long.valueOf(100), PDataType.LONG));
-        assertEquals(0, PDataType.DOUBLE.compareTo(Double.valueOf(Long.MAX_VALUE), Long.MAX_VALUE, PDataType.LONG));
-        assertEquals(-1, PDataType.DOUBLE.compareTo(Double.valueOf(1), Long.valueOf(100), PDataType.LONG));
-        
-        assertEquals(0, PDataType.DOUBLE.compareTo(Double.valueOf(101), BigDecimal.valueOf(101.0), PDataType.DECIMAL));
-    }
-
-    @Test
-    public void testBigDecimal() {
-        byte[] b;
-        BigDecimal na, nb;
-
-        b = new byte[] {
-                (byte)0xc2,0x02,0x10,0x36,0x22,0x22,0x22,0x22,0x22,0x22,0x0f,0x27,0x38,0x1c,0x05,0x40,0x62,0x21,0x54,0x4d,0x4e,0x01,0x14,0x36,0x0d,0x33
-        };
-        BigDecimal decodedBytes = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(decodedBytes.compareTo(BigDecimal.ZERO) > 0);
-
-        na = new BigDecimal(new BigInteger("12345678901239998123456789"), 2);
-        //[-52, 13, 35, 57, 79, 91, 13, 40, 100, 82, 24, 46, 68, 90]
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        TestUtil.assertRoundEquals(na,nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = new BigDecimal("115.533333333333331438552704639732837677001953125");
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        TestUtil.assertRoundEquals(na,nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-        
-        // test for negative serialization using biginteger
-        na = new BigDecimal("-5.00000000000000000000000001");
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        TestUtil.assertRoundEquals(na,nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-        
-        // test for serialization of 38 digits
-        na = new BigDecimal("-2.4999999999999999999999999999999999999");
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        TestUtil.assertRoundEquals(na,nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-        
-        // test for serialization of 39 digits, should round to -2.5
-        na = new BigDecimal("-2.499999999999999999999999999999999999999");
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(nb.compareTo(new BigDecimal("-2.5")) == 0);
-        assertEquals(new BigDecimal("-2.5"), nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = new BigDecimal(2.5);
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(na.compareTo(nb) == 0);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        // If we don't remove trailing zeros, this fails
-        na = new BigDecimal(Double.parseDouble("96.45238095238095"));
-        String naStr = na.toString();
-        assertTrue(naStr != null);
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        TestUtil.assertRoundEquals(na,nb);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        // If we don't remove trailing zeros, this fails
-        na = new BigDecimal(-1000);
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(na.compareTo(nb) == 0);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = new BigDecimal("1000.5829999999999913");
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(na.compareTo(nb) == 0);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = TestUtil.computeAverage(11000, 3);
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(na.compareTo(nb) == 0);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = new BigDecimal(new BigInteger("12345678901239999"), 2);
-        b = PDataType.DECIMAL.toBytes(na);
-        nb = (BigDecimal)PDataType.DECIMAL.toObject(b);
-        assertTrue(na.compareTo(nb) == 0);
-        assertTrue(b.length <= PDataType.DECIMAL.estimateByteSize(na));
-
-        na = new BigDecimal(1);
-        nb = new BigDecimal(-1);
-        byte[] ba = PDataType.DECIMAL.toBytes(na);
-        byte[] bb = PDataType.DECIMAL.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        assertTrue(ba.length <= PDataType.DECIMAL.estimateByteSize(na));
-        assertTrue(bb.length <= PDataType.DECIMAL.estimateByteSize(nb));
-
-        na = new BigDecimal(-1);
-        nb = new BigDecimal(-2);
-        ba = PDataType.DECIMAL.toBytes(na);
-        bb = PDataType.DECIMAL.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        assertTrue(ba.length <= PDataType.DECIMAL.estimateByteSize(na));
-        assertTrue(bb.length <= PDataType.DECIMAL.estimateByteSize(nb));
-
-        na = new BigDecimal(-3);
-        nb = new BigDecimal(-1000);
-        assertTrue(na.compareTo(nb) > 0);
-        ba = PDataType.DECIMAL.toBytes(na);
-        bb = PDataType.DECIMAL.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        assertTrue(ba.length <= PDataType.DECIMAL.estimateByteSize(na));
-        assertTrue(bb.length <= PDataType.DECIMAL.estimateByteSize(nb));
-
-        na = new BigDecimal(BigInteger.valueOf(12345678901239998L), 2);
-        nb = new BigDecimal(97);
-        assertTrue(na.compareTo(nb) > 0);
-        ba = PDataType.DECIMAL.toBytes(na);
-        bb = PDataType.DECIMAL.toBytes(nb);
-        assertTrue(Bytes.compareTo(ba, bb) > 0);
-        assertTrue(ba.length <= PDataType.DECIMAL.estimateByteSize(na));
-        assertTrue(bb.length <= PDataType.DECIMAL.estimateByteSize(nb));
-
-        List<BigDecimal> values = Arrays.asList(new BigDecimal[] {
-            new BigDecimal(-1000),
-            new BigDecimal(-100000000),
-            new BigDecimal(1000),
-            new BigDecimal("-0.001"),
-            new BigDecimal("0.001"),
-            new BigDecimal(new BigInteger("12345678901239999"), 2),
-            new BigDecimal(new BigInteger("12345678901239998"), 2),
-            new BigDecimal(new BigInteger("12345678901239998123456789"), 2), // bigger than long
-            new BigDecimal(new BigInteger("-1000"),3),
-            new BigDecimal(new BigInteger("-1000"),10),
-            new BigDecimal(99),
-            new BigDecimal(97),
-            new BigDecimal(-3)
-        });
-
-        List<byte[]> byteValues = new ArrayList<byte[]>();
-        for (int i = 0; i < values.size(); i++) {
-            byteValues.add(PDataType.DECIMAL.toBytes(values.get(i)));
-        }
-
-        for (int i = 0; i < values.size(); i++) {
-            BigDecimal expected = values.get(i);
-            BigDecimal actual = (BigDecimal)PDataType.DECIMAL.toObject(byteValues.get(i));
-            assertTrue("For " + i + " expected " + expected + " but got " + actual,expected.round(PDataType.DEFAULT_MATH_CONTEXT).compareTo(actual.round(PDataType.DEFAULT_MATH_CONTEXT)) == 0);
-            assertTrue(byteValues.get(i).length <= PDataType.DECIMAL.estimateByteSize(expected));
-        }
-
-        Collections.sort(values);
-        Collections.sort(byteValues, Bytes.BYTES_COMPARATOR);
-
-        for (int i = 0; i < values.size(); i++) {
-            BigDecimal expected = values.get(i);
-            byte[] bytes = PDataType.DECIMAL.toBytes(values.get(i));
-            assertNotNull("bytes converted from values should not be null!", bytes);
-            BigDecimal actual = (BigDecimal)PDataType.DECIMAL.toObject(byteValues.get(i));
-            assertTrue("For " + i + " expected " + expected + " but got " + actual,expected.round(PDataType.DEFAULT_MATH_CONTEXT).compareTo(actual.round(PDataType.DEFAULT_MATH_CONTEXT))==0);
-        }
-
-
-        {
-            String[] strs ={
-                    "\\xC2\\x03\\x0C\\x10\\x01\\x01\\x01\\x01\\x01\\x019U#\\x13W\\x09\\x09"
-                    ,"\\xC2\\x03<,ddddddN\\x1B\\x1B!.9N"
-                    ,"\\xC2\\x039"
-                    ,"\\xC2\\x03\\x16,\\x01\\x01\\x01\\x01\\x01\\x01E\\x16\\x16\\x03@\\x1EG"
-                    ,"\\xC2\\x02d6dddddd\\x15*]\\x0E<1F"
-                    ,"\\xC2\\x04 3"
-                    ,"\\xC2\\x03$Ldddddd\\x0A\\x06\\x06\\x1ES\\x1C\\x08"
-                    ,"\\xC2\\x03\\x1E\\x0A\\x01\\x01\\x01\\x01\\x01\\x01#\\x0B=4 AV"
-                    ,"\\xC2\\x02\\\\x04dddddd\\x15*]\\x0E<1F"
-                    ,"\\xC2\\x02V\"\\x01\\x01\\x01\\x01\\x01\\x02\\x1A\\x068\\x162&O"
-            };
-            for (String str : strs) {
-                byte[] bytes = Bytes.toBytesBinary(str);
-                Object o = PDataType.DECIMAL.toObject(bytes);
-                assertNotNull(o);
-                //System.out.println(o.getClass() +" " + bytesToHex(bytes)+" " + o+" ");
-            }
-        }
-    }
-    public static String bytesToHex(byte[] bytes) {
-        final char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
-        char[] hexChars = new char[bytes.length * 2];
-        int v;
-        for ( int j = 0; j < bytes.length; j++ ) {
-            v = bytes[j] & 0xFF;
-            hexChars[j * 2] = hexArray[v >>> 4];
-            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
-        }
-        return new String(hexChars);
-    }
-
-    @Test
-    public void testEmptyString() throws Throwable {
-        byte[] b1 = PDataType.VARCHAR.toBytes("");
-        byte[] b2 = PDataType.VARCHAR.toBytes(null);
-        assert (b1.length == 0 && Bytes.compareTo(b1, b2) == 0);
-    }
-
-    @Test
-    public void testNull() throws Throwable {
-        byte[] b = new byte[8];
-        for (PDataType type : PDataType.values()) {
-            try {
-				type.toBytes(null);
-				type.toBytes(null, b, 0);
-				type.toObject(new byte[0], 0, 0);
-				type.toObject(new byte[0], 0, 0, type);
-                if (type.isArrayType()) {
-					type.toBytes(new PhoenixArray());
-					type.toBytes(new PhoenixArray(), b, 0);
-                }
-            } catch (ConstraintViolationException e) {
-            	if (!type.isArrayType() && ! ( type.isFixedWidth() && e.getMessage().contains("may not be null"))) {
-            		// Fixed width types do not support the concept of a "null" value.
-                    fail(type + ":" + e);
-                }
-            }
-        }
-    }
-
-    @Test
-    public void testValueCoersion() throws Exception {
-        // Testing coercing integer to other values.
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.FLOAT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.FLOAT, 0.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.FLOAT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.FLOAT, Double.valueOf(Float.MAX_VALUE) + Double.valueOf(Float.MAX_VALUE)));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.LONG, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.LONG, 0.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.LONG, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.LONG, Double.valueOf(Long.MAX_VALUE) + Double.valueOf(Long.MAX_VALUE)));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.SMALLINT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.SMALLINT, 0.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.SMALLINT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.SMALLINT, -100000.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.TINYINT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.TINYINT, 0.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.TINYINT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.TINYINT, -1000.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -100000.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -1000.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 10.0));
-        assertTrue(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 0.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, -10.0));
-        assertFalse(PDataType.DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, Double.MAX_VALUE));
-        
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.DOUBLE));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.LONG, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.LONG, 0.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.LONG, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.LONG, Float.valueOf(Long.MAX_VALUE) + Float.valueOf(Long.MAX_VALUE)));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT, 0.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG, 0.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.SMALLINT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.SMALLINT, 0.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.SMALLINT, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.SMALLINT, -100000.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.TINYINT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.TINYINT, 0.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.TINYINT, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.TINYINT, -1000.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -100000.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -10.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -1000.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 10.0f));
-        assertTrue(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 0.0f));
-        assertFalse(PDataType.FLOAT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, -10.0f));
-        
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.FLOAT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.FLOAT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.FLOAT, Double.MAX_VALUE));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.LONG, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.LONG, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.LONG, Double.MAX_VALUE));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_INT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_LONG, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.SMALLINT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.SMALLINT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.TINYINT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.TINYINT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 10.0));
-        assertTrue(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 0.0));
-        assertFalse(PDataType.UNSIGNED_DOUBLE.isCoercibleTo(PDataType.UNSIGNED_FLOAT, Double.MAX_VALUE));
-        
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.DOUBLE));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.LONG, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.LONG, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.LONG, Float.MAX_VALUE));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_INT, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_LONG, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.SMALLINT, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.SMALLINT, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.TINYINT, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.TINYINT, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0.0f));
-        assertFalse(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0.0f));
-        assertTrue(PDataType.UNSIGNED_FLOAT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        
-        // Testing coercing integer to other values.
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.LONG, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.LONG, 0));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.LONG, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_INT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_INT, 0));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_INT, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_LONG, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_LONG, 0));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_LONG, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.SMALLINT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.SMALLINT, 0));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.SMALLINT, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.SMALLINT, -100000));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.TINYINT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.TINYINT, 0));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.TINYINT, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.TINYINT, -1000));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -100000));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -10));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -1000));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_FLOAT, -10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 0));
-        assertFalse(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, -10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 10));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 0));
-        assertTrue(PDataType.INTEGER.isCoercibleTo(PDataType.VARBINARY, 0));
-
-        // Testing coercing long to other values.
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.DOUBLE));
-        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));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, (long)Integer.MAX_VALUE));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Integer.MAX_VALUE - 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, 0L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, -10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Integer.MIN_VALUE + 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, (long)Integer.MIN_VALUE));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Integer.MIN_VALUE - 10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.INTEGER, Long.MIN_VALUE));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_INT, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_INT, 0L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_INT, -10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_LONG, Long.MAX_VALUE));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_LONG, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_LONG, 0L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_LONG, -10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_LONG, Long.MIN_VALUE));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.SMALLINT, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.SMALLINT, 0L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.SMALLINT, -10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.SMALLINT, -100000L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.TINYINT, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.TINYINT, 0L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.TINYINT, -10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.TINYINT, -1000L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, -100000L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10L));
-        assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -10L));
-        assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, -1000L));
-		assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 10L));
-		assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, 0L));
-		assertFalse(PDataType.LONG
-				.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, -1L));
-		assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 10L));
-		assertTrue(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_FLOAT, 0L));
-		assertFalse(PDataType.LONG.isCoercibleTo(PDataType.UNSIGNED_FLOAT, -1L));
-        
-        // Testing coercing smallint to other values.
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.LONG, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.LONG, (short)0));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.LONG, (short)-10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.INTEGER, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.INTEGER, (short)0));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.INTEGER, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)0));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)1000));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)-10));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)1000));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (short)-1));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (short)10));
-        assertTrue(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (short)0));
-        assertFalse(PDataType.SMALLINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (short)-1));
-        
-        // Testing coercing tinyint to other values.
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.LONG, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.LONG, (byte)0));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.LONG, (byte)-10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.INTEGER, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.INTEGER, (byte)0));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.INTEGER, (byte)-10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.SMALLINT, (byte)100));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.SMALLINT, (byte)0));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.SMALLINT, (byte)-10));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT, (byte)-10));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (byte)-10));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (byte)-10));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (byte)-10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE, (byte)-1));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (byte)10));
-        assertTrue(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (byte)0));
-        assertFalse(PDataType.TINYINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT, (byte)-1));
-
-        // Testing coercing unsigned_int to other values.
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.INTEGER, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.INTEGER, 0));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.LONG, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.LONG, 0));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_LONG, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_LONG, 0));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.SMALLINT, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.SMALLINT, 0));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.TINYINT, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.TINYINT, 0));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 100000));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 0));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 1000));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertTrue(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-
-        // Testing coercing unsigned_long to other values.
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.DOUBLE));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER, 10L));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.INTEGER, 0L));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.LONG));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.SMALLINT, 10L));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.SMALLINT, 0L));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.TINYINT, 10L));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.TINYINT, 0L));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 10L));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 0L));
-        assertFalse(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, 100000L));
-        assertFalse(PDataType.UNSIGNED_INT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.UNSIGNED_LONG.isCoercibleTo(PDataType.UNSIGNED_TINYINT, 10L));
-        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));
-        
-        // Testing coercing unsigned_smallint to other values.
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.INTEGER, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.INTEGER, (short)0));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.LONG, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.LONG, (short)0));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (short)0));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_INT, (short)0));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.SMALLINT, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.SMALLINT, (short)0));
-        assertFalse(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)0));
-        assertFalse(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.TINYINT, (short)1000));
-        assertFalse(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)10));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)0));
-        assertFalse(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_TINYINT, (short)1000));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertTrue(PDataType.UNSIGNED_SMALLINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-        
-        // Testing coercing unsigned_tinyint to other values.
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.DOUBLE));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.FLOAT));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.INTEGER));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.INTEGER, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.INTEGER, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.LONG));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.LONG, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.LONG, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_LONG, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_INT, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.SMALLINT));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.SMALLINT, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.SMALLINT, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.TINYINT));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.TINYINT, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.TINYINT, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (byte)10));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_SMALLINT, (byte)0));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_DOUBLE));
-        assertTrue(PDataType.UNSIGNED_TINYINT.isCoercibleTo(PDataType.UNSIGNED_FLOAT));
-        
-        // Testing coercing Date types
-        assertTrue(PDataType.DATE.isCoercibleTo(PDataType.TIMESTAMP));
-        assertTrue(PDataType.DATE.isCoercibleTo(PDataType.TIME));
-        assertFalse(PDataType.TIMESTAMP.isCoercibleTo(PDataType.DATE));
-        assertFalse(PDataType.TIMESTAMP.isCoercibleTo(PDataType.TIME));
-        assertTrue(PDataType.TIME.isCoercibleTo(PDataType.TIMESTAMP));
-        assertTrue(PDataType.TIME.isCoercibleTo(PDataType.DATE));
-    }
-
-    @Test
-    public void testGetDeicmalPrecisionAndScaleFromRawBytes() throws Exception {
-        // Special case for 0.
-        BigDecimal bd = new BigDecimal("0");
-        byte[] b = PDataType.DECIMAL.toBytes(bd);
-        int[] v = PDataType.getDecimalPrecisionAndScale(b, 0, b.length);
-        assertEquals(0, v[0]);
-        assertEquals(0, v[1]);
-
-        BigDecimal[] bds = new BigDecimal[] {
-                new BigDecimal("1"),
-                new BigDecimal("0.11"),
-                new BigDecimal("1.1"),
-                new BigDecimal("11"),
-                new BigDecimal("101"),
-                new BigDecimal("10.1"),
-                new BigDecimal("1.01"),
-                new BigDecimal("0.101"),
-                new BigDecimal("1001"),
-                new BigDecimal("100.1"),
-                new BigDecimal("10.01"),
-                new BigDecimal("1.001"),
-                new BigDecimal("0.1001"),
-                new BigDecimal("10001"),
-                new BigDecimal("1000.1"),
-                new BigDecimal("100.01"),
-                new BigDecimal("10.001"),
-                new BigDecimal("1.0001"),
-                new BigDecimal("0.10001"),
-                new BigDecimal("100000000000000000000000000000"),
-                new BigDecimal("1000000000000000000000000000000"),
-                new BigDecimal("0.000000000000000000000000000001"),
-                new BigDecimal("0.0000000000000000000000000000001"),
-                new BigDecimal("111111111111111111111111111111"),
-                new BigDecimal("1111111111111111111111111111111"),
-                new BigDecimal("0.111111111111111111111111111111"),
-                new BigDecimal("0.1111111111111111111111111111111"),
-        };
-
-        for (int i=0; i<bds.length; i++) {
-            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
-    public void testDateConversions() {
-        long now = System.currentTimeMillis();
-        Date date = new Date(now);
-        Time t = new Time(now);
-        Timestamp ts = new Timestamp(now);
-        
-        Object o = PDataType.DATE.toObject(ts, PDataType.TIMESTAMP);
-        assertEquals(o.getClass(), java.sql.Date.class);
-        o = PDataType.DATE.toObject(t, PDataType.TIME);
-        assertEquals(o.getClass(), java.sql.Date.class);
-        
-        o = PDataType.TIME.toObject(date, PDataType.DATE);
-        assertEquals(o.getClass(), java.sql.Time.class);
-        o = PDataType.TIME.toObject(ts, PDataType.TIMESTAMP);
-        assertEquals(o.getClass(), java.sql.Time.class);
-                
-        o = PDataType.TIMESTAMP.toObject(d

<TRUNCATED>

[22/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
PHOENIX-1514 Break up PDataType Enum


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/04ef859b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/04ef859b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/04ef859b

Branch: refs/heads/master
Commit: 04ef859b78704f5b56118ee30248652dcfcdee3f
Parents: a8d9eec
Author: Nick Dimiduk <nd...@apache.org>
Authored: Wed Dec 17 15:24:45 2014 -0800
Committer: Nick Dimiduk <nd...@apache.org>
Committed: Wed Dec 17 15:24:45 2014 -0800

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/ArrayIT.java     |    2 +-
 .../phoenix/end2end/CSVCommonsLoaderIT.java     |    6 +-
 .../end2end/ColumnProjectionOptimizationIT.java |   24 +-
 .../phoenix/end2end/DecodeFunctionIT.java       |    7 +-
 .../apache/phoenix/end2end/DynamicFamilyIT.java |   23 +-
 .../org/apache/phoenix/end2end/InListIT.java    |   23 +-
 .../phoenix/end2end/ParallelIteratorsIT.java    |    4 +-
 .../phoenix/end2end/ProductMetricsIT.java       |    6 +-
 .../end2end/QueryDatabaseMetaDataIT.java        |   37 +-
 .../org/apache/phoenix/end2end/QueryIT.java     |    6 +-
 .../phoenix/end2end/StatsCollectorIT.java       |   17 +
 .../phoenix/end2end/ToNumberFunctionIT.java     |    6 +-
 .../apache/phoenix/end2end/UpsertSelectIT.java  |   18 +-
 .../phoenix/end2end/index/IndexTestUtil.java    |    2 +-
 .../apache/phoenix/trace/TracingTestUtil.java   |   17 +
 phoenix-core/src/main/antlr3/PhoenixSQL.g       |    2 +-
 .../hbase/regionserver/LocalIndexSplitter.java  |    8 +-
 .../apache/phoenix/compile/ColumnProjector.java |    2 +-
 .../phoenix/compile/CreateSequenceCompiler.java |   13 +-
 .../apache/phoenix/compile/DeleteCompiler.java  |    6 +-
 .../phoenix/compile/ExpressionCompiler.java     |  204 +-
 .../phoenix/compile/ExpressionProjector.java    |    2 +-
 .../apache/phoenix/compile/GroupByCompiler.java |   13 +-
 .../apache/phoenix/compile/HavingCompiler.java  |    6 +-
 .../phoenix/compile/IndexStatementRewriter.java |    2 +-
 .../apache/phoenix/compile/JoinCompiler.java    |   61 +-
 .../apache/phoenix/compile/LimitCompiler.java   |    6 +-
 .../MutatingParallelIteratorFactory.java        |    4 +-
 .../apache/phoenix/compile/PostDDLCompiler.java |    4 +-
 .../phoenix/compile/ProjectionCompiler.java     |    2 +-
 .../apache/phoenix/compile/SequenceManager.java |    9 +-
 .../apache/phoenix/compile/UpsertCompiler.java  |    6 +-
 .../apache/phoenix/compile/WhereCompiler.java   |    8 +-
 .../apache/phoenix/compile/WhereOptimizer.java  |   10 +-
 .../GroupedAggregateRegionObserver.java         |    4 +-
 .../coprocessor/MetaDataEndpointImpl.java       |   48 +-
 .../coprocessor/MetaDataRegionObserver.java     |    8 +-
 .../coprocessor/SequenceRegionObserver.java     |   38 +-
 .../phoenix/coprocessor/SuffixFilter.java       |   17 +
 .../UngroupedAggregateRegionObserver.java       |    4 +-
 .../phoenix/exception/SQLExceptionCode.java     |    2 +-
 .../ValueTypeIncompatibleException.java         |    2 +-
 .../apache/phoenix/execute/AggregatePlan.java   |    4 +-
 .../apache/phoenix/execute/HashJoinPlan.java    |    7 +-
 .../phoenix/expression/AndExpression.java       |    6 +-
 .../phoenix/expression/AndOrExpression.java     |    7 +-
 .../expression/ArithmeticExpression.java        |    2 +-
 .../expression/ArrayConstructorExpression.java  |    4 +-
 .../expression/BaseAddSubtractExpression.java   |    2 +-
 .../phoenix/expression/BaseExpression.java      |   15 +-
 .../phoenix/expression/CaseExpression.java      |   10 +-
 .../phoenix/expression/CoerceExpression.java    |    2 +-
 .../phoenix/expression/ColumnExpression.java    |    2 +-
 .../expression/ComparisonExpression.java        |  131 +-
 .../phoenix/expression/DateAddExpression.java   |   16 +-
 .../expression/DateSubtractExpression.java      |   16 +-
 .../expression/DecimalAddExpression.java        |   11 +-
 .../expression/DecimalDivideExpression.java     |   11 +-
 .../expression/DecimalMultiplyExpression.java   |   11 +-
 .../expression/DecimalSubtractExpression.java   |   14 +-
 .../phoenix/expression/DelegateExpression.java  |    2 +-
 .../phoenix/expression/DivideExpression.java    |    2 +-
 .../phoenix/expression/DoubleAddExpression.java |    5 +-
 .../expression/DoubleDivideExpression.java      |    5 +-
 .../expression/DoubleMultiplyExpression.java    |    5 +-
 .../expression/DoubleSubtractExpression.java    |    5 +-
 .../phoenix/expression/InListExpression.java    |    9 +-
 .../phoenix/expression/IsNullExpression.java    |    9 +-
 .../phoenix/expression/LikeExpression.java      |   10 +-
 .../phoenix/expression/LiteralExpression.java   |   20 +-
 .../phoenix/expression/LongAddExpression.java   |    7 +-
 .../expression/LongDivideExpression.java        |    7 +-
 .../expression/LongMultiplyExpression.java      |    5 +-
 .../expression/LongSubtractExpression.java      |    8 +-
 .../phoenix/expression/ModulusExpression.java   |   11 +-
 .../phoenix/expression/MultiplyExpression.java  |    2 +-
 .../phoenix/expression/NotExpression.java       |   15 +-
 .../expression/RowKeyColumnExpression.java      |    2 +-
 .../phoenix/expression/RowKeyExpression.java    |    5 +-
 .../RowValueConstructorExpression.java          |    5 +-
 .../expression/StringConcatExpression.java      |    9 +-
 .../expression/TimestampAddExpression.java      |   22 +-
 .../expression/TimestampSubtractExpression.java |   22 +-
 .../aggregator/BaseDecimalStddevAggregator.java |   11 +-
 .../aggregator/BaseStddevAggregator.java        |   12 +-
 .../expression/aggregator/CountAggregator.java  |    5 +-
 .../aggregator/DecimalSumAggregator.java        |    9 +-
 .../DistinctCountClientAggregator.java          |    9 +-
 .../DistinctValueClientAggregator.java          |    4 +-
 .../DistinctValueWithCountClientAggregator.java |    5 +-
 .../DistinctValueWithCountServerAggregator.java |    5 +-
 .../aggregator/DoubleSumAggregator.java         |    9 +-
 .../FirstLastValueBaseClientAggregator.java     |    5 +-
 .../FirstLastValueServerAggregator.java         |    5 +-
 .../expression/aggregator/IntSumAggregator.java |    5 +-
 .../aggregator/LongSumAggregator.java           |    5 +-
 .../aggregator/NumberSumAggregator.java         |    7 +-
 .../aggregator/PercentRankClientAggregator.java |    7 +-
 .../aggregator/PercentileClientAggregator.java  |    7 +-
 .../PercentileDiscClientAggregator.java         |    5 +-
 .../aggregator/UnsignedIntSumAggregator.java    |    5 +-
 .../aggregator/UnsignedLongSumAggregator.java   |    5 +-
 .../function/ArrayAllComparisonExpression.java  |    2 +-
 .../function/ArrayAnyComparisonExpression.java  |    7 +-
 .../expression/function/ArrayIndexFunction.java |   18 +-
 .../function/ArrayLengthFunction.java           |   15 +-
 .../function/AvgAggregateFunction.java          |   13 +-
 .../expression/function/CeilDateExpression.java |    2 +-
 .../function/CeilDecimalExpression.java         |   20 +-
 .../expression/function/CeilFunction.java       |   12 +-
 .../function/CeilTimestampExpression.java       |   21 +-
 .../expression/function/CoalesceFunction.java   |    2 +-
 .../function/ConvertTimezoneFunction.java       |   16 +-
 .../function/CountAggregateFunction.java        |    5 +-
 .../function/CurrentDateFunction.java           |    9 +-
 .../function/CurrentTimeFunction.java           |    9 +-
 .../expression/function/DecodeFunction.java     |    8 +-
 ...elegateConstantToCountAggregateFunction.java |    6 +-
 .../DistinctCountAggregateFunction.java         |    9 +-
 .../DistinctValueAggregateFunction.java         |    8 +-
 .../expression/function/EncodeFunction.java     |   10 +-
 .../function/ExternalSqlTypeIdFunction.java     |   11 +-
 .../function/FirstLastValueBaseFunction.java    |    2 +-
 .../expression/function/FirstValueFunction.java |    4 +-
 .../function/FloorDateExpression.java           |   12 +-
 .../function/FloorDecimalExpression.java        |   20 +-
 .../expression/function/FloorFunction.java      |   12 +-
 .../function/IndexStateNameFunction.java        |    8 +-
 .../function/InlineArrayElemRefExpression.java  |    4 +-
 .../expression/function/InvertFunction.java     |    2 +-
 .../expression/function/LTrimFunction.java      |    7 +-
 .../expression/function/LastValueFunction.java  |    4 +-
 .../expression/function/LengthFunction.java     |   13 +-
 .../expression/function/LowerFunction.java      |    9 +-
 .../expression/function/LpadFunction.java       |   17 +-
 .../expression/function/MD5Function.java        |    5 +-
 .../function/MaxAggregateFunction.java          |    2 +-
 .../function/MinAggregateFunction.java          |    2 +-
 .../expression/function/NthValueFunction.java   |    7 +-
 .../function/PercentRankAggregateFunction.java  |    8 +-
 .../PercentileContAggregateFunction.java        |   12 +-
 .../PercentileDiscAggregateFunction.java        |   10 +-
 .../expression/function/PrefixFunction.java     |    2 +-
 .../expression/function/RTrimFunction.java      |    7 +-
 .../function/RegexpReplaceFunction.java         |   21 +-
 .../function/RegexpSplitFunction.java           |   22 +-
 .../function/RegexpSubstrFunction.java          |   16 +-
 .../expression/function/ReverseFunction.java    |    7 +-
 .../function/RoundDateExpression.java           |   12 +-
 .../function/RoundDecimalExpression.java        |   32 +-
 .../expression/function/RoundFunction.java      |   12 +-
 .../function/RoundTimestampExpression.java      |   21 +-
 .../function/SQLIndexTypeFunction.java          |    8 +-
 .../function/SQLTableTypeFunction.java          |    8 +-
 .../function/SQLViewTypeFunction.java           |    8 +-
 .../function/SingleAggregateFunction.java       |    2 +-
 .../function/SqlTypeNameFunction.java           |    8 +-
 .../expression/function/StddevPopFunction.java  |    9 +-
 .../expression/function/StddevSampFunction.java |    9 +-
 .../expression/function/SubstrFunction.java     |   16 +-
 .../function/SumAggregateFunction.java          |   69 +-
 .../function/TimezoneOffsetFunction.java        |   16 +-
 .../expression/function/ToCharFunction.java     |   11 +-
 .../expression/function/ToDateFunction.java     |   12 +-
 .../expression/function/ToNumberFunction.java   |   13 +-
 .../expression/function/TrimFunction.java       |    7 +-
 .../expression/function/TruncFunction.java      |   14 +-
 .../expression/function/UpperFunction.java      |    9 +-
 .../apache/phoenix/index/IndexMaintainer.java   |    2 +-
 .../phoenix/index/PhoenixIndexBuilder.java      |    4 +-
 .../index/PhoenixIndexFailurePolicy.java        |    4 +-
 .../apache/phoenix/iterate/ExplainTable.java    |    5 +-
 .../FilterAggregatingResultIterator.java        |    4 +-
 .../phoenix/iterate/FilterResultIterator.java   |    4 +-
 .../apache/phoenix/jdbc/PhoenixConnection.java  |   30 +-
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |    5 +-
 .../phoenix/jdbc/PhoenixParameterMetaData.java  |    2 +-
 .../phoenix/jdbc/PhoenixPreparedStatement.java  |    2 +-
 .../apache/phoenix/jdbc/PhoenixResultSet.java   |   83 +-
 .../phoenix/jdbc/PhoenixResultSetMetaData.java  |    9 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |    9 +-
 .../org/apache/phoenix/parse/CastParseNode.java |   13 +-
 .../org/apache/phoenix/parse/CeilParseNode.java |   12 +-
 .../org/apache/phoenix/parse/ColumnDef.java     |   17 +-
 .../apache/phoenix/parse/FloorParseNode.java    |    8 +-
 .../apache/phoenix/parse/FunctionParseNode.java |   43 +-
 .../apache/phoenix/parse/LiteralParseNode.java  |    7 +-
 .../apache/phoenix/parse/ParseNodeFactory.java  |    2 +-
 .../apache/phoenix/parse/RoundParseNode.java    |   11 +-
 .../apache/phoenix/parse/ToCharParseNode.java   |    9 +-
 .../apache/phoenix/parse/ToNumberParseNode.java |    8 +-
 .../query/ConnectionQueryServicesImpl.java      |   27 +-
 .../schema/ArgumentTypeMismatchException.java   |   17 +
 .../apache/phoenix/schema/DelegateDatum.java    |    2 +
 .../apache/phoenix/schema/KeyValueSchema.java   |    3 +-
 .../phoenix/schema/LocalIndexDataColumnRef.java |   17 +
 .../apache/phoenix/schema/MetaDataClient.java   |   23 +-
 .../apache/phoenix/schema/PArrayDataType.java   |  660 --
 .../org/apache/phoenix/schema/PColumnImpl.java  |    1 +
 .../org/apache/phoenix/schema/PDataType.java    | 7452 ------------------
 .../org/apache/phoenix/schema/PDateColumn.java  |    5 +-
 .../java/org/apache/phoenix/schema/PDatum.java  |    1 +
 .../org/apache/phoenix/schema/PIndexState.java  |    5 +-
 .../apache/phoenix/schema/PIntegerColumn.java   |    4 +-
 .../org/apache/phoenix/schema/PLongColumn.java  |    4 +-
 .../apache/phoenix/schema/PStringColumn.java    |    7 +-
 .../org/apache/phoenix/schema/PTableImpl.java   |    8 +-
 .../org/apache/phoenix/schema/PhoenixArray.java |  551 --
 .../org/apache/phoenix/schema/RowKeySchema.java |    2 +-
 .../org/apache/phoenix/schema/SaltingUtil.java  |    3 +-
 .../org/apache/phoenix/schema/Sequence.java     |   40 +-
 .../phoenix/schema/TypeMismatchException.java   |    1 +
 .../org/apache/phoenix/schema/ValueSchema.java  |    3 +-
 .../phoenix/schema/stats/StatisticsWriter.java  |   28 +-
 .../phoenix/schema/types/PArrayDataType.java    |  656 ++
 .../apache/phoenix/schema/types/PBinary.java    |  189 +
 .../phoenix/schema/types/PBinaryArray.java      |  108 +
 .../apache/phoenix/schema/types/PBoolean.java   |  140 +
 .../phoenix/schema/types/PBooleanArray.java     |  108 +
 .../org/apache/phoenix/schema/types/PChar.java  |  203 +
 .../apache/phoenix/schema/types/PCharArray.java |  108 +
 .../apache/phoenix/schema/types/PDataType.java  | 1178 +++
 .../phoenix/schema/types/PDataTypeFactory.java  |  118 +
 .../org/apache/phoenix/schema/types/PDate.java  |  192 +
 .../apache/phoenix/schema/types/PDateArray.java |  109 +
 .../apache/phoenix/schema/types/PDecimal.java   |  396 +
 .../phoenix/schema/types/PDecimalArray.java     |  110 +
 .../apache/phoenix/schema/types/PDouble.java    |  311 +
 .../phoenix/schema/types/PDoubleArray.java      |  108 +
 .../org/apache/phoenix/schema/types/PFloat.java |  308 +
 .../phoenix/schema/types/PFloatArray.java       |  109 +
 .../apache/phoenix/schema/types/PInteger.java   |  275 +
 .../phoenix/schema/types/PIntegerArray.java     |  109 +
 .../org/apache/phoenix/schema/types/PLong.java  |  331 +
 .../apache/phoenix/schema/types/PLongArray.java |  109 +
 .../apache/phoenix/schema/types/PSmallint.java  |  259 +
 .../phoenix/schema/types/PSmallintArray.java    |  109 +
 .../org/apache/phoenix/schema/types/PTime.java  |  137 +
 .../apache/phoenix/schema/types/PTimeArray.java |  110 +
 .../apache/phoenix/schema/types/PTimestamp.java |  209 +
 .../phoenix/schema/types/PTimestampArray.java   |  109 +
 .../apache/phoenix/schema/types/PTinyint.java   |  253 +
 .../phoenix/schema/types/PTinyintArray.java     |  109 +
 .../phoenix/schema/types/PUnsignedDate.java     |  164 +
 .../schema/types/PUnsignedDateArray.java        |  110 +
 .../phoenix/schema/types/PUnsignedDouble.java   |  158 +
 .../schema/types/PUnsignedDoubleArray.java      |  112 +
 .../phoenix/schema/types/PUnsignedFloat.java    |  152 +
 .../schema/types/PUnsignedFloatArray.java       |  109 +
 .../phoenix/schema/types/PUnsignedInt.java      |  178 +
 .../phoenix/schema/types/PUnsignedIntArray.java |  109 +
 .../phoenix/schema/types/PUnsignedLong.java     |  193 +
 .../schema/types/PUnsignedLongArray.java        |  109 +
 .../phoenix/schema/types/PUnsignedSmallint.java |  159 +
 .../schema/types/PUnsignedSmallintArray.java    |  110 +
 .../phoenix/schema/types/PUnsignedTime.java     |  115 +
 .../schema/types/PUnsignedTimeArray.java        |  109 +
 .../schema/types/PUnsignedTimestamp.java        |  151 +
 .../schema/types/PUnsignedTimestampArray.java   |  110 +
 .../phoenix/schema/types/PUnsignedTinyint.java  |  155 +
 .../schema/types/PUnsignedTinyintArray.java     |  110 +
 .../apache/phoenix/schema/types/PVarbinary.java |  171 +
 .../phoenix/schema/types/PVarbinaryArray.java   |  109 +
 .../apache/phoenix/schema/types/PVarchar.java   |  165 +
 .../phoenix/schema/types/PVarcharArray.java     |  109 +
 .../phoenix/schema/types/PhoenixArray.java      |  644 ++
 .../java/org/apache/phoenix/util/ByteUtil.java  |    2 +-
 .../apache/phoenix/util/CSVCommonsLoader.java   |    2 +-
 .../org/apache/phoenix/util/ColumnInfo.java     |    2 +-
 .../org/apache/phoenix/util/ExpressionUtil.java |    2 +-
 .../java/org/apache/phoenix/util/IndexUtil.java |   12 +-
 .../org/apache/phoenix/util/MetaDataUtil.java   |   15 +-
 .../org/apache/phoenix/util/NumberUtil.java     |    2 +-
 .../org/apache/phoenix/util/PhoenixRuntime.java |    4 +-
 .../java/org/apache/phoenix/util/ScanUtil.java  |    6 +-
 .../org/apache/phoenix/util/SchemaUtil.java     |    8 +-
 .../org/apache/phoenix/util/UpgradeUtil.java    |   11 +-
 .../phoenix/util/csv/CsvUpsertExecutor.java     |    2 +-
 .../util/csv/StringToArrayConverter.java        |    2 +-
 .../arithmetic/ArithmeticOperationTest.java     |  114 +-
 .../phoenix/compile/LimitCompilerTest.java      |   14 +-
 .../compile/ScanRangesIntersectTest.java        |   11 +-
 .../apache/phoenix/compile/ScanRangesTest.java  |  286 +-
 .../phoenix/compile/WhereCompilerTest.java      |   62 +-
 .../phoenix/compile/WhereOptimizerTest.java     |  312 +-
 .../expression/CoerceExpressionTest.java        |   25 +-
 .../expression/ColumnExpressionTest.java        |   18 +-
 .../RoundFloorCeilExpressionsTest.java          |  243 +-
 .../expression/SortOrderExpressionTest.java     |  105 +-
 .../function/ExternalSqlTypeIdFunctionTest.java |   11 +-
 .../filter/SkipScanFilterIntersectTest.java     |  342 +-
 .../phoenix/filter/SkipScanFilterTest.java      |  114 +-
 .../iterate/AggregateResultScannerTest.java     |   16 +-
 .../mapreduce/CsvBulkImportUtilTest.java        |    4 +-
 .../mapreduce/CsvToKeyValueMapperTest.java      |   16 +-
 .../ColumnInfoToStringEncoderDecoderTest.java   |    9 +-
 .../phoenix/parse/BuiltInFunctionInfoTest.java  |   21 +-
 .../phoenix/query/ConnectionlessTest.java       |   20 +-
 .../phoenix/query/KeyRangeCoalesceTest.java     |   59 +-
 .../phoenix/query/KeyRangeIntersectTest.java    |   31 +-
 .../apache/phoenix/query/KeyRangeUnionTest.java |   33 +-
 .../query/ParallelIteratorsSplitTest.java       |   13 +-
 .../phoenix/schema/PDataTypeForArraysTest.java  |  500 +-
 .../apache/phoenix/schema/PDataTypeTest.java    | 1678 ----
 .../apache/phoenix/schema/RowKeySchemaTest.java |    1 +
 .../phoenix/schema/RowKeyValueAccessorTest.java |    1 +
 .../apache/phoenix/schema/SortOrderTest.java    |   23 +-
 .../apache/phoenix/schema/ValueBitSetTest.java  |    1 +
 .../phoenix/schema/types/PDataTypeTest.java     | 1710 ++++
 .../org/apache/phoenix/util/ByteUtilTest.java   |    8 +-
 .../apache/phoenix/util/PhoenixRuntimeTest.java |    2 +-
 .../org/apache/phoenix/util/ScanUtilTest.java   |  138 +-
 .../java/org/apache/phoenix/util/TestUtil.java  |    2 +-
 .../phoenix/util/csv/CsvUpsertExecutorTest.java |   13 +-
 .../util/csv/StringToArrayConverterTest.java    |    7 +-
 .../flume/serializer/RegexEventSerializer.java  |    2 +-
 .../phoenix/pig/util/PhoenixPigSchemaUtil.java  |    2 +-
 .../org/apache/phoenix/pig/util/TypeUtil.java   |  137 +-
 .../pig/writable/PhoenixPigDBWritable.java      |    2 +-
 319 files changed, 14812 insertions(+), 12713 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
index e7221e9..ff8601b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
@@ -39,7 +39,7 @@ import java.sql.Types;
 import java.util.Properties;
 
 import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.schema.PhoenixArray;
+import org.apache.phoenix.schema.types.PhoenixArray;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
index 71616d2..dc25b19 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
@@ -36,8 +36,8 @@ import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixTestDriver;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PArrayDataType;
 import org.apache.phoenix.util.CSVCommonsLoader;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -639,7 +639,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
             assertTrue(phoenixResultSet.next());
             assertEquals(1L, phoenixResultSet.getLong(1));
             assertEquals(
-                    PArrayDataType.instantiatePhoenixArray(PDataType.INTEGER, new Integer[]{2, 3, 4}),
+                    PArrayDataType.instantiatePhoenixArray(PInteger.INSTANCE, new Integer[]{2, 3, 4}),
                     phoenixResultSet.getArray(2));
             assertFalse(phoenixResultSet.next());
         } finally {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
index 775bb46..e97c7e1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
@@ -52,7 +52,9 @@ import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
@@ -247,20 +249,20 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT {
         HTableInterface htable = null;
         try {
             htable = conn2.getQueryServices().getTable(htableName);
-            Put put = new Put(PDataType.INTEGER.toBytes(1));
-            put.add(cfB, c1, ts + 6, PDataType.INTEGER.toBytes(1));
-            put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(2));
+            Put put = new Put(PInteger.INSTANCE.toBytes(1));
+            put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(1));
+            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(2));
             htable.put(put);
 
-            put = new Put(PDataType.INTEGER.toBytes(2));
-            put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(10));
-            put.add(cfC, c3, ts + 6, PDataType.VARCHAR.toBytes("abcd"));
+            put = new Put(PInteger.INSTANCE.toBytes(2));
+            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
+            put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
             htable.put(put);
 
-            put = new Put(PDataType.INTEGER.toBytes(3));
-            put.add(cfB, c1, ts + 6, PDataType.INTEGER.toBytes(3));
-            put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(10));
-            put.add(cfC, c3, ts + 6, PDataType.VARCHAR.toBytes("abcd"));
+            put = new Put(PInteger.INSTANCE.toBytes(3));
+            put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(3));
+            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
+            put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
             htable.put(put);
 
             conn2.close();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
index ae259bc..68e0add 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeFunctionIT.java
@@ -29,7 +29,8 @@ import java.sql.SQLException;
 
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PUnsignedLong;
 import org.junit.Test;
 
 
@@ -44,7 +45,7 @@ public class DecodeFunctionIT extends BaseHBaseManagedTimeIT {
 		conn.createStatement().execute(ddl);
 		PreparedStatement ps = conn.prepareStatement("UPSERT INTO test_table (some_column) VALUES (?)");
 
-		byte[] kk = Bytes.add(PDataType.UNSIGNED_LONG.toBytes(2232594215l), PDataType.INTEGER.toBytes(-8));
+		byte[] kk = Bytes.add(PUnsignedLong.INSTANCE.toBytes(2232594215l), PInteger.INSTANCE.toBytes(-8));
 		ps.setBytes(1, kk);
 
 		ps.execute();
@@ -63,7 +64,7 @@ public class DecodeFunctionIT extends BaseHBaseManagedTimeIT {
 		conn.createStatement().execute(ddl);
 		PreparedStatement ps = conn.prepareStatement("UPSERT INTO test_table (some_column) VALUES (?)");
 
-		byte[] kk = Bytes.add(PDataType.UNSIGNED_LONG.toBytes(2232594215l), PDataType.INTEGER.toBytes(-8));
+		byte[] kk = Bytes.add(PUnsignedLong.INSTANCE.toBytes(2232594215l), PInteger.INSTANCE.toBytes(-8));
 		ps.setBytes(1, kk);
 
 		ps.execute();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
index cb795c9..370cfab 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicFamilyIT.java
@@ -43,7 +43,8 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTime;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
@@ -115,24 +116,24 @@ public class DynamicFamilyIT extends BaseHBaseManagedTimeIT {
             List<Row> mutations = new ArrayList<Row>();
             put = new Put(Bytes.toBytes("entry1"));
             put.add(A_CF, QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, ByteUtil.EMPTY_BYTE_ARRAY);
-            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID2_BYTES), PDataType.INTEGER.toBytes(ENTRY1_CLICK_COUNT));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID1_BYTES), PDataType.TIME.toBytes(ENTRY1_USER_ID1_LOGIN_TIME));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PDataType.TIME.toBytes(ENTRY1_USER_ID2_LOGIN_TIME));
+            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID2_BYTES), PInteger.INSTANCE.toBytes(ENTRY1_CLICK_COUNT));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID1_BYTES), PTime.INSTANCE.toBytes(ENTRY1_USER_ID1_LOGIN_TIME));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PTime.INSTANCE.toBytes(ENTRY1_USER_ID2_LOGIN_TIME));
             mutations.add(put);
             
             put = new Put(Bytes.toBytes("entry2"));
             put.add(A_CF, QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, ByteUtil.EMPTY_BYTE_ARRAY);
-            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID3_BYTES), PDataType.INTEGER.toBytes(ENTRY2_CLICK_COUNT));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PDataType.TIME.toBytes(ENTRY2_USER_ID2_LOGIN_TIME));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID3_BYTES), PDataType.TIME.toBytes(ENTRY2_USER_ID3_LOGIN_TIME));
+            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID3_BYTES), PInteger.INSTANCE.toBytes(ENTRY2_CLICK_COUNT));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PTime.INSTANCE.toBytes(ENTRY2_USER_ID2_LOGIN_TIME));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID3_BYTES), PTime.INSTANCE.toBytes(ENTRY2_USER_ID3_LOGIN_TIME));
             mutations.add(put);
             
             put = new Put(Bytes.toBytes("entry3"));
             put.add(A_CF, QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, ByteUtil.EMPTY_BYTE_ARRAY);
-            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID1_BYTES), PDataType.INTEGER.toBytes(ENTRY3_CLICK_COUNT));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID1_BYTES), PDataType.TIME.toBytes(ENTRY3_USER_ID1_LOGIN_TIME));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PDataType.TIME.toBytes(ENTRY3_USER_ID2_LOGIN_TIME));
-            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID3_BYTES), PDataType.TIME.toBytes(ENTRY3_USER_ID3_LOGIN_TIME));
+            put.add(A_CF, ByteUtil.concat(MAX_CLICK_COUNT_DYNCOL_PREFIX, USER_ID1_BYTES), PInteger.INSTANCE.toBytes(ENTRY3_CLICK_COUNT));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID1_BYTES), PTime.INSTANCE.toBytes(ENTRY3_USER_ID1_LOGIN_TIME));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID2_BYTES), PTime.INSTANCE.toBytes(ENTRY3_USER_ID2_LOGIN_TIME));
+            put.add(B_CF, ByteUtil.concat(LAST_LOGIN_TIME_DYNCOL_PREFIX, USER_ID3_BYTES), PTime.INSTANCE.toBytes(ENTRY3_USER_ID3_LOGIN_TIME));
             mutations.add(put);
 
             hTable.batch(mutations);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
index 315a18f..3fdd906 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
@@ -1,3 +1,20 @@
+/*
+ * 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.end2end;
 
 import static java.util.Collections.singletonList;
@@ -15,7 +32,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
@@ -144,7 +163,7 @@ public class InListIT extends BaseHBaseManagedTimeIT {
     
     // the different combinations to check each test against
     private static final List<Boolean> TENANCIES = Arrays.asList(false, true);
-    private static final List<PDataType> INTEGER_TYPES = Arrays.asList(PDataType.INTEGER, PDataType.LONG);
+    private static final List<? extends PDataType> INTEGER_TYPES = Arrays.asList(PInteger.INSTANCE, PLong.INSTANCE);
     private static final List<Integer> SALT_BUCKET_NUMBERS = Arrays.asList(0, 4);
 
     private static final List<String> HINTS = Arrays.asList("", "/*+ SKIP_SCAN */", "/*+ RANGE_SCAN */");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
index 509ca90..df25c46 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
@@ -34,7 +34,7 @@ import java.util.Map;
 
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -172,7 +172,7 @@ public class ParallelIteratorsIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
 
     private static KeyRange newKeyRange(byte[] lowerRange, byte[] upperRange) {
-        return PDataType.CHAR.getKeyRange(lowerRange, true, upperRange, false);
+        return PChar.INSTANCE.getKeyRange(lowerRange, true, upperRange, false);
     }
     
     private static void initTableValues(Connection conn) throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ProductMetricsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ProductMetricsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ProductMetricsIT.java
index 3d8c470..cd436e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ProductMetricsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ProductMetricsIT.java
@@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -82,8 +82,8 @@ public class ProductMetricsIT extends BaseClientManagedTimeIT {
     
     private static byte[][] getSplits(String tenantId) {
         return new byte[][] { 
-            ByteUtil.concat(Bytes.toBytes(tenantId), PDataType.DATE.toBytes(D3)),
-            ByteUtil.concat(Bytes.toBytes(tenantId), PDataType.DATE.toBytes(D5)),
+            ByteUtil.concat(Bytes.toBytes(tenantId), PDate.INSTANCE.toBytes(D3)),
+            ByteUtil.concat(Bytes.toBytes(tenantId), PDate.INSTANCE.toBytes(D5)),
             };
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
index c0d1f00..0df47b3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java
@@ -68,8 +68,11 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.schema.types.PChar;
 import org.apache.phoenix.schema.ColumnNotFoundException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.ReadOnlyTableException;
@@ -214,7 +217,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(null, rs.getString("TABLE_CAT"));
         assertEquals(SchemaUtil.normalizeIdentifier("id"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNoNulls, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.CHAR.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PChar.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(1, rs.getInt("ORDINAL_POSITION"));
         assertEquals(1, rs.getInt("COLUMN_SIZE"));
         assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
@@ -225,7 +228,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("a"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col1"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PInteger.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(2, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -238,7 +241,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col2"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.LONG.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PLong.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(3, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -251,7 +254,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col3"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(4, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -264,7 +267,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col4"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(5, rs.getInt("ORDINAL_POSITION"));
         assertEquals(5, rs.getInt("COLUMN_SIZE"));
         assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
@@ -275,7 +278,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col5"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(6, rs.getInt("ORDINAL_POSITION"));
         assertEquals(6, rs.getInt("COLUMN_SIZE"));
         assertEquals(3, rs.getInt("DECIMAL_DIGITS"));
@@ -290,7 +293,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("a"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col1"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PInteger.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(2, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -307,7 +310,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("a"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col1"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.INTEGER.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PInteger.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(2, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -320,7 +323,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col2"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.LONG.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PLong.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(3, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -333,7 +336,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col3"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(4, rs.getInt("ORDINAL_POSITION"));
         assertEquals(0, rs.getInt("COLUMN_SIZE"));
         assertTrue(rs.wasNull());
@@ -346,7 +349,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col4"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(5, rs.getInt("ORDINAL_POSITION"));
         assertEquals(5, rs.getInt("COLUMN_SIZE"));
         assertEquals(0, rs.getInt("DECIMAL_DIGITS"));
@@ -358,7 +361,7 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
         assertEquals(SchemaUtil.normalizeIdentifier("b"), rs.getString("COLUMN_FAMILY"));
         assertEquals(SchemaUtil.normalizeIdentifier("col5"), rs.getString("COLUMN_NAME"));
         assertEquals(DatabaseMetaData.attributeNullable, rs.getShort("NULLABLE"));
-        assertEquals(PDataType.DECIMAL.getSqlType(), rs.getInt("DATA_TYPE"));
+        assertEquals(PDecimal.INSTANCE.getSqlType(), rs.getInt("DATA_TYPE"));
         assertEquals(6, rs.getInt("ORDINAL_POSITION"));
         assertEquals(6, rs.getInt("COLUMN_SIZE"));
         assertEquals(3, rs.getInt("DECIMAL_DIGITS"));
@@ -761,8 +764,8 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
             
             HTableInterface htable = conn2.getQueryServices().getTable(SchemaUtil.getTableNameAsBytes(MDTEST_SCHEMA_NAME,MDTEST_NAME));
             Put put = new Put(Bytes.toBytes("0"));
-            put.add(cfB, Bytes.toBytes("COL1"), ts+6, PDataType.INTEGER.toBytes(1));
-            put.add(cfC, Bytes.toBytes("COL2"), ts+6, PDataType.LONG.toBytes(2));
+            put.add(cfB, Bytes.toBytes("COL1"), ts+6, PInteger.INSTANCE.toBytes(1));
+            put.add(cfC, Bytes.toBytes("COL2"), ts+6, PLong.INSTANCE.toBytes(2));
             htable.put(put);
             conn2.close();
             
@@ -826,8 +829,8 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT {
             conn92.close();
             
             put = new Put(Bytes.toBytes("1"));
-            put.add(cfB, Bytes.toBytes("COL1"), ts+39, PDataType.INTEGER.toBytes(3));
-            put.add(cfC, Bytes.toBytes("COL2"), ts+39, PDataType.LONG.toBytes(4));
+            put.add(cfB, Bytes.toBytes("COL1"), ts+39, PInteger.INSTANCE.toBytes(3));
+            put.add(cfC, Bytes.toBytes("COL2"), ts+39, PLong.INSTANCE.toBytes(4));
             htable.put(put);
 
             props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
index baf0dec..d3bbe23 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
@@ -49,7 +49,7 @@ import java.util.Properties;
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
@@ -245,7 +245,7 @@ public class QueryIT extends BaseQueryIT {
         stmt.setString(1, tenantId);
         stmt.setString(2, ROW4);
         Timestamp tsValue1 = new Timestamp(5000);
-        byte[] ts1 = PDataType.TIMESTAMP.toBytes(tsValue1);
+        byte[] ts1 = PTimestamp.INSTANCE.toBytes(tsValue1);
         stmt.setTimestamp(3, tsValue1);
         stmt.execute();
         
@@ -267,7 +267,7 @@ public class QueryIT extends BaseQueryIT {
         stmt.setString(2, ROW5);
         Timestamp tsValue2 = new Timestamp(5000);
         tsValue2.setNanos(200);
-        byte[] ts2 = PDataType.TIMESTAMP.toBytes(tsValue2);
+        byte[] ts2 = PTimestamp.INSTANCE.toBytes(tsValue2);
         stmt.setTimestamp(3, tsValue2);
         stmt.setTime(4, new Time(tsValue2.getTime()));
         stmt.execute();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
index 2986bf4..ca8ab81 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
@@ -1,3 +1,20 @@
+/*
+ * 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.end2end;
 
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToNumberFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToNumberFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToNumberFunctionIT.java
index daf2c63..90b860b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToNumberFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToNumberFunctionIT.java
@@ -34,7 +34,7 @@ import java.util.Locale;
 import java.util.Properties;
 
 import org.apache.phoenix.expression.function.ToNumberFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.AfterClass;
@@ -181,7 +181,7 @@ public class ToNumberFunctionIT extends BaseClientManagedTimeIT {
     @Test
     public void testKeyProjectionWithDecimalValue() throws Exception {
         String query = "select to_number(a_string) from " + TO_NUMBER_TABLE_NAME + " where a_id = 2";
-        BigDecimal expectedDecimalValue = (BigDecimal)PDataType.DECIMAL.toObject("2.2");
+        BigDecimal expectedDecimalValue = (BigDecimal) PDecimal.INSTANCE.toObject("2.2");
         runOneRowQueryTest(query, expectedDecimalValue);
     }
     
@@ -195,7 +195,7 @@ public class ToNumberFunctionIT extends BaseClientManagedTimeIT {
     @Test
     public void testNonKeyProjectionWithDecimalValue() throws Exception {
         String query = "select to_number(b_string) from " + TO_NUMBER_TABLE_NAME + " where a_id = 2";
-        BigDecimal expectedDecimalValue = (BigDecimal)PDataType.DECIMAL.toObject("2.2");
+        BigDecimal expectedDecimalValue = (BigDecimal) PDecimal.INSTANCE.toObject("2.2");
         runOneRowQueryTest(query, expectedDecimalValue);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
index c1a960f..d319b4d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
@@ -45,7 +45,7 @@ import java.util.Properties;
 
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
@@ -451,8 +451,8 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testUpsertSelectLongToInt() throws Exception {
-        byte[][] splits = new byte[][] {PDataType.INTEGER.toBytes(1), PDataType.INTEGER.toBytes(2),
-                PDataType.INTEGER.toBytes(3), PDataType.INTEGER.toBytes(4)};
+        byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1), PInteger.INSTANCE.toBytes(2),
+                PInteger.INSTANCE.toBytes(3), PInteger.INSTANCE.toBytes(4)};
         long ts = nextTimestamp();
         ensureTableCreated(getUrl(),"IntKeyTest",splits, ts-2);
         Properties props = new Properties();
@@ -488,8 +488,8 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testUpsertSelectRunOnServer() throws Exception {
-        byte[][] splits = new byte[][] {PDataType.INTEGER.toBytes(1), PDataType.INTEGER.toBytes(2),
-                PDataType.INTEGER.toBytes(3), PDataType.INTEGER.toBytes(4)};
+        byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1), PInteger.INSTANCE.toBytes(2),
+                PInteger.INSTANCE.toBytes(3), PInteger.INSTANCE.toBytes(4)};
         long ts = nextTimestamp();
         createTestTable(getUrl(), "create table IntKeyTest (i integer not null primary key desc, j integer)" ,splits, ts-2);
         Properties props = new Properties();
@@ -551,8 +551,8 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testUpsertSelectOnDescToAsc() throws Exception {
-        byte[][] splits = new byte[][] {PDataType.INTEGER.toBytes(1), PDataType.INTEGER.toBytes(2),
-                PDataType.INTEGER.toBytes(3), PDataType.INTEGER.toBytes(4)};
+        byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1), PInteger.INSTANCE.toBytes(2),
+                PInteger.INSTANCE.toBytes(3), PInteger.INSTANCE.toBytes(4)};
         long ts = nextTimestamp();
         createTestTable(getUrl(), "create table IntKeyTest (i integer not null primary key desc, j integer)" ,splits, ts-2);
         Properties props = new Properties();
@@ -591,8 +591,8 @@ public class UpsertSelectIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testUpsertSelectRowKeyMutationOnSplitedTable() throws Exception {
-        byte[][] splits = new byte[][] {PDataType.INTEGER.toBytes(1), PDataType.INTEGER.toBytes(2),
-                PDataType.INTEGER.toBytes(3), PDataType.INTEGER.toBytes(4)};
+        byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1), PInteger.INSTANCE.toBytes(2),
+                PInteger.INSTANCE.toBytes(3), PInteger.INSTANCE.toBytes(4)};
         long ts = nextTimestamp();
         ensureTableCreated(getUrl(),"IntKeyTest",splits,ts-2);
         Properties props = new Properties();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
index 825c09b..ba04ad7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexTestUtil.java
@@ -43,7 +43,7 @@ import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PRow;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.RowKeySchema;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/it/java/org/apache/phoenix/trace/TracingTestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/trace/TracingTestUtil.java b/phoenix-core/src/it/java/org/apache/phoenix/trace/TracingTestUtil.java
index d502175..b2b12f7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/trace/TracingTestUtil.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/trace/TracingTestUtil.java
@@ -1,3 +1,20 @@
+/*
+ * 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.trace;
 
 import org.apache.hadoop.metrics2.MetricsSink;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/antlr3/PhoenixSQL.g
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/antlr3/PhoenixSQL.g b/phoenix-core/src/main/antlr3/PhoenixSQL.g
index 9206cf4..2223380 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -147,11 +147,11 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.stats.StatisticsCollectionScope;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.parse.LikeParseNode.LikeType;
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/LocalIndexSplitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/LocalIndexSplitter.java b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/LocalIndexSplitter.java
index 9ec5d01..713fa59 100644
--- a/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/LocalIndexSplitter.java
+++ b/phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/LocalIndexSplitter.java
@@ -31,17 +31,13 @@ import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
-import org.apache.hadoop.hbase.regionserver.HRegion;
-import org.apache.hadoop.hbase.regionserver.HRegionServer;
-import org.apache.hadoop.hbase.regionserver.RegionServerServices;
-import org.apache.hadoop.hbase.regionserver.IndexSplitTransaction;
 import org.apache.hadoop.hbase.util.PairOfSameType;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.parse.AlterIndexStatement;
 import org.apache.phoenix.parse.ParseNodeFactory;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.schema.MetaDataClient;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
@@ -70,7 +66,7 @@ public class LocalIndexSplitter extends BaseRegionObserver {
         }
         RegionServerServices rss = ctx.getEnvironment().getRegionServerServices();
         if (tableDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) == null
-                || !Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(tableDesc
+                || !Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(tableDesc
                         .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
             HRegion indexRegion = IndexUtil.getIndexRegion(environment);
             if (indexRegion == null) return;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/ColumnProjector.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/ColumnProjector.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/ColumnProjector.java
index 59b5c10..934d73c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/ColumnProjector.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/ColumnProjector.java
@@ -22,7 +22,7 @@ import java.sql.SQLException;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
index d31a8f1..65d2c04 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateSequenceCompiler.java
@@ -23,7 +23,6 @@ import java.util.Collections;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.execute.MutationState;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -34,9 +33,11 @@ import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.MetaDataClient;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
 
 import org.apache.phoenix.util.SequenceUtil;
@@ -57,7 +58,7 @@ public class CreateSequenceCompiler {
 
         @Override
         public PDataType getDataType() {
-            return PDataType.LONG;
+            return PLong.INSTANCE;
         }
 
         @Override
@@ -85,7 +86,7 @@ public class CreateSequenceCompiler {
 
         @Override
         public PDataType getDataType() {
-            return PDataType.INTEGER;
+            return PInteger.INSTANCE;
         }
 
         @Override
@@ -119,11 +120,11 @@ public class CreateSequenceCompiler {
             Expression expression, SQLExceptionCode code) throws SQLException {
         ImmutableBytesWritable ptr = context.getTempPtr();
         expression.evaluate(null, ptr);
-        if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PDataType.LONG)) {
+        if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             TableName sequenceName = sequence.getSequenceName();
             throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code);
         }
-        return (Long) PDataType.LONG.toObject(ptr, expression.getDataType());
+        return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType());
     }
 
     public MutationPlan compile(final CreateSequenceStatement sequence) throws SQLException {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
index b04d6e3..0a2ee38 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
@@ -64,8 +64,8 @@ import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.MetaDataEntityNotFoundException;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PRow;
 import org.apache.phoenix.schema.PTable;
@@ -495,7 +495,7 @@ public class DeleteCompiler {
                             ResultIterator iterator = aggPlan.iterator();
                             try {
                                 Tuple row = iterator.next();
-                                final long mutationCount = (Long)projector.getColumnProjector(0).getValue(row, PDataType.LONG, ptr);
+                                final long mutationCount = (Long)projector.getColumnProjector(0).getValue(row, PLong.INSTANCE, ptr);
                                 return new MutationState(maxSize, connection) {
                                     @Override
                                     public long getUpdateCount() {
@@ -554,7 +554,7 @@ public class DeleteCompiler {
                             long totalRowCount = 0;
                             while ((tuple=iterator.next()) != null) {// Runs query
                                 Cell kv = tuple.getValue(0);
-                                totalRowCount += PDataType.LONG.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
+                                totalRowCount += PLong.INSTANCE.getCodec().decodeLong(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault());
                             }
                             // Return total number of rows that have been delete. In the case of auto commit being off
                             // the mutations will all be in the mutation state of the current connection.


[12/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
new file mode 100644
index 0000000..6b2dc84
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimal.java
@@ -0,0 +1,396 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.NumberUtil;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.text.Format;
+
+public class PDecimal extends PDataType<BigDecimal> {
+
+  public static final PDecimal INSTANCE = new PDecimal();
+
+  private static final BigDecimal MIN_DOUBLE_AS_BIG_DECIMAL =
+      BigDecimal.valueOf(-Double.MAX_VALUE);
+  private static final BigDecimal MAX_DOUBLE_AS_BIG_DECIMAL =
+      BigDecimal.valueOf(Double.MAX_VALUE);
+  private static final BigDecimal MIN_FLOAT_AS_BIG_DECIMAL =
+      BigDecimal.valueOf(-Float.MAX_VALUE);
+  private static final BigDecimal MAX_FLOAT_AS_BIG_DECIMAL =
+      BigDecimal.valueOf(Float.MAX_VALUE);
+
+  private PDecimal() {
+    super("DECIMAL", Types.DECIMAL, BigDecimal.class, null, 8);
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    if (object == null) {
+      return ByteUtil.EMPTY_BYTE_ARRAY;
+    }
+    BigDecimal v = (BigDecimal) object;
+    v = NumberUtil.normalize(v);
+    int len = getLength(v);
+    byte[] result = new byte[Math.min(len, MAX_BIG_DECIMAL_BYTES)];
+    PDataType.toBytes(v, result, 0, len);
+    return result;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      return 0;
+    }
+    BigDecimal v = (BigDecimal) object;
+    v = NumberUtil.normalize(v);
+    int len = getLength(v);
+    return PDataType.toBytes(v, bytes, offset, len);
+  }
+
+  private int getLength(BigDecimal v) {
+    int signum = v.signum();
+    if (signum == 0) { // Special case for zero
+      return 1;
+    }
+            /*
+             * Size of DECIMAL includes:
+             * 1) one byte for exponent
+             * 2) one byte for terminal byte if negative
+             * 3) one byte for every two digits with the following caveats:
+             *    a) add one to round up in the case when there is an odd number of digits
+             *    b) add one in the case that the scale is odd to account for 10x of lowest significant digit
+             *       (basically done to increase the range of exponents that can be represented)
+             */
+    return (signum < 0 ? 2 : 1) + (v.precision() + 1 + (v.scale() % 2 == 0 ? 0 : 1)) / 2;
+  }
+
+  @Override
+  public int estimateByteSize(Object o) {
+    if (o == null) {
+      return 1;
+    }
+    BigDecimal v = (BigDecimal) o;
+    // TODO: should we strip zeros and round here too?
+    return Math.min(getLength(v), MAX_BIG_DECIMAL_BYTES);
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    if (o == null) {
+      return MAX_PRECISION;
+    }
+    BigDecimal v = (BigDecimal) o;
+    return v.precision();
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return null;
+  }
+
+  @Override
+  public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    Preconditions.checkNotNull(sortOrder);
+    if (l == 0) {
+      return null;
+    }
+    if (actualType == PDecimal.INSTANCE) {
+      if (sortOrder == SortOrder.DESC) {
+        b = SortOrder.invert(b, o, new byte[l], 0, l);
+        o = 0;
+      }
+      return toBigDecimal(b, o, l);
+    } else if (equalsAny(actualType, PDate.INSTANCE, PTime.INSTANCE, PUnsignedDate.INSTANCE,
+        PUnsignedTime.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+        PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+        PUnsignedTinyint.INSTANCE)) {
+      return BigDecimal.valueOf(actualType.getCodec().decodeLong(b, o, sortOrder));
+    } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder));
+    } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+      return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder));
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE,
+        PUnsignedTimestamp.INSTANCE)) {
+      long millisPart = actualType.getCodec().decodeLong(b, o, sortOrder);
+      int nanoPart = PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder);
+      BigDecimal nanosPart = BigDecimal.valueOf(
+          (nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)
+              / QueryConstants.MILLIS_TO_NANOS_CONVERTOR);
+      return BigDecimal.valueOf(millisPart).add(nanosPart);
+    } else if (actualType == PBoolean.INSTANCE) {
+      return (Boolean) PBoolean.INSTANCE.toObject(b, o, l, actualType, sortOrder) ?
+          BigDecimal.ONE :
+          BigDecimal.ZERO;
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    if (equalsAny(actualType, PInteger.INSTANCE, PUnsignedInt.INSTANCE)) {
+      return BigDecimal.valueOf((Integer) object);
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return BigDecimal.valueOf((Long) object);
+    } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+      return BigDecimal.valueOf((Short) object);
+    } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+      return BigDecimal.valueOf((Byte) object);
+    } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      return BigDecimal.valueOf((Float) object);
+    } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+      return BigDecimal.valueOf((Double) object);
+    } else if (actualType == PDecimal.INSTANCE) {
+      return object;
+    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
+        PUnsignedTime.INSTANCE)) {
+      java.util.Date d = (java.util.Date) object;
+      return BigDecimal.valueOf(d.getTime());
+    } else if (equalsAny(actualType, PTimestamp.INSTANCE,
+        PUnsignedTimestamp.INSTANCE)) {
+      Timestamp ts = (Timestamp) object;
+      long millisPart = ts.getTime();
+      BigDecimal nanosPart = BigDecimal.valueOf(
+          (ts.getNanos() % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)
+              / QueryConstants.MILLIS_TO_NANOS_CONVERTOR);
+      BigDecimal value = BigDecimal.valueOf(millisPart).add(nanosPart);
+      return value;
+    } else if (actualType == PBoolean.INSTANCE) {
+      return ((Boolean) object) ? BigDecimal.ONE : BigDecimal.ZERO;
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return MAX_BIG_DECIMAL_BYTES;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PDecimal.INSTANCE) {
+      return ((BigDecimal) lhs).compareTo((BigDecimal) rhs);
+    }
+    return -rhsType.compareTo(rhs, lhs, this);
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return super.isCastableTo(targetType) || targetType.isCoercibleTo(
+        PTimestamp.INSTANCE) || targetType.equals(PBoolean.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      BigDecimal bd;
+      if (equalsAny(targetType, PUnsignedLong.INSTANCE, PUnsignedInt.INSTANCE,
+          PUnsignedSmallint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+        bd = (BigDecimal) value;
+        if (bd.signum() == -1) {
+          return false;
+        }
+      } else if (targetType.equals(PLong.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          bd.longValueExact();
+          return true;
+        } catch (ArithmeticException e) {
+          return false;
+        }
+      } else if (targetType.equals(PInteger.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          bd.intValueExact();
+          return true;
+        } catch (ArithmeticException e) {
+          return false;
+        }
+      } else if (targetType.equals(PSmallint.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          bd.shortValueExact();
+          return true;
+        } catch (ArithmeticException e) {
+          return false;
+        }
+      } else if (targetType.equals(PTinyint.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          bd.byteValueExact();
+          return true;
+        } catch (ArithmeticException e) {
+          return false;
+        }
+      } else if (targetType.equals(PUnsignedFloat.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          BigDecimal maxFloat = MAX_FLOAT_AS_BIG_DECIMAL;
+          boolean isNegtive = (bd.signum() == -1);
+          return bd.compareTo(maxFloat) <= 0 && !isNegtive;
+        } catch (Exception e) {
+          return false;
+        }
+      } else if (targetType.equals(PFloat.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          BigDecimal maxFloat = MAX_FLOAT_AS_BIG_DECIMAL;
+          // Float.MIN_VALUE should not be used here, as this is the
+          // smallest in terms of closest to zero.
+          BigDecimal minFloat = MIN_FLOAT_AS_BIG_DECIMAL;
+          return bd.compareTo(maxFloat) <= 0 && bd.compareTo(minFloat) >= 0;
+        } catch (Exception e) {
+          return false;
+        }
+      } else if (targetType.equals(PUnsignedDouble.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          BigDecimal maxDouble = MAX_DOUBLE_AS_BIG_DECIMAL;
+          boolean isNegtive = (bd.signum() == -1);
+          return bd.compareTo(maxDouble) <= 0 && !isNegtive;
+        } catch (Exception e) {
+          return false;
+        }
+      } else if (targetType.equals(PDouble.INSTANCE)) {
+        bd = (BigDecimal) value;
+        try {
+          BigDecimal maxDouble = MAX_DOUBLE_AS_BIG_DECIMAL;
+          BigDecimal minDouble = MIN_DOUBLE_AS_BIG_DECIMAL;
+          return bd.compareTo(maxDouble) <= 0 && bd.compareTo(minDouble) >= 0;
+        } catch (Exception e) {
+          return false;
+        }
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isSizeCompatible(ImmutableBytesWritable ptr, Object value, PDataType srcType,
+      Integer maxLength, Integer scale, Integer desiredMaxLength, Integer desiredScale) {
+    if (ptr.getLength() == 0) {
+      return true;
+    }
+    // Use the scale from the value if provided, as it prevents a deserialization.
+    // The maxLength and scale for the underlying expression are ignored, because they
+    // are not relevant in this case: for example a DECIMAL(10,2) may be assigned to a
+    // DECIMAL(5,0) as long as the value fits.
+    if (value != null) {
+      BigDecimal v = (BigDecimal) value;
+      maxLength = v.precision();
+      scale = v.scale();
+    } else {
+      int[] v = getDecimalPrecisionAndScale(ptr.get(), ptr.getOffset(), ptr.getLength());
+      maxLength = v[0];
+      scale = v[1];
+    }
+    if (desiredMaxLength != null && desiredScale != null && maxLength != null && scale != null &&
+        ((desiredScale == null && desiredMaxLength < maxLength) ||
+            (desiredMaxLength - desiredScale) < (maxLength - scale))) {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
+      SortOrder expectedModifier) {
+    if (desiredScale == null) {
+      // deiredScale not available, or we do not have scale requirement, delegate to parents.
+      super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,
+          desiredScale, expectedModifier);
+      return;
+    }
+    if (ptr.getLength() == 0) {
+      return;
+    }
+    if (scale == null) {
+      if (object != null) {
+        BigDecimal v = (BigDecimal) object;
+        scale = v.scale();
+      } else {
+        int[] v = getDecimalPrecisionAndScale(ptr.get(), ptr.getOffset(), ptr.getLength());
+        scale = v[1];
+      }
+    }
+    if (this == actualType && scale <= desiredScale) {
+      // No coerce and rescale necessary
+      return;
+    } else {
+      BigDecimal decimal;
+      // Rescale is necessary.
+      if (object != null) { // value object is passed in.
+        decimal = (BigDecimal) toObject(object, actualType);
+      } else { // only value bytes is passed in, need to convert to object first.
+        decimal = (BigDecimal) toObject(ptr);
+      }
+      decimal = decimal.setScale(desiredScale, BigDecimal.ROUND_DOWN);
+      ptr.set(toBytes(decimal));
+    }
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      return new BigDecimal(value);
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Integer estimateByteSizeFromLength(Integer length) {
+    // No association of runtime byte size from decimal precision.
+    return null;
+  }
+
+  @Override
+  public String toStringLiteral(byte[] b, int offset, int length, Format formatter) {
+    if (formatter == null) {
+      BigDecimal o = (BigDecimal) toObject(b, offset, length);
+      return o.toPlainString();
+    }
+    return super.toStringLiteral(b, offset, length, formatter);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return new BigDecimal((Long) PLong.INSTANCE.getSampleValue(maxLength, arrayLength));
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimalArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimalArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimalArray.java
new file mode 100644
index 0000000..6874ac3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDecimalArray.java
@@ -0,0 +1,110 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PDecimalArray extends PArrayDataType<BigDecimal[]> {
+
+  public static final PDecimalArray INSTANCE = new PDecimalArray();
+
+  private PDecimalArray() {
+    super("DECIMAL ARRAY", PDataType.ARRAY_TYPE_BASE + PDecimal.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 35);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PDecimal.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PDecimal.INSTANCE, sortOrder, maxLength, scale,
+        PDecimal.INSTANCE);
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray pArr = (PhoenixArray) value;
+    Object[] decimalArr = (Object[]) pArr.array;
+    for (Object i : decimalArr) {
+      if (!super.isCoercibleTo(PDecimal.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PDecimal.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDouble.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDouble.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDouble.java
new file mode 100644
index 0000000..d8e3c4f
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDouble.java
@@ -0,0 +1,311 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Doubles;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PDouble extends PDataType<Double> {
+
+  public static final PDouble INSTANCE = new PDouble();
+
+  private PDouble() {
+    super("DOUBLE", Types.DOUBLE, Double.class, new DoubleCodec(), 7);
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PDecimal.INSTANCE) {
+      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).doubleValue()));
+    }
+    return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_DOUBLE;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    if (o == null) {
+      return null;
+    }
+    Double v = (Double) o;
+    BigDecimal bd = BigDecimal.valueOf(v);
+    return bd.scale() == 0 ? null : bd.scale();
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    if (o == null) {
+      return null;
+    }
+    Double v = (Double) o;
+    BigDecimal db = BigDecimal.valueOf(v);
+    return db.precision();
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_DOUBLE];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeDouble(((Number) object).doubleValue(),
+        bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      return Double.parseDouble(value);
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    double de;
+    if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      de = (Float) object;
+      return de;
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      de = (Long) object;
+      return de;
+    } else if (equalsAny(actualType, PInteger.INSTANCE, PUnsignedInt.INSTANCE)) {
+      de = (Integer) object;
+      return de;
+    } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+      de = (Byte) object;
+      return de;
+    } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+      de = (Short) object;
+      return de;
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal d = (BigDecimal) object;
+      return d.doubleValue();
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Double toObject(byte[] b, int o, int l, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (l <= 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE,
+        PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+        PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+        PUnsignedTinyint.INSTANCE)) {
+      return actualType.getCodec().decodeDouble(b, o, sortOrder);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return bd.doubleValue();
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      double d = (Double) value;
+      if (targetType.equals(PUnsignedDouble.INSTANCE)) {
+        return d >= 0;
+      } else if (targetType.equals(PFloat.INSTANCE)) {
+        return Double.isNaN(d)
+            || d == Double.POSITIVE_INFINITY
+            || d == Double.NEGATIVE_INFINITY
+            || (d >= -Float.MAX_VALUE && d <= Float.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedFloat.INSTANCE)) {
+        return Double.isNaN(d) || d == Double.POSITIVE_INFINITY
+            || (d >= 0 && d <= Float.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedLong.INSTANCE)) {
+        return (d >= 0 && d <= Long.MAX_VALUE);
+      } else if (targetType.equals(PLong.INSTANCE)) {
+        return (d >= Long.MIN_VALUE && d <= Long.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedInt.INSTANCE)) {
+        return (d >= 0 && d <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PInteger.INSTANCE)) {
+        return (d >= Integer.MIN_VALUE && d <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
+        return (d >= 0 && d <= Short.MAX_VALUE);
+      } else if (targetType.equals(PSmallint.INSTANCE)) {
+        return (d >= Short.MIN_VALUE && d <= Short.MAX_VALUE);
+      } else if (targetType.equals(PTinyint.INSTANCE)) {
+        return (d >= Byte.MIN_VALUE && d < Byte.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
+        return (d >= 0 && d < Byte.MAX_VALUE);
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PDecimal.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return RANDOM.get().nextDouble();
+  }
+
+  static class DoubleCodec extends BaseCodec {
+
+    @Override
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+      double v = decodeDouble(b, o, sortOrder);
+      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Long without changing its value");
+      }
+      return (long) v;
+    }
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      double v = decodeDouble(b, o, sortOrder);
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Integer without changing its value");
+      }
+      return (int) v;
+    }
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      double v = decodeDouble(b, o, sortOrder);
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Byte without changing its value");
+      }
+      return (byte) v;
+    }
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      double v = decodeDouble(b, o, sortOrder);
+      if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Short without changing its value");
+      }
+      return (short) v;
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+      if (sortOrder == SortOrder.DESC) {
+        for (int i = o; i < Bytes.SIZEOF_LONG; i++) {
+          b[i] = (byte) (b[i] ^ 0xff);
+        }
+      }
+      long l = Bytes.toLong(b, o);
+      l--;
+      l ^= (~l >> Long.SIZE - 1) | Long.MIN_VALUE;
+      return Double.longBitsToDouble(l);
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      double v = decodeDouble(b, o, sortOrder);
+      if (Double.isNaN(v) || v == Double.NEGATIVE_INFINITY
+          || v == Double.POSITIVE_INFINITY
+          || (v >= -Float.MAX_VALUE && v <= Float.MAX_VALUE)) {
+        return (float) v;
+      } else {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Float without changing its value");
+      }
+
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      return encodeDouble(v, b, o);
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      return encodeDouble(v, b, o);
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      return encodeDouble(v, b, o);
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      return encodeDouble(v, b, o);
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+      long l = Double.doubleToLongBits(v);
+      l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1;
+      Bytes.putLong(b, o, l);
+      return Bytes.SIZEOF_LONG;
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      return encodeDouble(v, b, o);
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray.PrimitiveDoublePhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDoubleArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDoubleArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDoubleArray.java
new file mode 100644
index 0000000..7ecec61
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PDoubleArray.java
@@ -0,0 +1,108 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PDoubleArray extends PArrayDataType<double[]> {
+
+  public static final PDoubleArray INSTANCE = new PDoubleArray();
+
+  private PDoubleArray() {
+    super("DOUBLE ARRAY", PDataType.ARRAY_TYPE_BASE + PDouble.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 34);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PDouble.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+    return toObject(bytes, offset, length, PDouble.INSTANCE, sortOrder, maxLength, scale,
+        PDouble.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveDoublePhoenixArray pArr = (PhoenixArray.PrimitiveDoublePhoenixArray) value;
+    double[] doubleArr = (double[]) pArr.array;
+    for (double i : doubleArr) {
+      if (!super.isCoercibleTo(PDouble.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PDouble.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloat.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloat.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloat.java
new file mode 100644
index 0000000..608b270
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloat.java
@@ -0,0 +1,308 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PFloat extends PDataType<Float> {
+
+  public static final PFloat INSTANCE = new PFloat();
+
+  private PFloat() {
+    super("FLOAT", Types.FLOAT, Float.class, new FloatCodec(), 6);
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PDouble.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_FLOAT;
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    if (o == null) {
+      return null;
+    }
+    Float v = (Float) o;
+    BigDecimal bd = BigDecimal.valueOf(v);
+    return bd.scale() == 0 ? null : bd.scale();
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    if (o == null) {
+      return null;
+    }
+    Float v = (Float) o;
+    BigDecimal bd = BigDecimal.valueOf(v);
+    return bd.precision();
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_FLOAT];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] bytes, int offset) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeFloat(((Number) object).floatValue(),
+        bytes, offset);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      return Float.parseFloat(value);
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    float f;
+    if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+      double d = (Double) object;
+      if (Double.isNaN(d)
+          || d == Double.POSITIVE_INFINITY
+          || d == Double.NEGATIVE_INFINITY
+          || (d >= -Float.MAX_VALUE && d <= Float.MAX_VALUE)) {
+        return (float) d;
+      } else {
+        throw newIllegalDataException(
+            actualType + " value " + d + " cannot be cast to Float without changing its value");
+      }
+    } else if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      f = (Long) object;
+      return f;
+    } else if (equalsAny(actualType, PInteger.INSTANCE, PUnsignedInt.INSTANCE)) {
+      f = (Integer) object;
+      return f;
+    } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+      f = (Byte) object;
+      return f;
+    } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+      f = (Short) object;
+      return f;
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal dl = (BigDecimal) object;
+      return dl.floatValue();
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Float toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    if (l <= 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
+        PUnsignedDouble.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+        PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+        PUnsignedTinyint.INSTANCE)) {
+      return actualType.getCodec().decodeFloat(b, o, sortOrder);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return bd.floatValue();
+    }
+
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      float f = (Float) value;
+      if (targetType.equals(PUnsignedFloat.INSTANCE)) {
+        return f >= 0;
+      } else if (targetType.equals(PUnsignedLong.INSTANCE)) {
+        return (f >= 0 && f <= Long.MAX_VALUE);
+      } else if (targetType.equals(PLong.INSTANCE)) {
+        return (f >= Long.MIN_VALUE && f <= Long.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedInt.INSTANCE)) {
+        return (f >= 0 && f <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PInteger.INSTANCE)) {
+        return (f >= Integer.MIN_VALUE && f <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
+        return (f >= 0 && f <= Short.MAX_VALUE);
+      } else if (targetType.equals(PSmallint.INSTANCE)) {
+        return (f >= Short.MIN_VALUE && f <= Short.MAX_VALUE);
+      } else if (targetType.equals(PTinyint.INSTANCE)) {
+        return (f >= Byte.MIN_VALUE && f < Byte.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
+        return (f >= 0 && f < Byte.MAX_VALUE);
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return this.equals(targetType) || PDouble.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return RANDOM.get().nextFloat();
+  }
+
+  static class FloatCodec extends BaseCodec {
+
+    @Override
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+      float v = decodeFloat(b, o, sortOrder);
+      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Long without changing its value");
+      }
+      return (long) v;
+    }
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      float v = decodeFloat(b, o, sortOrder);
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Integer without changing its value");
+      }
+      return (int) v;
+    }
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      float v = decodeFloat(b, o, sortOrder);
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Byte without changing its value");
+      }
+      return (byte) v;
+    }
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      float v = decodeFloat(b, o, sortOrder);
+      if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Short without changing its value");
+      }
+      return (short) v;
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o,
+        SortOrder sortOrder) {
+      return decodeFloat(b, o, sortOrder);
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(b, o, Bytes.SIZEOF_INT);
+      if (sortOrder == SortOrder.DESC) {
+        for (int i = o; i < Bytes.SIZEOF_INT; i++) {
+          b[i] = (byte) (b[i] ^ 0xff);
+        }
+      }
+      int i = Bytes.toInt(b, o);
+      i--;
+      i ^= (~i >> Integer.SIZE - 1) | Integer.MIN_VALUE;
+      return Float.intBitsToFloat(i);
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      return encodeFloat(v, b, o);
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      return encodeFloat(v, b, o);
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      return encodeFloat(v, b, o);
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      return encodeFloat(v, b, o);
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      if (Double.isNaN(v) || v == Double.POSITIVE_INFINITY
+          || v == Double.NEGATIVE_INFINITY
+          || (v >= -Float.MAX_VALUE && v <= Float.MAX_VALUE)) {
+        return encodeFloat((float) v, b, o);
+      } else {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Float without changing its value");
+      }
+
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
+      int i = Float.floatToIntBits(v);
+      i = (i ^ ((i >> Integer.SIZE - 1) | Integer.MIN_VALUE)) + 1;
+      Bytes.putInt(b, o, i);
+      return Bytes.SIZEOF_FLOAT;
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray.PrimitiveFloatPhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloatArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloatArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloatArray.java
new file mode 100644
index 0000000..5e8ddb3
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PFloatArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PFloatArray extends PArrayDataType<float[]> {
+
+  public static final PFloatArray INSTANCE = new PFloatArray();
+
+  private PFloatArray() {
+    super("FLOAT ARRAY", PDataType.ARRAY_TYPE_BASE + PFloat.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 33);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PFloat.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PFloat.INSTANCE, sortOrder, maxLength, scale,
+        PFloat.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveFloatPhoenixArray pArr = (PhoenixArray.PrimitiveFloatPhoenixArray) value;
+    float[] floatArr = (float[]) pArr.array;
+    for (float i : floatArr) {
+      if (!super.isCoercibleTo(PFloat.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PFloat.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PInteger.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PInteger.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PInteger.java
new file mode 100644
index 0000000..c4760b5
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PInteger.java
@@ -0,0 +1,275 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PInteger extends PDataType<Integer> {
+
+  public static final PInteger INSTANCE = new PInteger();
+
+  private PInteger() {
+    super("INTEGER", Types.INTEGER, Integer.class, new IntCodec(), 3);
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_INT];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] b, int o) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeInt(((Number) object).intValue(), b, o);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    Object o = PLong.INSTANCE.toObject(object, actualType);
+    if (!(o instanceof Long) || o == null) {
+      return o;
+    }
+    long l = (Long) o;
+    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
+      throw newIllegalDataException(
+          actualType + " value " + l + " cannot be cast to Integer without changing its value");
+    }
+    int v = (int) l;
+    return v;
+  }
+
+  @Override
+  public Integer toObject(byte[] b, int o, int l, PDataType actualType,
+      SortOrder sortOrder, Integer maxLength, Integer scale) {
+    if (l == 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+        PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+        PUnsignedTinyint.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
+        PUnsignedDouble.INSTANCE)) {
+      return actualType.getCodec().decodeInt(b, o, sortOrder);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return bd.intValueExact();
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      int i;
+      if (equalsAny(targetType, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
+          PUnsignedLong.INSTANCE, PUnsignedInt.INSTANCE)) {
+        i = (Integer) value;
+        return i >= 0;
+      } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
+        i = (Integer) value;
+        return (i >= 0 && i <= Short.MAX_VALUE);
+      } else if (targetType.equals(PSmallint.INSTANCE)) {
+        i = (Integer) value;
+        return (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE);
+      } else if (targetType.equals(PTinyint.INSTANCE)) {
+        i = (Integer) value;
+        return (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
+        i = (Integer) value;
+        return (i >= 0 && i < Byte.MAX_VALUE);
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return equalsAny(targetType, this, PFloat.INSTANCE) || PLong.INSTANCE.isCoercibleTo(targetType);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_INT;
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return INT_PRECISION;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      return Integer.parseInt(value);
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return RANDOM.get().nextInt();
+  }
+
+  static class IntCodec extends BaseCodec {
+
+    @Override
+    public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+      return decodeInt(b, o, sortOrder);
+    }
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      return decodeInt(b, o, sortOrder);
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o,
+        SortOrder sortOrder) {
+      return decodeInt(b, o, sortOrder);
+    }
+
+    @Override
+    public int decodeInt(byte[] bytes, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(bytes, o, Bytes.SIZEOF_INT);
+      int v;
+      if (sortOrder == SortOrder.ASC) {
+        v = bytes[o] ^ 0x80; // Flip sign bit back
+        for (int i = 1; i < Bytes.SIZEOF_INT; i++) {
+          v = (v << 8) + (bytes[o + i] & 0xff);
+        }
+      } else {
+        v = bytes[o] ^ 0xff ^ 0x80; // Flip sign bit back
+        for (int i = 1; i < Bytes.SIZEOF_INT; i++) {
+          v = (v << 8) + ((bytes[o + i] ^ 0xff) & 0xff);
+        }
+      }
+      return v;
+    }
+
+    @Override
+    public int encodeInt(int v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_INT);
+      b[o + 0] = (byte) ((v >> 24) ^ 0x80); // Flip sign bit so that INTEGER is binary comparable
+      b[o + 1] = (byte) (v >> 16);
+      b[o + 2] = (byte) (v >> 8);
+      b[o + 3] = (byte) v;
+      return Bytes.SIZEOF_INT;
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Integer without changing its value");
+      }
+      return encodeInt((int) v, b, o);
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Integer without changing its value");
+      }
+      return encodeInt((int) v, b, o);
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Integer without changing its value");
+      }
+      return encodeInt((int) v, b, o);
+    }
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      int v = decodeInt(b, o, sortOrder);
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Byte without changing its value");
+      }
+      return (byte) v;
+    }
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      int v = decodeInt(b, o, sortOrder);
+      if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Short without changing its value");
+      }
+      return (short) v;
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      return encodeInt(v, b, o);
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      return encodeInt(v, b, o);
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray.PrimitiveIntPhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PIntegerArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PIntegerArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PIntegerArray.java
new file mode 100644
index 0000000..28a5c4c
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PIntegerArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PIntegerArray extends PArrayDataType<int[]> {
+
+  public static final PIntegerArray INSTANCE = new PIntegerArray();
+
+  private PIntegerArray() {
+    super("INTEGER ARRAY", PDataType.ARRAY_TYPE_BASE + PInteger.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 24);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PInteger.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PInteger.INSTANCE, sortOrder, maxLength, scale,
+        PInteger.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveIntPhoenixArray pArr = (PhoenixArray.PrimitiveIntPhoenixArray) value;
+    int[] intArr = (int[]) pArr.array;
+    for (int i : intArr) {
+      if (!super.isCoercibleTo(PInteger.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PInteger.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
new file mode 100644
index 0000000..1bef844
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java
@@ -0,0 +1,331 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Doubles;
+import com.google.common.primitives.Longs;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PLong extends PDataType<Long> {
+
+  public static final PLong INSTANCE = new PLong();
+
+  private PLong() {
+    super("BIGINT", Types.BIGINT, Long.class, new LongCodec(), 2);
+  }
+
+  @Override
+  public Integer getScale(Object o) {
+    return ZERO;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    byte[] b = new byte[Bytes.SIZEOF_LONG];
+    toBytes(object, b, 0);
+    return b;
+  }
+
+  @Override
+  public int toBytes(Object object, byte[] b, int o) {
+    if (object == null) {
+      throw newIllegalDataException(this + " may not be null");
+    }
+    return this.getCodec().encodeLong(((Number) object).longValue(), b, o);
+  }
+
+  @Override
+  public Object toObject(Object object, PDataType actualType) {
+    if (object == null) {
+      return null;
+    }
+    long s;
+    if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE)) {
+      return object;
+    } else if (equalsAny(actualType, PUnsignedInt.INSTANCE,
+        PInteger.INSTANCE)) {
+      s = (Integer) object;
+      return s;
+    } else if (equalsAny(actualType, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) {
+      s = (Byte) object;
+      return s;
+    } else if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+      s = (Short) object;
+      return s;
+    } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      Float f = (Float) object;
+      if (f > Long.MAX_VALUE || f < Long.MIN_VALUE) {
+        throw newIllegalDataException(
+            actualType + " value " + f + " cannot be cast to Long without changing its value");
+      }
+      s = f.longValue();
+      return s;
+    } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) {
+      Double de = (Double) object;
+      if (de > Long.MAX_VALUE || de < Long.MIN_VALUE) {
+        throw newIllegalDataException(
+            actualType + " value " + de + " cannot be cast to Long without changing its value");
+      }
+      s = de.longValue();
+      return s;
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal d = (BigDecimal) object;
+      return d.longValueExact();
+    } else if (equalsAny(actualType, PDate.INSTANCE, PUnsignedDate.INSTANCE, PTime.INSTANCE,
+        PUnsignedTime.INSTANCE)) {
+      java.util.Date date = (java.util.Date) object;
+      return date.getTime();
+    }
+    return throwConstraintViolationException(actualType, this);
+  }
+
+  @Override
+  public Long toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder,
+      Integer maxLength, Integer scale) {
+    if (l == 0) {
+      return null;
+    }
+    if (equalsAny(actualType, PLong.INSTANCE, PUnsignedLong.INSTANCE,
+        PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE,
+        PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PFloat.INSTANCE,
+        PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PDate.INSTANCE,
+        PUnsignedDate.INSTANCE, PTime.INSTANCE, PUnsignedTime.INSTANCE)) {
+      return actualType.getCodec().decodeLong(b, o, sortOrder);
+    } else if (actualType == PDecimal.INSTANCE) {
+      BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder);
+      return bd.longValueExact();
+    }
+    throwConstraintViolationException(actualType, this);
+    return null;
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    // In general, don't allow conversion of LONG to INTEGER. There are times when
+    // we check isComparableTo for a more relaxed check and then throw a runtime
+    // exception if we overflow
+    return equalsAny(targetType, this, PDecimal.INSTANCE, PVarbinary.INSTANCE, PBinary.INSTANCE, PDouble.INSTANCE);
+  }
+
+  @Override
+  public boolean isComparableTo(PDataType targetType) {
+    return PDecimal.INSTANCE.isComparableTo(targetType);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value != null) {
+      long l;
+      if (equalsAny(targetType, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
+          PUnsignedLong.INSTANCE)) {
+        l = (Long) value;
+        return l >= 0;
+      } else if (targetType.equals(PUnsignedInt.INSTANCE)) {
+        l = (Long) value;
+        return (l >= 0 && l <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PInteger.INSTANCE)) {
+        l = (Long) value;
+        return (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedSmallint.INSTANCE)) {
+        l = (Long) value;
+        return (l >= 0 && l <= Short.MAX_VALUE);
+      } else if (targetType.equals(PSmallint.INSTANCE)) {
+        l = (Long) value;
+        return (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE);
+      } else if (targetType.equals(PTinyint.INSTANCE)) {
+        l = (Long) value;
+        return (l >= Byte.MIN_VALUE && l < Byte.MAX_VALUE);
+      } else if (targetType.equals(PUnsignedTinyint.INSTANCE)) {
+        l = (Long) value;
+        return (l >= 0 && l < Byte.MAX_VALUE);
+      }
+    }
+    return super.isCoercibleTo(targetType, value);
+  }
+
+  @Override
+  public boolean isCastableTo(PDataType targetType) {
+    return super.isCastableTo(targetType) || targetType.isCoercibleTo(PTimestamp.INSTANCE);
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return true;
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return Bytes.SIZEOF_LONG;
+  }
+
+  @Override
+  public Integer getMaxLength(Object o) {
+    return LONG_PRECISION;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    if (rhsType == PDecimal.INSTANCE) {
+      return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
+    } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) {
+      return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
+    }
+    return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
+  }
+
+  @Override
+  public Object toObject(String value) {
+    if (value == null || value.length() == 0) {
+      return null;
+    }
+    try {
+      return Long.parseLong(value);
+    } catch (NumberFormatException e) {
+      throw newIllegalDataException(e);
+    }
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return RANDOM.get().nextLong();
+  }
+
+  static class LongCodec extends BaseCodec {
+
+    @Override
+    public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+      return decodeLong(b, o, sortOrder);
+    }
+
+    @Override
+    public double decodeDouble(byte[] b, int o, SortOrder sortOrder) {
+      return decodeLong(b, o, sortOrder);
+    }
+
+    @Override
+    public long decodeLong(byte[] bytes, int o, SortOrder sortOrder) {
+      Preconditions.checkNotNull(sortOrder);
+      checkForSufficientLength(bytes, o, Bytes.SIZEOF_LONG);
+      long v;
+      byte b = bytes[o];
+      if (sortOrder == SortOrder.ASC) {
+        v = b ^ 0x80; // Flip sign bit back
+        for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
+          b = bytes[o + i];
+          v = (v << 8) + (b & 0xff);
+        }
+      } else {
+        b = (byte) (b ^ 0xff);
+        v = b ^ 0x80; // Flip sign bit back
+        for (int i = 1; i < Bytes.SIZEOF_LONG; i++) {
+          b = bytes[o + i];
+          b ^= 0xff;
+          v = (v << 8) + (b & 0xff);
+        }
+      }
+      return v;
+    }
+
+    @Override
+    public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+      long v = decodeLong(b, o, sortOrder);
+      if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Integer without changing its value");
+      }
+      return (int) v;
+    }
+
+    @Override
+    public int encodeFloat(float v, byte[] b, int o) {
+      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Long without changing its value");
+      }
+      return encodeLong((long) v, b, o);
+    }
+
+    @Override
+    public int encodeDouble(double v, byte[] b, int o) {
+      if (v < Long.MIN_VALUE || v > Long.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be encoded as an Long without changing its value");
+      }
+      return encodeLong((long) v, b, o);
+    }
+
+    @Override
+    public int encodeLong(long v, byte[] b, int o) {
+      checkForSufficientLength(b, o, Bytes.SIZEOF_LONG);
+      b[o + 0] = (byte) ((v >> 56) ^ 0x80); // Flip sign bit so that INTEGER is binary comparable
+      b[o + 1] = (byte) (v >> 48);
+      b[o + 2] = (byte) (v >> 40);
+      b[o + 3] = (byte) (v >> 32);
+      b[o + 4] = (byte) (v >> 24);
+      b[o + 5] = (byte) (v >> 16);
+      b[o + 6] = (byte) (v >> 8);
+      b[o + 7] = (byte) v;
+      return Bytes.SIZEOF_LONG;
+    }
+
+    @Override
+    public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+      long v = decodeLong(b, o, sortOrder);
+      if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Byte without changing its value");
+      }
+      return (byte) v;
+    }
+
+    @Override
+    public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+      long v = decodeLong(b, o, sortOrder);
+      if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+        throw newIllegalDataException(
+            "Value " + v + " cannot be cast to Short without changing its value");
+      }
+      return (short) v;
+    }
+
+    @Override
+    public int encodeByte(byte v, byte[] b, int o) {
+      return encodeLong(v, b, o);
+    }
+
+    @Override
+    public int encodeShort(short v, byte[] b, int o) {
+      return encodeLong(v, b, o);
+    }
+
+    @Override
+    public PhoenixArrayFactory getPhoenixArrayFactory() {
+      return new PhoenixArrayFactory() {
+        @Override
+        public PhoenixArray newArray(PDataType type, Object[] elements) {
+          return new PhoenixArray.PrimitiveLongPhoenixArray(type, elements);
+        }
+      };
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLongArray.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLongArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLongArray.java
new file mode 100644
index 0000000..0670792
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLongArray.java
@@ -0,0 +1,109 @@
+/*
+ * 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.schema.types;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.sql.Types;
+
+public class PLongArray extends PArrayDataType<long[]> {
+
+  public static final PLongArray INSTANCE = new PLongArray();
+
+  private PLongArray() {
+    super("BIGINT ARRAY", PDataType.ARRAY_TYPE_BASE + PLong.INSTANCE.getSqlType(),
+        PhoenixArray.class, null, 30);
+  }
+
+  @Override
+  public boolean isArrayType() {
+    return true;
+  }
+
+  @Override
+  public boolean isFixedWidth() {
+    return false;
+  }
+
+  @Override
+  public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+    return compareTo(lhs, rhs);
+  }
+
+  @Override
+  public Integer getByteSize() {
+    return null;
+  }
+
+  @Override
+  public byte[] toBytes(Object object) {
+    return toBytes(object, SortOrder.ASC);
+  }
+
+  @Override
+  public byte[] toBytes(Object object, SortOrder sortOrder) {
+    return toBytes(object, PLong.INSTANCE, sortOrder);
+  }
+
+  @Override
+  public Object toObject(byte[] bytes, int offset, int length,
+      PDataType actualType, SortOrder sortOrder, Integer maxLength,
+      Integer scale) {
+    return toObject(bytes, offset, length, PLong.INSTANCE, sortOrder, maxLength, scale,
+        PLong.INSTANCE);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType) {
+    return isCoercibleTo(targetType, this);
+  }
+
+  @Override
+  public boolean isCoercibleTo(PDataType targetType, Object value) {
+    if (value == null) {
+      return true;
+    }
+    PhoenixArray.PrimitiveLongPhoenixArray pArr = (PhoenixArray.PrimitiveLongPhoenixArray) value;
+    long[] longArr = (long[]) pArr.array;
+    for (long i : longArr) {
+      if (!super.isCoercibleTo(PLong.INSTANCE, i)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public int getResultSetSqlType() {
+    return Types.ARRAY;
+  }
+
+  @Override
+  public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType,
+      Integer maxLength, Integer scale, SortOrder actualModifer, Integer desiredMaxLength,
+      Integer desiredScale, SortOrder desiredModifier) {
+    coerceBytes(ptr, object, actualType, maxLength, scale, desiredMaxLength, desiredScale,
+        this, actualModifer, desiredModifier);
+  }
+
+  @Override
+  public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+    return getSampleValue(PLong.INSTANCE, arrayLength, maxLength);
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallint.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallint.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallint.java
new file mode 100644
index 0000000..6ba631a
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PSmallint.java
@@ -0,0 +1,259 @@
+/*
+ * 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.schema.types;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.schema.SortOrder;
+
+import java.math.BigDecimal;
+import java.sql.Types;
+
+public class PSmallint extends PDataType<Short> {
+
+  public static final PSmallint INSTANCE = new PSmallint();
+
+  private PSmallint() {
+    super("SMALLINT", Types.SMALLINT, Short.class, new ShortCodec(), 4);
+  }
+
+  @Override
+    public Integer getScale(Object o) {
+      return ZERO;
+    }
+
+    @Override
+    public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
+      return PLong.INSTANCE.compareTo(lhs, rhs, rhsType);
+    }
+
+    @Override
+    public boolean isComparableTo(PDataType targetType) {
+      return PDecimal.INSTANCE.isComparableTo(targetType);
+    }
+
+    @Override
+    public boolean isFixedWidth() {
+      return true;
+    }
+
+    @Override
+    public Integer getByteSize() {
+      return Bytes.SIZEOF_SHORT;
+    }
+
+    @Override
+    public Integer getMaxLength(Object o) {
+      return SHORT_PRECISION;
+    }
+
+    @Override
+    public byte[] toBytes(Object object) {
+      byte[] b = new byte[Bytes.SIZEOF_SHORT];
+      toBytes(object, b, 0);
+      return b;
+    }
+
+    @Override
+    public int toBytes(Object object, byte[] bytes, int offset) {
+      if (object == null) {
+        throw newIllegalDataException(this + " may not be null");
+      }
+      return this.getCodec().encodeShort(((Number)object).shortValue(), bytes, offset);
+    }
+
+    @Override
+    public Object toObject(Object object, PDataType actualType) {
+      Object o = PLong.INSTANCE.toObject(object, actualType);
+      if (!(o instanceof Long) || o == null) {
+        return o;
+      }
+      long l = (Long)o;
+      if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) {
+        throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Short without changing its value");
+      }
+      short s = (short)l;
+      return s;
+    }
+
+    @Override
+    public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) {
+      if (l == 0) {
+        return null;
+      }
+      if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE,
+          PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE,
+          PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE,
+          PUnsignedDouble.INSTANCE)) {
+        return actualType.getCodec().decodeShort(b, o, sortOrder);
+      } else if (actualType == PDecimal.INSTANCE) {
+        BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder);
+        return bd.shortValueExact();
+      }
+      throwConstraintViolationException(actualType,this);
+      return null;
+    }
+
+    @Override
+    public Object toObject(String value) {
+      if (value == null || value.length() == 0) {
+        return null;
+      }
+      try {
+        return Short.parseShort(value);
+      } catch (NumberFormatException e) {
+        throw newIllegalDataException(e);
+      }
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType, Object value) {
+      if (value != null) {
+        short i;
+        if (equalsAny(targetType, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE,
+            PUnsignedLong.INSTANCE, PUnsignedInt.INSTANCE, PUnsignedSmallint.INSTANCE)) {
+          i = (Short) value;
+          return i >= 0;
+        } else if (targetType == PUnsignedTinyint.INSTANCE) {
+          i = (Short) value;
+          return (i >= 0 && i <= Byte.MAX_VALUE);
+        } else if (targetType == PTinyint.INSTANCE) {
+          i = (Short) value;
+          return (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE);
+        }
+      }
+      return super.isCoercibleTo(targetType, value);
+    }
+
+    @Override
+    public boolean isCoercibleTo(PDataType targetType) {
+      return this.equals(targetType) || PInteger.INSTANCE.isCoercibleTo(targetType);
+    }
+
+    @Override
+    public Object getSampleValue(Integer maxLength, Integer arrayLength) {
+      return ((Integer) PInteger.INSTANCE.getSampleValue(maxLength, arrayLength)).shortValue();
+    }
+
+  static class ShortCodec extends BaseCodec {
+
+      @Override
+      public long decodeLong(byte[] b, int o, SortOrder sortOrder) {
+        return decodeShort(b, o, sortOrder);
+      }
+
+      @Override
+      public int decodeInt(byte[] b, int o, SortOrder sortOrder) {
+        return decodeShort(b, o, sortOrder);
+      }
+
+      @Override
+      public byte decodeByte(byte[] b, int o, SortOrder sortOrder) {
+        short v = decodeShort(b, o, sortOrder);
+        if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE) {
+            throw newIllegalDataException("Value " + v + " cannot be cast to Byte without changing its value");
+        }
+        return (byte)v;
+      }
+
+      @Override
+      public short decodeShort(byte[] b, int o, SortOrder sortOrder) {
+    	Preconditions.checkNotNull(sortOrder);
+        checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT);
+        int v;
+        if (sortOrder == SortOrder.ASC) {
+            v = b[o] ^ 0x80; // Flip sign bit back
+            for (int i = 1; i < Bytes.SIZEOF_SHORT; i++) {
+                v = (v << 8) + (b[o + i] & 0xff);
+            }
+        } else {
+            v = b[o] ^ 0xff ^ 0x80; // Flip sign bit back
+            for (int i = 1; i < Bytes.SIZEOF_SHORT; i++) {
+                v = (v << 8) + ((b[o + i] ^ 0xff) & 0xff);
+            }
+        }
+        return (short)v;
+      }
+
+      @Override
+      public int encodeShort(short v, byte[] b, int o) {
+          checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT);
+          b[o + 0] = (byte) ((v >> 8) ^ 0x80); // Flip sign bit so that Short is binary comparable
+          b[o + 1] = (byte) v;
+          return Bytes.SIZEOF_SHORT;
+      }
+
+      @Override
+      public int encodeLong(long v, byte[] b, int o) {
+          if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+              throw newIllegalDataException("Value " + v + " cannot be encoded as an Short without changing its value");
+          }
+          return encodeShort((short)v,b,o);
+      }
+
+      @Override
+      public int encodeInt(int v, byte[] b, int o) {
+        if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+          throw newIllegalDataException("Value " + v + " cannot be encoded as an Short without changing its value");
+        }
+        return encodeShort((short)v,b,o);
+      }
+
+      @Override
+      public int encodeByte(byte v, byte[] b, int o) {
+        return encodeShort(v,b,o);
+      }
+
+      @Override
+      public float decodeFloat(byte[] b, int o, SortOrder sortOrder) {
+          return decodeShort(b, o, sortOrder);
+      }
+
+      @Override
+      public double decodeDouble(byte[] b, int o,
+              SortOrder sortOrder) {
+          return decodeShort(b, o, sortOrder);
+      }
+
+      @Override
+      public int encodeDouble(double v, byte[] b, int o) {
+          if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+              throw newIllegalDataException("Value " + v + " cannot be encoded as an Short without changing its value");
+          }
+          return encodeShort((short)v,b,o);
+      }
+
+      @Override
+      public int encodeFloat(float v, byte[] b, int o) {
+          if (v < Short.MIN_VALUE || v > Short.MAX_VALUE) {
+              throw newIllegalDataException("Value " + v + " cannot be encoded as an Short without changing its value");
+          }
+          return encodeShort((short)v,b,o);
+      }
+
+      @Override
+      public PhoenixArrayFactory getPhoenixArrayFactory() {
+          return new PhoenixArrayFactory() {
+              @Override
+              public PhoenixArray newArray(PDataType type, Object[] elements) {
+                  return new PhoenixArray.PrimitiveShortPhoenixArray(type, elements);
+              }
+          };
+      }
+    }
+}


[17/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 4c57d09..6b236e8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -45,6 +45,7 @@ import java.sql.Struct;
 import java.text.Format;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -67,14 +68,21 @@ import org.apache.phoenix.query.MetaDataMutated;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PArrayDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PArrayDataType;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PMetaData.Pruner;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PTime;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedTime;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.trace.util.Tracing;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.JDBCUtil;
@@ -112,7 +120,7 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
     private final ConnectionQueryServices services;
     private final Properties info;
     private List<SQLCloseable> statements = new ArrayList<SQLCloseable>();
-    private final Format[] formatters = new Format[PDataType.values().length];
+    private final Map<PDataType<?>, Format> formatters = new HashMap<>();
     private final MutationState mutationState;
     private final int mutateBatchSize;
     private final Long scn;
@@ -194,13 +202,13 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
         String numberPattern = this.services.getProps().get(QueryServices.NUMBER_FORMAT_ATTRIB, NumberUtil.DEFAULT_NUMBER_FORMAT);
         int maxSize = this.services.getProps().getInt(QueryServices.MAX_MUTATION_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE);
         Format dateTimeFormat = DateUtil.getDateFormatter(datePattern);
-        formatters[PDataType.DATE.ordinal()] = dateTimeFormat;
-        formatters[PDataType.TIME.ordinal()] = dateTimeFormat;
-        formatters[PDataType.TIMESTAMP.ordinal()] = dateTimeFormat;
-        formatters[PDataType.UNSIGNED_DATE.ordinal()] = dateTimeFormat;
-        formatters[PDataType.UNSIGNED_TIME.ordinal()] = dateTimeFormat;
-        formatters[PDataType.UNSIGNED_TIMESTAMP.ordinal()] = dateTimeFormat;
-        formatters[PDataType.DECIMAL.ordinal()] = FunctionArgumentType.NUMERIC.getFormatter(numberPattern);
+        formatters.put(PDate.INSTANCE, dateTimeFormat);
+        formatters.put(PTime.INSTANCE, dateTimeFormat);
+        formatters.put(PTimestamp.INSTANCE, dateTimeFormat);
+        formatters.put(PUnsignedDate.INSTANCE, dateTimeFormat);
+        formatters.put(PUnsignedTime.INSTANCE, dateTimeFormat);
+        formatters.put(PUnsignedTimestamp.INSTANCE, dateTimeFormat);
+        formatters.put(PDecimal.INSTANCE, FunctionArgumentType.NUMERIC.getFormatter(numberPattern));
         // We do not limit the metaData on a connection less than the global one,
         // as there's not much that will be cached here.
         this.metaData = metaData.pruneTables(new Pruner() {
@@ -351,7 +359,7 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
     }
     
     public Format getFormatter(PDataType type) {
-        return formatters[type.ordinal()];
+        return formatters.get(type);
     }
     
     public String getURL() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 433de72..ce27dfb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -52,11 +52,12 @@ import org.apache.phoenix.iterate.DelegateResultIterator;
 import org.apache.phoenix.iterate.MaterializedResultIterator;
 import org.apache.phoenix.iterate.ResultIterator;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PTable.LinkType;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.ResultTuple;
@@ -944,7 +945,7 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
         }
         @Override
         public PDataType getDataType() {
-            return PDataType.VARCHAR;
+            return PVarchar.INSTANCE;
         }
         @Override
         public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
index 9fd753f..53ca8e1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixParameterMetaData.java
@@ -24,7 +24,7 @@ import java.sql.SQLException;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.parse.BindParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
index 985bffb..25be8c0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
@@ -54,7 +54,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.schema.ExecuteQueryNotApplicableException;
 import org.apache.phoenix.schema.ExecuteUpdateNotApplicableException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.Sequence;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.SQLCloseable;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
index 8c3c863..1630dbd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
@@ -49,7 +49,20 @@ import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.iterate.ResultIterator;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PFloat;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PSmallint;
+import org.apache.phoenix.schema.types.PTime;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PTinyint;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.ResultTuple;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.DateUtil;
@@ -204,7 +217,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
         checkCursorState();
-        BigDecimal value = (BigDecimal)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.DECIMAL, ptr);
+        BigDecimal value = (BigDecimal)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PDecimal.INSTANCE, ptr);
         wasNull = (value == null);
         return value;
     }
@@ -255,18 +269,17 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
         if (value == null) {
             return false;
         }
-        switch(type) {
-        case BOOLEAN:
-            return Boolean.TRUE.equals(value);
-        case VARCHAR:
-            return !STRING_FALSE.equals(value);
-        case INTEGER:
-            return !INTEGER_FALSE.equals(value);
-        case DECIMAL:
-            return !BIG_DECIMAL_FALSE.equals(value);
-        default:
-            throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CALL_METHOD_ON_TYPE)
-                .setMessage("Method: getBoolean; Type:" + type).build().buildException();
+        if (type == PBoolean.INSTANCE) {
+          return Boolean.TRUE.equals(value);
+        } else if (type == PVarchar.INSTANCE) {
+          return !STRING_FALSE.equals(value);
+        } else if (type == PInteger.INSTANCE) {
+          return !INTEGER_FALSE.equals(value);
+        } else if (type == PDecimal.INSTANCE) {
+          return !BIG_DECIMAL_FALSE.equals(value);
+        } else {
+          throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CALL_METHOD_ON_TYPE)
+              .setMessage("Method: getBoolean; Type:" + type).build().buildException();
         }
     }
 
@@ -278,7 +291,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public byte[] getBytes(int columnIndex) throws SQLException {
         checkCursorState();
-        byte[] value = (byte[])rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.VARBINARY, ptr);
+        byte[] value = (byte[])rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PVarbinary.INSTANCE, ptr);
         wasNull = (value == null);
         return value;
     }
@@ -292,7 +306,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     public byte getByte(int columnIndex) throws SQLException {
 //        throw new SQLFeatureNotSupportedException();
         checkCursorState();
-        Byte value = (Byte)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TINYINT, ptr);
+        Byte value = (Byte)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PTinyint.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -338,7 +353,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Date getDate(int columnIndex) throws SQLException {
         checkCursorState();
-        Date value = (Date)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.DATE, ptr);
+        Date value = (Date)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PDate.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return null;
@@ -354,7 +370,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Date getDate(int columnIndex, Calendar cal) throws SQLException {
         checkCursorState();
-        Date value = (Date)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.DATE, ptr);
+        Date value = (Date)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PDate.INSTANCE, ptr);
         cal.setTime(value);
         return new Date(cal.getTimeInMillis());
     }
@@ -367,7 +384,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public double getDouble(int columnIndex) throws SQLException {
         checkCursorState();
-        Double value = (Double)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.DOUBLE, ptr);
+        Double value = (Double)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PDouble.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -393,7 +411,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public float getFloat(int columnIndex) throws SQLException {
         checkCursorState();
-        Float value = (Float)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.FLOAT, ptr);
+        Float value = (Float)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PFloat.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -414,7 +433,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public int getInt(int columnIndex) throws SQLException {
         checkCursorState();
-        Integer value = (Integer)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.INTEGER, ptr);
+        Integer value = (Integer)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PInteger.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -430,7 +450,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public long getLong(int columnIndex) throws SQLException {
         checkCursorState();
-        Long value = (Long)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.LONG, ptr);
+        Long value = (Long)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PLong.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -541,7 +562,7 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public short getShort(int columnIndex) throws SQLException {
         checkCursorState();
-        Short value = (Short)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.SMALLINT, ptr);
+        Short value = (Short)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PSmallint.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return 0;
@@ -585,7 +606,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Time getTime(int columnIndex) throws SQLException {
         checkCursorState();
-        Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TIME, ptr);
+        Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PTime.INSTANCE, ptr);
         wasNull = (value == null);
         return value;
     }
@@ -598,7 +620,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Time getTime(int columnIndex, Calendar cal) throws SQLException {
         checkCursorState();
-        Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TIME, ptr);
+        Time value = (Time)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PTime.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return null;
@@ -616,7 +639,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Timestamp getTimestamp(int columnIndex) throws SQLException {
         checkCursorState();
-        Timestamp value = (Timestamp)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TIMESTAMP, ptr);
+        Timestamp value = (Timestamp)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PTimestamp.INSTANCE, ptr);
         wasNull = (value == null);
         return value;
     }
@@ -629,7 +653,8 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
         checkCursorState();
-        Timestamp value = (Timestamp)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.TIMESTAMP, ptr);
+        Timestamp value = (Timestamp)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow,
+            PTimestamp.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return null;
@@ -651,7 +676,7 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     @Override
     public URL getURL(int columnIndex) throws SQLException {
         checkCursorState();
-        String value = (String)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PDataType.VARCHAR, ptr);
+        String value = (String)rowProjector.getColumnProjector(columnIndex-1).getValue(currentRow, PVarchar.INSTANCE, ptr);
         wasNull = (value == null);
         if (value == null) {
             return null;
@@ -1237,4 +1262,4 @@ public class PhoenixResultSet implements ResultSet, SQLCloseable, org.apache.pho
     public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
         return (T) getObject(columnLabel); // Just ignore type since we only support built-in types
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
index 30e9862..8ecb52c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSetMetaData.java
@@ -26,8 +26,9 @@ import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
-
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -87,7 +88,7 @@ public class PhoenixResultSetMetaData implements ResultSetMetaData {
         if (type == null) {
             return QueryConstants.NULL_DISPLAY_TEXT.length();
         }
-        if (type.isCoercibleTo(PDataType.DATE)) {
+        if (type.isCoercibleTo(PDate.INSTANCE)) {
             return connection.getDatePattern().length();
         }
         if (projector.getExpression().getMaxLength() != null) {
@@ -182,7 +183,7 @@ public class PhoenixResultSetMetaData implements ResultSetMetaData {
         if (type == null) {
             return false;
         }
-        return type.isCoercibleTo(PDataType.DECIMAL);
+        return type.isCoercibleTo(PDecimal.INSTANCE);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 1eae037..01fefdd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -102,11 +102,12 @@ import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.ExecuteQueryNotApplicableException;
 import org.apache.phoenix.schema.ExecuteUpdateNotApplicableException;
 import org.apache.phoenix.schema.MetaDataClient;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.Sequence;
 import org.apache.phoenix.schema.SortOrder;
@@ -326,7 +327,7 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
     }
     
     private static final byte[] EXPLAIN_PLAN_FAMILY = QueryConstants.SINGLE_COLUMN_FAMILY;
-    private static final byte[] EXPLAIN_PLAN_COLUMN = PDataType.VARCHAR.toBytes("Plan");
+    private static final byte[] EXPLAIN_PLAN_COLUMN = PVarchar.INSTANCE.toBytes("Plan");
     private static final String EXPLAIN_PLAN_ALIAS = "PLAN";
     private static final String EXPLAIN_PLAN_TABLE_NAME = "PLAN_TABLE";
     private static final PDatum EXPLAIN_PLAN_DATUM = new PDatum() {
@@ -336,7 +337,7 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
         }
         @Override
         public PDataType getDataType() {
-            return PDataType.VARCHAR;
+            return PVarchar.INSTANCE;
         }
         @Override
         public Integer getMaxLength() {
@@ -381,7 +382,7 @@ public class PhoenixStatement implements Statement, SQLCloseable, org.apache.pho
             List<String> planSteps = plan.getExplainPlan().getPlanSteps();
             List<Tuple> tuples = Lists.newArrayListWithExpectedSize(planSteps.size());
             for (String planStep : planSteps) {
-                Tuple tuple = new SingleKeyValueTuple(KeyValueUtil.newKeyValue(PDataType.VARCHAR.toBytes(planStep), EXPLAIN_PLAN_FAMILY, EXPLAIN_PLAN_COLUMN, MetaDataProtocol.MIN_TABLE_TIMESTAMP, ByteUtil.EMPTY_BYTE_ARRAY));
+                Tuple tuple = new SingleKeyValueTuple(KeyValueUtil.newKeyValue(PVarchar.INSTANCE.toBytes(planStep), EXPLAIN_PLAN_FAMILY, EXPLAIN_PLAN_COLUMN, MetaDataProtocol.MIN_TABLE_TIMESTAMP, ByteUtil.EMPTY_BYTE_ARRAY));
                 tuples.add(tuple);
             }
             final ResultIterator iterator = new MaterializedResultIterator(tuples);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
index a5c5c03..ea4e587 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
@@ -24,7 +24,12 @@ import java.util.List;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.function.RoundDecimalExpression;
 import org.apache.phoenix.expression.function.RoundTimestampExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -87,9 +92,11 @@ public class CastParseNode extends UnaryParseNode {
 //            return firstChildExpr;
 //        } else if(fromDataType.isCoercibleTo(PDataType.LONG) && (targetDataType == PDataType.DATE || targetDataType == PDataType.UNSIGNED_DATE)) {
 //            return firstChildExpr;
-	    } else if((fromDataType == PDataType.DECIMAL || fromDataType == PDataType.TIMESTAMP || fromDataType == PDataType.UNSIGNED_TIMESTAMP) && targetDataType.isCoercibleTo(PDataType.LONG)) {
+	    } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo(
+          PLong.INSTANCE)) {
 	        return RoundDecimalExpression.create(expressions);
-	    } else if((fromDataType == PDataType.DECIMAL || fromDataType == PDataType.TIMESTAMP || fromDataType == PDataType.UNSIGNED_TIMESTAMP) && targetDataType.isCoercibleTo(PDataType.DATE)) {
+	    } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo(
+          PDate.INSTANCE)) {
 	        return RoundTimestampExpression.create(expressions);
 	    } else if(fromDataType.isCastableTo(targetDataType)) {
 	        return firstChildExpr;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/CeilParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/CeilParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/CeilParseNode.java
index 08d7feb..b5f6669 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/CeilParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/CeilParseNode.java
@@ -26,7 +26,11 @@ import org.apache.phoenix.expression.function.CeilDateExpression;
 import org.apache.phoenix.expression.function.CeilDecimalExpression;
 import org.apache.phoenix.expression.function.CeilFunction;
 import org.apache.phoenix.expression.function.CeilTimestampExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 /**
@@ -52,11 +56,11 @@ public class CeilParseNode extends FunctionParseNode {
     public static Expression getCeilExpression(List<Expression> children) throws SQLException {
         final Expression firstChild = children.get(0);
         final PDataType firstChildDataType = firstChild.getDataType();
-        if(firstChildDataType.isCoercibleTo(PDataType.DATE)) {
+        if(firstChildDataType.isCoercibleTo(PDate.INSTANCE)) {
             return CeilDateExpression.create(children);
-        } else if (firstChildDataType == PDataType.TIMESTAMP || firstChildDataType == PDataType.UNSIGNED_TIMESTAMP) {
+        } else if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE) {
             return CeilTimestampExpression.create(children);
-        } else if(firstChildDataType.isCoercibleTo(PDataType.DECIMAL)) {
+        } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) {
             return CeilDecimalExpression.create(children);
         } else {
             throw TypeMismatchException.newException(firstChildDataType, "1");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
index e9da47c..169754c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ColumnDef.java
@@ -21,7 +21,12 @@ import java.sql.SQLException;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBinary;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -61,7 +66,7 @@ public class ColumnDef {
         	 localType = sqlTypeName == null ? null : PDataType.fromTypeId(PDataType.sqlArrayType(SchemaUtil.normalizeIdentifier(sqlTypeName)));
         	 this.dataType = sqlTypeName == null ? null : PDataType.fromSqlTypeName(SchemaUtil.normalizeIdentifier(sqlTypeName));
              this.arrSize = arrSize; // Can only be non negative based on parsing
-             if (this.dataType == PDataType.VARBINARY) {
+             if (this.dataType == PVarbinary.INSTANCE) {
                  throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_ARRAY_NOT_SUPPORTED)
                  .setColumnName(columnDefName.getColumnName()).build().buildException();
              }
@@ -71,7 +76,7 @@ public class ColumnDef {
          }
          
          this.isNull = isNull;
-         if (this.dataType == PDataType.CHAR) {
+         if (this.dataType == PChar.INSTANCE) {
              if (maxLength == null) {
                  throw new SQLExceptionInfo.Builder(SQLExceptionCode.MISSING_CHAR_LENGTH)
                      .setColumnName(columnDefName.getColumnName()).build().buildException();
@@ -81,13 +86,13 @@ public class ColumnDef {
                      .setColumnName(columnDefName.getColumnName()).build().buildException();
              }
              scale = null;
-         } else if (this.dataType == PDataType.VARCHAR) {
+         } else if (this.dataType == PVarchar.INSTANCE) {
              if (maxLength != null && maxLength < 1) {
                  throw new SQLExceptionInfo.Builder(SQLExceptionCode.NONPOSITIVE_CHAR_LENGTH)
                      .setColumnName(columnDefName.getColumnName()).build().buildException(); 
              }
              scale = null;
-         } else if (this.dataType == PDataType.DECIMAL) {
+         } else if (this.dataType == PDecimal.INSTANCE) {
              // for deciaml, 1 <= maxLength <= PDataType.MAX_PRECISION;
              if (maxLength != null) {
                  if (maxLength < 1 || maxLength > PDataType.MAX_PRECISION) {
@@ -106,7 +111,7 @@ public class ColumnDef {
                  // ignored. All decimal are stored with as much decimal points as possible.
                  scale = scale == null ? PDataType.DEFAULT_SCALE : scale > maxLength ? maxLength : scale; 
              }
-         } else if (this.dataType == PDataType.BINARY) {
+         } else if (this.dataType == PBinary.INSTANCE) {
              if (maxLength == null) {
                  throw new SQLExceptionInfo.Builder(SQLExceptionCode.MISSING_BINARY_LENGTH)
                      .setColumnName(columnDefName.getColumnName()).build().buildException();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/FloorParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/FloorParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/FloorParseNode.java
index 8da17ba..136d2a7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/FloorParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/FloorParseNode.java
@@ -25,7 +25,9 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.function.FloorDateExpression;
 import org.apache.phoenix.expression.function.FloorDecimalExpression;
 import org.apache.phoenix.expression.function.FloorFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 /**
@@ -54,9 +56,9 @@ public class FloorParseNode extends FunctionParseNode {
         
         //FLOOR on timestamp doesn't really care about the nanos part i.e. it just sets it to zero. 
         //Which is exactly what FloorDateExpression does too. 
-        if(firstChildDataType.isCoercibleTo(PDataType.TIMESTAMP)) {
+        if(firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) {
             return FloorDateExpression.create(children);
-        } else if(firstChildDataType.isCoercibleTo(PDataType.DECIMAL)) {
+        } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) {
             return FloorDecimalExpression.create(children);
         } else {
             throw TypeMismatchException.newException(firstChildDataType, "1");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
index 59f7d3c..e6ce6d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/FunctionParseNode.java
@@ -41,7 +41,9 @@ import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.function.AggregateFunction;
 import org.apache.phoenix.expression.function.FunctionExpression;
 import org.apache.phoenix.schema.ArgumentTypeMismatchException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataTypeFactory;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.ValueRangeExcpetion;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -139,14 +141,15 @@ public class FunctionParseNode extends CompoundParseNode {
         if (args.length > children.size()) {
             List<Expression> moreChildren = new ArrayList<Expression>(children);
             for (int i = children.size(); i < info.getArgs().length; i++) {
-                moreChildren.add(LiteralExpression.newConstant(null, args[i].allowedTypes.length == 0 ? null :  args[i].allowedTypes[0], Determinism.ALWAYS));
+                moreChildren.add(LiteralExpression.newConstant(null, args[i].allowedTypes.length == 0 ? null :
+                    PDataTypeFactory.getInstance().instanceFromClass(args[i].allowedTypes[0]), Determinism.ALWAYS));
             }
             children = moreChildren;
         }
         List<ParseNode> nodeChildren = this.getChildren();
         for (int i = 0; i < children.size(); i++) {
             BindParseNode bindNode = null;
-            PDataType[] allowedTypes = args[i].getAllowedTypes();
+            Class<? extends PDataType>[] allowedTypes = args[i].getAllowedTypes();
             // Check if the node is a bind parameter, and set the parameter
             // metadata based on the function argument annotation. Check to
             // make sure we're not looking past the end of the list of
@@ -176,7 +179,8 @@ public class FunctionParseNode extends CompoundParseNode {
                     // based on the function argument annonation set the parameter meta data.
                     if (child.getDataType() == null) {
                         if (allowedTypes.length > 0) {
-                            context.getBindManager().addParamMetaData(bindNode, LiteralExpression.newConstant(null, allowedTypes[0], Determinism.ALWAYS));
+                            context.getBindManager().addParamMetaData(bindNode, LiteralExpression.newConstant(null, PDataTypeFactory.getInstance().instanceFromClass(
+                                allowedTypes[0]), Determinism.ALWAYS));
                         }
                     } else { // Use expression as is, since we already have the data type set
                         context.getBindManager().addParamMetaData(bindNode, child);
@@ -185,15 +189,16 @@ public class FunctionParseNode extends CompoundParseNode {
             } else {
                 if (allowedTypes.length > 0) {
                     boolean isCoercible = false;
-                    for (PDataType type : allowedTypes) {
-                        if (child.getDataType().isCoercibleTo(type)) {
+                    for (Class<? extends PDataType> type : allowedTypes) {
+                        if (child.getDataType().isCoercibleTo(
+                            PDataTypeFactory.getInstance().instanceFromClass(type))) {
                             isCoercible = true;
                             break;
                         }
                     }
                     if (!isCoercible) {
-                        throw new ArgumentTypeMismatchException(Arrays.toString(args[i].getAllowedTypes()),
-                                child.getDataType().toString(), info.getName() + " argument " + (i + 1));
+                        throw new ArgumentTypeMismatchException(args[i].getAllowedTypes(),
+                            child.getDataType(), info.getName() + " argument " + (i + 1));
                     }
                     if (child instanceof LiteralExpression) {
                         LiteralExpression valueExp = (LiteralExpression) child;
@@ -262,7 +267,7 @@ public class FunctionParseNode extends CompoundParseNode {
     @Target(ElementType.TYPE)
     public
     @interface Argument {
-        PDataType[] allowedTypes() default {};
+        Class<? extends PDataType>[] allowedTypes() default {};
         boolean isConstant() default false;
         String defaultValue() default "";
         String enumeration() default "";
@@ -325,8 +330,8 @@ public class FunctionParseNode extends CompoundParseNode {
 
     @Immutable
     public static class BuiltInFunctionArgInfo {
-        private static final PDataType[] ENUMERATION_TYPES = new PDataType[] {PDataType.VARCHAR};
-        private final PDataType[] allowedTypes;
+        private static final Class<? extends PDataType>[] ENUMERATION_TYPES = new Class[] { PVarchar.class };
+        private final Class<? extends PDataType>[] allowedTypes;
         private final boolean isConstant;
         private final Set<String> allowedValues; // Enumeration of possible values
         private final LiteralExpression defaultValue;
@@ -378,11 +383,16 @@ public class FunctionParseNode extends CompoundParseNode {
                 SQLParser parser = new SQLParser(strValue);
                 try {
                     LiteralParseNode node = parser.parseLiteral();
-                    LiteralExpression defaultValue = LiteralExpression.newConstant(node.getValue(), this.allowedTypes[0], Determinism.ALWAYS);
+                    LiteralExpression defaultValue = LiteralExpression.newConstant(node.getValue(), PDataTypeFactory.getInstance().instanceFromClass(
+                        allowedTypes[0]), Determinism.ALWAYS);
                     if (this.getAllowedTypes().length > 0) {
-                        for (PDataType type : this.getAllowedTypes()) {
-                            if (defaultValue.getDataType() == null || defaultValue.getDataType().isCoercibleTo(type, node.getValue())) {
-                                return LiteralExpression.newConstant(node.getValue(), type, Determinism.ALWAYS);
+                        for (Class<? extends PDataType> type : this.getAllowedTypes()) {
+                            if (defaultValue.getDataType() == null || defaultValue.getDataType().isCoercibleTo(
+                                PDataTypeFactory.getInstance().instanceFromClass(type),
+                                node.getValue())) {
+                                return LiteralExpression.newConstant(node.getValue(),
+                                    PDataTypeFactory.getInstance().instanceFromClass(type),
+                                    Determinism.ALWAYS);
                             }
                         }
                         throw new IllegalStateException("Unable to coerce default value " + strValue + " to any of the allowed types of " + Arrays.toString(this.getAllowedTypes()));
@@ -410,8 +420,7 @@ public class FunctionParseNode extends CompoundParseNode {
         public LiteralExpression getMaxValue() {
             return maxValue;
         }
-
-        public PDataType[] getAllowedTypes() {
+        public Class<? extends PDataType>[] getAllowedTypes() {
             return allowedTypes;
         }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
index f9bbea1..b83ce23 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
@@ -21,9 +21,8 @@ import java.sql.SQLException;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.phoenix.schema.PDataType;
-
-
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 
 /**
  * 
@@ -79,6 +78,6 @@ public class LiteralParseNode extends TerminalParseNode {
     
     @Override
     public String toString() {
-        return type == PDataType.VARCHAR ? ("'" + value.toString() + "'") : value == null ? "null" : value.toString();
+        return type == PVarchar.INSTANCE ? ("'" + value.toString() + "'") : value == null ? "null" : value.toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 6d3123f..0329ef4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -41,7 +41,7 @@ import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.LikeParseNode.LikeType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PIndexState;
 import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTableType;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/RoundParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/RoundParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/RoundParseNode.java
index 5260f88..9bf4e70 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/RoundParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/RoundParseNode.java
@@ -26,7 +26,10 @@ import org.apache.phoenix.expression.function.RoundDateExpression;
 import org.apache.phoenix.expression.function.RoundDecimalExpression;
 import org.apache.phoenix.expression.function.RoundFunction;
 import org.apache.phoenix.expression.function.RoundTimestampExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.schema.TypeMismatchException;
 
 /**
@@ -54,11 +57,11 @@ public class RoundParseNode extends FunctionParseNode {
         final Expression firstChild = children.get(0);
         final PDataType firstChildDataType = firstChild.getDataType();
         
-        if(firstChildDataType.isCoercibleTo(PDataType.DATE)) {
+        if(firstChildDataType.isCoercibleTo(PDate.INSTANCE)) {
             return RoundDateExpression.create(children);
-        } else if (firstChildDataType.isCoercibleTo(PDataType.TIMESTAMP)) {
+        } else if (firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) {
             return RoundTimestampExpression.create(children);
-        } else if(firstChildDataType.isCoercibleTo(PDataType.DECIMAL)) {
+        } else if(firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) {
             return RoundDecimalExpression.create(children);
         } else {
             throw TypeMismatchException.newException(firstChildDataType, "1");

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToCharParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ToCharParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToCharParseNode.java
index b6c8ac6..0234df4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ToCharParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToCharParseNode.java
@@ -27,8 +27,9 @@ import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.function.FunctionArgumentType;
 import org.apache.phoenix.expression.function.FunctionExpression;
 import org.apache.phoenix.expression.function.ToCharFunction;
-import org.apache.phoenix.schema.PDataType;
-
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
 
 public class ToCharParseNode extends FunctionParseNode {
 
@@ -42,7 +43,7 @@ public class ToCharParseNode extends FunctionParseNode {
         String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
         Format formatter;
         FunctionArgumentType type;
-        if (dataType.isCoercibleTo(PDataType.TIMESTAMP)) {
+        if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
             if (formatString == null) {
                 formatString = context.getDateFormat();
                 formatter = context.getDateFormatter();
@@ -51,7 +52,7 @@ public class ToCharParseNode extends FunctionParseNode {
             }
             type = FunctionArgumentType.TEMPORAL;
         }
-        else if (dataType.isCoercibleTo(PDataType.DECIMAL)) {
+        else if (dataType.isCoercibleTo(PDecimal.INSTANCE)) {
             if (formatString == null)
                 formatString = context.getNumberFormat();
             formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToNumberParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ToNumberParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToNumberParseNode.java
index 4def24c..9a1b80f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ToNumberParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ToNumberParseNode.java
@@ -28,7 +28,9 @@ import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.function.FunctionArgumentType;
 import org.apache.phoenix.expression.function.FunctionExpression;
 import org.apache.phoenix.expression.function.ToNumberFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
 
 public class ToNumberParseNode extends FunctionParseNode {
 
@@ -44,7 +46,7 @@ public class ToNumberParseNode extends FunctionParseNode {
         Format formatter =  null;
         FunctionArgumentType type;
         
-        if (dataType.isCoercibleTo(PDataType.TIMESTAMP)) {
+        if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
             if (formatString == null) {
                 formatString = context.getDateFormat();
                 formatter = context.getDateFormatter();
@@ -53,7 +55,7 @@ public class ToNumberParseNode extends FunctionParseNode {
             }
             type = FunctionArgumentType.TEMPORAL;
         }
-        else if (dataType.isCoercibleTo(PDataType.CHAR)) {
+        else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
             if (formatString != null) {
                 formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
             }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 0732cff..4475dd1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -110,9 +110,10 @@ import org.apache.phoenix.protobuf.ProtobufUtil;
 import org.apache.phoenix.schema.EmptySequenceCacheException;
 import org.apache.phoenix.schema.MetaDataSplitPolicy;
 import org.apache.phoenix.schema.NewerTableAlreadyExistsException;
+import org.apache.phoenix.schema.types.PBoolean;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PColumnFamily;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PMetaDataImpl;
 import org.apache.phoenix.schema.PName;
@@ -644,7 +645,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             }
             
             if (descriptor.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null
-                    && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(descriptor
+                    && Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(descriptor
                             .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
                 if (!descriptor.hasCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName())) {
                     descriptor.addCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName(),
@@ -860,7 +861,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
      * @param tableName
      * @param splits
      * @param modifyExistingMetaData TODO
-     * @param familyNames
      * @return true if table was created and false if it already exists
      * @throws SQLException
      */
@@ -889,7 +889,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             HTableDescriptor newDesc = generateTableDescriptor(tableName, existingDesc, tableType , props, families, splits);
             
             if (!tableExist) {
-                if (newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null && Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
+                if (newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) != null && Boolean.TRUE.equals(
+                    PBoolean.INSTANCE.toObject(newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
                     newDesc.setValue(HTableDescriptor.SPLIT_POLICY, IndexRegionSplitPolicy.class.getName());
                 }
                 // Remove the splitPolicy attribute to prevent HBASE-12570
@@ -1116,7 +1117,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         tableProps.put(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME, TRUE_BYTES_AS_STRING);
         HTableDescriptor desc = ensureTableCreated(physicalIndexName, PTableType.TABLE, tableProps, families, splits, false);
         if (desc != null) {
-            if (!Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES)))) {
+            if (!Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES)))) {
                 String fullTableName = Bytes.toString(physicalIndexName);
                 throw new TableAlreadyExistsException(
                         "Unable to create shared physical table for indexes on views.",
@@ -1155,7 +1156,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         tableProps.put(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_NAME, TRUE_BYTES_AS_STRING);
         HTableDescriptor desc = ensureTableCreated(physicalTableName, PTableType.TABLE, tableProps, families, splits, true);
         if (desc != null) {
-            if (!Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
+            if (!Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
                 String fullTableName = Bytes.toString(physicalTableName);
                 throw new TableAlreadyExistsException(
                         "Unable to create shared physical table for local indexes.",
@@ -1174,7 +1175,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             admin = new HBaseAdmin(config);
             try {
                 desc = admin.getTableDescriptor(physicalIndexName);
-                if (Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES)))) {
+                if (Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES)))) {
                     this.tableStatsCache.invalidate(new ImmutableBytesPtr(physicalIndexName));
                     final ReadOnlyProps props = this.getProps();
                     final boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA);
@@ -1209,7 +1210,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
             admin = new HBaseAdmin(config);
             try {
                 desc = admin.getTableDescriptor(physicalIndexName);
-                if (Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(desc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
+                if (Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
                     this.tableStatsCache.invalidate(new ImmutableBytesPtr(physicalIndexName));
                     final ReadOnlyProps props = this.getProps();
                     final boolean dropMetadata = props.getBoolean(DROP_METADATA_ATTRIB, DEFAULT_DROP_METADATA);
@@ -1548,7 +1549,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
         if (result.getMutationCode() == MutationCode.COLUMN_NOT_FOUND) { // Success
             // Flush the table if transitioning DISABLE_WAL from TRUE to FALSE
             if (  MetaDataUtil.getMutationValue(m,PhoenixDatabaseMetaData.DISABLE_WAL_BYTES, kvBuilder, ptr)
-               && Boolean.FALSE.equals(PDataType.BOOLEAN.toObject(ptr))) {
+               && Boolean.FALSE.equals(PBoolean.INSTANCE.toObject(ptr))) {
                 flushTable(table.getPhysicalName().getBytes());
             }
             
@@ -1556,7 +1557,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
                 // If we're changing MULTI_TENANT to true or false, create or drop the view index table
                 if (MetaDataUtil.getMutationValue(m, PhoenixDatabaseMetaData.MULTI_TENANT_BYTES, kvBuilder, ptr)){
                     long timestamp = MetaDataUtil.getClientTimeStamp(m);
-                    if (Boolean.TRUE.equals(PDataType.BOOLEAN.toObject(ptr.get(), ptr.getOffset(), ptr.getLength()))) {
+                    if (Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(ptr.get(), ptr.getOffset(), ptr.getLength()))) {
                         this.ensureViewIndexTableCreated(table, timestamp);
                     } else {
                         this.ensureViewIndexTableDropped(table.getPhysicalName().getBytes(), timestamp);
@@ -1926,9 +1927,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
 
     /**
      * Gets the current sequence value
-     * @param tenantId
-     * @param sequence
-     * @throws SQLException if cached sequence cannot be found 
+     * @throws SQLException if cached sequence cannot be found
      */
     @Override
     public long currentSequenceValue(SequenceKey sequenceKey, long timestamp) throws SQLException {
@@ -1962,9 +1961,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
      * Increment any of the set of sequences that need more values. These are the sequences
      * that are asking for the next value within a given statement. The returned sequences
      * are the ones that were not found because they were deleted by another client. 
-     * @param tenantId
      * @param sequenceKeys sorted list of sequence kyes
-     * @param batchSize
      * @param timestamp
      * @throws SQLException if any of the sequences cannot be found
      * 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/ArgumentTypeMismatchException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ArgumentTypeMismatchException.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ArgumentTypeMismatchException.java
index 7a7d223..b6102fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ArgumentTypeMismatchException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ArgumentTypeMismatchException.java
@@ -18,9 +18,16 @@
 package org.apache.phoenix.schema;
 
 import java.sql.SQLException;
+import java.util.Arrays;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataTypeFactory;
+
+import javax.annotation.Nullable;
 
 /**
  * Exception thrown when we try to use use an argument that has the wrong type. 
@@ -36,6 +43,16 @@ public class ArgumentTypeMismatchException extends SQLException {
         super(new SQLExceptionInfo.Builder(code).setMessage("expected: " + expected + " but was: " + actual + " at " + location).build().toString(), code.getSQLState(), code.getErrorCode());
     }
 
+    public ArgumentTypeMismatchException(Class<? extends PDataType>[] expecteds, PDataType actual, String location) {
+        this(Arrays.toString(Collections2.transform(Arrays.asList(expecteds),
+            new Function<Class<? extends PDataType>, PDataType>() {
+              @Nullable @Override
+              public PDataType apply(@Nullable Class<? extends PDataType> input) {
+                return PDataTypeFactory.getInstance().instanceFromClass(input);
+              }
+            }).toArray()), actual.toString(), location);
+    }
+
     public ArgumentTypeMismatchException(String expected, String actual, String location) {
         super(new SQLExceptionInfo.Builder(code).setMessage("expected: " + expected + " but was: " + actual + " at " + location).build().toString(), code.getSQLState(), code.getErrorCode());
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
index 89e6c78..6e18cc5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateDatum.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.schema;
 
+import org.apache.phoenix.schema.types.PDataType;
+
 public class DelegateDatum implements PDatum {
     private final PDatum delegate;
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/KeyValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/KeyValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/KeyValueSchema.java
index d6c36c0..595103f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/KeyValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/KeyValueSchema.java
@@ -24,12 +24,13 @@ import org.apache.hadoop.io.WritableUtils;
 import org.apache.http.annotation.Immutable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.ByteUtil;
 
 
 /**
  * 
- * Simple flat schema over a byte array where fields may be any of {@link PDataType}.
+ * Simple flat schema over a byte array where fields may be any of {@link org.apache.phoenix.schema.types.PDataType}.
  * Optimized for positional access by index.
  *
  * 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
index 16fe1a5..362d59f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/LocalIndexDataColumnRef.java
@@ -1,3 +1,20 @@
+/*
+ * 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.schema;
 
 import java.sql.SQLException;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index ea333ac..5b1315f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -61,7 +61,6 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE;
 import static org.apache.phoenix.query.QueryServices.DROP_METADATA_ATTRIB;
 import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_DROP_METADATA;
-import static org.apache.phoenix.schema.PDataType.VARCHAR;
 
 import java.io.IOException;
 import java.sql.Connection;
@@ -141,6 +140,10 @@ import org.apache.phoenix.schema.PTable.IndexType;
 import org.apache.phoenix.schema.PTable.LinkType;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.stats.PTableStats;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.LogUtil;
@@ -197,7 +200,7 @@ public class MetaDataClient {
             TABLE_NAME + "," +
             COLUMN_FAMILY + "," +
             LINK_TYPE + "," +
-            PARENT_TENANT_ID + " " + PDataType.VARCHAR.getSqlTypeName() + // Dynamic column for now to prevent schema change
+            PARENT_TENANT_ID + " " + PVarchar.INSTANCE.getSqlTypeName() + // Dynamic column for now to prevent schema change
             ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String INCREMENT_SEQ_NUM =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " + 
@@ -347,8 +350,8 @@ public class MetaDataClient {
         MetaDataMutationResult result;
         
         do {
-            final byte[] schemaBytes = PDataType.VARCHAR.toBytes(schemaName);
-            final byte[] tableBytes = PDataType.VARCHAR.toBytes(tableName);
+            final byte[] schemaBytes = PVarchar.INSTANCE.toBytes(schemaName);
+            final byte[] tableBytes = PVarchar.INSTANCE.toBytes(tableName);
             result = connection.getQueryServices().getTable(tenantId, schemaBytes, tableBytes, tableTimestamp, clientTimeStamp);
             
             if (SYSTEM_CATALOG_SCHEMA.equals(schemaName)) {
@@ -809,7 +812,7 @@ public class MetaDataClient {
                         Cell kv = plan.iterator().next().getValue(0);
                         ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
                         // A single Cell will be returned with the count(*) - we decode that here
-                        long rowCount = PDataType.LONG.getCodec().decodeLong(tmpPtr, SortOrder.getDefault());
+                        long rowCount = PLong.INSTANCE.getCodec().decodeLong(tmpPtr, SortOrder.getDefault());
                         // The contract is to return a MutationState that contains the number of rows modified. In this
                         // case, it's the number of rows in the data table which corresponds to the number of index
                         // rows that were added.
@@ -1008,7 +1011,7 @@ public class MetaDataClient {
                 
                 // Don't re-allocate indexId on ConcurrentTableMutationException,
                 // as there's no need to burn another sequence value.
-                if (allocateIndexId && indexId == null) { 
+                if (allocateIndexId && indexId == null) {
                     Long scn = connection.getSCN();
                     long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
                     PName tenantId = connection.getTenantId();
@@ -1382,7 +1385,7 @@ public class MetaDataClient {
                     throw new ColumnAlreadyExistsException(schemaName, tableName, column.getName().getString());
                 }
                 columns.add(column);
-                if ((colDef.getDataType() == PDataType.VARBINARY || colDef.getDataType().isArrayType())  
+                if ((colDef.getDataType() == PVarbinary.INSTANCE || colDef.getDataType().isArrayType())
                         && SchemaUtil.isPKColumn(column)
                         && pkColumnsIterator.hasNext()) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_IN_ROW_KEY)
@@ -1688,7 +1691,7 @@ public class MetaDataClient {
         // NOT NULL is a requirement, since otherwise the table key would conflict
         // potentially with the global table definition.
         PColumn tenantIdCol = iterator.next();
-        if (!tenantIdCol.getDataType().isCoercibleTo(VARCHAR) || tenantIdCol.isNullable()) {
+        if (!tenantIdCol.getDataType().isCoercibleTo(PVarchar.INSTANCE) || tenantIdCol.isNullable()) {
             throw new SQLExceptionInfo.Builder(INSUFFICIENT_MULTI_TENANT_COLUMNS).setSchemaName(schemaName).setTableName(tableName).build().buildException();
         }
     }
@@ -1967,7 +1970,7 @@ public class MetaDataClient {
                 List<PColumn> currentPKs = table.getPKColumns();
                 PColumn lastPK = currentPKs.get(currentPKs.size()-1);
                 // Disallow adding columns if the last column is VARBIANRY.
-                if (lastPK.getDataType() == PDataType.VARBINARY || lastPK.getDataType().isArrayType()) {
+                if (lastPK.getDataType() == PVarbinary.INSTANCE || lastPK.getDataType().isArrayType()) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_LAST_PK)
                         .setColumnName(lastPK.getName().getString()).build().buildException();
                 }
@@ -1976,7 +1979,7 @@ public class MetaDataClient {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.NULLABLE_FIXED_WIDTH_LAST_PK)
                         .setColumnName(lastPK.getName().getString()).build().buildException();
                 }
-                          
+
                 Boolean isImmutableRows = null;
                 if (isImmutableRowsProp != null) {
                     if (isImmutableRowsProp.booleanValue() != table.isImmutableRows()) {


[19/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DecimalSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DecimalSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DecimalSumAggregator.java
index 2e564ab..4fa46b1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DecimalSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DecimalSumAggregator.java
@@ -21,8 +21,9 @@ import java.math.BigDecimal;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SizedUtil;
 
@@ -42,12 +43,12 @@ public class DecimalSumAggregator extends BaseAggregator {
         super(sortOrder);
         if (ptr != null) {
             initBuffer();
-            sum = (BigDecimal)PDataType.DECIMAL.toObject(ptr);
+            sum = (BigDecimal) PDecimal.INSTANCE.toObject(ptr);
         }
     }
     
     private PDataType getInputDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
     
     private int getBufferLength() {
@@ -79,7 +80,7 @@ public class DecimalSumAggregator extends BaseAggregator {
     
     @Override
     public final PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctCountClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctCountClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctCountClientAggregator.java
index 9c8ec0a..9ef6cc0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctCountClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctCountClientAggregator.java
@@ -19,8 +19,9 @@ package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -41,9 +42,9 @@ public class DistinctCountClientAggregator extends DistinctValueWithCountClientA
             initBuffer();
         }
         if (cachedResult != null) {
-            buffer = PDataType.LONG.toBytes(cachedResult);
+            buffer = PLong.INSTANCE.toBytes(cachedResult);
         } else {
-            buffer = PDataType.LONG.toBytes(this.valueVsCount.size());
+            buffer = PLong.INSTANCE.toBytes(this.valueVsCount.size());
         }
         ptr.set(buffer);
         return true;
@@ -51,6 +52,6 @@ public class DistinctCountClientAggregator extends DistinctValueWithCountClientA
 
     @Override
     protected PDataType getResultDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueClientAggregator.java
index 2af99ca..d9d66d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueClientAggregator.java
@@ -19,8 +19,8 @@ package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountClientAggregator.java
index 56ca000..cea6d49 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountClientAggregator.java
@@ -31,7 +31,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -111,7 +112,7 @@ public abstract class DistinctValueWithCountClientAggregator extends BaseAggrega
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
index 3a1789b..ee9f7f2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DistinctValueWithCountServerAggregator.java
@@ -27,7 +27,8 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -138,7 +139,7 @@ public class DistinctValueWithCountServerAggregator extends BaseAggregator {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DoubleSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DoubleSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DoubleSumAggregator.java
index 3e893e3..3f953e6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DoubleSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/DoubleSumAggregator.java
@@ -19,8 +19,9 @@ package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
+import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SizedUtil;
 
@@ -33,12 +34,12 @@ public class DoubleSumAggregator extends BaseAggregator {
         super(sortOrder);
         if (ptr != null) {
             initBuffer();
-            sum = PDataType.DOUBLE.getCodec().decodeDouble(ptr, sortOrder);
+            sum = PDouble.INSTANCE.getCodec().decodeDouble(ptr, sortOrder);
         }
     }
     
     protected PDataType getInputDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
     
     private void initBuffer() {
@@ -69,7 +70,7 @@ public class DoubleSumAggregator extends BaseAggregator {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DOUBLE;
+        return PDouble.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueBaseClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueBaseClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueBaseClientAggregator.java
index 6dfca39..804c38e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueBaseClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueBaseClientAggregator.java
@@ -27,7 +27,8 @@ import java.util.TreeMap;
 import org.apache.hadoop.hbase.filter.BinaryComparator;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes.ByteArrayComparator;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
 import org.apache.phoenix.schema.tuple.Tuple;
@@ -142,7 +143,7 @@ public class FirstLastValueBaseClientAggregator extends BaseAggregator {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
 
     public void init(int offset) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java
index 5e51e07..273b890 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/FirstLastValueServerAggregator.java
@@ -18,7 +18,8 @@
 package org.apache.phoenix.expression.aggregator;
 
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.SizedUtil;
@@ -188,7 +189,7 @@ public class FirstLastValueServerAggregator extends BaseAggregator {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARBINARY;
+        return PVarbinary.INSTANCE;
     }
 
     public void init(List<Expression> children, boolean isAscending, int offset) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/IntSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/IntSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/IntSumAggregator.java
index 229bf56..ef62b27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/IntSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/IntSumAggregator.java
@@ -17,8 +17,9 @@
  */
 package org.apache.phoenix.expression.aggregator;
 
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -35,7 +36,7 @@ public class IntSumAggregator extends NumberSumAggregator {
     
     @Override
     protected PDataType getInputDataType() {
-        return PDataType.INTEGER;
+        return PInteger.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/LongSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/LongSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/LongSumAggregator.java
index a4d8fc6..4007bb4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/LongSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/LongSumAggregator.java
@@ -17,8 +17,9 @@
  */
 package org.apache.phoenix.expression.aggregator;
 
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -35,6 +36,6 @@ public class LongSumAggregator extends NumberSumAggregator {
     
     @Override
     protected PDataType getInputDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/NumberSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/NumberSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/NumberSumAggregator.java
index 1179aa0..bfcecd1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/NumberSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/NumberSumAggregator.java
@@ -19,8 +19,9 @@ package org.apache.phoenix.expression.aggregator;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SizedUtil;
 
@@ -44,7 +45,7 @@ abstract public class NumberSumAggregator extends BaseAggregator {
         this(sortOrder);
         if (ptr != null) {
             initBuffer();
-            sum = PDataType.LONG.getCodec().decodeLong(ptr, sortOrder);
+            sum = PLong.INSTANCE.getCodec().decodeLong(ptr, sortOrder);
         }
     }
 
@@ -88,7 +89,7 @@ abstract public class NumberSumAggregator extends BaseAggregator {
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentRankClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentRankClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentRankClientAggregator.java
index 3bb9445..fceb162 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentRankClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentRankClientAggregator.java
@@ -23,8 +23,9 @@ import java.util.Map.Entry;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.*;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -70,13 +71,13 @@ public class PercentRankClientAggregator extends DistinctValueWithCountClientAgg
         if (buffer == null) {
             initBuffer();
         }
-        buffer = PDataType.DECIMAL.toBytes(this.cachedResult);
+        buffer = PDecimal.INSTANCE.toBytes(this.cachedResult);
         ptr.set(buffer);
         return true;
     }
 
     @Override
     protected PDataType getResultDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileClientAggregator.java
index fb50fea..82807e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileClientAggregator.java
@@ -23,8 +23,9 @@ import java.util.Map.Entry;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.*;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -88,13 +89,13 @@ public class PercentileClientAggregator extends DistinctValueWithCountClientAggr
         if (buffer == null) {
             initBuffer();
         }
-        buffer = PDataType.DECIMAL.toBytes(this.cachedResult);
+        buffer = PDecimal.INSTANCE.toBytes(this.cachedResult);
         ptr.set(buffer);
         return true;
     }
 
     @Override
     protected PDataType getResultDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileDiscClientAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileDiscClientAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileDiscClientAggregator.java
index 84d9fff..54541e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileDiscClientAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/PercentileDiscClientAggregator.java
@@ -22,8 +22,9 @@ import java.util.Map.Entry;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.*;
+import org.apache.phoenix.schema.types.PDecimal;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -89,7 +90,7 @@ public class PercentileDiscClientAggregator extends DistinctValueWithCountClient
 	@Override
 	protected int getBufferLength() {
 		// Will be used in the aggregate() call
-		return PDataType.DECIMAL.getByteSize();
+		return PDecimal.INSTANCE.getByteSize();
 	}
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedIntSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedIntSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedIntSumAggregator.java
index 7768312..ed08cb2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedIntSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedIntSumAggregator.java
@@ -17,8 +17,9 @@
  */
 package org.apache.phoenix.expression.aggregator;
 
+import org.apache.phoenix.schema.types.PUnsignedInt;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -35,7 +36,7 @@ public class UnsignedIntSumAggregator extends NumberSumAggregator {
     
     @Override
     protected PDataType getInputDataType() {
-        return PDataType.UNSIGNED_INT;
+        return PUnsignedInt.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedLongSumAggregator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedLongSumAggregator.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedLongSumAggregator.java
index aa811a8..3c474c6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedLongSumAggregator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/UnsignedLongSumAggregator.java
@@ -17,8 +17,9 @@
  */
 package org.apache.phoenix.expression.aggregator;
 
+import org.apache.phoenix.schema.types.PUnsignedLong;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 /**
  * 
@@ -36,7 +37,7 @@ public class UnsignedLongSumAggregator extends NumberSumAggregator {
     
     @Override
     protected PDataType getInputDataType() {
-        return PDataType.UNSIGNED_LONG;
+        return PUnsignedLong.INSTANCE;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
index 9acdadb..22d9f0e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAllComparisonExpression.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 
 public class ArrayAllComparisonExpression extends ArrayAnyComparisonExpression {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
index dd85bb7..b57901b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayAnyComparisonExpression.java
@@ -24,8 +24,9 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.expression.BaseCompoundExpression;
 import org.apache.phoenix.expression.ComparisonExpression;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PBoolean;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class ArrayAnyComparisonExpression extends BaseCompoundExpression {
@@ -73,6 +74,6 @@ public class ArrayAnyComparisonExpression extends BaseCompoundExpression {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.BOOLEAN;
+        return PBoolean.INSTANCE;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
index a1f8b6d..7a23ef5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayIndexFunction.java
@@ -24,15 +24,18 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.ParseException;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBinaryArray;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinaryArray;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 @BuiltInFunction(name = ArrayIndexFunction.NAME, args = {
-		@Argument(allowedTypes = { PDataType.BINARY_ARRAY,
-				PDataType.VARBINARY_ARRAY }),
-		@Argument(allowedTypes = { PDataType.INTEGER }) })
+		@Argument(allowedTypes = { PBinaryArray.class,
+        PVarbinaryArray.class }),
+		@Argument(allowedTypes = { PInteger.class }) })
 public class ArrayIndexFunction extends ScalarFunction {
 
 	public static final String NAME = "ARRAY_ELEM";
@@ -53,12 +56,13 @@ public class ArrayIndexFunction extends ScalarFunction {
 		  return true;
 		}
 		// Use Codec to prevent Integer object allocation
-		int index = PDataType.INTEGER.getCodec().decodeInt(ptr, indexExpr.getSortOrder());
+		int index = PInteger.INSTANCE.getCodec().decodeInt(ptr, indexExpr.getSortOrder());
 		if(index < 0) {
 			throw new ParseException("Index cannot be negative :" + index);
 		}
 		Expression arrayExpr = children.get(0);
-		return PArrayDataType.positionAtArrayElement(tuple, ptr, index, arrayExpr, getDataType(), getMaxLength());
+		return PArrayDataType.positionAtArrayElement(tuple, ptr, index, arrayExpr, getDataType(),
+        getMaxLength());
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayLengthFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayLengthFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayLengthFunction.java
index 1988e9d..1c1c7df 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayLengthFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ArrayLengthFunction.java
@@ -23,12 +23,15 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBinaryArray;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 @BuiltInFunction(name = ArrayLengthFunction.NAME, args = { @Argument(allowedTypes = {
-		PDataType.BINARY_ARRAY, PDataType.VARBINARY_ARRAY }) })
+		PBinaryArray.class, PVarbinary.class }) })
 public class ArrayLengthFunction extends ScalarFunction {
 	public static final String NAME = "ARRAY_LENGTH";
 
@@ -51,8 +54,8 @@ public class ArrayLengthFunction extends ScalarFunction {
 				.getSqlType()
 				- PDataType.ARRAY_TYPE_BASE);
 		int length = PArrayDataType.getArrayLength(ptr, baseType, arrayExpr.getMaxLength());
-		byte[] lengthBuf = new byte[PDataType.INTEGER.getByteSize()];
-		PDataType.INTEGER.getCodec().encodeInt(length, lengthBuf, 0);
+		byte[] lengthBuf = new byte[PInteger.INSTANCE.getByteSize()];
+    PInteger.INSTANCE.getCodec().encodeInt(length, lengthBuf, 0);
 		ptr.set(lengthBuf);
 		return true;
 	}
@@ -60,7 +63,7 @@ public class ArrayLengthFunction extends ScalarFunction {
 	@Override
 	public PDataType getDataType() {
 		// Array length will return an Integer
-		return PDataType.INTEGER;
+		return PInteger.INSTANCE;
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/AvgAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/AvgAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/AvgAggregateFunction.java
index db277a0..ccba14f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/AvgAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/AvgAggregateFunction.java
@@ -26,12 +26,13 @@ import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.parse.AvgAggregateParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
-@BuiltInFunction(name=AvgAggregateFunction.NAME, nodeClass=AvgAggregateParseNode.class, args= {@Argument(allowedTypes={PDataType.DECIMAL})} )
+@BuiltInFunction(name=AvgAggregateFunction.NAME, nodeClass=AvgAggregateParseNode.class, args= {@Argument(allowedTypes={PDecimal.class})} )
 public class AvgAggregateFunction extends CompositeAggregateFunction {
     public static final String NAME = "AVG";
     private final CountAggregateFunction countFunc;
@@ -64,7 +65,7 @@ public class AvgAggregateFunction extends CompositeAggregateFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DECIMAL;
+        return PDecimal.INSTANCE;
     }
 
     @Override
@@ -80,17 +81,17 @@ public class AvgAggregateFunction extends CompositeAggregateFunction {
         // Normal case where a column reference was used as the argument to AVG
         if (!countFunc.isConstantExpression()) {
             sumFunc.evaluate(tuple, ptr);
-            BigDecimal sum = (BigDecimal)PDataType.DECIMAL.toObject(ptr, sumFunc.getDataType());
+            BigDecimal sum = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, sumFunc.getDataType());
             // For the final column projection, we divide the sum by the count, both coerced to BigDecimal.
             // TODO: base the precision on column metadata instead of constant
             BigDecimal avg = sum.divide(BigDecimal.valueOf(count), PDataType.DEFAULT_MATH_CONTEXT);
             avg = avg.setScale(scale, BigDecimal.ROUND_DOWN);
-            ptr.set(PDataType.DECIMAL.toBytes(avg));
+            ptr.set(PDecimal.INSTANCE.toBytes(avg));
             return true;
         }
         BigDecimal value = (BigDecimal) ((LiteralExpression)countFunc.getChildren().get(0)).getValue();
         value = value.setScale(scale, BigDecimal.ROUND_DOWN);
-        ptr.set(PDataType.DECIMAL.toBytes(value));
+        ptr.set(PDecimal.INSTANCE.toBytes(value));
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
index e5b2806..220b453 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDateExpression.java
@@ -25,7 +25,7 @@ import org.apache.phoenix.expression.Expression;
 
 /**
  * 
- * Class encapsulating ceil operation on {@link org.apache.phoenix.schema.PDataType#DATE}.
+ * Class encapsulating ceil operation on {@link org.apache.phoenix.schema.types.PDataType#DATE}.
  *
  * 
  * @since 3.0.0

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
index bd36d0f..208d5ee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilDecimalExpression.java
@@ -24,19 +24,19 @@ import java.util.List;
 import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
 
 import com.google.common.collect.Lists;
 
 import java.math.BigDecimal;
 
 import org.apache.phoenix.query.KeyRange;
-
-import static org.apache.phoenix.schema.PDataType.DECIMAL;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
 
 /**
  *
- * Class encapsulating the CEIL operation on a {@link org.apache.phoenix.schema.PDataType#DECIMAL}
+ * Class encapsulating the CEIL operation on a {@link org.apache.phoenix.schema.types.PDecimal}
  *
  *
  * @since 3.0.0
@@ -54,21 +54,21 @@ public class CeilDecimalExpression extends RoundDecimalExpression {
      *
      */
     public static Expression create(Expression expr, int scale) throws SQLException {
-       if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+       if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
-        Expression scaleExpr = LiteralExpression.newConstant(scale, PDataType.INTEGER, Determinism.ALWAYS);
+        Expression scaleExpr = LiteralExpression.newConstant(scale, PInteger.INSTANCE, Determinism.ALWAYS);
         List<Expression> expressions = Lists.newArrayList(expr, scaleExpr);
         return new CeilDecimalExpression(expressions);
     }
 
     public static Expression create(List<Expression> exprs) throws SQLException {
         Expression expr = exprs.get(0);
-       if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+       if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
        if (exprs.size() == 1) {
-            Expression scaleExpr = LiteralExpression.newConstant(0, PDataType.INTEGER, Determinism.ALWAYS);
+            Expression scaleExpr = LiteralExpression.newConstant(0, PInteger.INSTANCE, Determinism.ALWAYS);
             exprs = Lists.newArrayList(expr, scaleExpr);
         }
         return new CeilDecimalExpression(exprs);
@@ -101,8 +101,8 @@ public class CeilDecimalExpression extends RoundDecimalExpression {
             throw new IllegalArgumentException("Cannot produce input range for decimal " + result 
                 + ", not enough precision with scale " + getRoundingScale());
         }
-        byte[] lowerRange = DECIMAL.toBytes(stepPrevInScale(result));
-        byte[] upperRange = DECIMAL.toBytes(result);
+        byte[] lowerRange = PDecimal.INSTANCE.toBytes(stepPrevInScale(result));
+        byte[] upperRange = PDecimal.INSTANCE.toBytes(result);
         return KeyRange.getKeyRange(lowerRange, false, upperRange, true);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
index 67d21a2..706aadf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
@@ -23,7 +23,11 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.CeilParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
+
 /**
  * 
  * Base class for built-in CEIL function.
@@ -34,9 +38,9 @@ import org.apache.phoenix.schema.PDataType;
 @BuiltInFunction(name = CeilFunction.NAME,
                  nodeClass = CeilParseNode.class,
                  args = {
-                        @Argument(allowedTypes={PDataType.TIMESTAMP, PDataType.DECIMAL}),
-                        @Argument(allowedTypes={PDataType.VARCHAR, PDataType.INTEGER}, defaultValue = "null", isConstant=true),
-                        @Argument(allowedTypes={PDataType.INTEGER}, defaultValue="1", isConstant=true)
+                        @Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
+                        @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+                        @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
                         } 
                 )
 public abstract class CeilFunction extends ScalarFunction {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
index a22bdd2..c2d7daf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilTimestampExpression.java
@@ -27,14 +27,18 @@ import com.google.common.collect.Lists;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 import org.apache.phoenix.schema.SortOrder;
-import org.apache.phoenix.schema.PDataType;
-import org.apache.phoenix.schema.PDataType.PDataCodec;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDataType.PDataCodec;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
  * 
- * Class encapsulating the CEIL operation on {@link org.apache.phoenix.schema.PDataType#TIMESTAMP}
+ * Class encapsulating the CEIL operation on {@link org.apache.phoenix.schema.types.PTimestamp}
  * This class only supports CEIL {@link TimeUnit#MILLISECOND}. If you want more options of CEIL like 
  * using {@link TimeUnit#HOUR} use {@link CeilDateExpression}
  * 
@@ -67,7 +71,8 @@ public class CeilTimestampExpression extends CeilDateExpression {
         }
         // Coerce TIMESTAMP to DATE, as the nanos has no affect
         List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
-        newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PDataType.TIMESTAMP ? PDataType.DATE : PDataType.UNSIGNED_DATE));
+        newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ?
+            PDate.INSTANCE : PUnsignedDate.INSTANCE));
         newChildren.addAll(children.subList(1, children.size()));
         return CeilDateExpression.create(newChildren);
     }
@@ -82,10 +87,10 @@ public class CeilTimestampExpression extends CeilDateExpression {
 
     @Override
     protected PDataCodec getKeyRangeCodec(PDataType columnDataType) {
-        return columnDataType == PDataType.TIMESTAMP 
-                ? PDataType.DATE.getCodec() 
-                : columnDataType == PDataType.UNSIGNED_TIMESTAMP 
-                    ? PDataType.UNSIGNED_DATE.getCodec() 
+        return columnDataType == PTimestamp.INSTANCE
+                ? PDate.INSTANCE.getCodec()
+                : columnDataType == PUnsignedTimestamp.INSTANCE
+                    ? PUnsignedDate.INSTANCE.getCodec()
                     : super.getKeyRangeCodec(columnDataType);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
index 4c6d3a2..773120a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CoalesceFunction.java
@@ -28,7 +28,7 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ExpressionUtil;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
index b8e5edb..dcde31f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
@@ -26,7 +26,9 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
@@ -35,9 +37,9 @@ import org.apache.phoenix.schema.tuple.Tuple;
  *
  */
 @FunctionParseNode.BuiltInFunction(name = ConvertTimezoneFunction.NAME, args = {
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.DATE}),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.VARCHAR}),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.VARCHAR})})
+    @FunctionParseNode.Argument(allowedTypes = { PDate.class }),
+    @FunctionParseNode.Argument(allowedTypes = { PVarchar.class }),
+    @FunctionParseNode.Argument(allowedTypes = { PVarchar.class })})
 public class ConvertTimezoneFunction extends ScalarFunction {
 
     public static final String NAME = "CONVERT_TZ";
@@ -61,7 +63,7 @@ public class ConvertTimezoneFunction extends ScalarFunction {
             return false;
         }
 
-        Date dateo = (Date) PDataType.DATE.toObject(ptr, children.get(0).getSortOrder());
+        Date dateo = (Date) PDate.INSTANCE.toObject(ptr, children.get(0).getSortOrder());
         Long date = dateo.getTime();
 
         if (!children.get(1).evaluate(tuple, ptr)) {
@@ -77,7 +79,7 @@ public class ConvertTimezoneFunction extends ScalarFunction {
         long dateInUtc = date - timezoneFrom.getOffset(date);
         long dateInTo = dateInUtc + timezoneTo.getOffset(dateInUtc);
 
-        ptr.set(PDataType.DATE.toBytes(new Date(dateInTo)));
+        ptr.set(PDate.INSTANCE.toBytes(new Date(dateInTo)));
 
         return true;
     }
@@ -96,6 +98,6 @@ public class ConvertTimezoneFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CountAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CountAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CountAggregateFunction.java
index f1e8ab5..6eef42d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CountAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CountAggregateFunction.java
@@ -30,7 +30,8 @@ import org.apache.phoenix.expression.aggregator.CountAggregator;
 import org.apache.phoenix.expression.aggregator.LongSumAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.util.SchemaUtil;
 
 
@@ -79,7 +80,7 @@ public class CountAggregateFunction extends SingleAggregateFunction {
     
     @Override
     public PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
     @Override 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
index 1ef48e9..57b82e4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentDateFunction.java
@@ -22,7 +22,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.CurrentDateTimeFunction;
 import org.apache.phoenix.parse.CurrentDateParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -39,7 +40,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
 @BuiltInFunction(name=CurrentDateFunction.NAME, nodeClass=CurrentDateParseNode.class, args= {} )
 public class CurrentDateFunction extends CurrentDateTimeFunction {
     public static final String NAME = "CURRENT_DATE";
-    private final ImmutableBytesWritable currentDate = new ImmutableBytesWritable(new byte[PDataType.DATE.getByteSize()]);
+    private final ImmutableBytesWritable currentDate = new ImmutableBytesWritable(new byte[PDate.INSTANCE.getByteSize()]);
     
     public CurrentDateFunction() {
         this(System.currentTimeMillis());
@@ -51,13 +52,13 @@ public class CurrentDateFunction extends CurrentDateTimeFunction {
 
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
-        ptr.set(currentDate.get(), 0, PDataType.DATE.getByteSize());
+        ptr.set(currentDate.get(), 0, PDate.INSTANCE.getByteSize());
         return true;
     }
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.DATE;
+        return PDate.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
index ab59609..12abb3b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CurrentTimeFunction.java
@@ -22,7 +22,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.CurrentDateTimeFunction;
 import org.apache.phoenix.parse.CurrentTimeParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTime;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -39,7 +40,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
 @BuiltInFunction(name=CurrentTimeFunction.NAME, nodeClass=CurrentTimeParseNode.class, args={} )
 public class CurrentTimeFunction extends CurrentDateTimeFunction {
     public static final String NAME = "CURRENT_TIME";
-    private final ImmutableBytesWritable currentDate = new ImmutableBytesWritable(new byte[PDataType.TIME.getByteSize()]);
+    private final ImmutableBytesWritable currentDate = new ImmutableBytesWritable(new byte[PTime.INSTANCE.getByteSize()]);
     
     public CurrentTimeFunction() {
         this(System.currentTimeMillis());
@@ -51,13 +52,13 @@ public class CurrentTimeFunction extends CurrentDateTimeFunction {
 
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
-        ptr.set(currentDate.get(), 0, PDataType.TIME.getByteSize());
+        ptr.set(currentDate.get(), 0, PTime.INSTANCE.getByteSize());
         return true;
     }
 
     @Override
     public final PDataType getDataType() {
-        return PDataType.TIME;
+        return PTime.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java
index 2107ab9..7b6ef38 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java
@@ -26,14 +26,16 @@ import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**
  * Convert string to bytes
  */
 @FunctionParseNode.BuiltInFunction(name = DecodeFunction.NAME, args = {
-	@FunctionParseNode.Argument(allowedTypes = {PDataType.VARCHAR}),
+	@FunctionParseNode.Argument(allowedTypes = { PVarchar.class }),
 	@FunctionParseNode.Argument(enumeration = "EncodeFormat")})
 public class DecodeFunction extends ScalarFunction {
 
@@ -105,7 +107,7 @@ public class DecodeFunction extends ScalarFunction {
 
 	@Override
 	public PDataType getDataType() {
-		return PDataType.VARBINARY;
+		return PVarbinary.INSTANCE;
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DelegateConstantToCountAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DelegateConstantToCountAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DelegateConstantToCountAggregateFunction.java
index 9c4700e..e6532c6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DelegateConstantToCountAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DelegateConstantToCountAggregateFunction.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -36,7 +36,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 0.1
  */
 abstract public class DelegateConstantToCountAggregateFunction extends SingleAggregateFunction {
-    private static final ImmutableBytesWritable ZERO = new ImmutableBytesWritable(PDataType.LONG.toBytes(0L));
+    private static final ImmutableBytesWritable ZERO = new ImmutableBytesWritable(PLong.INSTANCE.toBytes(0L));
     private CountAggregateFunction delegate;
     
     public DelegateConstantToCountAggregateFunction() {
@@ -58,7 +58,7 @@ abstract public class DelegateConstantToCountAggregateFunction extends SingleAgg
             return super.evaluate(tuple, ptr);
         }
         delegate.evaluate(tuple, ptr);
-        if (PDataType.LONG.compareTo(ptr,ZERO) == 0) {
+        if (PLong.INSTANCE.compareTo(ptr,ZERO) == 0) {
             return false;
         }
         return true;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctCountAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctCountAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctCountAggregateFunction.java
index a17eee5..6ce3c27 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctCountAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctCountAggregateFunction.java
@@ -28,7 +28,8 @@ import org.apache.phoenix.expression.aggregator.DistinctCountClientAggregator;
 import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.SchemaUtil;
 
@@ -44,8 +45,8 @@ import org.apache.phoenix.util.SchemaUtil;
 public class DistinctCountAggregateFunction extends DelegateConstantToCountAggregateFunction {
     public static final String NAME = "DISTINCT_COUNT";
     public static final String NORMALIZED_NAME = SchemaUtil.normalizeIdentifier(NAME);
-    public final static byte[] ZERO = PDataType.LONG.toBytes(0L);
-    public final static byte[] ONE = PDataType.LONG.toBytes(1L);
+    public final static byte[] ZERO = PLong.INSTANCE.toBytes(0L);
+    public final static byte[] ONE = PLong.INSTANCE.toBytes(1L);
     
     public DistinctCountAggregateFunction() {
     }
@@ -84,7 +85,7 @@ public class DistinctCountAggregateFunction extends DelegateConstantToCountAggre
 
     @Override
     public PDataType getDataType() {
-        return PDataType.LONG;
+        return PLong.INSTANCE;
     }
 
     @Override 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctValueAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctValueAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctValueAggregateFunction.java
index 6877409..a48e523 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctValueAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/DistinctValueAggregateFunction.java
@@ -27,7 +27,8 @@ import org.apache.phoenix.expression.aggregator.DistinctValueWithCountClientAggr
 import org.apache.phoenix.expression.aggregator.DistinctValueWithCountServerAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 
 @BuiltInFunction(name=DistinctValueAggregateFunction.NAME, args= {@Argument()} )
 public class DistinctValueAggregateFunction extends DistinctValueWithCountAggregateFunction {
@@ -47,7 +48,8 @@ public class DistinctValueAggregateFunction extends DistinctValueWithCountAggreg
 
     @Override
     public DistinctValueWithCountClientAggregator newClientAggregator() {
-        PDataType baseType = getAggregatorExpression().getDataType().isArrayType() ? PDataType.VARBINARY : getAggregatorExpression().getDataType();
+        PDataType baseType = getAggregatorExpression().getDataType().isArrayType() ?
+            PVarbinary.INSTANCE : getAggregatorExpression().getDataType();
         PDataType resultType = PDataType.fromTypeId(baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE);
         return new DistinctValueClientAggregator(getAggregatorExpression().getSortOrder(), baseType, resultType);
     }
@@ -59,7 +61,7 @@ public class DistinctValueAggregateFunction extends DistinctValueWithCountAggreg
 
     @Override
     public PDataType getDataType() {
-        PDataType baseType = getAggregatorExpression().getDataType().isArrayType() ? PDataType.VARBINARY : getAggregatorExpression().getDataType();
+        PDataType baseType = getAggregatorExpression().getDataType().isArrayType() ? PVarbinary.INSTANCE : getAggregatorExpression().getDataType();
         return PDataType.fromTypeId(baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/EncodeFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/EncodeFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/EncodeFunction.java
index 8a0f9e1..ebb4953 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/EncodeFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/EncodeFunction.java
@@ -23,7 +23,9 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.Base62Encoder;
 
@@ -32,7 +34,7 @@ import org.apache.phoenix.util.Base62Encoder;
  * 
  * Converts the given base 10 number to a base 62 number and returns a string representing the number.
  */
-@BuiltInFunction(name = EncodeFunction.NAME, args = { @Argument(allowedTypes = { PDataType.LONG }),
+@BuiltInFunction(name = EncodeFunction.NAME, args = { @Argument(allowedTypes = { PLong.class }),
     @Argument(enumeration = "EncodeFormat") })
 public class EncodeFunction extends ScalarFunction {
     public static final String NAME = "ENCODE";
@@ -67,7 +69,7 @@ public class EncodeFunction extends ScalarFunction {
         switch (format) {
             case BASE62:
                 String encodedString = Base62Encoder.toString(num);
-                ptr.set(PDataType.VARCHAR.toBytes(encodedString));
+                ptr.set(PVarchar.INSTANCE.toBytes(encodedString));
                 break;
             default:
                 throw new IllegalDataException(getUnsupportedEncodeFormatMsg(encodingFormat));
@@ -85,7 +87,7 @@ public class EncodeFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunction.java
index ba8a875..f510181 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunction.java
@@ -22,7 +22,8 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.schema.IllegalDataException;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 
@@ -44,7 +45,7 @@ import java.util.List;
  * @since 3.0
  */
 @BuiltInFunction(name=ExternalSqlTypeIdFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.INTEGER)} )
+    @Argument(allowedTypes= PInteger.class )} )
 public class ExternalSqlTypeIdFunction extends ScalarFunction {
     public static final String NAME = "ExternalSqlTypeId";
 
@@ -66,8 +67,8 @@ public class ExternalSqlTypeIdFunction extends ScalarFunction {
         }
         int sqlType = child.getDataType().getCodec().decodeInt(ptr, child.getSortOrder());
         try {
-            byte[] externalIdTypeBytes = PDataType.INTEGER.toBytes(
-                    PDataType.fromTypeId(sqlType).getResultSetSqlType());
+            byte[] externalIdTypeBytes = PInteger.INSTANCE.toBytes(
+                PDataType.fromTypeId(sqlType).getResultSetSqlType());
             ptr.set(externalIdTypeBytes);
         } catch (IllegalDataException e) {
             ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
@@ -77,7 +78,7 @@ public class ExternalSqlTypeIdFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.INTEGER;
+        return PInteger.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
index 0c14c18..5b2c8a1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
@@ -20,7 +20,7 @@ package org.apache.phoenix.expression.function;
 import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 /**

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
index ef01534..df9d26b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstValueFunction.java
@@ -26,7 +26,7 @@ import org.apache.phoenix.expression.aggregator.FirstLastValueBaseClientAggregat
 import org.apache.phoenix.expression.aggregator.FirstLastValueServerAggregator;
 import org.apache.phoenix.parse.FirstValueAggregateParseNode;
 import org.apache.phoenix.parse.FunctionParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 
 /**
  * Built-in function for FIRST_VALUE(<expression>) WITHIN GROUP (ORDER BY <expression> ASC/DESC) aggregate
@@ -35,7 +35,7 @@ import org.apache.phoenix.schema.PDataType;
  */
 @FunctionParseNode.BuiltInFunction(name = FirstValueFunction.NAME, nodeClass = FirstValueAggregateParseNode.class, args = {
     @FunctionParseNode.Argument(),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.BOOLEAN}, isConstant = true),
+    @FunctionParseNode.Argument(allowedTypes = { PBoolean.class }, isConstant = true),
     @FunctionParseNode.Argument()})
 public class FirstValueFunction extends FirstLastValueBaseFunction {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
index ab4e554..e3d0543 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDateExpression.java
@@ -23,12 +23,16 @@ import java.util.List;
 import com.google.common.collect.Lists;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PUnsignedDate;
+import org.apache.phoenix.schema.types.PUnsignedTimestamp;
 
 /**
  * 
  * Class encapsulating the FLOOR operation on 
- * a column/literal of type {@link org.apache.phoenix.schema.PDataType#DATE}.
+ * a column/literal of type {@link org.apache.phoenix.schema.types.PDate}.
  *
  * 
  * @since 3.0.0
@@ -44,10 +48,10 @@ public class FloorDateExpression extends RoundDateExpression {
     public static Expression create(List<Expression> children) throws SQLException {
         Expression firstChild = children.get(0);
         PDataType firstChildDataType = firstChild.getDataType();
-        if (firstChildDataType == PDataType.TIMESTAMP || firstChildDataType == PDataType.UNSIGNED_TIMESTAMP){
+        if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE){
             // Coerce TIMESTAMP to DATE, as the nanos has no affect
             List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
-            newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PDataType.TIMESTAMP ? PDataType.DATE : PDataType.UNSIGNED_DATE));
+            newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE));
             newChildren.addAll(children.subList(1, children.size()));
             children = newChildren;
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
index 037fcc5..2d81c2e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorDecimalExpression.java
@@ -24,20 +24,20 @@ import java.util.List;
 import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
 
 import com.google.common.collect.Lists;
 
 import java.math.BigDecimal;
 
 import org.apache.phoenix.query.KeyRange;
-
-import static org.apache.phoenix.schema.PDataType.DECIMAL;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PLong;
 
 /**
  *
  * Class encapsulating the FLOOR operation on 
- * a column/literal of type {@link org.apache.phoenix.schema.PDataType#DECIMAL}.
+ * a column/literal of type {@link org.apache.phoenix.schema.types.PDecimal}.
  *
  *
  * @since 3.0.0
@@ -55,21 +55,21 @@ public class FloorDecimalExpression extends RoundDecimalExpression {
      *
      */
     public static Expression create(Expression expr, int scale) throws SQLException {
-        if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+        if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
-        Expression scaleExpr = LiteralExpression.newConstant(scale, PDataType.INTEGER, Determinism.ALWAYS);
+        Expression scaleExpr = LiteralExpression.newConstant(scale, PInteger.INSTANCE, Determinism.ALWAYS);
         List<Expression> expressions = Lists.newArrayList(expr, scaleExpr);
         return new FloorDecimalExpression(expressions);
     }
 
     public static Expression create(List<Expression> exprs) throws SQLException {
         Expression expr = exprs.get(0);
-        if (expr.getDataType().isCoercibleTo(PDataType.LONG)) {
+        if (expr.getDataType().isCoercibleTo(PLong.INSTANCE)) {
             return expr;
         }
         if (exprs.size() == 1) {
-            Expression scaleExpr = LiteralExpression.newConstant(0, PDataType.INTEGER, Determinism.ALWAYS);
+            Expression scaleExpr = LiteralExpression.newConstant(0, PInteger.INSTANCE, Determinism.ALWAYS);
             exprs = Lists.newArrayList(expr, scaleExpr);
         }
         return new FloorDecimalExpression(exprs);
@@ -102,8 +102,8 @@ public class FloorDecimalExpression extends RoundDecimalExpression {
             throw new IllegalArgumentException("Cannot produce input range for decimal " + result 
                 + ", not enough precision with scale " + getRoundingScale());
         }
-        byte[] lowerRange = DECIMAL.toBytes(result);
-        byte[] upperRange = DECIMAL.toBytes(stepNextInScale(result));
+        byte[] lowerRange = PDecimal.INSTANCE.toBytes(result);
+        byte[] upperRange = PDecimal.INSTANCE.toBytes(stepNextInScale(result));
         return KeyRange.getKeyRange(lowerRange, upperRange);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
index a177068..7938324 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
@@ -23,7 +23,11 @@ import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FloorParseNode;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
+
 /**
  * 
  * Base class for built-in FLOOR function.
@@ -34,9 +38,9 @@ import org.apache.phoenix.schema.PDataType;
 @BuiltInFunction(name = FloorFunction.NAME,
                  nodeClass = FloorParseNode.class,
                  args = {
-                        @Argument(allowedTypes={PDataType.TIMESTAMP, PDataType.DECIMAL}),
-                        @Argument(allowedTypes={PDataType.VARCHAR, PDataType.INTEGER}, defaultValue = "null", isConstant=true),
-                        @Argument(allowedTypes={PDataType.INTEGER}, defaultValue="1", isConstant=true)
+                        @Argument(allowedTypes={PTimestamp.class, PDecimal.class}),
+                        @Argument(allowedTypes={PVarchar.class, PInteger.class}, defaultValue = "null", isConstant=true),
+                        @Argument(allowedTypes={PInteger.class}, defaultValue="1", isConstant=true)
                         } 
                 )
 public abstract class FloorFunction extends ScalarFunction {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/IndexStateNameFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/IndexStateNameFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/IndexStateNameFunction.java
index fe37c52..d8440df 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/IndexStateNameFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/IndexStateNameFunction.java
@@ -25,8 +25,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -41,7 +43,7 @@ import org.apache.phoenix.schema.tuple.Tuple;
  * @since 2.1
  */
 @BuiltInFunction(name=IndexStateNameFunction.NAME, args= {
-    @Argument(allowedTypes=PDataType.CHAR)} )
+    @Argument(allowedTypes= PChar.class)} )
 public class IndexStateNameFunction extends ScalarFunction {
     public static final String NAME = "IndexStateName";
 
@@ -69,7 +71,7 @@ public class IndexStateNameFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-        return PDataType.VARCHAR;
+        return PVarchar.INSTANCE;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
index 9082911..c5c1eea 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InlineArrayElemRefExpression.java
@@ -25,8 +25,8 @@ import java.util.List;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.BaseCompoundExpression;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.schema.PArrayDataType;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PArrayDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 public class InlineArrayElemRefExpression extends BaseCompoundExpression {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
index 6756806..3dcbf7c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/InvertFunction.java
@@ -28,7 +28,7 @@ import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
index 987b006..bfbe2f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LTrimFunction.java
@@ -24,7 +24,8 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -41,7 +42,7 @@ import org.apache.phoenix.util.StringUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=LTrimFunction.NAME, args={
-    @Argument(allowedTypes={PDataType.VARCHAR})})
+    @Argument(allowedTypes={PVarchar.class})})
 public class LTrimFunction extends ScalarFunction {
     public static final String NAME = "LTRIM";
 
@@ -94,7 +95,7 @@ public class LTrimFunction extends ScalarFunction {
 
     @Override
     public PDataType getDataType() {
-      return PDataType.VARCHAR;
+      return PVarchar.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
index 9c5f133..9f01c61 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LastValueFunction.java
@@ -26,7 +26,7 @@ import org.apache.phoenix.expression.aggregator.FirstLastValueBaseClientAggregat
 import org.apache.phoenix.expression.aggregator.FirstLastValueServerAggregator;
 import org.apache.phoenix.parse.FunctionParseNode;
 import org.apache.phoenix.parse.LastValueAggregateParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PBoolean;
 
 /**
  * Built-in function for LAST_VALUE(<expression>) WITHIN GROUP (ORDER BY <expression> ASC/DESC) aggregate
@@ -35,7 +35,7 @@ import org.apache.phoenix.schema.PDataType;
  */
 @FunctionParseNode.BuiltInFunction(name = LastValueFunction.NAME, nodeClass = LastValueAggregateParseNode.class, args = {
     @FunctionParseNode.Argument(),
-    @FunctionParseNode.Argument(allowedTypes = {PDataType.BOOLEAN}, isConstant = true),
+    @FunctionParseNode.Argument(allowedTypes = { PBoolean.class}, isConstant = true),
     @FunctionParseNode.Argument()})
 public class LastValueFunction extends FirstLastValueBaseFunction {
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LengthFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LengthFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LengthFunction.java
index 5822759..76d9e59 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LengthFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LengthFunction.java
@@ -25,7 +25,10 @@ import org.apache.phoenix.exception.UndecodableByteException;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -41,7 +44,7 @@ import org.apache.phoenix.util.StringUtil;
  * @since 0.1
  */
 @BuiltInFunction(name=LengthFunction.NAME, args={
-    @Argument(allowedTypes={PDataType.VARCHAR})} )
+    @Argument(allowedTypes={ PVarchar.class })} )
 public class LengthFunction extends ScalarFunction {
     public static final String NAME = "LENGTH";
 
@@ -66,7 +69,7 @@ public class LengthFunction extends ScalarFunction {
             return true;
         }
         int len;
-        if (child.getDataType() == PDataType.CHAR) {
+        if (child.getDataType() == PChar.INSTANCE) {
             // Only single-byte characters allowed in CHAR
             len = ptr.getLength();
         } else {
@@ -76,13 +79,13 @@ public class LengthFunction extends ScalarFunction {
                 return false;
             }
         }
-        ptr.set(PDataType.INTEGER.toBytes(len));
+        ptr.set(PInteger.INSTANCE.toBytes(len));
         return true;
     }
 
     @Override
     public PDataType getDataType() {
-        return PDataType.INTEGER;
+        return PInteger.INSTANCE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java
index 5ee869e..0d8d817 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/LowerFunction.java
@@ -25,11 +25,12 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 @FunctionParseNode.BuiltInFunction(name=LowerFunction.NAME,  args={
-        @FunctionParseNode.Argument(allowedTypes={PDataType.VARCHAR})} )
+        @FunctionParseNode.Argument(allowedTypes={PVarchar.class})} )
 public class LowerFunction extends ScalarFunction {
     public static final String NAME = "LOWER";
 
@@ -46,13 +47,13 @@ public class LowerFunction extends ScalarFunction {
             return false;
         }
 
-        String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, getStrExpression().getSortOrder());
+        String sourceStr = (String) PVarchar.INSTANCE.toObject(ptr, getStrExpression().getSortOrder());
 
         if (sourceStr == null) {
             return true;
         }
 
-        ptr.set(PDataType.VARCHAR.toBytes(sourceStr.toLowerCase()));
+        ptr.set(PVarchar.INSTANCE.toBytes(sourceStr.toLowerCase()));
         return true;
     }
 


[06/22] phoenix git commit: PHOENIX-1514 Break up PDataType Enum

Posted by nd...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
index 6d44818..a2b6115 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java
@@ -26,8 +26,10 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SortOrder;
@@ -93,81 +95,81 @@ public class SkipScanFilterIntersectTest {
         // Causes increment of slot 2 to increment slot 1
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("e"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("j"), true, Bytes.toBytes("m"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("e"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("j"), true, Bytes.toBytes("m"), false),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("j3A"),
                 Bytes.toBytes("k4C"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("j"), true, Bytes.toBytes("m"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("j"), true, Bytes.toBytes("m"), false),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                 }}));
         // Single matching in the first 2 slots.
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("b1B"),
                 Bytes.toBytes("b1C"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                 }}));
         // Single matching in the first slot.
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("b1Z"),
                 Bytes.toBytes("b3Z"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         // No overlap
         testCases.addAll(foreach(
                 new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     },{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
                     },{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("G"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("G"), true),
                 }},
                 new int[] {1,1,1}, 
                 Bytes.toBytes("a1I"), 
@@ -175,14 +177,14 @@ public class SkipScanFilterIntersectTest {
                 null));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
@@ -190,277 +192,277 @@ public class SkipScanFilterIntersectTest {
                 null));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
                 Bytes.toBytes("b1C"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
                 Bytes.toBytes("b1D"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
                 Bytes.toBytes("b1D"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("b1B"),
                 Bytes.toBytes("b1D"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("d"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("3"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
                 Bytes.toBytes("b1F"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0Z"),
                 Bytes.toBytes("b3Z"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0Z"),
                 Bytes.toBytes("b9Z"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         // Multiple matching in all slot.
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0Z"),
                 Bytes.toBytes("c3Z"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,1},
                 Bytes.toBytes("a0A"),
                 Bytes.toBytes("f4F"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         // VARCHAR as the last column, various cases.
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,-1},
                 Bytes.toBytes("d3AA"),
                 Bytes.toBytes("d4FF"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,-1},
                 Bytes.toBytes("d0AA"),
                 Bytes.toBytes("d4FF"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         testCases.addAll(foreach(
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }},
                 new int[] {1,1,-1},
                 Bytes.toBytes("a0AA"),
                 Bytes.toBytes("f4FF"),
                 new KeyRange[][] {{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true), 
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("c"), true, Bytes.toBytes("e"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("4"), true),
                     }, {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("B"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("E"), true),
                 }}));
         return testCases;
     }
@@ -479,7 +481,7 @@ public class SkipScanFilterIntersectTest {
                         }
                         @Override
                         public PDataType getDataType() {
-                            return width <= 0 ? PDataType.VARCHAR : PDataType.CHAR;
+                            return width <= 0 ? PVarchar.INSTANCE : PChar.INSTANCE;
                         }
                        @Override
                         public Integer getMaxLength() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
index d21396f..7e68e25 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterTest.java
@@ -30,8 +30,10 @@ import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.PDatum;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.RowKeySchema.RowKeySchemaBuilder;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.util.ByteUtil;
@@ -70,7 +72,7 @@ public class SkipScanFilterTest extends TestCase {
 
                 @Override
                 public PDataType getDataType() {
-                    return width <= 0 ? PDataType.VARCHAR : PDataType.CHAR;
+                    return width <= 0 ? PVarchar.INSTANCE : PChar.INSTANCE;
                 }
 
                 @Override
@@ -106,20 +108,20 @@ public class SkipScanFilterTest extends TestCase {
         List<Object> testCases = Lists.newArrayList();
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AA"), true, Bytes.toBytes("AB"), false),
                 }},
                 new int[]{3,2,2,2,2},
                 //new SeekNext("abcABABABAB", "abdAAAAAAAA"),
@@ -128,7 +130,7 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                        PDataType.VARCHAR.getKeyRange(Bytes.toBytes("j"), false, Bytes.toBytes("k"), true),
+                        PVarchar.INSTANCE.getKeyRange(Bytes.toBytes("j"), false, Bytes.toBytes("k"), true),
                     }},
                     new int[]{0},
                     new SeekNext(Bytes.toBytes("a"), ByteUtil.nextKey(new byte[] {'j',QueryConstants.SEPARATOR_BYTE})),
@@ -138,9 +140,9 @@ public class SkipScanFilterTest extends TestCase {
                     new Finished("ka")));
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aac"), true, Bytes.toBytes("aad"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true)
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aac"), true, Bytes.toBytes("aad"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true)
                 }},
                 new int[]{3},
                 new SeekNext("aab", "aac"),
@@ -151,8 +153,8 @@ public class SkipScanFilterTest extends TestCase {
                 new Finished("deg")));
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), false, Bytes.toBytes("def"), true)
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), false, Bytes.toBytes("def"), true)
                 }},
                 new int[]{3},
                 new SeekNext("aba", "abd"),
@@ -161,8 +163,8 @@ public class SkipScanFilterTest extends TestCase {
                 new Finished("deg")));
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), false, Bytes.toBytes("def"), false)
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), false, Bytes.toBytes("def"), false)
                 }},
                 new int[]{3},
                 new SeekNext("aba", "abd"),
@@ -170,8 +172,8 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
                 }},
                 new int[]{3},
                 new Include("def"),
@@ -181,14 +183,14 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("abc"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("abc"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
                 }},
                 new int[]{3,2},
                 new Include("abcAB"),
@@ -202,13 +204,13 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("abc"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("abc"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
                 }},
                 new int[]{2,3},
                 new Include("ABabc"),
@@ -223,10 +225,10 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
                 }},
                 new int[]{2,3},
                 new Include("POdef"),
@@ -234,24 +236,24 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
             foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PO"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PO"), true),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("def"), true, Bytes.toBytes("def"), true),
                 }},
                 new int[]{2,3},
                 new Include("POdef"))
         );
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AAA"), true, Bytes.toBytes("AAA"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AAA"), true, Bytes.toBytes("AAA"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
                 }},
                 new int[]{3,2},
                 new SeekNext("aaaAA", "abcAB"),
@@ -277,9 +279,9 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("dzz"), true, Bytes.toBytes("xyz"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("aaa"), true, Bytes.toBytes("aaa"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("dzz"), true, Bytes.toBytes("xyz"), false),
                 }},
                 new int[]{3},
                 new SeekNext("abb", "abc"),
@@ -289,17 +291,17 @@ public class SkipScanFilterTest extends TestCase {
         );
         testCases.addAll(
                 foreach(new KeyRange[][]{{
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("abc"), true, Bytes.toBytes("def"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("dzy"), false, Bytes.toBytes("xyz"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
                 },
                 {
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("100"), true, Bytes.toBytes("250"), false),
-                    PDataType.CHAR.getKeyRange(Bytes.toBytes("700"), false, Bytes.toBytes("901"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("100"), true, Bytes.toBytes("250"), false),
+                    PChar.INSTANCE.getKeyRange(Bytes.toBytes("700"), false, Bytes.toBytes("901"), false),
                 }},
                 new int[]{3,2,3},
                 new SeekNext("abcEB700", "abcEB701"),
@@ -310,17 +312,17 @@ public class SkipScanFilterTest extends TestCase {
 // TODO variable length columns
 //        testCases.addAll(
 //                foreach(new KeyRange[][]{{
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("apple"), true, Bytes.toBytes("lemon"), true),
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("pear"), false, Bytes.toBytes("yam"), false),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("apple"), true, Bytes.toBytes("lemon"), true),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("pear"), false, Bytes.toBytes("yam"), false),
 //                },
 //                {
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("AB"), true, Bytes.toBytes("AX"), true),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("EA"), false, Bytes.toBytes("EZ"), false),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("PO"), true, Bytes.toBytes("PP"), false),
 //                },
 //                {
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("100"), true, Bytes.toBytes("250"), false),
-//                    PDataType.CHAR.getKeyRange(Bytes.toBytes("700"), false, Bytes.toBytes("901"), false),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("100"), true, Bytes.toBytes("250"), false),
+//                    Char.INSTANCE.getKeyRange(Bytes.toBytes("700"), false, Bytes.toBytes("901"), false),
 //                }},
 //                new int[]{3,3})
 //        );

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
index 1c3e650..f02738d 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/iterate/AggregateResultScannerTest.java
@@ -45,7 +45,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
 import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.PLongColumn;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.SortOrder;
@@ -64,17 +64,17 @@ public class AggregateResultScannerTest extends BaseConnectionlessQueryTest {
     @Test
     public void testAggregatingMergeSort() throws Throwable {
         Tuple[] results1 = new Tuple[] {
-                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(1L))),
+                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))),
             };
         Tuple[] results2 = new Tuple[] {
-                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(1L)))
+                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L)))
             };
         Tuple[] results3 = new Tuple[] {
-                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(1L))),
-                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(1L))),
+                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))),
+                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))),
             };
         Tuple[] results4 = new Tuple[] {
-                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(1L))),
+                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(1L))),
             };
         final List<PeekingResultIterator>results = new ArrayList<PeekingResultIterator>(Arrays.asList(new PeekingResultIterator[] {
                 new MaterializedResultIterator(Arrays.asList(results1)), 
@@ -83,8 +83,8 @@ public class AggregateResultScannerTest extends BaseConnectionlessQueryTest {
                 new MaterializedResultIterator(Arrays.asList(results4))}));
 
         Tuple[] expectedResults = new Tuple[] {
-                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(3L))),
-                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PDataType.LONG.toBytes(2L))),
+                new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(3L))),
+                new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, PLong.INSTANCE.toBytes(2L))),
             };
 
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvBulkImportUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvBulkImportUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvBulkImportUtilTest.java
index 6bf3e47..4cb5732 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvBulkImportUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvBulkImportUtilTest.java
@@ -20,7 +20,7 @@ package org.apache.phoenix.mapreduce;
 import com.google.common.collect.ImmutableList;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.util.ColumnInfo;
 import org.junit.Test;
 
@@ -41,7 +41,7 @@ public class CsvBulkImportUtilTest {
         char escape = '\\';
 
         List<ColumnInfo> columnInfoList = ImmutableList.of(
-                new ColumnInfo("MYCOL", PDataType.INTEGER.getSqlType()));
+                new ColumnInfo("MYCOL", PInteger.INSTANCE.getSqlType()));
 
         CsvBulkImportUtil.initCsvImportJob(
                 conf, tableName, delimiter, quote, escape, null, columnInfoList, true);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapperTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapperTest.java b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapperTest.java
index 56a03e2..ee9d0e1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapperTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapperTest.java
@@ -23,7 +23,9 @@ import org.apache.commons.csv.CSVRecord;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PInteger;
+import org.apache.phoenix.schema.types.PIntegerArray;
+import org.apache.phoenix.schema.types.PUnsignedInt;
 import org.apache.phoenix.util.ColumnInfo;
 import org.junit.Test;
 
@@ -63,9 +65,9 @@ public class CsvToKeyValueMapperTest {
     @Test
     public void testBuildColumnInfoList() {
         List<ColumnInfo> columnInfoList = ImmutableList.of(
-                new ColumnInfo("idCol", PDataType.INTEGER.getSqlType()),
-                new ColumnInfo("unsignedIntCol", PDataType.UNSIGNED_INT.getSqlType()),
-                new ColumnInfo("stringArrayCol", PDataType.INTEGER_ARRAY.getSqlType()));
+                new ColumnInfo("idCol", PInteger.INSTANCE.getSqlType()),
+                new ColumnInfo("unsignedIntCol", PUnsignedInt.INSTANCE.getSqlType()),
+                new ColumnInfo("stringArrayCol", PIntegerArray.INSTANCE.getSqlType()));
 
         Configuration conf = new Configuration();
         CsvToKeyValueMapper.configureColumnInfoList(conf, columnInfoList);
@@ -78,10 +80,10 @@ public class CsvToKeyValueMapperTest {
     public void testBuildColumnInfoList_ContainingNulls() {
         // A null value in the column info list means "skip that column in the input"
         List<ColumnInfo> columnInfoListWithNull = Lists.newArrayList(
-                new ColumnInfo("idCol", PDataType.INTEGER.getSqlType()),
+                new ColumnInfo("idCol", PInteger.INSTANCE.getSqlType()),
                 null,
-                new ColumnInfo("unsignedIntCol", PDataType.UNSIGNED_INT.getSqlType()),
-                new ColumnInfo("stringArrayCol", PDataType.INTEGER_ARRAY.getSqlType()));
+                new ColumnInfo("unsignedIntCol", PUnsignedInt.INSTANCE.getSqlType()),
+                new ColumnInfo("stringArrayCol", PIntegerArray.INSTANCE.getSqlType()));
 
         Configuration conf = new Configuration();
         CsvToKeyValueMapper.configureColumnInfoList(conf, columnInfoListWithNull);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/ColumnInfoToStringEncoderDecoderTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/ColumnInfoToStringEncoderDecoderTest.java b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/ColumnInfoToStringEncoderDecoderTest.java
index 1004981..ddb5fb1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/ColumnInfoToStringEncoderDecoderTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/ColumnInfoToStringEncoderDecoderTest.java
@@ -23,8 +23,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.List;
 
-import org.apache.phoenix.mapreduce.util.ColumnInfoToStringEncoderDecoder;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.util.ColumnInfo;
 import org.junit.Test;
 
@@ -37,21 +36,21 @@ public class ColumnInfoToStringEncoderDecoderTest {
 
     @Test
     public void testEncode() {
-        final ColumnInfo columnInfo = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final ColumnInfo columnInfo = new ColumnInfo("col1", PVarchar.INSTANCE.getSqlType());
         final String encodedColumnInfo = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo));
         assertEquals(columnInfo.toString(),encodedColumnInfo);
     }
     
     @Test
     public void testDecode() {
-        final ColumnInfo columnInfo = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final ColumnInfo columnInfo = new ColumnInfo("col1", PVarchar.INSTANCE.getSqlType());
         final String encodedColumnInfo = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo));
         assertEquals(columnInfo.toString(),encodedColumnInfo);
     }
     
     @Test
     public void testEncodeDecodeWithNulls() {
-        final ColumnInfo columnInfo1 = new ColumnInfo("col1", PDataType.VARCHAR.getSqlType());
+        final ColumnInfo columnInfo1 = new ColumnInfo("col1", PVarchar.INSTANCE.getSqlType());
         final ColumnInfo columnInfo2 = null;
         final String columnInfoStr = ColumnInfoToStringEncoderDecoder.encode(Lists.newArrayList(columnInfo1,columnInfo2));
         final List<ColumnInfo> decodedColumnInfo = ColumnInfoToStringEncoderDecoder.decode(columnInfoStr);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java b/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
index c5957d6..4443c21 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
@@ -20,7 +20,8 @@ package org.apache.phoenix.parse;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.function.FunctionExpression;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.junit.Test;
 
@@ -77,7 +78,7 @@ public class BuiltInFunctionInfoTest {
 
         @Override
         public PDataType getDataType() {
-            return PDataType.VARCHAR;
+            return PVarchar.INSTANCE;
         }
 
         @Override
@@ -87,8 +88,8 @@ public class BuiltInFunctionInfoTest {
     }
 
     @BuiltInFunction(name="NO_DEFAULT_ARGS", args={
-            @Argument(allowedTypes={PDataType.VARCHAR}),
-            @Argument(allowedTypes={PDataType.VARCHAR})})
+            @Argument(allowedTypes={PVarchar.class}),
+            @Argument(allowedTypes={PVarchar.class})})
     static class NoDefaultArgsFunction extends BaseFunctionAdapter {
 
         public NoDefaultArgsFunction(List<Expression> ignoreChildren) {
@@ -98,9 +99,9 @@ public class BuiltInFunctionInfoTest {
     }
 
     @BuiltInFunction(name="WITH_ONE_DEFAULT_ARG", args={
-            @Argument(allowedTypes={PDataType.VARCHAR}),
-            @Argument(allowedTypes={PDataType.VARCHAR}),
-            @Argument(allowedTypes={PDataType.VARCHAR}, defaultValue = "'a'") })
+            @Argument(allowedTypes={PVarchar.class}),
+            @Argument(allowedTypes={PVarchar.class}),
+            @Argument(allowedTypes={PVarchar.class}, defaultValue = "'a'") })
     static class WithOneDefaultArg extends BaseFunctionAdapter {
 
         public WithOneDefaultArg(List<Expression> ignoreChildren) {
@@ -109,9 +110,9 @@ public class BuiltInFunctionInfoTest {
     }
 
     @BuiltInFunction(name="WITH_MULTIPLE_DEFAULT_ARGS", args={
-            @Argument(allowedTypes={PDataType.VARCHAR}),
-            @Argument(allowedTypes={PDataType.VARCHAR}, defaultValue = "'a'"),
-            @Argument(allowedTypes={PDataType.VARCHAR}, defaultValue = "'b'") })
+            @Argument(allowedTypes={PVarchar.class}),
+            @Argument(allowedTypes={PVarchar.class}, defaultValue = "'a'"),
+            @Argument(allowedTypes={PVarchar.class}, defaultValue = "'b'") })
     static class WithMultipleDefaultArgs extends BaseFunctionAdapter {
 
         public WithMultipleDefaultArgs(List<Expression> ignoreChildren) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
index 4a58540..2b2841b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionlessTest.java
@@ -40,7 +40,9 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.jdbc.PhoenixDriver;
-import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.types.PChar;
+import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PVarchar;
 import org.apache.phoenix.schema.SaltingUtil;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -60,9 +62,9 @@ public class ConnectionlessTest {
     private static final String name2 = "Simon";
     private static final Date now = new Date(System.currentTimeMillis());
     private static final byte[] unsaltedRowKey1 = ByteUtil.concat(
-            PDataType.CHAR.toBytes(orgId),PDataType.CHAR.toBytes(keyPrefix1),PDataType.CHAR.toBytes(entityHistoryId1));
+            PChar.INSTANCE.toBytes(orgId), PChar.INSTANCE.toBytes(keyPrefix1), PChar.INSTANCE.toBytes(entityHistoryId1));
     private static final byte[] unsaltedRowKey2 = ByteUtil.concat(
-            PDataType.CHAR.toBytes(orgId),PDataType.CHAR.toBytes(keyPrefix2),PDataType.CHAR.toBytes(entityHistoryId2));
+            PChar.INSTANCE.toBytes(orgId), PChar.INSTANCE.toBytes(keyPrefix2), PChar.INSTANCE.toBytes(entityHistoryId2));
     private static final byte[] saltedRowKey1 = ByteUtil.concat(
             new byte[] {SaltingUtil.getSaltingByte(unsaltedRowKey1, 0, unsaltedRowKey1.length, saltBuckets)},
             unsaltedRowKey1);
@@ -142,15 +144,15 @@ public class ConnectionlessTest {
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey1, kv.getRow());        
-        assertEquals(name1, PDataType.VARCHAR.toObject(kv.getValue()));
+        assertEquals(name1, PVarchar.INSTANCE.toObject(kv.getValue()));
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey1, kv.getRow());        
-        assertEquals(now, PDataType.DATE.toObject(kv.getValue()));
+        assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey1, kv.getRow());        
-        assertNull(PDataType.VARCHAR.toObject(kv.getValue()));
+        assertNull(PVarchar.INSTANCE.toObject(kv.getValue()));
     }
 
     private static void assertRow2(Iterator<KeyValue> iterator, byte[] expectedRowKey2) {
@@ -158,15 +160,15 @@ public class ConnectionlessTest {
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey2, kv.getRow());        
-        assertEquals(name2, PDataType.VARCHAR.toObject(kv.getValue()));
+        assertEquals(name2, PVarchar.INSTANCE.toObject(kv.getValue()));
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey2, kv.getRow());        
-        assertEquals(now, PDataType.DATE.toObject(kv.getValue()));
+        assertEquals(now, PDate.INSTANCE.toObject(kv.getValue()));
         assertTrue(iterator.hasNext());
         kv = iterator.next();
         assertArrayEquals(expectedRowKey2, kv.getRow());        
-        assertNull(PDataType.VARCHAR.toObject(kv.getValue()));
+        assertNull(PVarchar.INSTANCE.toObject(kv.getValue()));
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeCoalesceTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeCoalesceTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeCoalesceTest.java
index 7fe7319..bc0636e 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeCoalesceTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeCoalesceTest.java
@@ -27,13 +27,12 @@ import java.util.*;
 
 import junit.framework.TestCase;
 
+import org.apache.phoenix.schema.types.PChar;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import org.apache.phoenix.schema.PDataType;
-
 @RunWith(Parameterized.class)
 public class KeyRangeCoalesceTest extends TestCase {
     private static final Random RANDOM = new Random(1);
@@ -53,64 +52,64 @@ public class KeyRangeCoalesceTest extends TestCase {
                 input(
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("E"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("E"), true)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("Z"), true)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("E"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), true)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("E"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("E"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), true)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("D"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), false),
-                        PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
+                        PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("D"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), false),
+                        PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("Z"), true)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("A"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("A"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("A"), true),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("A"), true),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("B"), false),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), false, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("B"), false),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), false, toBytes("Z"), false)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("B"), false),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), false, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("B"), false),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), false, toBytes("Z"), false)
                 )},
                 {expect(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("Z"), false)
                 ),
                 input(
-                        PDataType.CHAR.getKeyRange(toBytes("A"), true, toBytes("B"), false),
-                        PDataType.CHAR.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
+                        PChar.INSTANCE.getKeyRange(toBytes("A"), true, toBytes("B"), false),
+                        PChar.INSTANCE.getKeyRange(toBytes("B"), true, toBytes("Z"), false)
                 )},
                 {expect(
                     EVERYTHING_RANGE

http://git-wip-us.apache.org/repos/asf/phoenix/blob/04ef859b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
index f34b956..98c10a8 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/KeyRangeIntersectTest.java
@@ -27,13 +27,12 @@ import java.util.Collection;
 
 import junit.framework.TestCase;
 
+import org.apache.phoenix.schema.types.PChar;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import org.apache.phoenix.schema.PDataType;
-
 @RunWith(Parameterized.class)
 public class KeyRangeIntersectTest extends TestCase {
     private final KeyRange a, b, intersection;
@@ -48,29 +47,29 @@ public class KeyRangeIntersectTest extends TestCase {
     public static Collection<?> data() {
         return Arrays.asList(new Object[][] {
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), true, toBytes("E"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), true, toBytes("E"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), false, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), false, toBytes("E"), true)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), false, toBytes("E"), true)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), false),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), false, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("D"), false, toBytes("E"), false)
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("D"), false, toBytes("E"), false)
                 },
                 {
-                    PDataType.CHAR.getKeyRange(toBytes("C"), true, toBytes("E"), false),
-                    PDataType.CHAR.getKeyRange(toBytes("E"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("C"), true, toBytes("E"), false),
+                    PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
                     EMPTY_RANGE
                 },
                 {
                     EVERYTHING_RANGE,
-                    PDataType.CHAR.getKeyRange(toBytes("E"), false, toBytes("F"), true),
-                    PDataType.CHAR.getKeyRange(toBytes("E"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
                 },
                 {
                     EVERYTHING_RANGE,
@@ -84,7 +83,7 @@ public class KeyRangeIntersectTest extends TestCase {
                 },
                 {
                     EMPTY_RANGE,
-                    PDataType.CHAR.getKeyRange(toBytes("E"), false, toBytes("F"), true),
+                    PChar.INSTANCE.getKeyRange(toBytes("E"), false, toBytes("F"), true),
                     EMPTY_RANGE
                 },
         });