MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / resolve_type

Method resolve_type

src/sql/src/plan/statement.rs:845–881  ·  view source on GitHub ↗
(&self, mut ty: mz_pgrepr::Type)

Source from the content-addressed store, hash-verified

843 }
844
845 pub fn resolve_type(&self, mut ty: mz_pgrepr::Type) -> Result<ResolvedDataType, PlanError> {
846 // Ignore precision constraints on date/time types until we support
847 // it. This should be safe enough because our types are wide enough
848 // to support the maximum possible precision.
849 //
850 // See: https://github.com/MaterializeInc/database-issues/issues/3179
851 match &mut ty {
852 mz_pgrepr::Type::Interval { constraints } => *constraints = None,
853 mz_pgrepr::Type::Time { precision } => *precision = None,
854 mz_pgrepr::Type::TimeTz { precision } => *precision = None,
855 mz_pgrepr::Type::Timestamp { precision } => *precision = None,
856 mz_pgrepr::Type::TimestampTz { precision } => *precision = None,
857 _ => (),
858 }
859 // NOTE(benesch): this *looks* gross, but it is
860 // safe enough. The `fmt::Display`
861 // representation on `pgrepr::Type` promises to
862 // produce an unqualified type name that does
863 // not require quoting.
864 let mut ty = if ty.oid() >= FIRST_USER_OID {
865 sql_bail!("internal error, unexpected user type: {ty:?} ");
866 } else if ty.oid() < FIRST_MATERIALIZE_OID {
867 format!("pg_catalog.{}", ty)
868 } else {
869 // This relies on all non-PG types existing in `mz_catalog`, which is annoying.
870 format!("mz_catalog.{}", ty)
871 };
872 // TODO(benesch): converting `json` to `jsonb`
873 // is wrong. We ought to support the `json` type
874 // directly.
875 if ty == "pg_catalog.json" {
876 ty = "pg_catalog.jsonb".into();
877 }
878 let data_type = mz_sql_parser::parser::parse_data_type(&ty)?;
879 let (data_type, _) = names::resolve(self.catalog, data_type)?;
880 Ok(data_type)
881 }
882
883 pub fn get_object_type(&self, id: &ObjectId) -> ObjectType {
884 self.catalog.get_object_type(id)

Calls 3

resolveFunction · 0.85
parse_data_typeFunction · 0.50
oidMethod · 0.45

Tested by

no test coverage detected