Gabriel39 commented on code in PR #68614: URL: https://github.com/apache/doris/pull/68614#discussion_r4130325541
########## samples/arrow-flight-sql/python/test_nested_type_metadata.py: ########## @@ -0,0 +1,92 @@ +# 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. + +"""Run with DORIS_FLIGHT_SQL_URI and optional DORIS_USER/DORIS_PASSWORD. + +LARGEINT retains its string storage encoding. PyArrow does not interpret custom +field metadata automatically; applications can use doris_type to distinguish +these strings from text and convert them to Python integers without losing range. +""" + +import os +import unittest + +import adbc_driver_flightsql.dbapi as flight_sql +import adbc_driver_manager +import pyarrow as pa + + [email protected](os.getenv("DORIS_FLIGHT_SQL_URI"), "Set DORIS_FLIGHT_SQL_URI to run against Doris") +class NestedTypeMetadataTest(unittest.TestCase): + def setUp(self): + self.connection = flight_sql.connect( + uri=os.environ["DORIS_FLIGHT_SQL_URI"], + db_kwargs={ + adbc_driver_manager.DatabaseOptions.USERNAME.value: os.getenv("DORIS_USER", "root"), + adbc_driver_manager.DatabaseOptions.PASSWORD.value: os.getenv("DORIS_PASSWORD", ""), + }, + ) + self.addCleanup(self.connection.close) + self.cursor = self.connection.cursor() + self.addCleanup(self.cursor.close) + + def assert_logical_type(self, field, name): + self.assertEqual((field.metadata or {}).get(b"doris_type"), name.encode()) + + def test_largeint_metadata_and_full_range(self): + self.cursor.execute(""" + SELECT CAST('170141183460469231731687303715884105727' AS LARGEINT) AS scalar_value, + named_struct('number', CAST(17 AS LARGEINT), 'text', '17') AS struct_value, + array(CAST('-170141183460469231731687303715884105728' AS LARGEINT), + CAST(NULL AS LARGEINT)) AS array_value, + map(CAST(17 AS LARGEINT), CAST(19 AS LARGEINT)) AS map_value + """) + table = self.cursor.fetch_arrow_table() + table.validate(full=True) + self.assert_logical_type(table.schema.field("scalar_value"), "LARGEINT") + structure = table.schema.field("struct_value").type + self.assert_logical_type(structure.field("number"), "LARGEINT") + self.assertNotIn(b"doris_type", structure.field("text").metadata or {}) + self.assert_logical_type(table.schema.field("array_value").type.value_field, "LARGEINT") + mapping = table.schema.field("map_value").type + self.assert_logical_type(mapping.key_field, "LARGEINT") + self.assert_logical_type(mapping.item_field, "LARGEINT") + self.assertFalse(mapping.key_field.nullable) + self.assertTrue(pa.types.is_string(table.schema.field("scalar_value").type)) + row = table.to_pylist()[0] + self.assertEqual(row["scalar_value"], str(2**127 - 1)) + self.assertEqual(row["array_value"], [str(-(2**127)), None]) + self.assertEqual(row["struct_value"], {"number": "17", "text": "17"}) + self.assertEqual(row["map_value"], [("17", "19")]) + + def test_other_logical_types(self): + self.cursor.execute(""" + SELECT array(CAST('192.0.2.1' AS IPV4)) AS ip4, + named_struct('address', CAST('2001:db8::1' AS IPV6)) AS ip6, + map('k', CAST('{"n":1}' AS JSON)) AS json_value, Review Comment: Fixed in c9a595013c. Fixed by splitting IPV4, IPV6, JSON and VARIANT into independent tests. JSON and VARIANT now use ARRAY_REPEAT, which accepts these element types in the default mode. Their assertions inspect the resulting array value fields. Validation: the original combined query fails FE analysis with the reported error. A temporary FE test analyzes all five updated sample queries successfully and verifies that the JSON/VARIANT outputs remain ARRAY<JSON>/ARRAY<VARIANT>. Python syntax/import checks and clang-format 16 pass. Live ADBC execution remains unverified because no cluster URI is configured. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
