Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 705A411AA0 for ; Mon, 2 Jun 2014 11:32:05 +0000 (UTC) Received: (qmail 13141 invoked by uid 500); 2 Jun 2014 11:32:05 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 13100 invoked by uid 500); 2 Jun 2014 11:32:05 -0000 Mailing-List: contact commits-help@phoenix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.incubator.apache.org Delivered-To: mailing list commits@phoenix.incubator.apache.org Received: (qmail 13093 invoked by uid 99); 2 Jun 2014 11:32:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Jun 2014 11:32:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 22675885AB5; Mon, 2 Jun 2014 11:32:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ramkrishna@apache.org To: commits@phoenix.apache.org Message-Id: <72ee7cf7e2dd432189a988e11ba276f5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Phoenix-1008-Problem initiating and using FLOAT ARRAY Type (Ram) Date: Mon, 2 Jun 2014 11:32:05 +0000 (UTC) Repository: phoenix Updated Branches: refs/heads/master 3a327fa7e -> eb2a61e94 Phoenix-1008-Problem initiating and using FLOAT ARRAY Type (Ram) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/eb2a61e9 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/eb2a61e9 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/eb2a61e9 Branch: refs/heads/master Commit: eb2a61e9474c6e74590b4d8d110e8cc2fa4ce5fe Parents: 3a327fa Author: Ramkrishna Authored: Mon Jun 2 17:00:48 2014 +0530 Committer: Ramkrishna Committed: Mon Jun 2 17:00:48 2014 +0530 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/ArrayIT.java | 36 +++++++++++++++++--- .../apache/phoenix/schema/PArrayDataType.java | 6 ++-- .../org/apache/phoenix/schema/PhoenixArray.java | 5 ++- 3 files changed, 40 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb2a61e9/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java index bf4be73..bfff64a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java @@ -290,7 +290,7 @@ public class ArrayIT extends BaseClientManagedTimeIT { String tenantId = getOrganizationId(); createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2); String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array) values('" + tenantId - + "','00A123122312312',ARRAY[2.0d,345.8d])"; + + "','00A123122312312',ARRAY[2.0,345.8])"; Properties props = new Properties(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute // at @@ -336,7 +336,7 @@ public class ArrayIT extends BaseClientManagedTimeIT { conn = DriverManager.getConnection(getUrl(), props); String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array) " + "SELECT organization_id, entity_id, a_double_array FROM " + SIMPLE_TABLE_WITH_ARRAY - + " WHERE a_double_array[2] = 89.96d"; + + " WHERE a_double_array[2] = 89.96"; PreparedStatement statement = conn.prepareStatement(query); int executeUpdate = statement.executeUpdate(); assertEquals(1, executeUpdate); @@ -474,8 +474,8 @@ public class ArrayIT extends BaseClientManagedTimeIT { props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 conn = DriverManager.getConnection(getUrl(), props); String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID, a_unsigned_double, a_double_array) " - + "SELECT organization_id, entity_id, x_double, ARRAY[23.4d, 22.1d, x_double] FROM " + SIMPLE_TABLE_WITH_ARRAY - + " WHERE a_double_array[2] = 89.96d"; + + "SELECT organization_id, entity_id, x_double, ARRAY[23.4, 22.1, x_double] FROM " + SIMPLE_TABLE_WITH_ARRAY + + " WHERE a_double_array[2] = 89.96"; PreparedStatement statement = conn.prepareStatement(query); int executeUpdate = statement.executeUpdate(); assertEquals(1, executeUpdate); @@ -564,6 +564,34 @@ public class ArrayIT extends BaseClientManagedTimeIT { } @Test + public void testArrayWithFloatArray() 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 Float ARRAY[])"); + conn.close(); + + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30)); + conn = DriverManager.getConnection(getUrl(), props); + stmt = conn.prepareStatement("UPSERT INTO t VALUES('a',ARRAY[2.0,3.0])"); + int res = stmt.executeUpdate(); + assertEquals(1, res); + conn.commit(); + conn.close(); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40)); + conn = DriverManager.getConnection(getUrl(), props); + rs = conn.createStatement().executeQuery("SELECT ARRAY_ELEM(a,2) FROM t"); + assertTrue(rs.next()); + Float f = new Float(3.0); + assertEquals(f, (Float)rs.getFloat(1)); + conn.close(); + } + + @Test public void testArraySelectSingleArrayElemWithCast() throws Exception { Connection conn; PreparedStatement stmt; http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb2a61e9/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 01b28da..507e9d1 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 @@ -224,13 +224,15 @@ public class PArrayDataType { && baseType.isFixedWidth() == desiredBaseType.isFixedWidth() && actualModifer == expectedModifier) { return; } - if (value == null && actualType != desiredType) { + if (value == null || actualType != desiredType) { value = toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), baseType, actualModifer, maxLength, desiredScale, desiredBaseType); PhoenixArray pArr = (PhoenixArray)value; // VARCHAR <=> CHAR if(baseType.isFixedWidth() != desiredBaseType.isFixedWidth()) { - pArr = new PhoenixArray(pArr, desiredMaxLength); + if (!pArr.isPrimitiveType()) { + pArr = new PhoenixArray(pArr, desiredMaxLength); + } } baseType = desiredBaseType; ptr.set(toBytes(pArr, baseType, expectedModifier)); http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb2a61e9/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java index b2826a8..59d0aff 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PhoenixArray.java @@ -33,7 +33,6 @@ public class PhoenixArray implements Array,SQLCloseable { Object array; int numElements; Integer maxLength; - public PhoenixArray() { // empty constructor } @@ -42,6 +41,10 @@ public class PhoenixArray implements Array,SQLCloseable { return maxLength; } + public boolean isPrimitiveType() { + return this.baseType.getCodec() != null; + } + private static Object[] coerceToNewLength(PDataType baseType, Object[] elements, int maxLength) { Object[] resizedElements = new Object[elements.length]; for (int i = 0; i < elements.length; i++) {