Skip to content

Commit

Permalink
Use table names in oracle source schemas fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
karolisg committed Apr 8, 2024
1 parent 5a84688 commit 668bf18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
21 changes: 12 additions & 9 deletions dozer-ingestion/oracle/src/connector/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ pub struct TableColumn {
}

impl TableColumn {
pub fn list(connection: &Connection, schemas: &[String]) -> Result<Vec<TableColumn>, Error> {
assert!(!schemas.is_empty());
pub fn list(
connection: &Connection,
table_names: &[String],
) -> Result<Vec<TableColumn>, Error> {
assert!(!table_names.is_empty());
let sql = "
SELECT OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE, NULLABLE, DATA_PRECISION, DATA_SCALE
FROM ALL_TAB_COLUMNS
WHERE OWNER IN (SELECT COLUMN_VALUE FROM TABLE(:2))
WHERE TABLE_NAME IN (:2)
";
let schemas = super::string_collection(connection, schemas)?;
let schemas = super::string_collection(connection, table_names)?;
debug!("{}, {}", sql, schemas);
let rows = connection.query_as::<(
String,
Expand Down Expand Up @@ -63,19 +66,19 @@ pub struct ConstraintColumn {
impl ConstraintColumn {
pub fn list(
connection: &Connection,
schemas: &[String],
table_names: &[String],
) -> Result<Vec<ConstraintColumn>, Error> {
assert!(!schemas.is_empty());
assert!(!table_names.is_empty());
let sql = "
SELECT
OWNER,
CONSTRAINT_NAME,
TABLE_NAME,
COLUMN_NAME
FROM ALL_CONS_COLUMNS
WHERE OWNER IN (SELECT COLUMN_VALUE FROM TABLE(:2))
WHERE TABLE_NAME IN (:2)
";
let schemas = super::string_collection(connection, schemas)?;
let schemas = super::string_collection(connection, table_names)?;
debug!("{}, {}", sql, schemas);
let rows =
connection.query_as::<(String, String, String, Option<String>)>(sql, &[&schemas])?;
Expand Down Expand Up @@ -110,7 +113,7 @@ impl Constraint {
CONSTRAINT_NAME
FROM ALL_CONSTRAINTS
WHERE
OWNER IN (SELECT COLUMN_VALUE FROM TABLE(:2))
TABLE_NAME IN (SELECT COLUMN_VALUE FROM TABLE(:2))
AND
CONSTRAINT_TYPE = 'P'
";
Expand Down
14 changes: 2 additions & 12 deletions dozer-ingestion/oracle/src/connector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ impl Connector {
// List all tables and columns.
let schemas = tables
.iter()
.map(|table| {
table
.schema
.clone()
.unwrap_or_else(|| self.username.clone())
})
.map(|table| table.name.clone())
.collect::<HashSet<_>>();
let table_columns =
listing::TableColumn::list(&self.connection, &schemas.into_iter().collect::<Vec<_>>())?;
Expand Down Expand Up @@ -206,12 +201,7 @@ impl Connector {
// Collect all tables and columns.
let schemas = table_infos
.iter()
.map(|table| {
table
.schema
.clone()
.unwrap_or_else(|| self.username.clone())
})
.map(|table| table.name.clone())
.collect::<HashSet<_>>()
.into_iter()
.collect::<Vec<_>>();
Expand Down

0 comments on commit 668bf18

Please sign in to comment.