You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kou (via GitHub)" <gi...@apache.org> on 2023/06/25 20:24:24 UTC

[GitHub] [arrow] kou commented on issue #36291: [Ruby] Allow dynamic queries defined at runtime (e.g. based on user input)

kou commented on issue #36291:
URL: https://github.com/apache/arrow/issues/36291#issuecomment-1606251661

   It's dynamic. Here are examples to build conditions by arguments:
   
   ```ruby
   def read1(status, message)
     Arrow::FileInputStream.open(file) do |input|
       reader = Parquet::ArrowFileReader.new(input)
       reader.n_row_groups.times do |i|
         table = reader.read_row_group(i)
         result = table.slice { |slicer| (slicer['status'] == status) & (slicer['message'].match_substring? message) }
         puts result if result.n_rows > 0
       end
     end
   end
   ```
   
   ```ruby
   def read2(status: nil, message: nil)
     Arrow::FileInputStream.open(file) do |input|
       reader = Parquet::ArrowFileReader.new(input)
       reader.n_row_groups.times do |i|
         table = reader.read_row_group(i)
         result = table.slice do |slicer|
           conditions = []
           conditions << (slicer['status'] == status) if status
           conditions << (slicer['message'].match_substring? message) if message
           conditions.inject(:&)
         end
         puts result if result.n_rows > 0
       end
     end
   end
   ```
   
   ```ruby
   def read3(conditions)
     Arrow::FileInputStream.open(file) do |input|
       reader = Parquet::ArrowFileReader.new(input)
       reader.n_row_groups.times do |i|
         table = reader.read_row_group(i)
         result = table.slice do |slicer|
           conditions = conditions.collect do |operator, target, *args|
             slicer[target].public_send(operator, *args)
           end
           conditions.inject(:&)
         end
         puts result if result.n_rows > 0
       end
     end
   end
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org