|
21 | 21 | import trino
|
22 | 22 | from tests.integration.conftest import trino_version
|
23 | 23 | from trino import constants
|
| 24 | +from trino.dbapi import DescribeOutput |
24 | 25 | from trino.exceptions import NotSupportedError, TrinoQueryError, TrinoUserError
|
25 | 26 | from trino.transaction import IsolationLevel
|
26 | 27 |
|
@@ -1155,3 +1156,69 @@ def test_connection_without_timezone(run_trino):
|
1155 | 1156 | assert session_tz == localzone or \
|
1156 | 1157 | (session_tz == "UTC" and localzone == "Etc/UTC") \
|
1157 | 1158 | # Workaround for difference between Trino timezone and tzlocal for UTC
|
| 1159 | + |
| 1160 | + |
| 1161 | +def test_describe(run_trino): |
| 1162 | + _, host, port = run_trino |
| 1163 | + |
| 1164 | + trino_connection = trino.dbapi.Connection( |
| 1165 | + host=host, port=port, user="test", catalog="tpch", |
| 1166 | + ) |
| 1167 | + cur = trino_connection.cursor() |
| 1168 | + |
| 1169 | + result = cur.describe("SELECT 1, DECIMAL '1.0' as a") |
| 1170 | + |
| 1171 | + assert result == [ |
| 1172 | + DescribeOutput(name='_col0', catalog='', schema='', table='', type='integer', type_size=4, aliased=False), |
| 1173 | + DescribeOutput(name='a', catalog='', schema='', table='', type='decimal(2,1)', type_size=8, aliased=True) |
| 1174 | + ] |
| 1175 | + |
| 1176 | + |
| 1177 | +def test_describe_table_query(run_trino): |
| 1178 | + _, host, port = run_trino |
| 1179 | + |
| 1180 | + trino_connection = trino.dbapi.Connection( |
| 1181 | + host=host, port=port, user="test", catalog="tpch", |
| 1182 | + ) |
| 1183 | + cur = trino_connection.cursor() |
| 1184 | + |
| 1185 | + result = cur.describe("SELECT * from tpch.tiny.nation") |
| 1186 | + |
| 1187 | + assert result == [ |
| 1188 | + DescribeOutput( |
| 1189 | + name='nationkey', |
| 1190 | + catalog='tpch', |
| 1191 | + schema='tiny', |
| 1192 | + table='nation', |
| 1193 | + type='bigint', |
| 1194 | + type_size=8, |
| 1195 | + aliased=False, |
| 1196 | + ), |
| 1197 | + DescribeOutput( |
| 1198 | + name='name', |
| 1199 | + catalog='tpch', |
| 1200 | + schema='tiny', |
| 1201 | + table='nation', |
| 1202 | + type='varchar(25)', |
| 1203 | + type_size=0, |
| 1204 | + aliased=False, |
| 1205 | + ), |
| 1206 | + DescribeOutput( |
| 1207 | + name='regionkey', |
| 1208 | + catalog='tpch', |
| 1209 | + schema='tiny', |
| 1210 | + table='nation', |
| 1211 | + type='bigint', |
| 1212 | + type_size=8, |
| 1213 | + aliased=False, |
| 1214 | + ), |
| 1215 | + DescribeOutput( |
| 1216 | + name='comment', |
| 1217 | + catalog='tpch', |
| 1218 | + schema='tiny', |
| 1219 | + table='nation', |
| 1220 | + type='varchar(152)', |
| 1221 | + type_size=0, |
| 1222 | + aliased=False, |
| 1223 | + ) |
| 1224 | + ] |
0 commit comments