mz_expr/scalar/func/
unmaterializable.rs1use std::fmt;
20
21use mz_lowertest::MzReflect;
22use mz_repr::{SqlColumnType, SqlScalarType};
23use serde::{Deserialize, Serialize};
24
25#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect)]
26pub enum UnmaterializableFunc {
27 CurrentDatabase,
28 CurrentSchema,
29 CurrentSchemasWithSystem,
30 CurrentSchemasWithoutSystem,
31 CurrentTimestamp,
32 CurrentUser,
33 IsRbacEnabled,
34 MzEnvironmentId,
35 MzIsSuperuser,
36 MzNow,
37 MzRoleOidMemberships,
38 MzSessionId,
39 MzUptime,
40 MzVersion,
41 MzVersionNum,
42 PgBackendPid,
43 PgPostmasterStartTime,
44 SessionUser,
45 Version,
46 ViewableVariables,
47}
48
49impl UnmaterializableFunc {
50 pub fn output_type(&self) -> SqlColumnType {
51 match self {
52 UnmaterializableFunc::CurrentDatabase => SqlScalarType::String.nullable(false),
53 UnmaterializableFunc::CurrentSchema => SqlScalarType::String.nullable(true),
57 UnmaterializableFunc::CurrentSchemasWithSystem => {
62 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false)
63 }
64 UnmaterializableFunc::CurrentSchemasWithoutSystem => {
65 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false)
66 }
67 UnmaterializableFunc::CurrentTimestamp => {
68 SqlScalarType::TimestampTz { precision: None }.nullable(false)
69 }
70 UnmaterializableFunc::CurrentUser => SqlScalarType::String.nullable(false),
71 UnmaterializableFunc::IsRbacEnabled => SqlScalarType::Bool.nullable(false),
72 UnmaterializableFunc::MzEnvironmentId => SqlScalarType::String.nullable(false),
73 UnmaterializableFunc::MzIsSuperuser => SqlScalarType::Bool.nullable(false),
74 UnmaterializableFunc::MzNow => SqlScalarType::MzTimestamp.nullable(false),
75 UnmaterializableFunc::MzRoleOidMemberships => SqlScalarType::Map {
76 value_type: Box::new(SqlScalarType::Array(Box::new(SqlScalarType::String))),
77 custom_id: None,
78 }
79 .nullable(false),
80 UnmaterializableFunc::MzSessionId => SqlScalarType::Uuid.nullable(false),
81 UnmaterializableFunc::MzUptime => SqlScalarType::Interval.nullable(true),
82 UnmaterializableFunc::MzVersion => SqlScalarType::String.nullable(false),
83 UnmaterializableFunc::MzVersionNum => SqlScalarType::Int32.nullable(false),
84 UnmaterializableFunc::PgBackendPid => SqlScalarType::Int32.nullable(false),
85 UnmaterializableFunc::PgPostmasterStartTime => {
86 SqlScalarType::TimestampTz { precision: None }.nullable(false)
87 }
88 UnmaterializableFunc::SessionUser => SqlScalarType::String.nullable(false),
89 UnmaterializableFunc::Version => SqlScalarType::String.nullable(false),
90 UnmaterializableFunc::ViewableVariables => SqlScalarType::Map {
91 value_type: Box::new(SqlScalarType::String),
92 custom_id: None,
93 }
94 .nullable(false),
95 }
96 }
97}
98
99impl fmt::Display for UnmaterializableFunc {
100 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101 match self {
102 UnmaterializableFunc::CurrentDatabase => f.write_str("current_database"),
103 UnmaterializableFunc::CurrentSchema => f.write_str("current_schema"),
104 UnmaterializableFunc::CurrentSchemasWithSystem => f.write_str("current_schemas(true)"),
105 UnmaterializableFunc::CurrentSchemasWithoutSystem => {
106 f.write_str("current_schemas(false)")
107 }
108 UnmaterializableFunc::CurrentTimestamp => f.write_str("current_timestamp"),
109 UnmaterializableFunc::CurrentUser => f.write_str("current_user"),
110 UnmaterializableFunc::IsRbacEnabled => f.write_str("is_rbac_enabled"),
111 UnmaterializableFunc::MzEnvironmentId => f.write_str("mz_environment_id"),
112 UnmaterializableFunc::MzIsSuperuser => f.write_str("mz_is_superuser"),
113 UnmaterializableFunc::MzNow => f.write_str("mz_now"),
114 UnmaterializableFunc::MzRoleOidMemberships => f.write_str("mz_role_oid_memberships"),
115 UnmaterializableFunc::MzSessionId => f.write_str("mz_session_id"),
116 UnmaterializableFunc::MzUptime => f.write_str("mz_uptime"),
117 UnmaterializableFunc::MzVersion => f.write_str("mz_version"),
118 UnmaterializableFunc::MzVersionNum => f.write_str("mz_version_num"),
119 UnmaterializableFunc::PgBackendPid => f.write_str("pg_backend_pid"),
120 UnmaterializableFunc::PgPostmasterStartTime => f.write_str("pg_postmaster_start_time"),
121 UnmaterializableFunc::SessionUser => f.write_str("session_user"),
122 UnmaterializableFunc::Version => f.write_str("version"),
123 UnmaterializableFunc::ViewableVariables => f.write_str("viewable_variables"),
124 }
125 }
126}