This is an automated email from the ASF dual-hosted git repository. htowaileb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 98603d1282f554bae2b5a51d2310557d81d33bd8 Author: Ali Alsuliman <[email protected]> AuthorDate: Thu Jun 30 00:10:46 2022 +0300 [ASTERIXDB-3045][RT] Skip adding fields with UNKNOWN fields names in record builder - user model changes: no - storage format changes: no - interface changes: no Details: Do not add fields whose field names is MISSING/NULL (e.g. a field name is computed dynamically). Change-Id: I7b292755a7aee99cdbbb6debc83de95d7ee8dbac Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/16765 Reviewed-by: Ali Alsuliman <[email protected]> Reviewed-by: Wail Alkowaileet <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> --- .../queries_sqlpp/objects/ObjectsQueries.xml | 5 +++ ...nstructor-with-missing-field-name.1.query.sqlpp | 21 +++++++++++ ...nstructor-with-missing-field-name.2.query.sqlpp | 44 ++++++++++++++++++++++ ...bject-constructor-with-missing-field-name.1.adm | 2 + ...bject-constructor-with-missing-field-name.2.adm | 3 ++ .../org/apache/asterix/builders/RecordBuilder.java | 11 +++++- 6 files changed, 84 insertions(+), 2 deletions(-) diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml index 2400affb79..623237b550 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml @@ -203,6 +203,11 @@ <expected-warn>Duplicate field name 'name' (in line 30, at column 16)</expected-warn> </compilation-unit> </test-case> + <test-case FilePath="objects" check-warnings="true"> + <compilation-unit name="open-object-constructor-with-missing-field-name"> + <output-dir compare="Text">open-object-constructor-with-missing-field-name</output-dir> + </compilation-unit> + </test-case> <test-case FilePath="objects" check-warnings="true"> <compilation-unit name="open-closed-fieldname-conflict_issue173"> <output-dir compare="Text">open-closed-fieldname-conflict_issue173</output-dir> diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.query.sqlpp new file mode 100644 index 0000000000..8a892ef46d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.query.sqlpp @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +FROM [{"fieldName": "status", "fieldValue": "shipped"}, {"fieldValue": "pending"}] AS g +SELECT VALUE { g.fieldName : g.fieldValue}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.query.sqlpp new file mode 100644 index 0000000000..e132460294 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.query.sqlpp @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +WITH src AS [ + { "category_name": "Video Card", "status": "Shipped", "order_id": 1, "order_value": 10 }, + { "category_name": "Video Card", "status": "Shipped", "order_id": 2, "order_value": 20 }, + { "category_name": "Video Card", "status": "Cancelled", "order_id": 3, "order_value": 30 }, + { "category_name": "Video Card", "status": "Cancelled", "order_id": 4, "order_value": 40 }, + { "category_name": "Video Card", "status": "Pending", "order_id": 5, "order_value": 50 }, + { "category_name": "Video Card", "status": "Pending", "order_id": 6, "order_value": 50 }, + { "category_name": "Storage", "status": "Shipped", "order_id": 11, "order_value": 110 }, + { "category_name": "Storage", "status": "Shipped", "order_id": 12, "order_value": 120 }, + { "category_name": "Storage", "status": "Cancelled", "order_id": 13, "order_value": 130 }, + { "category_name": "Storage", "status": "Cancelled", "order_id": 14, "order_value": 140 }, + { "category_name": "Storage", "status": "Pending", "order_id": 15, "order_value": 150 }, + { "category_name": "Storage", "status": "Pending", "order_id": 16, "order_value": 160 } +], +t1 AS ( + select category_name, status, count(order_id) orders, sum(order_value) sales + from src + group by category_name, status +) +SELECT status, v.* +FROM t1 group BY status GROUP AS g +let v = OBJECT_CONCAT(( + SELECT VALUE { g.t1.category_name || " Orders": g.t1.orders, g.t1.UNKNOWN_FIELD || " Sales": g.t1.sales } FROM g +)) +ORDER BY status; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.adm new file mode 100644 index 0000000000..ca4649213f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.1.adm @@ -0,0 +1,2 @@ +{ "status": "shipped" } +{ } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.adm new file mode 100644 index 0000000000..008b55055a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/open-object-constructor-with-missing-field-name/open-object-constructor-with-missing-field-name.2.adm @@ -0,0 +1,3 @@ +{ "Video Card Orders": 2, "Storage Orders": 2, "status": "Cancelled" } +{ "Video Card Orders": 2, "Storage Orders": 2, "status": "Pending" } +{ "Video Card Orders": 2, "Storage Orders": 2, "status": "Shipped" } \ No newline at end of file diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java index 58e59d6e95..d08865ba94 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java @@ -186,9 +186,16 @@ public class RecordBuilder implements IARecordBuilder { if (data[offset] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) { return; } - // ignore adding duplicate fields byte[] nameBytes = name.getByteArray(); - int nameStart = name.getStartOffset() + 1; + int nameOffset = name.getStartOffset(); + // ignore adding fields with NULL/MISSING names + if (nameBytes[nameOffset] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG + || nameBytes[nameOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) { + // TODO(ali): issue a warning + return; + } + // ignore adding duplicate fields + int nameStart = nameOffset + 1; int nameLength = name.getLength() - 1; if (recType != null && recTypeInfo.getFieldIndex(nameBytes, nameStart, nameLength) >= 0) { // TODO(ali): issue a warning
