[NO ISSUE][COMP] Remove check-unknown for Insert/Upsert on datasets with meta part

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

Ext-ref: MB-67221
Change-Id: I55766c9a334f40efd996e2b453f7237aec739966
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20010
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
index a9ad7ce..7121bc0 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
@@ -27,6 +27,7 @@
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.metadata.declared.DataSource;
+import org.apache.asterix.metadata.declared.DatasetDataSource;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.typecomputer.base.TypeCastUtils;
 import org.apache.asterix.om.types.ARecordType;
@@ -165,6 +166,11 @@
             inputRecordType = ((AUnionType) inputRecordType).getActualType();
             checkUnknown = true;
         }
+        boolean hasMetaPart = op.getOperatorTag() == LogicalOperatorTag.INSERT_DELETE_UPSERT
+                && ((DatasetDataSource) ((InsertDeleteUpsertOperator) op).getDataSource()).getDataset().hasMetaPart();
+        if (hasMetaPart) {
+            checkUnknown = false;
+        }
 
         /** see whether the input record type needs to be casted */
         boolean cast = !compatible(requiredRecordType, inputRecordType, op);
@@ -173,7 +179,11 @@
             recordVar = addWrapperFunction(requiredRecordType, recordVar, op, context, BuiltinFunctions.CHECK_UNKNOWN);
         }
         if (cast) {
-            addWrapperFunction(requiredRecordType, recordVar, op, context, BuiltinFunctions.CAST_TYPE);
+            if (hasMetaPart) {
+                addWrapperFunction(requiredRecordType, recordVar, op, context, BuiltinFunctions.CAST_TYPE_LAX);
+            } else {
+                addWrapperFunction(requiredRecordType, recordVar, op, context, BuiltinFunctions.CAST_TYPE);
+            }
         }
         return cast || checkUnknown;
     }