iffyio commented on code in PR #2364:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2364#discussion_r3652024936


##########
src/ast/query.rs:
##########
@@ -293,28 +293,49 @@ impl fmt::Display for SetQuantifier {
     }
 }
 
+/// SQL:2016 `<explicit table>`: `TABLE <name>`, shorthand for `SELECT * FROM 
<name>`.
+/// Postgres extends with `ONLY` and trailing `*`; see [`InheritanceModifier`].
+///
+/// 
<https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#explicit-table>
+/// <https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE>
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-/// A [`TABLE` command]( 
https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE)
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-/// A (possibly schema-qualified) table reference used in `FROM` clauses.
-pub struct Table {
-    /// Optional table name (absent for e.g. `TABLE` command without argument).
-    pub table_name: Option<String>,
-    /// Optional schema/catalog name qualifying the table.
-    pub schema_name: Option<String>,
+pub struct ExplicitTable {

Review Comment:
   hmm not sure if there's a need to rename Table (its not clear to me what we 
gain by doing so)?



##########
src/dialect/mod.rs:
##########
@@ -1425,6 +1425,29 @@ pub trait Dialect: Debug + Any {
     fn supports_array_typedef_with_brackets(&self) -> bool {
         false
     }
+
+    /// Returns true if the dialect supports the `TABLE` command
+    /// (SQL:2016 `<explicit table>`). See [`ExplicitTable`].
+    fn supports_table_command(&self) -> bool {
+        false
+    }
+
+    /// Returns true if the dialect supports Postgres inheritance modifiers
+    /// (`ONLY` prefix and trailing `*`) on the `TABLE` command.
+    /// See [`InheritanceModifier`].
+    fn supports_explicit_table_inheritance_modifiers(&self) -> bool {
+        false
+    }
+
+    /// Returns the maximum number of dot-separated parts allowed in a
+    /// table name for the `TABLE` command. For example, `2` means only
+    /// `schema.table` is accepted; `3` would allow `catalog.schema.table`.
+    ///
+    /// Returns `None` if the dialect does not restrict the number of parts.
+    fn table_command_max_name_parts(&self) -> Option<usize> {
+        None

Review Comment:
   I think we should be able to drop these dialect methods, the latter two are 
a bit too specific I think, and in general since we're introducing an entirely 
new statement it should be fine to have the parser always accept the statement 
without it conflicting with other dialects



##########
src/ast/query.rs:
##########
@@ -293,28 +293,49 @@ impl fmt::Display for SetQuantifier {
     }
 }
 
+/// SQL:2016 `<explicit table>`: `TABLE <name>`, shorthand for `SELECT * FROM 
<name>`.
+/// Postgres extends with `ONLY` and trailing `*`; see [`InheritanceModifier`].
+///
+/// 
<https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#explicit-table>
+/// <https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE>
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-/// A [`TABLE` command]( 
https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE)
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-/// A (possibly schema-qualified) table reference used in `FROM` clauses.
-pub struct Table {
-    /// Optional table name (absent for e.g. `TABLE` command without argument).
-    pub table_name: Option<String>,
-    /// Optional schema/catalog name qualifying the table.
-    pub schema_name: Option<String>,
+pub struct ExplicitTable {
+    /// The (possibly schema-qualified) table name.
+    pub name: ObjectName,
+    /// Postgres inheritance modifier (`ONLY` or trailing `*`), if present.
+    pub inheritance: InheritanceModifier,

Review Comment:
   this should be an Option instead of introducing a custom None variant in the 
enum



##########
src/parser/mod.rs:
##########
@@ -660,6 +660,10 @@ impl<'a> Parser<'a> {
                     self.prev_token();
                     self.parse_query().map(Into::into)
                 }
+                Keyword::TABLE if self.dialect.supports_table_command() => {
+                    self.prev_token();
+                    self.parse_query().map(Into::into)

Review Comment:
   which statement type is being returned?



##########
src/ast/query.rs:
##########
@@ -293,28 +293,49 @@ impl fmt::Display for SetQuantifier {
     }
 }
 
+/// SQL:2016 `<explicit table>`: `TABLE <name>`, shorthand for `SELECT * FROM 
<name>`.
+/// Postgres extends with `ONLY` and trailing `*`; see [`InheritanceModifier`].
+///
+/// 
<https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#explicit-table>
+/// <https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE>
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-/// A [`TABLE` command]( 
https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE)
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-/// A (possibly schema-qualified) table reference used in `FROM` clauses.
-pub struct Table {
-    /// Optional table name (absent for e.g. `TABLE` command without argument).
-    pub table_name: Option<String>,
-    /// Optional schema/catalog name qualifying the table.
-    pub schema_name: Option<String>,
+pub struct ExplicitTable {
+    /// The (possibly schema-qualified) table name.
+    pub name: ObjectName,
+    /// Postgres inheritance modifier (`ONLY` or trailing `*`), if present.
+    pub inheritance: InheritanceModifier,
+}
+
+/// Postgres inheritance-hierarchy modifier for table references.
+///
+/// Controls whether a query against a table includes rows from descendant
+/// tables (inheritance children or partitions). See
+/// <https://www.postgresql.org/docs/current/ddl-inherit.html>.
+#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub enum InheritanceModifier {

Review Comment:
   ```suggestion
   pub enum TableInheritanceModifier {
   ```



##########
src/ast/query.rs:
##########
@@ -293,28 +293,49 @@ impl fmt::Display for SetQuantifier {
     }
 }
 
+/// SQL:2016 `<explicit table>`: `TABLE <name>`, shorthand for `SELECT * FROM 
<name>`.
+/// Postgres extends with `ONLY` and trailing `*`; see [`InheritanceModifier`].
+///
+/// 
<https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#explicit-table>
+/// <https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE>
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-/// A [`TABLE` command]( 
https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE)
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-/// A (possibly schema-qualified) table reference used in `FROM` clauses.
-pub struct Table {
-    /// Optional table name (absent for e.g. `TABLE` command without argument).
-    pub table_name: Option<String>,
-    /// Optional schema/catalog name qualifying the table.
-    pub schema_name: Option<String>,
+pub struct ExplicitTable {
+    /// The (possibly schema-qualified) table name.
+    pub name: ObjectName,
+    /// Postgres inheritance modifier (`ONLY` or trailing `*`), if present.

Review Comment:
   ```suggestion
       /// Inheritance modifier.
   ```
   the rest of the comment is duplicated, the pg part we can drop since other 
dialects can support it either now or in the future



##########
src/ast/query.rs:
##########
@@ -293,28 +293,49 @@ impl fmt::Display for SetQuantifier {
     }
 }
 
+/// SQL:2016 `<explicit table>`: `TABLE <name>`, shorthand for `SELECT * FROM 
<name>`.
+/// Postgres extends with `ONLY` and trailing `*`; see [`InheritanceModifier`].
+///
+/// 
<https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#explicit-table>
+/// <https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE>
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-/// A [`TABLE` command]( 
https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE)
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-/// A (possibly schema-qualified) table reference used in `FROM` clauses.
-pub struct Table {
-    /// Optional table name (absent for e.g. `TABLE` command without argument).
-    pub table_name: Option<String>,
-    /// Optional schema/catalog name qualifying the table.
-    pub schema_name: Option<String>,
+pub struct ExplicitTable {
+    /// The (possibly schema-qualified) table name.
+    pub name: ObjectName,
+    /// Postgres inheritance modifier (`ONLY` or trailing `*`), if present.
+    pub inheritance: InheritanceModifier,
+}
+
+/// Postgres inheritance-hierarchy modifier for table references.
+///
+/// Controls whether a query against a table includes rows from descendant
+/// tables (inheritance children or partitions). See
+/// <https://www.postgresql.org/docs/current/ddl-inherit.html>.

Review Comment:
   ```suggestion
   /// Inheritance-hierarchy modifier for table references.
   ///
   /// Controls whether a query against a table includes rows from descendant
   /// tables (inheritance children or partitions).
   /// [Postgres]: https://www.postgresql.org/docs/current/ddl-inherit.html.
   ```
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to