Skip to main content

RewriteRegCastToSubquery

Struct RewriteRegCastToSubquery 

Source
pub struct RewriteRegCastToSubquery { /* private fields */ }
Expand description

Rewrite forward oid-alias casts ('x'::regclass, 'public'::regnamespace, …) to oid values the way Postgres does.

Postgres oid-alias types cast a name to the matching catalog oid; DataFusion has no such types. This rule rewrites the forward (name->oid) direction at the AST layer, before DataFusion plans the query:

  • a numeric string operand ('16417') becomes a literal oid – Postgres treats a numeric string as the oid itself, and emitting a literal avoids embedding a (SELECT ...) in contexts DataFusion can’t decorrelate (e.g. VALUES ('16417'::regclass) inside IN (...));
  • a name string operand ('public') becomes a scalar subquery against the backing catalog table. The subquery is plain SQL, so DataFusion resolves pg_catalog.pg_namespace / pg_class / pg_type / pg_proc through the catalog at plan time – no TableProvider or catalog handle is needed in the rule, which is why this lives at the SQL layer rather than as an analyzer rule.

Only the forward direction is rewritten (operand is a string literal or a prepared-statement $N placeholder). Reverse / column-operand casts such as prorettype::regtype::text (oid -> name for display) are left untouched; the PgOidTypePlanner maps those cast types to Int32 so they still parse.

§Limitation vs an analyzer rule

Because the SQL layer has no schema, this rule can only resolve casts that explicitly name an oid-alias type. The implicit form oid_col = 'public' (bare string vs an oid column) is not recognized here – there’s no cast in the AST to key off. Resolving that would require schema awareness (an analyzer rule + a catalog provider). In practice the only client query affected is blacklisted.

Implementations§

Trait Implementations§

Source§

impl Debug for RewriteRegCastToSubquery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RewriteRegCastToSubquery

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SqlStatementRewriteRule for RewriteRegCastToSubquery

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V