You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/01/27 23:46:54 UTC
git commit: Disallow array element reference in LHS of UPSERT VALUES
Updated Branches:
refs/heads/master 934203694 -> 4066a331b
Disallow array element reference in LHS of UPSERT VALUES
Project: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/commit/4066a331
Tree: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/tree/4066a331
Diff: http://git-wip-us.apache.org/repos/asf/incubator-phoenix/diff/4066a331
Branch: refs/heads/master
Commit: 4066a331b9c209417b40e3a68da2f8422d7fbaa2
Parents: 9342036
Author: James Taylor <ja...@apache.org>
Authored: Mon Jan 27 14:46:49 2014 -0800
Committer: James Taylor <ja...@apache.org>
Committed: Mon Jan 27 14:46:49 2014 -0800
----------------------------------------------------------------------
phoenix-core/src/main/antlr3/PhoenixSQL.g | 8 ++--
.../phoenix/compile/QueryCompileTest.java | 13 ++++++
.../org/apache/phoenix/end2end/ArrayTest.java | 47 --------------------
3 files changed, 17 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/4066a331/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 5dcfe81..53abed6 100644
--- a/phoenix-core/src/main/antlr3/PhoenixSQL.g
+++ b/phoenix-core/src/main/antlr3/PhoenixSQL.g
@@ -511,8 +511,8 @@ dyn_column_defs returns [List<ColumnDef> ret]
;
dyn_column_def returns [ColumnDef ret]
- : c=column_name dt=identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? (lsq=LSQUARE (a=NUMBER)? RSQUARE)?
- {$ret = factory.columnDef(c, dt, true,
+ : c=column_name dt=identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)?
+ {$ret = factory.columnDef(c, dt, ar != null || lsq != null, a == null ? null : Integer.parseInt( a.getText() ), true,
l == null ? null : Integer.parseInt( l.getText() ),
s == null ? null : Integer.parseInt( s.getText() ),
false,
@@ -520,8 +520,8 @@ dyn_column_def returns [ColumnDef ret]
;
dyn_column_name_or_def returns [ColumnDef ret]
- : c=column_name (dt=identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? )? (lsq=LSQUARE (a=NUMBER)? RSQUARE)?
- {$ret = factory.columnDef(c, dt, true,
+ : c=column_name (dt=identifier (LPAREN l=NUMBER (COMMA s=NUMBER)? RPAREN)? ar=ARRAY? (lsq=LSQUARE (a=NUMBER)? RSQUARE)? )?
+ {$ret = factory.columnDef(c, dt, ar != null || lsq != null, a == null ? null : Integer.parseInt( a.getText() ), true,
l == null ? null : Integer.parseInt( l.getText() ),
s == null ? null : Integer.parseInt( s.getText() ),
false,
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/4066a331/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
index 0434331..92c1423 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompileTest.java
@@ -1247,6 +1247,19 @@ public class QueryCompileTest extends BaseConnectionlessQueryTest {
}
@Test
+ public void testInvalidArrayElemRefInUpsert() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ conn.createStatement().execute("CREATE TABLE t (k VARCHAR PRIMARY KEY, a INTEGER[10], B INTEGER[10])");
+ try {
+ conn.createStatement().execute("UPSERT INTO t(k,a[2]) VALUES('A', 5)");
+ fail();
+ } catch (SQLException e) {
+ assertEquals(SQLExceptionCode.PARSER_ERROR.getErrorCode(), e.getErrorCode());
+ }
+ conn.close();
+ }
+
+ @Test
public void testInvalidNextValueFor() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE SEQUENCE alpha.zeta");
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/4066a331/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 c9d5f9b..de9e961 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
@@ -43,7 +43,6 @@ import org.apache.phoenix.schema.PhoenixArray;
import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.StringUtil;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import com.google.common.primitives.Floats;
@@ -438,52 +437,6 @@ public class ArrayTest extends BaseClientManagedTimeTest {
}
}
- @Ignore //TODO: Ram to fix
- @Test
- public void testUpsertSelectWithSelectAsSubQuery3() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- //initTablesWithArrays(tenantId, null, ts, false);
- try {
- createSimpleTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(tenantId, null, ts, false);
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL,
- props);
- // TODO: this is invalid, as you can't have an array reference in upsert
- String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array[3]) values('"
- + tenantId + "','00A123122312312',2.0d)";
- PreparedStatement statement = conn.prepareStatement(query);
- int executeUpdate = statement.executeUpdate();
- assertEquals(1, executeUpdate);
- conn.commit();
- statement.close();
- conn.close();
- // create another connection
- props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 4));
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- query = "SELECT ARRAY_ELEM(a_double_array,3) FROM table_with_array";
- statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 2.0d;
- conn.createArrayOf("DOUBLE", doubleArr);
- Double result = rs.getDouble(1);
- assertEquals(result, doubleArr[0]);
-
- } finally {
- }
- }
-
@Test
public void testSelectArrayUsingUpsertLikeSyntax() throws Exception {
long ts = nextTimestamp();