All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.neo4j.server.http.cypher.entity.HttpExecutionPlanDescription Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [http://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.server.http.cypher.entity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.neo4j.graphdb.ExecutionPlanDescription;
import org.neo4j.kernel.impl.util.DefaultValueMapper;
import org.neo4j.values.AnyValue;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.virtual.ListValue;
import org.neo4j.values.virtual.MapValue;

import static org.neo4j.server.http.cypher.entity.HttpProfilerStatistics.fromMapValue;

public class HttpExecutionPlanDescription implements ExecutionPlanDescription
{
    private final String name;
    private final List children;
    private final Map arguments;
    private final Set identifiers;
    private final ProfilerStatistics profilerStatistics;
    private static final DefaultValueMapper valueMapper = new DefaultValueMapper( null );

    public HttpExecutionPlanDescription( String name, List children,
                                         Map arguments, Set identifiers,
                                         ProfilerStatistics profilerStatistics )
    {
        this.name = name;
        this.children = children;
        this.arguments = arguments;
        this.identifiers = identifiers;
        this.profilerStatistics = profilerStatistics;
    }

    public static ExecutionPlanDescription fromAnyValue( AnyValue anyValue )
    {
        if ( anyValue == null )
        {
            return EMPTY;
        }
        else
        {
            MapValue mapValue = (MapValue) anyValue;
            ProfilerStatistics profilerStatistics = fromMapValue( mapValue );

            return new HttpExecutionPlanDescription( ((TextValue) mapValue.get( "operatorType" )).stringValue(),
                                                     extractChildren( (ListValue) mapValue.get( "children" ) ),
                                                     extractArguments( (MapValue) mapValue.get( "args" ) ),
                                                     extractIdentifiers( (ListValue) mapValue.get( "identifiers" ) ),
                                                     profilerStatistics
            );
        }
    }

    private static List extractChildren( ListValue listValue )
    {
        var children = new ArrayList();
        listValue.forEach( v -> children.add( fromAnyValue( v ) ) );
        return children;
    }

    private static Set extractIdentifiers( ListValue identifiers )
    {
        List identifierList = (List) identifiers.map( valueMapper );
        return new HashSet<>( identifierList );
    }

    private static Map extractArguments( MapValue argumentsMapValue )
    {
        return (Map) argumentsMapValue.map( valueMapper );
    }

    @Override
    public String getName()
    {
        return name;
    }

    @Override
    public List getChildren()
    {
        return children;
    }

    @Override
    public Map getArguments()
    {
        return arguments;
    }

    @Override
    public Set getIdentifiers()
    {
        return identifiers;
    }

    @Override
    public boolean hasProfilerStatistics()
    {
        return profilerStatistics == null;
    }

    @Override
    public ProfilerStatistics getProfilerStatistics()
    {
        return profilerStatistics;
    }

    public static ExecutionPlanDescription EMPTY = new ExecutionPlanDescription()
    {
        @Override
        public String getName()
        {
            return "";
        }

        @Override
        public List getChildren()
        {
            return Collections.emptyList();
        }

        @Override
        public Map getArguments()
        {
            return Collections.emptyMap();
        }

        @Override
        public Set getIdentifiers()
        {
            return Collections.emptySet();
        }

        @Override
        public boolean hasProfilerStatistics()
        {
            return false;
        }

        @Override
        public ProfilerStatistics getProfilerStatistics()
        {
            return null;
        }
    };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy