private static boolean isOpen(ARecordType recordType) { return recordType == null || recordType.isOpen(); }
public boolean isOpen() { return type.isOpen(); }
private boolean isExpandedRecord(DataInput in) throws IOException { in.readInt(); // recordSize if (recordType == null) { boolean exp = in.readBoolean(); in.readInt(); // openPartOffset return exp; } else { if (recordType.isOpen()) { boolean exp = in.readBoolean(); if (exp) { in.readInt(); // openPartOffset } return exp; } return false; } }
private static ARecordType generalizeRecordTypes(ARecordType leftType, ARecordType rightType) { boolean knowsAdditonalFieldNames = true; Set<String> allPossibleAdditionalFieldNames = new HashSet<>(); if (leftType.isOpen() && !leftType.knowsAllPossibleAdditonalFieldNames()) { knowsAdditonalFieldNames = false; } else if (leftType.isOpen()) { allPossibleAdditionalFieldNames.addAll(leftType.getAllPossibleAdditonalFieldNames()); } if (rightType.isOpen() && !rightType.knowsAllPossibleAdditonalFieldNames()) { knowsAdditonalFieldNames = false; } else if (rightType.isOpen()) { allPossibleAdditionalFieldNames.addAll(rightType.getAllPossibleAdditonalFieldNames()); } boolean canBeClosed = !leftType.isOpen() && !rightType.isOpen(); List<String> fieldNames = new ArrayList<>(); List<IAType> fieldTypes = new ArrayList<>(); boolean leftAllMatched = generalizeRecordFields(leftType, rightType, allPossibleAdditionalFieldNames, fieldNames, fieldTypes); boolean rightAllMatched = generalizeRecordFields(rightType, leftType, allPossibleAdditionalFieldNames, fieldNames, fieldTypes); return new ARecordType("generalized-record-type", fieldNames.toArray(new String[fieldNames.size()]), fieldTypes.toArray(new IAType[fieldTypes.size()]), !(canBeClosed && leftAllMatched && rightAllMatched), knowsAdditonalFieldNames ? allPossibleAdditionalFieldNames : null); }
private IAType buildOutputType(Deque<String> fieldPathStack, ARecordType inputRecordType, Set<String> fieldNameSet, List<List<String>> pathList) throws AlgebricksException { List<String> resultFieldNames = new ArrayList<>(); List<IAType> resultFieldTypes = new ArrayList<>(); String[] fieldNames = inputRecordType.getFieldNames(); IAType[] fieldTypes = inputRecordType.getFieldTypes(); for (int i = 0; i < fieldNames.length; i++) { if (!fieldNameSet.contains(fieldNames[i])) { // The main field is to be kept addField(inputRecordType, fieldNames[i], resultFieldNames, resultFieldTypes); } else if (!pathList.isEmpty() && fieldTypes[i].getTypeTag() == ATypeTag.OBJECT) { ARecordType subRecord = (ARecordType) fieldTypes[i]; fieldPathStack.push(fieldNames[i]); subRecord = deepCheckAndCopy(fieldPathStack, subRecord, pathList, inputRecordType.isOpen()); fieldPathStack.pop(); if (subRecord != null) { resultFieldNames.add(fieldNames[i]); resultFieldTypes.add(subRecord); } } } int n = resultFieldNames.size(); String resultTypeName = "result-record(" + inputRecordType.getTypeName() + ")"; return new ARecordType(resultTypeName, resultFieldNames.toArray(new String[n]), resultFieldTypes.toArray(new IAType[n]), true); // Make the output type open always }
private ARecordType getStrippedPKType(List<String> partitioningKeys, ARecordType recType) throws AlgebricksException, HyracksDataException { List<String> fieldNames = new LinkedList<>(); List<IAType> fieldTypes = new LinkedList<>(); int j = 0; for (int i = 0; i < recType.getFieldNames().length; i++) { IAType fieldType; if (partitioningKeys.get(0).equals(recType.getFieldNames()[j])) { if (recType.getFieldTypes()[j].getTypeTag() == ATypeTag.OBJECT) { if (j != 0) { throw new AsterixException("Autogenerated key " + StringUtils.join(partitioningKeys, '.') + " should be a first field of the type " + recType.getTypeName()); } partitioningKeys.remove(0); fieldType = getStrippedPKType(partitioningKeys, (ARecordType) recType.getFieldTypes()[j]); } else { j++; continue; } } else { fieldType = recType.getFieldTypes()[j]; } fieldTypes.add(fieldType); fieldNames.add(recType.getFieldNames()[j]); j++; } return new ARecordType(recType.getTypeName(), fieldNames.toArray(new String[0]), fieldTypes.toArray(new IAType[0]), recType.isOpen()); }
this.offsetPosition = 0; if (recType != null) { this.isOpen = recType.isOpen(); this.containsOptionalField = NonTaggedFormatUtil.hasOptionalField(recType); this.numberOfSchemaFields = recType.getFieldNames().length;
if (openFields[i] && !cachedReqType.isOpen()) {
resultType.getFieldTypes()[pos], sourceLoc); resultType = new ARecordType(resultType.getTypeName(), resultType.getFieldNames(), oldTypes, resultType.isOpen()); resultType = new ARecordType(resultType.getTypeName(), ArrayUtils.addAll(resultType.getFieldNames(), fieldType1Copy.getFieldNames()[i]), combinedFieldTypes, resultType.isOpen());
fieldValueType = recordType.getFieldTypes()[fieldIndex]; fieldValueOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, offset, fieldIndex, nullBitmapSize, recordType.isOpen());
if (recType.isOpen()) { AString as = new AString(fieldName); try {
int nullBitmapSize = RecordUtil.computeNullBitmapSize(recordType); subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, serRecordOffset, subFieldIndex, nullBitmapSize, recordType.isOpen()); if (subFieldOffset == 0) {
if (expr.getFunctionIdentifier().equals(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR)) { ARecordType reqType = (ARecordType) TypeCastUtils.getRequiredType(expr); if (reqType == null || !reqType.isOpen()) { int n = expr.getArguments().size(); if (n % 2 > 0) {
final int fieldIndex = recordType.getFieldIndex(fieldName); if (!recordType.isOpen() && fieldIndex < 0) { throw new RuntimeDataException(ErrorCode.PARSER_ADM_DATA_PARSER_EXTRA_FIELD_IN_CLOSED_RECORD, fieldName);
return new Datatype( datatype.getDataverseName(), datatype.getDatatypeName(), new ARecordType(aRecType.getTypeName(), aRecType.getFieldNames(), aRecType.getFieldTypes(), aRecType.isOpen()), datatype.getIsAnonymous());
fldIds[i] = recBuilder.getFieldId(name); if (fldIds[i] < 0) { if (!recordType.isOpen()) { throw new RuntimeDataException(ErrorCode.PARSER_DELIMITED_ILLEGAL_FIELD, name, recordType); } else {
if (recType != null) { fieldId = recBuilder.getFieldId(fldName); if (fieldId < 0 && !recType.isOpen()) { throw new HyracksDataException("This record is closed, you can not add extra fields !!"); } else if (fieldId < 0 && recType.isOpen()) { aStringFieldName.setValue(fldName); stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
booleanSerde.serialize(recType.isOpen() ? ABoolean.TRUE : ABoolean.FALSE, fieldValue.getDataOutput()); recordRecordBuilder.addField(MetadataRecordTypes.RECORDTYPE_ARECORD_ISOPEN_FIELD_INDEX, fieldValue);