package edu.uci.ics.asterix.formats.nontagged;

import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.hyracks.algebricks.data.IBinaryBooleanInspector;
import edu.uci.ics.hyracks.algebricks.data.IBinaryBooleanInspectorFactory;
import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;

public class AqlBinaryBooleanInspectorImpl implements IBinaryBooleanInspector {
    public static final IBinaryBooleanInspectorFactory FACTORY = new IBinaryBooleanInspectorFactory() {
        private static final long serialVersionUID = 1L;

        @Override
        public IBinaryBooleanInspector createBinaryBooleanInspector(IHyracksTaskContext ctx) {
            return new AqlBinaryBooleanInspectorImpl();
        }
    };

    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();

    private AqlBinaryBooleanInspectorImpl() {
    }

    @Override
    public boolean getBooleanValue(byte[] bytes, int offset, int length) {
        if (bytes[offset] == SER_NULL_TYPE_TAG)
            return false;
        return bytes[offset + 1] == 1;
    }

}

@@ -87,16 +87,70 @@
 ypeTag;%0A
+import edu.uci.ics.asterix.om.types.EnumDeserializer;%0A
 import e
@@ -1068,16 +1068,329 @@
  false;%0A
+        /** check if the runtime type is boolean */%0A        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes%5Boffset%5D);%0A        if (typeTag != ATypeTag.BOOLEAN) %7B%0A            throw new IllegalStateException(%22Runtime error: the select condition should be of the boolean type!%22);%0A        %7D%0A
         

add runtime type check for the evaluatation results of boolean expressions