You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2014/06/02 13:34:51 UTC
git commit: Phoenix-1008 : Problem initiating and using FLOAT ARRAY
Type (Ram)
Repository: phoenix
Updated Branches:
refs/heads/4.0 4c4dbbe8c -> 09a323a6c
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/09a323a6
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/09a323a6
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/09a323a6
Branch: refs/heads/4.0
Commit: 09a323a6c4bcfe7a6cae70f79002d4091c1a2388
Parents: 4c4dbbe
Author: Ramkrishna <ra...@intel.com>
Authored: Mon Jun 2 17:04:07 2014 +0530
Committer: Ramkrishna <ra...@intel.com>
Committed: Mon Jun 2 17:04:07 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/09a323a6/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/09a323a6/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/09a323a6/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++) {