community: Add support for clob datatype in oracle database (#27330)

**Description**:
This PR add support of clob/blob data type for oracle document loader,
clob/blob can only be read by oracledb package when connection is open,
so reformat code to process data before connection closes.

**Dependencies**:
oracledb package same as before. pip install oracledb

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
xsai9101 2024-10-15 19:19:20 -07:00 committed by GitHub
parent 8e66822100
commit 15c1ddaf99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,7 +100,13 @@ class OracleAutonomousDatabaseLoader(BaseLoader):
cursor.execute(self.query)
columns = [col[0] for col in cursor.description]
data = cursor.fetchall()
data = [dict(zip(columns, row)) for row in data]
data = [
{
i: (j if not isinstance(j, oracledb.LOB) else j.read())
for i, j in zip(columns, row)
}
for row in data
]
except oracledb.DatabaseError as e:
print("Got error while connecting: " + str(e)) # noqa: T201
data = []