phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [3/5] phoenix git commit: PHOENIX-1646 Views and functional index expressions may lose information when stringified
Date Tue, 10 Feb 2015 16:13:03 GMT
http://git-wip-us.apache.org/repos/asf/phoenix/blob/92298f8d/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 ff4ad8b..28942ac 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
@@ -79,12 +79,18 @@ import com.google.common.collect.ImmutableList;
 
 public class WhereCompilerTest extends BaseConnectionlessQueryTest {
 
+    private PhoenixPreparedStatement newPreparedStatement(PhoenixConnection pconn, String query) throws SQLException {
+        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        assertRoundtrip(query);
+        return pstmt;
+    }
+    
     @Test
     public void testSingleEqualFilter() throws SQLException {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -101,7 +107,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
         pconn.createStatement().execute("CREATE TABLE t (k bigint not null primary key, v varchar) SALT_BUCKETS=20");
         String query = "select * from t where k=" + 1;
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -122,7 +128,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
         pconn.createStatement().execute("CREATE TABLE t (k varchar primary key, v varchar) SALT_BUCKETS=20");
         String query = "select * from t where k='a'";
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -143,7 +149,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
         pconn.createStatement().execute("CREATE TABLE t (k bigint not null primary key, v varchar) SALT_BUCKETS=20");
         String query = "select * from t where k in (1,3)";
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -195,7 +201,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_string=b_string";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -212,7 +218,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and substr(entity_id,null) = 'foo'";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -229,7 +235,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         List<Object> binds = Arrays.<Object>asList(tenantId);
         
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
@@ -253,7 +259,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and 0 >= a_integer";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         
@@ -272,7 +278,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String dateStr = "2012-01-01 12:00:00";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_date >= to_date('" + dateStr + "')";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -291,7 +297,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and x_decimal >= " + toNumberClause;
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -348,7 +354,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = "select * from atable where substr(entity_id,1,3)=?";
         List<Object> binds = Arrays.<Object>asList(keyPrefix);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
@@ -374,7 +380,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = "select * from atable where entity_id=?";
         List<Object> binds = Arrays.<Object>asList(keyPrefix);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
@@ -390,7 +396,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = "select * from atable where organization_id=? AND entity_id=?";
         List<Object> binds = Arrays.<Object>asList(tenantId,keyPrefix);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
@@ -405,7 +411,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = "select * from atable where substr(entity_id,1,3)=?";
         List<Object> binds = Arrays.<Object>asList(keyPrefix);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         // Degenerate b/c "foobar" is more than 3 characters
@@ -420,7 +426,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         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);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         // Degenerate b/c a_string length is 100
@@ -435,7 +441,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = "select * from atable where organization_id=? and (substr(entity_id,1,3)=? or a_integer=?)";
         List<Object> binds = Arrays.<Object>asList(tenantId, keyPrefix, aInt);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         bindParams(pstmt, binds);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
@@ -464,7 +470,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer > 'foo'";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
 
         try {
             pstmt.optimizeQuery();
@@ -479,7 +485,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0 and 2=3";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         assertDegenerate(plan.getContext());
     }
@@ -489,7 +495,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and 2=3";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         assertDegenerate(plan.getContext());
     }
@@ -499,7 +505,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and 2<=2";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         assertNull(scan.getFilter());
@@ -514,7 +520,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0 and 2<3";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -536,7 +542,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and (a_integer=0 or 3!=3)";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -557,7 +563,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and (a_integer=0 or 3>2)";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -573,7 +579,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_string IN ('a','b')";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
@@ -598,7 +604,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s','%s')",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId1);
@@ -625,7 +631,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id='%s' OR organization_id='%s' OR organization_id='%s'",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
 
@@ -653,7 +659,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id='%s' AND entity_id IN ('%s','%s')",
                 ATABLE_NAME, tenantId, entityId1, entityId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId + entityId1);
