alamb commented on code in PR #10876:
URL: https://github.com/apache/datafusion/pull/10876#discussion_r1637155792


##########
datafusion/core/src/catalog/mod.rs:
##########
@@ -295,6 +296,118 @@ impl CatalogProvider for MemoryCatalogProvider {
     }
 }
 
+/// Resolve all table references in the SQL statement.
+///
+/// ## Example
+///
+/// ```
+/// use datafusion_sql::parser::DFParser;
+/// use datafusion::catalog::resolve_table_references;
+///
+/// let query = "SELECT a FROM foo where x IN (SELECT y FROM bar)";
+/// let statement = DFParser::parse_sql(query).unwrap().pop_back().unwrap();
+/// let table_refs = resolve_table_references(&statement, true).unwrap();
+/// assert_eq!(table_refs.len(), 2);
+/// assert_eq!(table_refs[0].to_string(), "foo");
+/// assert_eq!(table_refs[1].to_string(), "bar");
+/// ```

Review Comment:
   ```suggestion
   /// ```
   ///
   /// ## Example with CTEs
   ///
   /// ```
   /// # use datafusion_sql::parser::DFParser;
   /// # use datafusion::catalog::resolve_table_references;
   /// let query = "with my_cte as (values (1), (2)) SELECT * from my_cte;";
   /// let statement = DFParser::parse_sql(query).unwrap().pop_back().unwrap();
   /// let table_refs = resolve_table_references(&statement, true).unwrap();
   /// assert_eq!(table_refs.len(), 1);
   /// assert_eq!(table_refs[0].to_string(), "my_cte");
   /// ```
   ```



##########
datafusion/core/src/catalog/mod.rs:
##########
@@ -295,6 +296,118 @@ impl CatalogProvider for MemoryCatalogProvider {
     }
 }
 
+/// Resolve all table references in the SQL statement.
+///
+/// ## Example
+///
+/// ```
+/// use datafusion_sql::parser::DFParser;
+/// use datafusion::catalog::resolve_table_references;
+///

Review Comment:
   I think the example will format nicer if you add # in front of the use 
(which hides them from the docs)
   ```suggestion
   /// # use datafusion_sql::parser::DFParser;
   /// # use datafusion::catalog::resolve_table_references;
   ```



##########
datafusion/core/src/catalog/mod.rs:
##########
@@ -295,6 +296,118 @@ impl CatalogProvider for MemoryCatalogProvider {
     }
 }
 
+/// Resolve all table references in the SQL statement.
+///
+/// ## Example
+///
+/// ```
+/// use datafusion_sql::parser::DFParser;
+/// use datafusion::catalog::resolve_table_references;
+///
+/// let query = "SELECT a FROM foo where x IN (SELECT y FROM bar)";
+/// let statement = DFParser::parse_sql(query).unwrap().pop_back().unwrap();
+/// let table_refs = resolve_table_references(&statement, true).unwrap();
+/// assert_eq!(table_refs.len(), 2);
+/// assert_eq!(table_refs[0].to_string(), "foo");

Review Comment:
   BTW this example fails for me locally (it seems "bar" is returned) -- 
perhaps related to the fact code is gathered in a hash table. Perhaps we could 
add a sort (or use a BTreeSet rather than a HashSet) to ensure the output order 
is consistent



##########
datafusion/core/src/catalog/mod.rs:
##########
@@ -295,6 +296,118 @@ impl CatalogProvider for MemoryCatalogProvider {
     }
 }
 
+/// Resolve all table references in the SQL statement.

Review Comment:
   ```suggestion
   /// Resolve all table references in the SQL statement.
   ///
   /// Note that this will also return the names of any common 
   /// table expressions (CTEs) that are may be defined in the
   /// query
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to