Class: Neo4j::Driver::Summary::ResultSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/driver/summary/result_summary.rb

Overview

Summary of query execution. Mirrors Java's org.neo4j.driver.summary.ResultSummary — same name and place in the namespace; no public metadata accessor, no Bolt-wire-format leakage.

Instance Method Summary collapse

Constructor Details

#initialize(metadata, query_text = nil, parameters = {}, connection = nil, had_record: false) ⇒ ResultSummary

Returns a new instance of ResultSummary.



11
12
13
14
15
16
17
# File 'lib/neo4j/driver/summary/result_summary.rb', line 11

def initialize(, query_text = nil, parameters = {}, connection = nil, had_record: false)
  @metadata = 
  @query_text = query_text
  @parameters = parameters
  @connection = connection
  @had_record = had_record
end

Instance Method Details

#countersObject



42
43
44
# File 'lib/neo4j/driver/summary/result_summary.rb', line 42

def counters
  @counters ||= SummaryCounters.new(@metadata[:stats] || {})
end

#databaseObject



61
62
63
# File 'lib/neo4j/driver/summary/result_summary.rb', line 61

def database
  @database_info ||= DatabaseInfo.new(@metadata[:db])
end

#gql_status_objectsObject

GQL status objects. Bolt 5.6+ servers report them natively in the summary statuses list, which we preserve verbatim (server order — the driver must not reorder them). Older servers (or any SUCCESS without statuses) don't, so we synthesise the list from the legacy notifications plus a mandatory outcome status — the pre-5.6 backfill. A status carrying a neo4j_code is also a notification (GqlNotification); the rest are plain status objects.



125
126
127
128
129
# File 'lib/neo4j/driver/summary/result_summary.rb', line 125

def gql_status_objects
  (@metadata[:statuses] || polyfilled_statuses).map do |status|
    (status[:neo4j_code] ? GqlNotification : GqlStatusObject).new(status)
  end
end

#has_plan?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/neo4j/driver/summary/result_summary.rb', line 100

def has_plan?
  !@metadata[:plan].nil? || !@metadata[:profile].nil?
end

#has_profile?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/neo4j/driver/summary/result_summary.rb', line 104

def has_profile?
  !@metadata[:profile].nil?
end

#notificationsObject

Bolt 5.5+ servers report query info via statuses (GQL status objects) rather than the legacy notifications list. Statuses without a neo4j_code are pure-GQL info (e.g. "successful completion") and have no legacy-notification equivalent, so we drop them; the rest are reshaped to look like notifications.



113
114
115
116
# File 'lib/neo4j/driver/summary/result_summary.rb', line 113

def notifications
  (@metadata[:notifications] || statuses_as_notifications)
    .map { |n| Notification.new(n) }
end

#planObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/neo4j/driver/summary/result_summary.rb', line 75

def plan
  return @plan if defined?(@plan)

  @plan =
    if @metadata[:plan]
      Plan.new(@metadata[:plan])
    elsif @metadata[:profile]
      # A profiled query exposes both: `plan` is the plan-only view
      # (no stats), `profile` adds them. Distinct objects, matching
      # the Java driver 6.2 model.
      Plan.new(@metadata[:profile])
    end
end

#profileObject



89
90
91
92
93
# File 'lib/neo4j/driver/summary/result_summary.rb', line 89

def profile
  return @profile if defined?(@profile)

  @profile = @metadata[:profile] ? Profile.new(@metadata[:profile]) : nil
end

#queryObject



19
20
21
# File 'lib/neo4j/driver/summary/result_summary.rb', line 19

def query
  Query.new(@query_text, @parameters)
end

#query_profileObject

MRI has a single profile concept; the modern (JRuby 6.2) query_profile accessor maps to it. MRI doesn't advertise OptionalStats, so absent stats still default to 0 (testkit uses its strict-driver path).



98
# File 'lib/neo4j/driver/summary/result_summary.rb', line 98

def query_profile = profile

#query_typeObject

Mirrors Java's ResultSummary#queryType — returns nil only when the server omitted the :type field (testkit relies on this). A field that is present but holds anything other than a known code — an unrecognised string, or an explicit null — is a protocol violation, so we raise (Java's extractQueryType chokes on those too) rather than silently returning nil.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/neo4j/driver/summary/result_summary.rb', line 29

def query_type
  return nil unless @metadata.key?(:type)

  case @metadata[:type]
  when 'r' then QueryType::READ_ONLY
  when 'w' then QueryType::WRITE_ONLY
  when 'rw' then QueryType::READ_WRITE
  when 's' then QueryType::SCHEMA_WRITE
  else
    raise Exceptions::ProtocolException, "Unexpected query type: #{@metadata[:type].inspect}"
  end
end

#result_available_afterObject

Time until results are available (milliseconds). 't_first' on the wire.



66
67
68
# File 'lib/neo4j/driver/summary/result_summary.rb', line 66

def result_available_after
  @metadata[:t_first]
end

#result_consumed_afterObject

Time to consume results (milliseconds). 't_last' on the wire.



71
72
73
# File 'lib/neo4j/driver/summary/result_summary.rb', line 71

def result_consumed_after
  @metadata[:t_last]
end

#serverObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/neo4j/driver/summary/result_summary.rb', line 46

def server
  @server_info ||=
    if @metadata[:server]
      ServerInfo.new(@metadata[:server])
    elsif @connection
      ServerInfo.new(
        address: @connection.address,
        agent: @connection.server_agent,
        protocol_version: @connection.protocol&.version
      )
    else
      ServerInfo.new(nil)
    end
end