phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeffr...@apache.org
Subject [22/50] [abbrv] git commit: Phoneix-82
Date Wed, 05 Mar 2014 22:55:08 GMT
Phoneix-82


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

Branch: refs/heads/4.0
Commit: 9f1ce1e684eb600cabec00f986c6ee1eded6b800
Parents: 3ed0f61
Author: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Authored: Tue Mar 4 15:59:01 2014 +0530
Committer: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Committed: Tue Mar 4 15:59:01 2014 +0530

----------------------------------------------------------------------
 .../phoenix/exception/SQLExceptionCode.java     |   2 +-
 .../expression/ComparisonExpression.java        |  11 +-
 .../apache/phoenix/schema/MetaDataClient.java   |  13 +-
 .../apache/phoenix/schema/PArrayDataType.java   |   2 +-
 .../phoenix/compile/QueryCompilerTest.java      |  27 ---
 .../org/apache/phoenix/end2end/ArrayTest.java   | 175 +++++++++++++++++++
 6 files changed, 180 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/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 814f45a..42a6c3e 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
@@ -155,7 +155,7 @@ public enum SQLExceptionCode {
     // Primary/row key related exceptions.
     PRIMARY_KEY_WITH_FAMILY_NAME(1003, "42J01", "Primary key columns must not have a family
name."),
     PRIMARY_KEY_OUT_OF_ORDER(1004, "42J02", "Order of columns in primary key constraint must
match the order in which they're declared."),
-    VARBINARY_IN_ROW_KEY(1005, "42J03", "The VARBINARY type can only be used as the last
part of a multi-part row key."),
+    VARBINARY_IN_ROW_KEY(1005, "42J03", "The VARBINARY/ARRAY type can only be used as the
last part of a multi-part row key."),
     NOT_NULLABLE_COLUMN_IN_ROW_KEY(1006, "42J04", "Only nullable columns may be added to
a multi-part row key."),
     VARBINARY_LAST_PK(1015, "42J04", "Cannot add column to table when the last PK column
is of type VARBINARY."),
     NULLABLE_FIXED_WIDTH_LAST_PK(1023, "42J04", "Cannot add column to table when the last
PK column is nullable and fixed width."),

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/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 3849f54..b7e3976 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
@@ -29,11 +29,9 @@ import java.util.List;
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 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.SortOrder;
 import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TypeMismatchException;
 import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.util.ByteUtil;
@@ -112,13 +110,6 @@ public class ComparisonExpression extends BaseCompoundExpression {
         Expression rhsExpr = children.get(1);
         PDataType lhsExprDataType = lhsExpr.getDataType();
         PDataType rhsExprDataType = rhsExpr.getDataType();
-        // We don't yet support comparison between entire arrays
-        if ( ( (lhsExprDataType != null && lhsExprDataType.isArrayType()) || 
-               (rhsExprDataType != null && rhsExprDataType.isArrayType()) ) &&
-             ( op != CompareOp.EQUAL && op != CompareOp.NOT_EQUAL ) ) {
-            throw new SQLExceptionInfo.Builder(SQLExceptionCode.NON_EQUALITY_ARRAY_COMPARISON)
-            .setMessage(ComparisonExpression.toString(op, children)).build().buildException();
-        }
         
         if (lhsExpr instanceof RowValueConstructorExpression || rhsExpr instanceof RowValueConstructorExpression)
{
             if (op == CompareOp.EQUAL || op == CompareOp.NOT_EQUAL) {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/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 0f8eb18..59fd613 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
@@ -946,14 +946,6 @@ public class MetaDataClient {
                             .setColumnName(colDef.getColumnDefName().getColumnName())
                             .build().buildException();
                     }
-                    // disallow array type usage in primary key constraint
-                    if (colDef.isArray()) {
-                        throw new SQLExceptionInfo.Builder(SQLExceptionCode.ARRAY_NOT_ALLOWED_IN_PRIMARY_KEY)
-                        .setSchemaName(schemaName)
-                        .setTableName(tableName)
-                        .setColumnName(colDef.getColumnDefName().getColumnName())
-                        .build().buildException();
-                    }
                     if (!pkColumns.add(column)) {
                         throw new ColumnAlreadyExistsException(schemaName, tableName, column.getName().getString());
                     }
@@ -963,10 +955,9 @@ public class MetaDataClient {
                     throw new ColumnAlreadyExistsException(schemaName, tableName, column.getName().getString());
                 }
                 columns.add(column);
-                if (colDef.getDataType() == PDataType.VARBINARY 
+                if ((colDef.getDataType() == PDataType.VARBINARY || colDef.getDataType().isArrayType())
 
                         && SchemaUtil.isPKColumn(column)
-                        && pkColumnsNames.size() > 1 
-                        && column.getPosition() < pkColumnsNames.size() - 1) {
+                        && pkColumnsIterator.hasNext()) {
                     throw new SQLExceptionInfo.Builder(SQLExceptionCode.VARBINARY_IN_ROW_KEY)
                         .setSchemaName(schemaName)
                         .setTableName(tableName)

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/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
index 047e6f0..3538bf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PArrayDataType.java
@@ -301,7 +301,7 @@ public class PArrayDataType {
                 int elementLength = 0;
                 if (arrayIndex == (noOfElements - 1)) {
                     elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE
? 0 : indexOffset
-                            - currOffset - 3;
+                            - (currOffset + initPos) - 3;
                 } else {
                     elementLength = bytes[currOffset + initPos] == QueryConstants.SEPARATOR_BYTE
? 0 : getOffset(bytes,
                             arrayIndex + 1, useShort, indexOffset) - currOffset - 1;

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 0c29230..61dcda7 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -1210,33 +1210,6 @@ public class QueryCompilerTest extends BaseConnectionlessQueryTest
{
     }
     
     @Test
-    public void testInvalidArrayTypeAsPK () throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
-        try {
-            String query = "CREATE TABLE foo (col1 INTEGER[10] NOT NULL PRIMARY KEY)";
-            PreparedStatement statement = conn.prepareStatement(query);
-            statement.execute();
-            fail();
-        } catch (SQLException e) {
-                assertEquals(SQLExceptionCode.ARRAY_NOT_ALLOWED_IN_PRIMARY_KEY.getErrorCode(),
e.getErrorCode());
-        } finally {
-                conn.close();
-        }
-
-        conn = DriverManager.getConnection(getUrl());
-        try {
-            String query = "CREATE TABLE foo (col1 VARCHAR, col2 INTEGER ARRAY[10] CONSTRAINT
pk PRIMARY KEY (col1, col2))";
-            PreparedStatement statement = conn.prepareStatement(query);
-            statement.execute();
-            fail();
-        } catch (SQLException e) {
-            assertEquals(SQLExceptionCode.ARRAY_NOT_ALLOWED_IN_PRIMARY_KEY.getErrorCode(),
e.getErrorCode());
-        } finally {
-            conn.close();
-        }
-    }
-
-    @Test
     public void testInvalidArraySize() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
         try {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/9f1ce1e6/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
index a936fad..7b5daed 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Array;
 import java.sql.Connection;
@@ -957,7 +958,181 @@ public class ArrayTest extends BaseClientManagedTimeTest {
             conn.close();
         }
     }
+    
+    @Test
+    public void testVarLengthArrComparisonInWhereClauseWithSameArrays() throws Exception
{
+        Connection conn;
+        PreparedStatement stmt;
+        ResultSet rs;
+        
+        long ts = nextTimestamp();
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement()
+                .execute(
+                        "CREATE TABLE t_same_size ( k VARCHAR PRIMARY KEY, a_string_array
VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
+        conn.close();
+        
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("UPSERT INTO t_same_size VALUES(?,?,?)");
+        stmt.setString(1, "a");
+        String[] s = new String[] {"abc","def", "ghi","jkl"};
+        Array array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(2, array);
+        s = new String[] {"abc","def", "ghi","jkl"};
+        array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(3, array);
+        stmt.execute();
+        conn.commit();
+        conn.close();
+        
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery("SELECT k, a_string_array[2] FROM t_same_size
where a_string_array=b_string_array");
+        assertTrue(rs.next());
+        assertEquals("a",rs.getString(1));
+        assertEquals("def",rs.getString(2));
+        conn.close();
+    }
+    
+    @Test
+    public void testVarLengthArrComparisonInWhereClauseWithDiffSizeArrays() throws Exception
{
+        Connection conn;
+        PreparedStatement stmt;
+        ResultSet rs;
+
+        long ts = nextTimestamp();
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement()
+                .execute(
+                        "CREATE TABLE t ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100)
ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
+        stmt.setString(1, "a");
+        String[] s = new String[] { "abc", "def", "ghi", "jkll" };
+        Array array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(2, array);
+        s = new String[] { "abc", "def", "ghi", "jklm" };
+        array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(3, array);
+        stmt.execute();
+        conn.commit();
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery(
+                "SELECT k, a_string_array[2] FROM t where a_string_array<b_string_array");
+        assertTrue(rs.next());
+        assertEquals("a", rs.getString(1));
+        assertEquals("def", rs.getString(2));
+        conn.close();
+    }
+    
+    @Test
+    public void testVarLengthArrComparisonWithNulls() throws Exception {
+        Connection conn;
+        PreparedStatement stmt;
+        ResultSet rs;
 
+        long ts = nextTimestamp();
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement()
+                .execute(
+                        "CREATE TABLE t ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100)
ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
+        stmt.setString(1, "a");
+        String[] s = new String[] { "abc", "def", "ghi", "jkll", null, null, "xxx" };
+        Array array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(2, array);
+        s = new String[] { "abc", "def", "ghi", "jkll", null, null, null, "xxx" };
+        array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(3, array);
+        stmt.execute();
+        conn.commit();
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery(
+                "SELECT k, a_string_array[2] FROM t where a_string_array>b_string_array");
+        assertTrue(rs.next());
+        assertEquals("a", rs.getString(1));
+        assertEquals("def", rs.getString(2));
+        conn.close();
+    }
+
+    @Test
+    public void testPKWithArray() throws Exception {
+        Connection conn;
+        PreparedStatement stmt;
+        ResultSet rs;
+        long ts = nextTimestamp();
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.createStatement()
+                .execute(
+                        "CREATE TABLE t ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4],
b_string_array VARCHAR(100) ARRAY[4] \n"
+                        + " CONSTRAINT pk PRIMARY KEY (k, b_string_array)) \n");
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
+        stmt.setString(1, "a");
+        String[] s = new String[] { "abc", "def", "ghi", "jkll", null, null, "xxx" };
+        Array array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(2, array);
+        s = new String[] { "abc", "def", "ghi", "jkll", null, null, null, "xxx" };
+        array = conn.createArrayOf("VARCHAR", s);
+        stmt.setArray(3, array);
+        stmt.execute();
+        conn.commit();
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        rs = conn.createStatement().executeQuery(
+                "SELECT k, a_string_array[2] FROM t where b_string_array[8]='xxx'");
+        assertTrue(rs.next());
+        assertEquals("a", rs.getString(1));
+        assertEquals("def", rs.getString(2));
+        conn.close();
+    }
+
+    @Test
+    public void testPKWithArrayNotInEnd() throws Exception {
+        Connection conn;
+        long ts = nextTimestamp();
+        Properties props = new Properties(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            conn.createStatement().execute(
+                    "CREATE TABLE t ( a_string_array VARCHAR(100) ARRAY[4], b_string_array
VARCHAR(100) ARRAY[4], k VARCHAR  \n"
+                            + " CONSTRAINT pk PRIMARY KEY (b_string_array, k))");
+            conn.close();
+            fail();
+        } catch (SQLException e) {
+        } finally {
+            if (conn != null) {
+                conn.close();
+            }
+        }
+
+    }
+    
     static void createTableWithArray(String url, byte[][] bs, Object object,
 			long ts) throws SQLException {
 		String ddlStmt = "create table "


Mime
View raw message