use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory in project asterixdb by apache.
the class NonTaggedDataFormat method getFieldAccessEvaluatorFactory.
@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getFieldAccessEvaluatorFactory(ARecordType recType, List<String> fldName, int recordColumn) throws AlgebricksException {
String[] names = recType.getFieldNames();
int n = names.length;
boolean fieldFound = false;
IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(recordColumn);
ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
DataOutput dos = abvs.getDataOutput();
IScalarEvaluatorFactory evalFactory = null;
if (fldName.size() == 1) {
for (int i = 0; i < n; i++) {
if (names[i].equals(fldName.get(0))) {
fieldFound = true;
try {
AInt32 ai = new AInt32(i);
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
IScalarEvaluatorFactory fldIndexEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
evalFactory = new FieldAccessByIndexEvalFactory(recordEvalFactory, fldIndexEvalFactory, recType);
return evalFactory;
}
}
}
if (fldName.size() > 1 || (!fieldFound && recType.isOpen())) {
if (fldName.size() == 1) {
AString as = new AString(fldName.get(0));
try {
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
} else {
AOrderedList as = new AOrderedList(fldName);
try {
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
}
IScalarEvaluatorFactory[] factories = new IScalarEvaluatorFactory[2];
factories[0] = recordEvalFactory;
if (fldName.size() > 1) {
evalFactory = new FieldAccessNestedEvalFactory(recordEvalFactory, recType, fldName);
} else {
evalFactory = FieldAccessByNameDescriptor.FACTORY.createFunctionDescriptor().createEvaluatorFactory(factories);
}
return evalFactory;
} else {
throw new AlgebricksException("Could not find field " + fldName + " in the schema.");
}
}
Aggregations