Skip to main content

mz_expr/scalar/func/
impls.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10mod array;
11mod boolean;
12mod byte;
13mod case_literal;
14mod catalog;
15mod char;
16mod date;
17mod datum;
18mod float32;
19mod float64;
20mod int16;
21mod int2vector;
22mod int32;
23mod int64;
24mod interval;
25mod jsonb;
26mod list;
27mod map;
28mod mz_acl_item;
29mod mz_timestamp;
30mod numeric;
31mod oid;
32mod pg_legacy_char;
33mod range;
34mod record;
35mod regproc;
36mod string;
37mod time;
38mod timestamp;
39mod try_cast;
40mod uint16;
41mod uint32;
42mod uint64;
43mod uuid;
44mod varchar;
45
46pub use crate::scalar::func::impls::array::*;
47pub use crate::scalar::func::impls::boolean::*;
48pub use crate::scalar::func::impls::byte::*;
49pub use crate::scalar::func::impls::case_literal::*;
50pub use crate::scalar::func::impls::catalog::*;
51pub use crate::scalar::func::impls::char::*;
52pub use crate::scalar::func::impls::date::*;
53pub use crate::scalar::func::impls::datum::*;
54pub use crate::scalar::func::impls::float32::*;
55pub use crate::scalar::func::impls::float64::*;
56pub use crate::scalar::func::impls::int2vector::*;
57pub use crate::scalar::func::impls::int16::*;
58pub use crate::scalar::func::impls::int32::*;
59pub use crate::scalar::func::impls::int64::*;
60pub use crate::scalar::func::impls::interval::*;
61pub use crate::scalar::func::impls::jsonb::*;
62pub use crate::scalar::func::impls::list::*;
63pub use crate::scalar::func::impls::map::*;
64pub use crate::scalar::func::impls::mz_acl_item::*;
65pub use crate::scalar::func::impls::mz_timestamp::*;
66pub use crate::scalar::func::impls::numeric::*;
67pub use crate::scalar::func::impls::oid::*;
68pub use crate::scalar::func::impls::pg_legacy_char::*;
69pub use crate::scalar::func::impls::range::*;
70pub use crate::scalar::func::impls::record::*;
71pub use crate::scalar::func::impls::regproc::*;
72pub use crate::scalar::func::impls::string::*;
73pub use crate::scalar::func::impls::time::*;
74pub use crate::scalar::func::impls::timestamp::*;
75pub use crate::scalar::func::impls::try_cast::*;
76pub use crate::scalar::func::impls::uint16::*;
77pub use crate::scalar::func::impls::uint32::*;
78pub use crate::scalar::func::impls::uint64::*;
79pub use crate::scalar::func::impls::uuid::*;
80pub use crate::scalar::func::impls::varchar::*;
81
82use mz_repr::SqlScalarType;
83
84/// Reports whether rendering values of type `ty` as text maps distinct values
85/// to distinct strings.
86///
87/// Values of `time`, `timestamp` and `timestamptz` can carry nanoseconds, for
88/// example from `date + time`, but their text form is rounded to microseconds.
89/// Any type that contains one of them is therefore not uniqueness-preserving.
90pub(crate) fn text_preserves_uniqueness(ty: &SqlScalarType) -> bool {
91    match ty {
92        SqlScalarType::Time
93        | SqlScalarType::Timestamp { .. }
94        | SqlScalarType::TimestampTz { .. } => false,
95        SqlScalarType::Array(element_type)
96        | SqlScalarType::List { element_type, .. }
97        | SqlScalarType::Range { element_type }
98        | SqlScalarType::Map {
99            value_type: element_type,
100            ..
101        } => text_preserves_uniqueness(element_type),
102        SqlScalarType::Record { fields, .. } => fields
103            .iter()
104            .all(|(_, typ)| text_preserves_uniqueness(&typ.scalar_type)),
105        SqlScalarType::Bool
106        | SqlScalarType::Int16
107        | SqlScalarType::Int32
108        | SqlScalarType::Int64
109        | SqlScalarType::UInt16
110        | SqlScalarType::UInt32
111        | SqlScalarType::UInt64
112        | SqlScalarType::Float32
113        | SqlScalarType::Float64
114        | SqlScalarType::Numeric { .. }
115        | SqlScalarType::Date
116        | SqlScalarType::Interval
117        | SqlScalarType::PgLegacyChar
118        | SqlScalarType::PgLegacyName
119        | SqlScalarType::Bytes
120        | SqlScalarType::String
121        | SqlScalarType::Char { .. }
122        | SqlScalarType::VarChar { .. }
123        | SqlScalarType::Jsonb
124        | SqlScalarType::Uuid
125        | SqlScalarType::Oid
126        | SqlScalarType::RegProc
127        | SqlScalarType::RegType
128        | SqlScalarType::RegClass
129        | SqlScalarType::Int2Vector
130        | SqlScalarType::MzTimestamp
131        | SqlScalarType::MzAclItem
132        | SqlScalarType::AclItem => true,
133    }
134}