/** * Maintains the {@code updatedRecordType} as nullable/missable (?) in case it was originally nullable/missable * @param originalRecordType the original record type * @param updatedRecordType the original record type being enforced/modified with new non-declared fields included * @return {@code updatedRecordType} */ private static IAType keepUnknown(IAType originalRecordType, ARecordType updatedRecordType) { if (originalRecordType.getTypeTag() == ATypeTag.UNION) { return AUnionType.createUnknownableType(updatedRecordType, updatedRecordType.getTypeName()); } return updatedRecordType; }
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 }
return null; return new ARecordType(srcRecType.getTypeName(), destFieldNames.toArray(new String[n]), destFieldTypes.toArray(new IAType[n]), isOpen);
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()); }
@Override public void generateNestedDerivedTypeNames() { for (int i = 0; i < fieldTypes.length; i++) { IAType fieldType = fieldTypes[i]; if (fieldType.getTypeTag().isDerivedType() && (fieldType.getTypeName() == null)) { AbstractComplexType nestedType = (AbstractComplexType) fieldType; nestedType.setTypeName(getTypeName() + "_" + fieldNames[i]); nestedType.generateNestedDerivedTypeNames(); } } }
String resultTypeName = "appended(" + inputRecordType.getTypeName() + ")"; int n = resultFieldNames.size(); IAType resultType = new ARecordType(resultTypeName, resultFieldNames.toArray(new String[n]),
AUnionType.createUnknownableType(index.getKeyFieldTypes().get(i))); enforcedRecordType = new ARecordType(lastNestedRecord.getTypeName(), recordNameTypesMap.keySet().toArray(new String[recordNameTypesMap.size()]), recordNameTypesMap.values().toArray(new IAType[recordNameTypesMap.size()]), IAType[] nestedRecTypeFieldTypes = nestedRecType.getFieldTypes().clone(); nestedRecTypeFieldTypes[nestedRecType.getFieldIndex(nestedType.second)] = enforcedRecordType; enforcedRecordType = new ARecordType(nestedRecType.getTypeName() + "_enforced", nestedRecType.getFieldNames(), nestedRecTypeFieldTypes, nestedRecType.isOpen());
String resultTypeName = "merged(" + recType0.getTypeName() + ", " + recType1.getTypeName() + ")"; boolean isOpen = recType0.isOpen() || recType1.isOpen();
/** * Inserts a metadata dataset to the physical dataset index Should be performed * on a bootstrap of a new universe * * @param mdTxnCtx * @param indexes * @throws AlgebricksException */ public static void insertMetadataDatasets(MetadataTransactionContext mdTxnCtx, IMetadataIndex[] indexes) throws AlgebricksException { for (int i = 0; i < indexes.length; i++) { IDatasetDetails id = new InternalDatasetDetails(FileStructure.BTREE, PartitioningStrategy.HASH, indexes[i].getPartitioningExpr(), indexes[i].getPartitioningExpr(), null, indexes[i].getPartitioningExprType(), false, null); MetadataManager.INSTANCE.addDataset(mdTxnCtx, new Dataset(indexes[i].getDataverseName(), indexes[i].getIndexedDatasetName(), indexes[i].getDataverseName(), indexes[i].getPayloadRecordType().getTypeName(), indexes[i].getNodeGroupName(), GlobalConfig.DEFAULT_COMPACTION_POLICY_NAME, GlobalConfig.DEFAULT_COMPACTION_POLICY_PROPERTIES, id, new HashMap<String, String>(), DatasetType.INTERNAL, indexes[i].getDatasetId().getId(), MetadataUtil.PENDING_NO_OP)); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Finished inserting initial datasets."); } }
oldTypes[pos] = mergedNestedType(fname, fieldType1Copy.getFieldTypes()[i], resultType.getFieldTypes()[pos], sourceLoc); resultType = new ARecordType(resultType.getTypeName(), resultType.getFieldNames(), oldTypes, resultType.isOpen()); IAType[] combinedFieldTypes = ArrayUtils.addAll(resultType.getFieldTypes().clone(), fieldType1Copy.getFieldTypes()[i]); resultType = new ARecordType(resultType.getTypeName(), ArrayUtils.addAll(resultType.getFieldNames(), fieldType1Copy.getFieldNames()[i]), combinedFieldTypes, resultType.isOpen());
datatype.getDataverseName(), datatype.getDatatypeName(), new ARecordType(aRecType.getTypeName(), aRecType.getFieldNames(), aRecType.getFieldTypes(), aRecType.isOpen()), datatype.getIsAnonymous());
outputType.getTypeName()); MetadataManager.INSTANCE.addFeedConnection(metadataProvider.getMetadataTxnContext(), fc); MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);