Skip to content

Commit e081f7d

Browse files
committed
Add collect_demanded_relations
1 parent a8cb9fb commit e081f7d

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

sdks/julia/LogicalQueryProtocol.jl/src/properties.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,61 @@ function is_supported_decimal_bits(bits::Integer)
9898
return bits in [8, 16, 32, 64, 128]
9999
end
100100

101+
"""
102+
collect_demanded_relations(epoch::Epoch)::Set{LQPRelationId}
103+
104+
Collect the set of relation IDs that are demanded by the reads of an epoch.
105+
"""
106+
function collect_demanded_relations(epoch::Epoch)
107+
ids = Set{LQPRelationId}()
108+
for read in epoch.reads
109+
_collect_read_ids!(ids, read)
110+
end
111+
return ids
112+
end
113+
114+
function _collect_read_ids!(ids::Set{LQPRelationId}, read::Read)
115+
isnothing(read.read_type) && return nothing
116+
if read.read_type.name == :demand
117+
_collect_read_ids!(ids, read.read_type[]::Demand)
118+
elseif read.read_type.name == :output
119+
_collect_read_ids!(ids, read.read_type[]::Output)
120+
elseif read.read_type.name == :abort
121+
_collect_read_ids!(ids, read.read_type[]::Abort)
122+
elseif read.read_type.name == :var"#export"
123+
_collect_read_ids!(ids, read.read_type[]::Export)
124+
else
125+
@assert false
126+
end
127+
return nothing
128+
end
129+
function _collect_read_ids!(ids::Set{LQPRelationId}, demand::Demand)
130+
!isnothing(demand.relation_id) && push!(ids, persistent_id(demand.relation_id))
131+
return nothing
132+
end
133+
function _collect_read_ids!(ids::Set{LQPRelationId}, output::Output)
134+
!isnothing(output.relation_id) && push!(ids, persistent_id(output.relation_id))
135+
return nothing
136+
end
137+
function _collect_read_ids!(ids::Set{LQPRelationId}, abort::Abort)
138+
!isnothing(abort.relation_id) && push!(ids, persistent_id(abort.relation_id))
139+
return nothing
140+
end
141+
function _collect_read_ids!(ids::Set{LQPRelationId}, _export::Export)
142+
isnothing(_export.export_config) && return nothing
143+
config = _export.export_config
144+
if config.name == :csv_config
145+
csv_config = config[]::ExportCSVConfig
146+
for column in csv_config.data_columns
147+
!isnothing(column.column_data) && push!(ids, persistent_id(column.column_data))
148+
end
149+
elseif config.name == :iceberg_config
150+
iceberg_config = config[]::ExportIcebergConfig
151+
!isnothing(iceberg_config.table_def) && push!(ids, persistent_id(iceberg_config.table_def))
152+
end
153+
return nothing
154+
end
155+
101156
persistent_id(fragment::Fragment) = persistent_id(fragment.id::FragmentId)
102157
persistent_id(id::FragmentId) = LQPFragmentId(id.id)
103158
persistent_id(id::RelationId) = UInt128(id.id_low) + (UInt128(id.id_high) << 64)

0 commit comments

Comments
 (0)