summaryrefslogtreecommitdiffstats
path: root/src/arrow/c_glib/example/lua/read-batch.lua
blob: a4c86763f08e142a403d12383593dec465849885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements.  See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership.  The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License.  You may obtain a copy of the License at
--
--   http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied.  See the License for the
-- specific language governing permissions and limitations
-- under the License.

local lgi = require 'lgi'
local Arrow = lgi.Arrow

local input_path = arg[1] or "/tmp/batch.arrow";

local input = Arrow.MemoryMappedInputStream.new(input_path)
local reader = Arrow.RecordBatchFileReader.new(input)

for i = 0, reader:get_n_record_batches() - 1 do
   local record_batch = reader:read_record_batch(i)
   print(string.rep("=", 40))
   print("record-batch["..i.."]:")
   for j = 0, record_batch:get_n_columns() - 1 do
      local column_name = record_batch:get_column_name(j)
      local column_data = record_batch:get_column_data(j)
      io.write("  "..column_name..": [")
      for k = 0, record_batch:get_n_rows() - 1 do
	 if k > 0 then
	    io.write(", ")
	 end
	 io.write(column_data:get_value(k))
      end
      print("]")
   end
end

input:close()