Skip to content

Commit 5c98ea4

Browse files
krzysztof-kwittcpcloud
authored andcommitted
feat(bigquery): add BIGNUMERIC type support
1 parent 4a04c9b commit 5c98ea4

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

ibis/backends/bigquery/datatypes.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ def trans_type(t):
6666

6767
@ibis_type_to_bigquery_type.register(dt.Decimal)
6868
def trans_numeric(t):
69-
if (t.precision, t.scale) not in [(38, 9), (None, None)]:
70-
raise TypeError(
71-
"BigQuery only supports decimal types with precision of 38 and "
72-
"scale of 9"
73-
)
74-
return "NUMERIC"
69+
if (t.precision, t.scale) == (76, 38):
70+
return 'BIGNUMERIC'
71+
if (t.precision, t.scale) in [(38, 9), (None, None)]:
72+
return "NUMERIC"
73+
raise TypeError(
74+
"BigQuery only supports decimal types with precision of 38 and "
75+
f"scale of 9 (NUMERIC) or precision of 76 and scale of 38 (BIGNUMERIC). "
76+
f"Current precision: {t.precision}. Current scale: {t.scale}"
77+
)
7578

7679

7780
@ibis_type_to_bigquery_type.register(dt.JSON)

ibis/backends/bigquery/tests/unit/test_datatypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def test_no_ambiguities():
4949
param(
5050
"array<struct<a: string>>", "ARRAY<STRUCT<a STRING>>", id="array<struct>"
5151
),
52-
param(dt.Decimal(38, 9), "NUMERIC", id="decimal"),
52+
param(dt.Decimal(38, 9), "NUMERIC", id="decimal-numeric"),
53+
param(dt.Decimal(76, 38), "BIGNUMERIC", id="decimal-bignumeric"),
5354
],
5455
)
5556
def test_simple(datatype, expected):

ibis/backends/tests/test_generic.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,40 @@ def test_exists(batting, awards_players, method_name):
13741374
],
13751375
id="decimal-big",
13761376
),
1377+
param(
1378+
ibis.literal(decimal.Decimal("1.1"), type=dt.Decimal(76, 38)),
1379+
{
1380+
'bigquery': "BIGNUMERIC",
1381+
'snowflake': "VARCHAR",
1382+
'sqlite': "real",
1383+
'trino': 'decimal(2,1)',
1384+
"duckdb": "DECIMAL(18,3)",
1385+
"postgres": "numeric",
1386+
},
1387+
marks=[
1388+
pytest.mark.broken(
1389+
['clickhouse'],
1390+
"Code: 46. DB::Exception: Unknown function Decimal: "
1391+
"While processing toTypeName(Decimal('1.2')).",
1392+
raises=ClickhouseDriverOperationalError,
1393+
),
1394+
pytest.mark.broken(
1395+
['impala'],
1396+
"impala.error.HiveServer2Error: AnalysisException: Syntax error in line 1:"
1397+
"SELECT typeof(Decimal('1.2')) AS `TypeOf(Decimal('1.2'))"
1398+
"Encountered: DECIMAL"
1399+
"Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, "
1400+
"INTERVAL, LEFT, NOT, NULL, REPLACE, RIGHT, TRUNCATE, TRUE, IDENTIFIER"
1401+
"CAUSED BY: Exception: Syntax error",
1402+
),
1403+
pytest.mark.broken(
1404+
['duckdb'],
1405+
"(duckdb.ParserException) Parser Error: Width must be between 1 and 38!",
1406+
raises=sqlalchemy.exc.ProgrammingError,
1407+
),
1408+
],
1409+
id="decimal-big",
1410+
),
13771411
param(
13781412
ibis.array([1.0, 2.0, 3.0]),
13791413
{

0 commit comments

Comments
 (0)