>From Shahrzad Shirazi <[email protected]>: Shahrzad Shirazi has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20939?usp=email )
Change subject: [ASTERIXDB-3738][COMP] Not allowing Closed-type records in object-transform function. ...................................................................... [ASTERIXDB-3738][COMP] Not allowing Closed-type records in object-transform function. - user model changes: no - storage format changes: no - interface changes: no Ext-ref: MB-70606 Change-Id: Ifa3d1a6b983e5aab778e1c50810af175dc2367bd Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20939 Reviewed-by: Shahrzad Shirazi <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> --- M asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/RecordTransformTypeComputer.java 1 file changed, 20 insertions(+), 1 deletion(-) Approvals: Jenkins: Verified; Verified Ali Alsuliman: Looks good to me, approved Shahrzad Shirazi: Looks good to me, but someone else must approve Objections: Anon. E. Moose #1000171: Violations found diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/RecordTransformTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/RecordTransformTypeComputer.java index 1404424..323cc8c 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/RecordTransformTypeComputer.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/RecordTransformTypeComputer.java @@ -19,8 +19,11 @@ package org.apache.asterix.om.typecomputer.impl; +import org.apache.asterix.common.exceptions.CompilationException; +import org.apache.asterix.common.exceptions.ErrorCode; import org.apache.asterix.om.typecomputer.base.IResultTypeComputer; import org.apache.asterix.om.types.ARecordType; +import org.apache.asterix.om.types.ATypeTag; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.types.TypeHelper; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; @@ -47,9 +50,21 @@ * </ul> */ public class RecordTransformTypeComputer implements IResultTypeComputer { - public static final RecordTransformTypeComputer INSTANCE = new RecordTransformTypeComputer(); + private static boolean isRecordAndSubfieldsOpen(ARecordType rec) { + if (!rec.isOpen()) { + return false; + } + for (IAType fieldType : rec.getFieldTypes()) { + IAType actual = TypeComputeUtils.getActualType(fieldType); + if (actual.getTypeTag() == ATypeTag.OBJECT && !isRecordAndSubfieldsOpen((ARecordType) actual)) { + return false; + } + } + return true; + } + @Override public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException { @@ -65,6 +80,10 @@ } return resultType; } + if (!isRecordAndSubfieldsOpen(recType0)) { + throw new CompilationException(ErrorCode.COMPILATION_ERROR, f.getSourceLocation(), + "The operation cannot be performed since the arguments provided to the object-transform function are defined as closed types."); + } /** Infer merged type only if t0 is a record of type 'transform' and t1 is a record */ resultType = RecordMergeTypeComputer.INSTANCE_IGNORE_DUPLICATES_MERGE_ON_TRANSFORM_RECORDS -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20939?usp=email To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: asterixdb Gerrit-Branch: lumina Gerrit-Change-Id: Ifa3d1a6b983e5aab778e1c50810af175dc2367bd Gerrit-Change-Number: 20939 Gerrit-PatchSet: 8 Gerrit-Owner: Shahrzad Shirazi <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Shahrzad Shirazi <[email protected]>
