Skip to content

Commit 99be73b

Browse files
NickCrewscpcloud
andauthored
fix(oracle): return a sqlglot.DataType, not str, when compiling string dtype (#11124)
Co-authored-by: Phillip Cloud <[email protected]>
1 parent a21b49f commit 99be73b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ibis/backends/oracle/tests/test_datatypes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from __future__ import annotations
22

3+
import pytest
4+
import sqlglot as sg
5+
import sqlglot.expressions as sge
6+
37
import ibis
8+
import ibis.expr.datatypes as dt
9+
from ibis.backends.sql.datatypes import OracleType
410

511

612
def test_failed_column_inference(con):
@@ -21,3 +27,13 @@ def test_blob_raw(con):
2127
raw_blob = con.table("blob_raw_blobs_blob_raw")
2228

2329
assert raw_blob.schema() == ibis.Schema(dict(blob="binary", raw="binary"))
30+
31+
32+
@pytest.mark.parametrize(
33+
("typ", "length"),
34+
[("VARCHAR(4000)", None), ("VARCHAR(3)", 3), ("VARCHAR(4000)", 4000)],
35+
)
36+
def test_string(typ, length):
37+
expected = sg.parse_one(typ, read="oracle", into=sge.DataType)
38+
result = OracleType.from_ibis(dt.String(length=length))
39+
assert result == expected

ibis/backends/sql/datatypes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,14 @@ def _from_sqlglot_DECIMAL(
769769

770770
@classmethod
771771
def _from_ibis_String(cls, dtype: dt.String) -> sge.DataType:
772-
nullable = " NOT NULL" if not dtype.nullable else ""
773-
return "VARCHAR2(4000)" + nullable
772+
expressions = [
773+
sge.DataTypeParam(
774+
this=sge.convert(dtype.length if dtype.length is not None else 4000)
775+
)
776+
]
777+
return sge.DataType(
778+
this=typecode.VARCHAR, expressions=expressions, is_nested=False
779+
)
774780

775781

776782
class SnowflakeType(SqlglotType):

0 commit comments

Comments
 (0)