Search in sources :

Example 1 with NestableCollectExpression.forFunction

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()));
            });
    }
}
Also used : DocSysColumns(io.crate.metadata.doc.DocSysColumns) NestableCollectExpression.forFunction(io.crate.execution.engine.collect.NestableCollectExpression.forFunction) List(java.util.List) Maps(io.crate.common.collections.Maps) CollectExpression(io.crate.execution.engine.collect.CollectExpression) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) NestableCollectExpression(io.crate.execution.engine.collect.NestableCollectExpression) ValueExtractors(io.crate.expression.ValueExtractors) PartitionName(io.crate.metadata.PartitionName) ColumnIdent(io.crate.metadata.ColumnIdent)

Aggregations

Maps (io.crate.common.collections.Maps)1 CollectExpression (io.crate.execution.engine.collect.CollectExpression)1 NestableCollectExpression (io.crate.execution.engine.collect.NestableCollectExpression)1 NestableCollectExpression.forFunction (io.crate.execution.engine.collect.NestableCollectExpression.forFunction)1 ValueExtractors (io.crate.expression.ValueExtractors)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 PartitionName (io.crate.metadata.PartitionName)1 Reference (io.crate.metadata.Reference)1 DocSysColumns (io.crate.metadata.doc.DocSysColumns)1 List (java.util.List)1