use of org.apache.asterix.common.annotations.RecordDataGenAnnotation in project asterixdb by apache.
the class AdmDataGen method dataGen.
public void dataGen() throws Exception {
for (Map.Entry<TypeSignature, IAType> me : typeMap.entrySet()) {
TypeSignature tn = me.getKey();
TypeDataGen tdg = typeAnnotMap.get(tn);
if (tdg.isDataGen()) {
IAType t = me.getValue();
if (t.getTypeTag() != ATypeTag.OBJECT) {
throw new NotImplementedException();
}
ARecordType rt = (ARecordType) t;
RecordDataGenAnnotation dga = firstDataGenAnnotation(rt);
if (dga == null) {
throw new Exception("No data generator annotations for type " + tn);
}
File outFile = new File(outputDir + File.separator + tdg.getOutputFileName());
PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outFile)));
RecordGenerator rg = new RecordGenerator(rt, dga, "\n");
rg.init(outStream, dgCtx);
for (long i = 0; i < tdg.getNumValues(); i++) {
rg.generate();
}
outStream.close();
}
}
}
use of org.apache.asterix.common.annotations.RecordDataGenAnnotation in project asterixdb by apache.
the class TypeTranslator method computeRecordType.
private static ARecordType computeRecordType(TypeSignature typeSignature, RecordTypeDefinition rtd, Map<TypeSignature, IAType> typeMap, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, String defaultDataverse) throws AsterixException {
List<String> names = rtd.getFieldNames();
int n = names.size();
String[] fldNames = new String[n];
IAType[] fldTypes = new IAType[n];
int i = 0;
for (String s : names) {
fldNames[i++] = s;
}
boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
ARecordType recType = new ARecordType(typeSignature == null ? null : typeSignature.getName(), fldNames, fldTypes, isOpen);
List<IRecordFieldDataGen> fieldDataGen = rtd.getFieldDataGen();
if (fieldDataGen.size() == n) {
IRecordFieldDataGen[] rfdg = new IRecordFieldDataGen[n];
rfdg = fieldDataGen.toArray(rfdg);
recType.getAnnotations().add(new RecordDataGenAnnotation(rfdg, rtd.getUndeclaredFieldsDataGen()));
}
for (int j = 0; j < n; j++) {
TypeExpression texpr = rtd.getFieldTypes().get(j);
switch(texpr.getTypeKind()) {
case TYPEREFERENCE:
{
TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
TypeSignature signature = new TypeSignature(tre.getIdent().first == null ? defaultDataverse : tre.getIdent().first.getValue(), tre.getIdent().second.getValue());
IAType tref = solveTypeReference(signature, typeMap);
if (tref != null) {
if (!rtd.getOptionableFields().get(j)) {
// not nullable
fldTypes[j] = tref;
} else {
// optional
fldTypes[j] = AUnionType.createUnknownableType(tref);
}
} else {
addIncompleteFieldTypeReference(recType, j, tre, incompleteFieldTypes);
if (rtd.getOptionableFields().get(j)) {
fldTypes[j] = AUnionType.createUnknownableType(null);
}
}
break;
}
case RECORD:
{
RecordTypeDefinition recTypeDef2 = (RecordTypeDefinition) texpr;
IAType t2 = computeRecordType(null, recTypeDef2, typeMap, incompleteFieldTypes, incompleteItemTypes, defaultDataverse);
if (!rtd.getOptionableFields().get(j)) {
// not nullable
fldTypes[j] = t2;
} else {
// nullable
fldTypes[j] = AUnionType.createUnknownableType(t2);
}
break;
}
case ORDEREDLIST:
{
OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
IAType t2 = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes, defaultDataverse);
fldTypes[j] = rtd.getOptionableFields().get(j) ? AUnionType.createUnknownableType(t2) : t2;
break;
}
case UNORDEREDLIST:
{
UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
IAType t2 = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes, defaultDataverse);
fldTypes[j] = rtd.getOptionableFields().get(j) ? AUnionType.createUnknownableType(t2) : t2;
break;
}
default:
{
throw new IllegalStateException();
}
}
}
return recType;
}
Aggregations