asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AsterixDB Code Review <do-not-re...@asterix-gerrit.ics.uci.edu>
Subject Change in asterixdb[mad-hatter]: [ASTERIXDB-2732][FUN] Support missing and union type in get_object_fi...
Date Thu, 03 Jun 2021 17:51:01 GMT
>From Ali Alsuliman <ali.al.solaiman@gmail.com>:

Ali Alsuliman has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11764
)


Change subject: [ASTERIXDB-2732][FUN] Support missing and union type in get_object_field_value
......................................................................

[ASTERIXDB-2732][FUN] Support missing and union type in get_object_field_value

- user model changes: no
- storage format changes: no
- interface changes: no

Change-Id: I84355e0ae91afd0328e636aa4f3bed6eeb44e055
---
C asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.ddl.sqlpp
C asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.2.update.sqlpp
R asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.3.query.sqlpp
C asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.4.query.sqlpp
M asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.1.adm
A asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.2.adm
M asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
7 files changed, 61 insertions(+), 31 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/64/11764/1

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.ddl.sqlpp
similarity index 73%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.ddl.sqlpp
index 7be4593..0d6ab35 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.ddl.sqlpp
@@ -17,7 +17,18 @@
  * under the License.
  */
 
-{
-  'null': {'a': null}.a,
-  'missing': {'b': missing}.b
-};
\ No newline at end of file
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+drop dataset samptable if exists;
+drop type samptabletype if exists;
+
+create type samptabletype as closed {
+  id: tinyint,
+  mf: tinyint?,
+  rf: { pid:tinyint}?
+};
+
+
+create dataset samptable(samptabletype) primary key id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.2.update.sqlpp
similarity index 80%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.2.update.sqlpp
index 7be4593..8a7e88b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.2.update.sqlpp
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-{
-  'null': {'a': null}.a,
-  'missing': {'b': missing}.b
-};
\ No newline at end of file
+use test;
+insert into samptable ({'id' : 0, 'mf':missing, 'rf':{'pid':4}});
+insert into samptable ({'id' : 1, 'mf':null, 'rf':missing});
+insert into samptable ({'id' : 2, 'mf':5, 'rf':null});
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.3.query.sqlpp
similarity index 82%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.3.query.sqlpp
index 7be4593..bed3710 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.3.query.sqlpp
@@ -17,7 +17,9 @@
  * under the License.
  */
 
-{
-  'null': {'a': null}.a,
-  'missing': {'b': missing}.b
-};
\ No newline at end of file
+use test;
+
+from samptable d
+select id, get_object_field_value(d, 'rf') as field_value,
+           get_object_field_value(d, 'rf') is missing as is_missing
+order by id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.4.query.sqlpp
similarity index 82%
copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.4.query.sqlpp
index 7be4593..553dc55 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/null-missing/field-access/field-access.4.query.sqlpp
@@ -16,8 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+use test;
 
-{
-  'null': {'a': null}.a,
-  'missing': {'b': missing}.b
-};
\ No newline at end of file
+from samptable d
+select id, get_object_field_value(d, 'mf') as field_value,
+           get_object_field_value(d, 'mf') is missing as is_missing
+order by id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.1.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.1.adm
index d7a20ef..f157d67 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.1.adm
@@ -1 +1,3 @@
-{ "null": null }
+{ "id": 0, "field_value": { "pid": 4 }, "is_missing": false }
+{ "id": 1, "is_missing": true }
+{ "id": 2, "field_value": null, "is_missing": false }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.2.adm
b/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.2.adm
new file mode 100644
index 0000000..767c19b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/null-missing/field-access/field-access.2.adm
@@ -0,0 +1,3 @@
+{ "id": 0, "is_missing": true }
+{ "id": 1, "field_value": null, "is_missing": false }
+{ "id": 2, "field_value": 5, "is_missing": false }
\ No newline at end of file
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
index 103a164..d6c0e21 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
@@ -27,7 +27,9 @@
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo;
 import org.apache.asterix.om.utils.NonTaggedFormatUtil;
 import org.apache.asterix.om.utils.RecordUtil;
@@ -93,7 +95,6 @@
                     if (PointableHelper.checkAndSetMissingOrNull(result, inputArg0, inputArg1))
{
                         return;
                     }
-
                     byte[] serFldName = inputArg1.getByteArray();
                     int serFldNameOffset = inputArg1.getStartOffset();
                     int serFldNameLen = inputArg1.getLength();
@@ -114,22 +115,32 @@
                     int subFieldIndex = recTypeInfo.getFieldIndex(serFldName, serFldNameOffset
+ 1, serFldNameLen - 1);
                     if (subFieldIndex >= 0) {
                         int nullBitmapSize = RecordUtil.computeNullBitmapSize(recordType);
+
                         subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord,
serRecordOffset,
                                 subFieldIndex, nullBitmapSize, recordType.isOpen());
-                        if (subFieldOffset == 0) {
-                            // the field is null, we checked the null bit map
-                            out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
-                            result.set(resultStorage);
-                            return;
+                        switch (subFieldOffset) {
+                            case -1:
+                                out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
+                                result.set(resultStorage);
+                                return;
+                            case 0:
+                                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                                result.set(resultStorage);
+                                return;
+                            default:
+                                IAType fieldType = recordType.getFieldTypes()[subFieldIndex];
+                                if (fieldType.getTypeTag() == ATypeTag.UNION) {
+                                    fieldType = ((AUnionType) fieldType).getActualType();
+                                }
+                                ATypeTag fieldTypeTag = fieldType.getTypeTag();
+                                subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord,
subFieldOffset,
+                                        fieldTypeTag, false);
+                                // write result.
+                                out.writeByte(fieldTypeTag.serialize());
+                                out.write(serRecord, subFieldOffset, subFieldLength);
+                                result.set(resultStorage);
+                                return;
                         }
-                        ATypeTag fieldTypeTag = recordType.getFieldTypes()[subFieldIndex].getTypeTag();
-                        subFieldLength =
-                                NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset,
fieldTypeTag, false);
-                        // write result.
-                        out.writeByte(fieldTypeTag.serialize());
-                        out.write(serRecord, subFieldOffset, subFieldLength);
-                        result.set(resultStorage);
-                        return;
                     }
 
                     // Look at open fields.

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11764
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: mad-hatter
Gerrit-Change-Id: I84355e0ae91afd0328e636aa4f3bed6eeb44e055
Gerrit-Change-Number: 11764
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <ali.al.solaiman@gmail.com>
Gerrit-MessageType: newchange

Mime
View raw message