Skip to content

Commit

Permalink
fix default schema fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Jan 29, 2025
1 parent a0df965 commit df41098
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/datasources/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async function v2ToV3(
failedAt: 'failedAt' in v2 ? new Date(v2.failedAt) : null,
error: 'error' in v2 ? v2.error : undefined,
defaultSchema:
'structure' in v2 ? (v2.structure?.defaultSchema ?? null) : null,
'structure' in v2 ? v2.structure?.defaultSchema ?? null : null,
},
})

Expand Down Expand Up @@ -544,8 +544,8 @@ async function _refreshDataSourceStructure(
const updateQueue = new PQueue({ concurrency: 1 })
const tables: { schema: string; table: string }[] = []
let defaultSchema = ''
const onTable: OnTable = (schema, tableName, table, defaultSchema) => {
defaultSchema = defaultSchema || schema
const onTable: OnTable = (schema, tableName, table, newDefaultSchema) => {
defaultSchema = newDefaultSchema || schema
tables.push({ schema, table: tableName })
updateQueue.add(async () => {
let embedding: number[] | null = null
Expand Down
15 changes: 11 additions & 4 deletions apps/api/src/python/query/sqlalchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def get_columns(conn, inspector, table_name, schema_name):
return inspector.get_columns(table_name, schema=schema_name)
def schema_from_tables(conn, inspector, tables):
def schema_from_tables(conn, inspector, tables, default_schema):
made_progress = False
exceptions = []
for table in tables:
Expand All @@ -438,7 +438,7 @@ def schema_from_tables(conn, inspector, tables):
"table": {
"columns": columns
},
"defaultSchema": "public"
"defaultSchema": default_schema
}
print(json.dumps(progress, default=str))
Expand All @@ -460,9 +460,16 @@ def get_data_source_structure(data_source_id, credentials_info=None):
oracledb.init_oracle_client()
inspector = inspect(engine)
default_schema = "public"
try:
default_schema = inspector.default_schema_name or default_schema
except:
pass
if ${JSON.stringify(ds.type)} == "bigquery":
tables = inspector.get_table_names()
schema_from_tables(conn, inspector, tables)
schema_from_tables(conn, inspector, tables, default_schema)
else:
tables = []
exceptions = []
Expand All @@ -475,7 +482,7 @@ def get_data_source_structure(data_source_id, credentials_info=None):
exceptions.append(e)
print(json.dumps({"log": f"Failed to get tables for schema {schema_name}: {str(e)}"}))
continue
schema_from_tables(conn, inspector, tables)
schema_from_tables(conn, inspector, tables, default_schema)
if len(tables) == 0 and len(exceptions) > 0:
raise BrieferAggregateException(exceptions)
finally:
Expand Down

0 comments on commit df41098

Please sign in to comment.