|
| 1 | +################################################################################ |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +################################################################################ |
| 18 | + |
| 19 | +import os |
| 20 | +import pyarrow as pa |
| 21 | + |
| 22 | +from pypaimon import Schema |
| 23 | +from pypaimon.py4j.tests import PypaimonTestBase |
| 24 | + |
| 25 | + |
| 26 | +class ObjectInfoTest(PypaimonTestBase): |
| 27 | + |
| 28 | + @classmethod |
| 29 | + def setUpClass(cls): |
| 30 | + super().setUpClass() |
| 31 | + cls.simple_pa_schema = pa.schema([ |
| 32 | + ('f0', pa.int32()), |
| 33 | + ('f1', pa.string()) |
| 34 | + ]) |
| 35 | + |
| 36 | + def test_read_type_metadata(self): |
| 37 | + schema = Schema(self.simple_pa_schema) |
| 38 | + self.catalog.create_table('default.test_read_type_metadata', schema, False) |
| 39 | + table = self.catalog.get_table('default.test_read_type_metadata') |
| 40 | + |
| 41 | + read_builder = table.new_read_builder() |
| 42 | + read_builder.with_projection(['f1']) |
| 43 | + pa_schema = read_builder.read_type().as_arrow() |
| 44 | + |
| 45 | + self.assertEqual(len(pa_schema.names), 1) |
| 46 | + self.assertEqual(pa_schema.names[0], 'f1') |
| 47 | + |
| 48 | + def test_split_metadata(self): |
| 49 | + schema = Schema(self.simple_pa_schema) |
| 50 | + self.catalog.create_table('default.test_split_metadata', schema, False) |
| 51 | + table = self.catalog.get_table('default.test_split_metadata') |
| 52 | + |
| 53 | + write_builder = table.new_batch_write_builder() |
| 54 | + table_write = write_builder.new_write() |
| 55 | + table_commit = write_builder.new_commit() |
| 56 | + data = { |
| 57 | + 'f0': [1, 2, 3, 4, 5], |
| 58 | + 'f1': ['a', 'b', 'c', 'd', 'e'], |
| 59 | + } |
| 60 | + pa_table = pa.Table.from_pydict(data, schema=self.simple_pa_schema) |
| 61 | + table_write.write_arrow(pa_table) |
| 62 | + table_commit.commit(table_write.prepare_commit()) |
| 63 | + table_write.close() |
| 64 | + table_commit.close() |
| 65 | + read_builder = table.new_read_builder() |
| 66 | + table_scan = read_builder.new_scan() |
| 67 | + splits = table_scan.plan().splits() |
| 68 | + |
| 69 | + self.assertEqual(len(splits), 1) |
| 70 | + self.assertEqual(len(splits[0].file_paths()), 1) |
| 71 | + self.assertEqual(splits[0].row_count(), 5) |
| 72 | + self.assertTrue(splits[0].file_paths()[0].endswith('.parquet')) |
| 73 | + self.assertEqual(splits[0].file_size(), os.path.getsize(splits[0].file_paths()[0])) |
0 commit comments