]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/c_glib/example/lua/read-stream.lua
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / example / lua / read-stream.lua
1 -- Licensed to the Apache Software Foundation (ASF) under one
2 -- or more contributor license agreements. See the NOTICE file
3 -- distributed with this work for additional information
4 -- regarding copyright ownership. The ASF licenses this file
5 -- to you under the Apache License, Version 2.0 (the
6 -- "License"); you may not use this file except in compliance
7 -- with the License. You may obtain a copy of the License at
8 --
9 -- http://www.apache.org/licenses/LICENSE-2.0
10 --
11 -- Unless required by applicable law or agreed to in writing,
12 -- software distributed under the License is distributed on an
13 -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 -- KIND, either express or implied. See the License for the
15 -- specific language governing permissions and limitations
16 -- under the License.
17
18 local lgi = require 'lgi'
19 local Arrow = lgi.Arrow
20
21 local input_path = arg[1] or "/tmp/stream.arrow";
22
23 local input = Arrow.MemoryMappedInputStream.new(input_path)
24 local reader = Arrow.RecordBatchStreamReader.new(input)
25
26 local i = 0
27 while true do
28 local record_batch = reader:read_next()
29 if not record_batch then
30 break
31 end
32
33 print(string.rep("=", 40))
34 print("record-batch["..i.."]:")
35 for j = 0, record_batch:get_n_columns() - 1 do
36 local column_name = record_batch:get_column_name(j)
37 local column_data = record_batch:get_column_data(j)
38 io.write(" "..column_name..": [")
39 for k = 0, record_batch:get_n_rows() - 1 do
40 if k > 0 then
41 io.write(", ")
42 end
43 io.write(column_data:get_value(k))
44 end
45 print("]")
46 end
47
48 i = i + 1
49 end
50
51 input:close()