asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xi...@apache.org
Subject asterixdb git commit: Fix NULL/MISSING field value handing in Java UDF
Date Wed, 26 Apr 2017 18:16:22 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master b58572a9c -> c9571fc08


Fix NULL/MISSING field value handing in Java UDF

Add NULL/MISSING value support in Java UDF. This fixed the NPE when there
is a NULL/MISSING field in a record.

Change-Id: Icf110b2f5b3658847967f5ee7163fb2e47713813
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1695
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/c9571fc0
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/c9571fc0
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/c9571fc0

Branch: refs/heads/master
Commit: c9571fc089821a7967635ff999d4b38ec38ad48e
Parents: b58572a
Author: Xikui Wang <xkkwww@gmail.com>
Authored: Tue Apr 25 13:31:16 2017 -0700
Committer: Xikui Wang <xkkwww@gmail.com>
Committed: Wed Apr 26 11:15:41 2017 -0700

----------------------------------------------------------------------
 .../external/library/JTypeObjectFactory.java    |  8 +++++
 .../external/library/java/JObjectAccessors.java | 26 +++++++++++++++
 .../asterix/external/library/java/JObjects.java | 33 +++++++++++++++++++-
 3 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c9571fc0/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
index e2ed092..fb9fd79 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.external.library;
 
 import org.apache.asterix.external.api.IJObject;
+import org.apache.asterix.external.library.java.JObjects;
 import org.apache.asterix.external.library.java.JObjects.JBoolean;
 import org.apache.asterix.external.library.java.JObjects.JCircle;
 import org.apache.asterix.external.library.java.JObjects.JDate;
@@ -46,6 +47,7 @@ import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.util.container.IObjectFactory;
 
+
 public class JTypeObjectFactory implements IObjectFactory<IJObject, IAType> {
 
     public static final JTypeObjectFactory INSTANCE = new JTypeObjectFactory();
@@ -108,6 +110,12 @@ public class JTypeObjectFactory implements IObjectFactory<IJObject,
IAType> {
             case INT64:
                 retValue = new JLong(0);
                 break;
+            case NULL:
+                retValue = JObjects.JNull.INSTANCE;
+                break;
+            case MISSING:
+                retValue = JObjects.JMissing.INSTANCE;
+                break;
             case ORDEREDLIST:
                 AOrderedListType ot = (AOrderedListType) type;
                 IAType orderedItemType = ot.getItemType();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c9571fc0/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
index f8755b4..a35bc69 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
@@ -140,6 +140,12 @@ public class JObjectAccessors {
             case DURATION:
                 accessor = new JDurationAccessor();
                 break;
+            case NULL:
+                accessor = new JNullAccessor();
+                break;
+            case MISSING:
+                accessor = new JMissingAccessor();
+                break;
             default:
                 break;
         }
@@ -189,6 +195,26 @@ public class JObjectAccessors {
         }
     }
 
+    public static class JNullAccessor implements IJObjectAccessor {
+
+        @Override
+        public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType>
objPool)
+                throws HyracksDataException {
+            IJObject jObject = objPool.allocate(BuiltinType.ANULL);
+            return jObject;
+        }
+    }
+
+    public static class JMissingAccessor implements  IJObjectAccessor {
+
+        @Override
+        public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType>
objPool)
+                throws HyracksDataException {
+            IJObject jObject = objPool.allocate(BuiltinType.AMISSING);
+            return jObject;
+        }
+    }
+
     public static class JInt64Accessor implements IJObjectAccessor {
 
         @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c9571fc0/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
index 78b14e7..859a327 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
@@ -61,6 +61,7 @@ import org.apache.asterix.om.base.AFloat;
 import org.apache.asterix.om.base.AInt32;
 import org.apache.asterix.om.base.AInt64;
 import org.apache.asterix.om.base.AInt8;
+import org.apache.asterix.om.base.AMissing;
 import org.apache.asterix.om.base.AMutableCircle;
 import org.apache.asterix.om.base.AMutableDate;
 import org.apache.asterix.om.base.AMutableDateTime;
@@ -144,7 +145,7 @@ public class JObjects {
         public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException
{
             if (writeTypeTag) {
                 try {
-                    dataOutput.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
+                    dataOutput.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
                 } catch (IOException e) {
                     throw new HyracksDataException(e);
                 }
@@ -157,6 +158,36 @@ public class JObjects {
 
     }
 
+    public static class JMissing implements IJObject {
+        public final static JMissing INSTANCE = new JMissing();
+
+        @Override
+        public ATypeTag getTypeTag() {
+            return ATypeTag.MISSING;
+        }
+
+        @Override
+        public IAObject getIAObject() {
+            return AMissing.MISSING;
+        }
+
+        @Override
+        public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException
{
+            if (writeTypeTag) {
+                try {
+                    dataOutput.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
+                } catch (IOException e) {
+                    throw new HyracksDataException(e);
+                }
+            }
+        }
+
+        @Override
+        public void reset() throws HyracksDataException {
+            // no op
+        }
+    }
+
     public static final class JByte extends JObject {
 
         public JByte(byte value) {


Mime
View raw message