class StaticTableReferenceResolver<R> implements ReferenceResolver<NestableCollectExpression<R, ?>> {

    private final Map<ColumnIdent, ? extends RowCollectExpressionFactory<R>> expressionFactories;

    public StaticTableReferenceResolver(Map<ColumnIdent, ? extends RowCollectExpressionFactory<R>> expressionFactories) {
        this.expressionFactories = expressionFactories;
    }

    @Override
    public NestableCollectExpression<R, ?> getImplementation(Reference ref) {
        return rowCollectExpressionFromFactoryMap(expressionFactories, ref);
    }

    private static <R> NestableCollectExpression<R, ?> rowCollectExpressionFromFactoryMap(
        Map<ColumnIdent, ? extends RowCollectExpressionFactory<R>> factories,
        Reference ref) {

        ColumnIdent columnIdent = ref.column();
        RowCollectExpressionFactory<R> factory = factories.get(columnIdent);
        if (factory != null) {
            return factory.create();
        }
        if (columnIdent.isRoot()) {
            return null;
        }
        return getImplementationByRootTraversal(factories, columnIdent);
    }

    private static <R> NestableCollectExpression<R, ?> getImplementationByRootTraversal(
        Map<ColumnIdent, ? extends RowCollectExpressionFactory<R>> innerFactories,
        ColumnIdent columnIdent) {<FILL_FUNCTION_BODY>}
}


        RowCollectExpressionFactory<R> factory = innerFactories.get(columnIdent.getRoot());
        if (factory == null) {
            return null;
        }
        NestableInput<?> refImpl = factory.create();
        NestableInput<?> childByPath = NestableInput.getChildByPath(refImpl, columnIdent.path());
        assert childByPath instanceof NestableCollectExpression
            : "Child " + columnIdent.path() + " of " + refImpl + " must be a NestableCollectExpression";
        return (NestableCollectExpression<R, ?>) childByPath;
    
<no_super_class>