use of io.crate.execution.engine.collect.NestableCollectExpression.forFunction in project crate by crate.
the class DocRefResolver method getImplementation.
@Override
public CollectExpression<Doc, ?> getImplementation(Reference ref) {
ColumnIdent columnIdent = ref.column();
String fqn = columnIdent.fqn();
switch(fqn) {
case DocSysColumns.Names.VERSION:
return forFunction(Doc::getVersion);
case DocSysColumns.Names.SEQ_NO:
return forFunction(Doc::getSeqNo);
case DocSysColumns.Names.PRIMARY_TERM:
return forFunction(Doc::getPrimaryTerm);
case DocSysColumns.Names.ID:
return NestableCollectExpression.forFunction(Doc::getId);
case DocSysColumns.Names.DOCID:
return forFunction(Doc::docId);
case DocSysColumns.Names.RAW:
return forFunction(Doc::getRaw);
case DocSysColumns.Names.DOC:
return forFunction(Doc::getSource);
default:
for (int i = 0; i < partitionedByColumns.size(); i++) {
var pColumn = partitionedByColumns.get(i);
if (pColumn.equals(columnIdent)) {
final int idx = i;
return forFunction(getResp -> ref.valueType().implicitCast(PartitionName.fromIndexOrTemplate(getResp.getIndex()).values().get(idx)));
} else if (pColumn.isChildOf(columnIdent)) {
final int idx = i;
return forFunction(response -> {
if (response == null) {
return null;
}
var partitionName = PartitionName.fromIndexOrTemplate(response.getIndex());
var partitionValue = partitionName.values().get(idx);
var source = response.getSource();
Maps.mergeInto(source, pColumn.name(), pColumn.path(), partitionValue);
return ref.valueType().implicitCast(ValueExtractors.fromMap(source, columnIdent));
});
}
}
return forFunction(response -> {
if (response == null) {
return null;
}
return ref.valueType().implicitCast(ValueExtractors.fromMap(response.getSource(), ref.column()));
});
}
}
Aggregations