@@ -683,7 +689,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id>='%s' AND entity_id<='%s'",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId1, entityId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -712,7 +718,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id='%s'",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -735,7 +741,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id='%s'",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId1), PVarchar.INSTANCE.toBytes(entityId));
@@ -765,7 +771,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s') AND entity_id IN ('%s', '%s')",
                 ATABLE_NAME, tenantId1, tenantId2, entityId1, entityId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
 
@@ -789,7 +795,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id > '%s' AND organization_id < '%s'",
                 ATABLE_NAME, tenantId1, tenantId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
 
@@ -810,7 +816,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id IN ('%s', '%s')",
                 ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId1, entityId2);
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId1), PVarchar.INSTANCE.toBytes(entityId1));
@@ -825,7 +831,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer between 0 and 10";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -847,7 +853,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         String tenantId = "000000000000001";
         String query = "select * from atable where organization_id='" + tenantId + "' and a_integer not between 0 and 10";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -875,7 +881,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         
         String query = "select * from tenant_filter_test where a_integer=0 and a_string='foo'";
         PhoenixConnection pconn = DriverManager.getConnection(url, PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -907,7 +913,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
         
         String query = "select * from tenant_filter_test where a_integer=0 and a_string='foo'";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(tenantId), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         Filter filter = scan.getFilter();
@@ -934,7 +940,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
     public void testScanCaching_Default() throws SQLException {
         String query = "select * from atable where a_integer=0";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         QueryPlan plan = pstmt.optimizeQuery();
         Scan scan = plan.getContext().getScan();
         assertEquals(QueryServicesOptions.DEFAULT_SCAN_CACHE_SIZE, pstmt.getFetchSize());
@@ -945,7 +951,7 @@ public class WhereCompilerTest extends BaseConnectionlessQueryTest {
     public void testScanCaching_CustomFetchSizeOnStatement() throws SQLException {
         String query = "select * from atable where a_integer=0";
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
-        PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
         final int FETCH_SIZE = 25;
         pstmt.setFetchSize(FETCH_SIZE);
         QueryPlan plan = pstmt.optimizeQuery();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/92298f8d/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 ad8e5f5..ddbacb7 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,8 @@ 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.types.PChar;
 import org.apache.phoenix.schema.types.PDate;
 import org.apache.phoenix.schema.types.PUnsignedLong;
 import org.apache.phoenix.schema.types.PVarchar;
@@ -86,6 +86,7 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
     private static StatementContext compileStatement(String query, List<Object> binds, Integer limit) throws SQLException {
         PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
         PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
+        assertRoundtrip(query);
         TestUtil.bindParams(pstmt, binds);
         QueryPlan plan = pstmt.compileQuery();
         assertEquals(limit, plan.getLimit());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/92298f8d/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
index 866365a..bf599ae 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.io.StringReader;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
@@ -29,24 +30,43 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
 import org.apache.phoenix.schema.SortOrder;
 import org.junit.Test;
 
 
 public class QueryParserTest {
+    private void parseQuery(String sql) throws IOException, SQLException {
+        SQLParser parser = new SQLParser(new StringReader(sql));
+        BindableStatement stmt = null;
+        stmt = parser.parseStatement();
+        if (stmt.getOperation() != Operation.QUERY) {
+            return;
+        }
+        String newSQL = stmt.toString();
+        SQLParser newParser = new SQLParser(new StringReader(newSQL));
+        BindableStatement newStmt = null;
+        try {
+            newStmt = newParser.parseStatement();
+        } catch (SQLException e) {
+            fail("Unable to parse new:\n" + newSQL);
+        }
+        assertEquals("Expected equality:\n" + sql + "\n" + newSQL, stmt, newStmt);
+    }
+    
     @Test
     public void testParsePreQuery0() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select a from b\n" +
             "where ((ind.name = 'X')" +
             "and rownum <= (1000 + 1000))\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParsePreQuery1() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ count(1) from core.search_name_lookup ind\n" +
             "where( (ind.name = 'X'\n" +
             "and rownum <= 1 + 2)\n" +
@@ -54,12 +74,12 @@ public class QueryParserTest {
             "and (ind.key_prefix = '00T')\n" +
             "and (ind.name_type = 't'))"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParsePreQuery2() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ count(1) from core.custom_index_value ind\n" + 
             "where (ind.string_value in ('a', 'b', 'c', 'd'))\n" + 
             "and rownum <= ( 3 + 1 )\n" + 
@@ -68,12 +88,12 @@ public class QueryParserTest {
             "and (ind.deleted = '0')\n" + 
             "and (ind.index_num = 1)"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParsePreQuery3() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ count(1) from core.custom_index_value ind\n" + 
             "where (ind.number_value > 3)\n" + 
             "and rownum <= 1000\n" + 
@@ -82,54 +102,54 @@ public class QueryParserTest {
             "and (ind.deleted = '0'))\n" + 
             "and (ind.index_num = 2)"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParsePreQuery4() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*+ index(t iecustom_entity_data_created) */ /*gatherSlowStats*/ count(1) from core.custom_entity_data t\n" + 
             "where (t.created_date > to_date('01/01/2001'))\n" + 
             "and rownum <= 4500\n" + 
             "and (t.organization_id = '000000000000000')\n" + 
             "and (t.key_prefix = '001')"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testCountDistinctQuery() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
                 "select count(distinct foo) from core.custom_entity_data t\n"
                         + "where (t.created_date > to_date('01/01/2001'))\n"
                         + "and (t.organization_id = '000000000000000')\n"
                         + "and (t.key_prefix = '001')\n" + "limit 4500"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testIsNullQuery() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select count(foo) from core.custom_entity_data t\n" + 
             "where (t.created_date is null)\n" + 
             "and (t.organization_id is not null)\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testAsInColumnAlias() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select count(foo) AS c from core.custom_entity_data t\n" + 
             "where (t.created_date is null)\n" + 
             "and (t.organization_id is not null)\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParseJoin1() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*SOQL*/ \"Id\"\n" + 
             "from (select /*+ ordered index(cft) */\n" + 
             "cft.val188 \"Marketing_Offer_Code__c\",\n" + 
@@ -143,12 +163,12 @@ public class QueryParserTest {
             "and (t.account_id != '000000000000000'))\n" + 
             "where (\"Marketing_Offer_Code__c\" = 'FSCR')"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParseJoin2() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*rptacctlist 00O40000002C3of*/ \"00N40000001M8VK\",\n" + 
             "\"00N40000001M8VK.ID\",\n" + 
             "\"00N30000000r0K2\",\n" + 
@@ -175,12 +195,12 @@ public class QueryParserTest {
             "AND (\"00N40000001M8VK\" is null or \"00N40000001M8VK\" in ('BRIAN IRWIN', 'BRIAN MILLER', 'COLLEEN HORNYAK', 'ERNIE ZAVORAL JR', 'JAMIE TRIMBUR', 'JOE ANTESBERGER', 'MICHAEL HYTLA', 'NATHAN DELSIGNORE', 'SANJAY GANDHI', 'TOM BASHIOUM'))\n" + 
             "AND (\"LAST_UPDATE\" >= to_date('2009-08-01 07:00:00'))"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
     
     @Test
     public void testNegative1() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ count(1) core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -189,7 +209,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't')"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode());
@@ -198,7 +218,7 @@ public class QueryParserTest {
 
     @Test
     public void testNegative2() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "seelect /*gatherSlowStats*/ count(1) from core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -207,7 +227,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't')"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 601 (42P00): Syntax error. Encountered \"seelect\" at line 1, column 1."));
@@ -216,7 +236,7 @@ public class QueryParserTest {
 
     @Test
     public void testNegative3() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ count(1) from core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -225,7 +245,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't'))"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 603 (42P00): Syntax error. Unexpected input. Expecting \"EOF\", got \")\" at line 6, column 26."));
@@ -234,7 +254,7 @@ public class QueryParserTest {
 
     @Test
     public void testNegativeCountDistinct() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ max( distinct 1) from core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -243,7 +263,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't')"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLFeatureNotSupportedException e) {
             // expected
@@ -252,7 +272,7 @@ public class QueryParserTest {
 
     @Test
     public void testNegativeCountStar() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ max(*) from core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -261,7 +281,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't')"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 601 (42P00): Syntax error. Encountered \"*\" at line 1, column 32."));
@@ -270,7 +290,7 @@ public class QueryParserTest {
 
     @Test
     public void testUnknownFunction() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ bogus_function(ind.key_prefix) from core.search_name_lookup ind\n" +
             "where (ind.name = 'X')\n" +
             "and rownum <= 2000\n" +
@@ -279,7 +299,7 @@ public class QueryParserTest {
             "and (ind.name_type = 't')"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.UNKNOWN_FUNCTION.getErrorCode(), e.getErrorCode());
@@ -288,12 +308,12 @@ public class QueryParserTest {
 
     @Test
     public void testNegativeNonBooleanWhere() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select /*gatherSlowStats*/ max( distinct 1) from core.search_name_lookup ind\n" +
             "where 1"
             ));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLFeatureNotSupportedException e) {
             // expected
@@ -302,48 +322,48 @@ public class QueryParserTest {
     
     @Test
     public void testCommentQuery() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select a from b -- here we come\n" +
             "where ((ind.name = 'X') // to save the day\n" +
             "and rownum /* won't run */ <= (1000 + 1000))\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testQuoteEscapeQuery() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select a from b\n" +
             "where ind.name = 'X''Y'\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testSubtractionInSelect() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
             "select a, 3-1-2, -4- -1-1 from b\n" +
             "where d = c - 1\n"
             ));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testParsingStatementWithMispellToken() throws Exception {
         try {
-            SQLParser parser = new SQLParser(new StringReader(
+            String sql = ((
                     "selects a from b\n" +
                     "where e = d\n"));
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught exception.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 601 (42P00): Syntax error. Encountered \"selects\" at line 1, column 1."));
         }
         try {
-            SQLParser parser = new SQLParser(new StringReader(
+            String sql = ((
                     "select a froms b\n" +
                     "where e = d\n"));
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught exception.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 602 (42P00): Syntax error. Missing \"FROM\" at line 1, column 16."));
@@ -353,19 +373,19 @@ public class QueryParserTest {
     @Test
     public void testParsingStatementWithExtraToken() throws Exception {
         try {
-            SQLParser parser = new SQLParser(new StringReader(
+            String sql = ((
                     "select a,, from b\n" +
                     "where e = d\n"));
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught exception.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 601 (42P00): Syntax error. Encountered \",\" at line 1, column 10."));
         }
         try {
-            SQLParser parser = new SQLParser(new StringReader(
+            String sql = ((
                     "select a from from b\n" +
                     "where e = d\n"));
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught exception.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 601 (42P00): Syntax error. Encountered \"from\" at line 1, column 15."));
@@ -375,10 +395,10 @@ public class QueryParserTest {
     @Test
     public void testParsingStatementWithMissingToken() throws Exception {
         try {
-            SQLParser parser = new SQLParser(new StringReader(
+            String sql = ((
                     "select a b\n" +
                     "where e = d\n"));
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught exception.");
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode());
@@ -389,7 +409,7 @@ public class QueryParserTest {
     public void testParseCreateTableInlinePrimaryKeyWithOrder() throws Exception {
     	for (String order : new String[]{"asc", "desc"}) {
             String s = "create table core.entity_history_archive (id char(15) primary key ${o})".replace("${o}", order);
-    		CreateTableStatement stmt = (CreateTableStatement)new SQLParser(new StringReader(s)).parseStatement();
+    		CreateTableStatement stmt = (CreateTableStatement)new SQLParser((s)).parseStatement();
     		List<ColumnDef> columnDefs = stmt.getColumnDefs();
     		assertEquals(1, columnDefs.size());
     		assertEquals(SortOrder.fromDDLValue(order), columnDefs.iterator().next().getSortOrder()); 
@@ -401,7 +421,7 @@ public class QueryParserTest {
     	for (String order : new String[]{"asc", "desc"}) {
     		String stmt = "create table core.entity_history_archive (id varchar(20) ${o})".replace("${o}", order);
     		try {
-    			new SQLParser(new StringReader(stmt)).parseStatement();
+    			new SQLParser((stmt)).parseStatement();
     			fail("Expected parse exception to be thrown");
     		} catch (SQLException e) {
     			String errorMsg = "ERROR 603 (42P00): Syntax error. Unexpected input. Expecting \"RPAREN\", got \"${o}\"".replace("${o}", order);
@@ -414,7 +434,7 @@ public class QueryParserTest {
     public void testParseCreateTablePrimaryKeyConstraintWithOrder() throws Exception {
     	for (String order : new String[]{"asc", "desc"}) {
     		String s = "create table core.entity_history_archive (id CHAR(15), name VARCHAR(150), constraint pk primary key (id ${o}, name ${o}))".replace("${o}", order);
-    		CreateTableStatement stmt = (CreateTableStatement)new SQLParser(new StringReader(s)).parseStatement();
+    		CreateTableStatement stmt = (CreateTableStatement)new SQLParser((s)).parseStatement();
     		PrimaryKeyConstraint pkConstraint = stmt.getPrimaryKeyConstraint();
     		List<Pair<ColumnName,SortOrder>> columns = pkConstraint.getColumnNames();
     		assertEquals(2, columns.size());
@@ -429,7 +449,7 @@ public class QueryParserTest {
         for (String leadingComma : new String[]{",", ""}) {
             String s = "create table core.entity_history_archive (id CHAR(15), name VARCHAR(150)${o} constraint pk primary key (id))".replace("${o}", leadingComma);
 
-            CreateTableStatement stmt = (CreateTableStatement)new SQLParser(new StringReader(s)).parseStatement();
+            CreateTableStatement stmt = (CreateTableStatement)new SQLParser((s)).parseStatement();
 
             assertEquals(2, stmt.getColumnDefs().size());
             assertNotNull(stmt.getPrimaryKeyConstraint());
@@ -438,11 +458,11 @@ public class QueryParserTest {
 
     @Test
     public void testInvalidTrailingCommaOnCreateTable() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "create table foo (c1 varchar primary key, c2 varchar,)"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode());
@@ -451,42 +471,42 @@ public class QueryParserTest {
 
     @Test
 	public void testCreateSequence() throws Exception {
-		SQLParser parser = new SQLParser(new StringReader(
+		String sql = ((
 				"create sequence foo.bar\n" + 
 						"start with 0\n"	+ 
 						"increment by 1\n"));
-		parser.parseStatement();
+		parseQuery(sql);
 	}
 	
 	@Test
 	public void testNextValueForSelect() throws Exception {
-		SQLParser parser = new SQLParser(new StringReader(
+		String sql = ((
 				"select next value for foo.bar \n" + 
 						"from core.custom_entity_data\n"));						
-		parser.parseStatement();
+		parseQuery(sql);
 	}
 	
 	@Test
     public void testNextValueForWhere() throws Exception {
-        SQLParser parser = new SQLParser(new StringReader(
+        String sql = ((
                 "upsert into core.custom_entity_data\n" + 
                         "select next value for foo.bar from core.custom_entity_data\n"));                    
-        parser.parseStatement();
+        parseQuery(sql);
     }
 	
     public void testBadCharDef() throws Exception {
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col CHAR(0))");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad char definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 208 (22003): CHAR or VARCHAR must have a positive length. columnName=COL"));
         }
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col CHAR)");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad char definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 207 (22003): Missing length for CHAR. columnName=COL"));
@@ -496,9 +516,9 @@ public class QueryParserTest {
     @Test
     public void testBadVarcharDef() throws Exception {
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col VARCHAR(0))");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad varchar definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 208 (22003): CHAR or VARCHAR must have a positive length. columnName=COL"));
@@ -508,17 +528,17 @@ public class QueryParserTest {
     @Test
     public void testBadDecimalDef() throws Exception {
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadDecimalDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadDecimalDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col DECIMAL(0, 5))");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad decimal definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 209 (22003): Decimal precision outside of range. Should be within 1 and 38. columnName=COL"));
         }
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadDecimalDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadDecimalDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col DECIMAL(40, 5))");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad decimal definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 209 (22003): Decimal precision outside of range. Should be within 1 and 38. columnName=COL"));
@@ -528,17 +548,17 @@ public class QueryParserTest {
     @Test
     public void testBadBinaryDef() throws Exception {
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadBinaryDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadBinaryDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col BINARY(0))");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad binary definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 211 (22003): BINARY must have a positive length. columnName=COL"));
         }
         try {
-            SQLParser parser = new SQLParser("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
+            String sql = ("CREATE TABLE IF NOT EXISTS testBadVarcharDef" + 
                     "  (pk VARCHAR NOT NULL PRIMARY KEY, col BINARY)");
-            parser.parseStatement();
+            parseQuery(sql);
             fail("Should have caught bad char definition.");
         } catch (SQLException e) {
             assertTrue(e.getMessage(), e.getMessage().contains("ERROR 210 (22003): Missing length for BINARY. columnName=COL"));
@@ -547,67 +567,67 @@ public class QueryParserTest {
 
     @Test
     public void testPercentileQuery1() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY salary DESC) from core.custom_index_value ind"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testPercentileQuery2() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY mark ASC) from core.custom_index_value ind"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
     
     @Test
     public void testRowValueConstructorQuery() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select a_integer FROM aTable where (x_integer, y_integer) > (3, 4)"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testSingleTopLevelNot() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where not c = 5"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testTopLevelNot() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where not c"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testRVCInList() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where k in ( (1,2), (3,4) )"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testInList() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where k in ( 1,2 )"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testInvalidSelectStar() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select *,k from t where k in ( 1,2 )"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode());
@@ -616,11 +636,11 @@ public class QueryParserTest {
 
     @Test
     public void testInvalidUpsertSelectHint() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "upsert into t select /*+ NO_INDEX */ k from t where k in ( 1,2 )"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.PARSER_ERROR.getErrorCode(), e.getErrorCode());
@@ -629,11 +649,11 @@ public class QueryParserTest {
 
     @Test
     public void testTableNameStartsWithUnderscore() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select* from _t where k in ( 1,2 )"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.PARSER_ERROR.getErrorCode(), e.getErrorCode());
@@ -642,16 +662,16 @@ public class QueryParserTest {
 
     @Test
     public void testValidUpsertSelectHint() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "upsert /*+ NO_INDEX */ into t select k from t where k in ( 1,2 )"));
-            parser.parseStatement();
+            parseQuery(sql);
     }
 
     @Test
     public void testHavingWithNot() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select\n" + 
                         "\"WEB_STAT_ALIAS\".\"DOMAIN\" as \"c0\"\n" + 
                         "from \"WEB_STAT\" \"WEB_STAT_ALIAS\"\n" + 
@@ -668,73 +688,73 @@ public class QueryParserTest {
                         ")\n" + 
                         "order by CASE WHEN \"WEB_STAT_ALIAS\".\"DOMAIN\" IS NULL THEN 1 ELSE 0 END,\n" + 
                         "\"WEB_STAT_ALIAS\".\"DOMAIN\" ASC"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testToDateInList() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader("select * from date_test where d in (to_date('2013-11-04 09:12:00'))"));
-        parser.parseStatement();
+        String sql = (
+                ("select * from date_test where d in (to_date('2013-11-04 09:12:00'))"));
+        parseQuery(sql);
     }
     
     @Test
     public void testDateLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = DATE '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testTimeLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = TIME '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
 
     @Test
     public void testTimestampLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = TIMESTAMP '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
     
     @Test
     public void testUnsignedDateLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = UNSIGNED_DATE '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
     @Test
     public void testUnsignedTimeLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = UNSIGNED_TIME '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
 
 
     @Test
     public void testUnsignedTimestampLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = UNSIGNED_TIMESTAMP '2013-11-04 09:12:00'"));
-        parser.parseStatement();
+        parseQuery(sql);
     }
     
     @Test
     public void testUnknownLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = FOO '2013-11-04 09:12:00'"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), e.getErrorCode());
@@ -743,14 +763,32 @@ public class QueryParserTest {
     
     @Test
     public void testUnsupportedLiteral() throws Exception {
-        SQLParser parser = new SQLParser(
-                new StringReader(
+        String sql = (
+                (
                         "select * from t where d = DECIMAL '2013-11-04 09:12:00'"));
         try {
-            parser.parseStatement();
+            parseQuery(sql);
             fail();
         } catch (SQLException e) {
             assertEquals(SQLExceptionCode.TYPE_MISMATCH.getErrorCode(), e.getErrorCode());
         }
     }
+    
+    @Test
+    public void testAnyElementExpression1() throws Exception {
+        String sql = "select * from t where 'a' = ANY(a)";
+        parseQuery(sql);
+    }
+
+    @Test
+    public void testAnyElementExpression2() throws Exception {
+        String sql = "select * from t where 'a' <= ANY(a-b+1)";
+        parseQuery(sql);
+    }
+
+    @Test
+    public void testAllElementExpression() throws Exception {
+        String sql = "select * from t where 'a' <= ALL(a-b+1)";
+        parseQuery(sql);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/92298f8d/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
index 8f17a7c..abaaeb5 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseConnectionlessQueryTest.java
@@ -32,17 +32,23 @@ import static org.apache.phoenix.util.TestUtil.PTSDB3_NAME;
 import static org.apache.phoenix.util.TestUtil.PTSDB_NAME;
 import static org.apache.phoenix.util.TestUtil.TABLE_WITH_ARRAY;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.DriverManager;
+import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
+import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
 import org.apache.phoenix.jdbc.PhoenixTestDriver;
+import org.apache.phoenix.parse.BindableStatement;
+import org.apache.phoenix.parse.SQLParser;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
@@ -146,4 +152,21 @@ public class BaseConnectionlessQueryTest extends BaseTest {
         }
     }
 
+    protected static void assertRoundtrip(String sql) throws SQLException {
+        SQLParser parser = new SQLParser(sql);
+        BindableStatement stmt = null;
+        stmt = parser.parseStatement();
+        if (stmt.getOperation() != Operation.QUERY) {
+            return;
+        }
+        String newSQL = stmt.toString();
+        SQLParser newParser = new SQLParser(newSQL);
+        BindableStatement newStmt = null;
+        try {
+            newStmt = newParser.parseStatement();
+        } catch (SQLException e) {
+            fail("Unable to parse new:\n" + newSQL);
+        }
+        assertEquals("Expected equality:\n" + sql + "\n" + newSQL, stmt, newStmt);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/92298f8d/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
index 321567c..90730bc 100644
--- 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
@@ -1746,4 +1746,11 @@ public class PDataTypeTest {
              coercibleToMap.toString());
     }
     
+    @Test
+    public void testIntVersusLong() {
+        long l = -1L;
+        int i = -1;
+        assertTrue(PLong.INSTANCE.compareTo(l, i, PInteger.INSTANCE)==0);
+        assertTrue(PInteger.INSTANCE.compareTo(i, l, PLong.INSTANCE)==0);
+    }
 }


Mime
View raw message