You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2021/11/10 10:04:47 UTC
[phoenix] branch 4.x updated: PHOENIX-6583 Inserting explicit Null
into a (fixed length) binary field is stored as an array of zeroes
This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push:
new bdaa98e PHOENIX-6583 Inserting explicit Null into a (fixed length) binary field is stored as an array of zeroes
bdaa98e is described below
commit bdaa98e7b5d7823e3681e439938a5d85753e9fbd
Author: Alejandro Anadon <al...@hotmail.com>
AuthorDate: Tue Nov 2 14:54:47 2021 +0100
PHOENIX-6583 Inserting explicit Null into a (fixed length) binary field is stored as an array of zeroes
---
.../it/java/org/apache/phoenix/end2end/NullIT.java | 56 +++++++++++++++++++++-
.../org/apache/phoenix/schema/types/PBinary.java | 11 +++--
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NullIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NullIT.java
index da9a133..36a008b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NullIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NullIT.java
@@ -36,6 +36,8 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
@@ -149,5 +151,57 @@ public class NullIT extends BaseQueryIT {
conn.close();
}
}
-
+
+ // PHOENIX-6583
+ @Test
+ public void testBinaryNullAssignment() throws SQLException {
+ Properties props = new Properties();
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+
+ ResultSet rs;
+
+ try (Statement stmt = conn.createStatement()) {
+
+ String binTestTable=generateUniqueName();
+
+ stmt.execute("create table "+binTestTable+" (id integer not null, text varchar(255), testbin binary(16), CONSTRAINT pk primary key (id))");
+ conn.commit();
+
+ String queryIsNull = "select id, text , testbin from "+binTestTable+" where testbin is null";
+
+
+ // Let's see if without providing it, it is stored as null
+ stmt.execute("upsert into "+binTestTable+" (id,text) values (1,'anytext')");
+ conn.commit();
+ rs= stmt.executeQuery(queryIsNull);
+ assertTrue(rs.next());
+ rs.close();
+
+ // Let's see if providing it, but it is set as null, it is also stored as null
+ stmt.execute("upsert into "+binTestTable+" (id,text,testbin) values (1,'anytext',null)");
+ conn.commit();
+ rs = stmt.executeQuery(queryIsNull);
+ assertTrue(rs.next());
+ rs.close();
+
+ //Now let's set a value. Now It should be NOT null
+ stmt.execute("upsert into "+binTestTable+" (id,text,testbin) values (1,'anytext','a')");
+ conn.commit();
+ rs = stmt.executeQuery(queryIsNull);
+ assertTrue(false == rs.next());
+ rs.close();
+
+ //Right now it has a value.... let's see if we can set it again a null value
+ stmt.execute("upsert into "+binTestTable+" (id,text,testbin) values (1,'anytext',null)");
+ conn.commit();
+ rs = stmt.executeQuery(queryIsNull);
+ assertTrue(rs.next());
+ rs.close();
+
+ stmt.execute("DROP TABLE "+binTestTable+" ");
+ conn.commit();
+
+ rs.close();
+ }
+ }
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
index b6d2c82..539bc87 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PBinary.java
@@ -36,11 +36,12 @@ public class PBinary extends PBinaryBase {
}
@Override
- public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, Integer actualMaxLength,
- Integer actualScale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale,
- SortOrder expectedModifier) {
- PVarbinary.INSTANCE.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
- if (null != desiredMaxLength && null != expectedModifier) {
+ public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType,
+ Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
+ Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
+ PVarbinary.INSTANCE.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale,
+ actualModifier, desiredMaxLength, desiredScale, expectedModifier);
+ if (ptr.getLength() > 0 && null != desiredMaxLength && null != expectedModifier) {
pad(ptr, desiredMaxLength, expectedModifier);
}
}