ARecordType fieldType1Copy = (ARecordType) fieldType1; for (int i = 0; i < fieldType1Copy.getFieldTypes().length; i++) { String fname = fieldType1Copy.getFieldNames()[i]; int pos = resultType.getFieldIndex(fname); if (pos >= 0) { if (fieldType1Copy.getFieldTypes()[i].getTypeTag() == ATypeTag.OBJECT) { IAType[] oldTypes = resultType.getFieldTypes(); oldTypes[pos] = mergedNestedType(fname, fieldType1Copy.getFieldTypes()[i], resultType.getFieldTypes()[pos], sourceLoc); resultType = new ARecordType(resultType.getTypeName(), resultType.getFieldNames(), oldTypes, resultType.isOpen()); ArrayUtils.addAll(resultType.getFieldTypes().clone(), fieldType1Copy.getFieldTypes()[i]); resultType = new ARecordType(resultType.getTypeName(), ArrayUtils.addAll(resultType.getFieldNames(), fieldType1Copy.getFieldNames()[i]), combinedFieldTypes, resultType.isOpen());
private static boolean generalizeRecordFields(ARecordType leftType, ARecordType rightType, Set<String> allPossibleAdditionalFieldNames, List<String> fieldNames, List<IAType> fieldTypes) { boolean allMatched = true; Set<String> existingFieldNames = new HashSet<>(fieldNames); for (String fieldName : leftType.getFieldNames()) { IAType leftFieldType = leftType.getFieldType(fieldName); IAType rightFieldType = rightType.getFieldType(fieldName); IAType generalizedFieldType = rightFieldType == null ? null : generalizeTypes(leftFieldType, rightFieldType); if (generalizedFieldType == null || generalizedFieldType.equals(BuiltinType.ANY)) { allPossibleAdditionalFieldNames.add(fieldName); allMatched = false; } else if (!existingFieldNames.contains(fieldName)) { fieldNames.add(fieldName); fieldTypes.add(generalizedFieldType); } } return allMatched; }
private static IAType keyFieldType(List<String> expr, ARecordType recType) throws AlgebricksException { IAType fieldType = recType; fieldType = recType.getSubFieldType(expr); return fieldType; }
public static ARecordType createRecordType(String recordTypeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen) { ARecordType recordType = new ARecordType(recordTypeName, fieldNames, fieldTypes, isOpen); if (recordTypeName != null) { recordType.generateNestedDerivedTypeNames(); } return recordType; }
public static ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) { String[] fieldNames = new String[recType1.getFieldNames().length + recType2.getFieldNames().length]; IAType[] fieldTypes = new IAType[recType1.getFieldTypes().length + recType2.getFieldTypes().length]; int i = 0; for (; i < recType1.getFieldNames().length; i++) { fieldNames[i] = recType1.getFieldNames()[i]; fieldTypes[i] = recType1.getFieldTypes()[i]; } for (int j = 0; j < recType2.getFieldNames().length; i++, j++) { fieldNames[i] = recType2.getFieldNames()[j]; fieldTypes[i] = recType2.getFieldTypes()[j]; } return new ARecordType(null, fieldNames, fieldTypes, true); }
/** * Creates a map from name to type for fields in the passed type * * @param recordType the type to be mapped * @return a map mapping all fields to their types */ private static Map<String, IAType> createRecordNameTypeMap(ARecordType recordType) { LinkedHashMap<String, IAType> recordNameTypesMap = new LinkedHashMap<>(); for (int j = 0; j < recordType.getFieldNames().length; j++) { recordNameTypesMap.put(recordType.getFieldNames()[j], recordType.getFieldTypes()[j]); } return recordNameTypesMap; }
for (String fieldName : recType0.getFieldNames()) { resultFieldNames.add(fieldName); if (recType0.getFieldType(fieldName).getTypeTag() == ATypeTag.OBJECT) { ARecordType nestedType = (ARecordType) recType0.getFieldType(fieldName); resultFieldTypes.add(nestedType.deepCopy(nestedType)); } else { resultFieldTypes.add(recType0.getFieldType(fieldName)); String fieldNames[] = recType1.getFieldNames(); IAType fieldTypes[] = recType1.getFieldTypes(); for (int i = 0; i < fieldNames.length; ++i) { int pos = Collections.binarySearch(resultFieldNames, fieldNames[i]); String resultTypeName = "merged(" + recType0.getTypeName() + ", " + recType1.getTypeName() + ")"; boolean isOpen = recType0.isOpen() || recType1.isOpen(); IAType resultType = new ARecordType(resultTypeName, resultFieldNames.toArray(new String[] {}), resultFieldTypes.toArray(new IAType[] {}), isOpen);
if (reqType.isOpen() != inputRecType.isOpen()) { return false; IAType[] reqTypes = reqType.getFieldTypes(); String[] reqFieldNames = reqType.getFieldNames(); IAType[] inputTypes = inputRecType.getFieldTypes(); String[] inputFieldNames = ((ARecordType) inputType).getFieldNames();
public int getSchemeFieldCount(ARecordType recordType) { return recordType.getFieldNames().length; }
curTypes = curRecType.getFieldTypes(); curFNames = curRecType.getFieldNames(); for (IAType curType : curTypes) { if (!(curType instanceof AUnionType)) { recBuilder.init(); if (curRecType != null && !curRecType.isOpen()) { DataOutput fieldOutput = fieldValueBuffer.getDataOutput(); if (obj.get(curFNames[iter1]).isNull() && !(curTypes[iter1] instanceof AUnionType)) { if (curRecType.isClosedField(curFNames[iter1])) { throw new RuntimeDataException(ErrorCode.PARSER_TWEET_PARSER_CLOSED_FIELD_NULL, curFNames[iter1]); curFieldType = curRecType.getFieldType(attrName);
private Object getColTypes(ARecordType record) throws HyracksDataException { int n = record.getFieldTypes().length; if (n < 1) { throw new RuntimeDataException(ErrorCode.PARSER_HIVE_GET_COLUMNS); } //First Column String cols = getHiveTypeString(record.getFieldTypes(), 0); for (int i = 1; i < n; i++) { cols = cols + "," + getHiveTypeString(record.getFieldTypes(), i); } return cols; }
final IMutableValueStorage valueBuffer = parserContext.enterObject(); final IARecordBuilder objectBuilder = parserContext.getObjectBuilder(recordType); final BitSet nullBitMap = parserContext.getNullBitmap(recordType.getFieldTypes().length); while (nextToken() != ADMToken.OBJECT_END) { 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); } else { final IAType fieldType = recordType.getFieldType(fieldName);
this.offsetPosition = 0; if (recType != null) { this.isOpen = recType.isOpen(); this.containsOptionalField = NonTaggedFormatUtil.hasOptionalField(recType); this.numberOfSchemaFields = recType.getFieldNames().length; } else { this.isOpen = true;
private static ARecordType getStorageBlockCompressionType() { final String[] schemeName = { STORAGE_BLOCK_COMPRESSION_SCHEME_PARAMETER_NAME }; final IAType[] schemeType = { BuiltinType.ASTRING }; return new ARecordType(STORAGE_BLOCK_COMPRESSION_PARAMETER_NAME, schemeName, schemeType, 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); }
ARecordType subType = KeyFieldTypeUtil.chooseSource(keySourceIndicators, keyIndex, aRecordType, metaRecordType); boolean isOpen = subType.isOpen(); int i = 0; if (fieldExpr.first.size() > 1 && !isOpen) { while (i < fieldExpr.first.size() - 1 && !isOpen) { subType = (ARecordType) subType.getFieldType(fieldExpr.first.get(i)); i++; isOpen = subType.isOpen(); fieldType = subType.getSubFieldType(fieldExpr.first.subList(i, fieldExpr.first.size())); } else { if (!stmtCreateIndex.isEnforced() && stmtCreateIndex.getIndexType() != IndexType.BTREE) { && subType.getSubFieldType(fieldExpr.first.subList(i, fieldExpr.first.size())) != null) { throw new AsterixException(ErrorCode.INDEX_ILLEGAL_ENFORCED_ON_CLOSED_FIELD, sourceLoc, String.valueOf(fieldExpr.first)); List<List<String>> partitioningKeys = ds.getPrimaryKeys(); for (List<String> partitioningKey : partitioningKeys) { IAType keyType = aRecordType.getSubFieldType(partitioningKey); ITypeTraits typeTrait = TypeTraitProvider.INSTANCE.getTypeTrait(keyType);
int nullBitmapSize = RecordUtil.computeNullBitmapSize(recordType); subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, serRecordOffset, subFieldIndex, nullBitmapSize, recordType.isOpen()); if (subFieldOffset == 0) { return; ATypeTag fieldTypeTag = recordType.getFieldTypes()[subFieldIndex].getTypeTag(); subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset, fieldTypeTag, false);
private String getCompressionScheme(ARecord datasetRecord) { final ARecordType datasetType = datasetRecord.getType(); final int compressionIndex = datasetType .getFieldIndex(MetadataRecordTypes.DATASET_ARECORD_BLOCK_LEVEL_STORAGE_COMPRESSION_FIELD_NAME); if (compressionIndex >= 0) { final ARecordType compressionType = (ARecordType) datasetType.getFieldTypes()[compressionIndex]; final int schemeIndex = compressionType .getFieldIndex(MetadataRecordTypes.DATASET_ARECORD_DATASET_COMPRESSION_SCHEME_FIELD_NAME); return ((AString) datasetRecord.getValueByPos(schemeIndex)).getStringValue(); } return CompressionManager.NONE; }
/** * Returns true or false indicating whether or not a field is closed. * * @param fieldName * the name of the field to check * @return true if fieldName is a closed field, otherwise false */ public boolean isClosedField(String fieldName) { return getFieldIndex(fieldName) != -1; }
private static boolean isOpen(ARecordType recordType) { return recordType == null || recordType.isOpen(); }