1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
include!(concat!(
env!("OUT_DIR"),
"/mz_dataflow_types.postgres_source.rs"
));
use proptest::prelude::{any, Arbitrary};
use proptest::strategy::{BoxedStrategy, Strategy};
use mz_postgres_util::{PgColumn, TableInfo};
impl From<PgColumn> for PostgresColumn {
fn from(c: PgColumn) -> PostgresColumn {
PostgresColumn {
name: c.name,
type_oid: c.oid.try_into().unwrap(),
type_mod: c.typmod,
nullable: c.nullable,
primary_key: c.primary_key,
}
}
}
impl From<PostgresColumn> for PgColumn {
fn from(c: PostgresColumn) -> PgColumn {
PgColumn {
name: c.name,
oid: c.type_oid.try_into().unwrap(),
typmod: c.type_mod,
nullable: c.nullable,
primary_key: c.primary_key,
}
}
}
impl From<TableInfo> for PostgresTable {
fn from(t: TableInfo) -> PostgresTable {
PostgresTable {
name: t.name,
namespace: t.namespace,
relation_id: t.rel_id,
columns: t.schema.into_iter().map(|c| c.into()).collect(),
}
}
}
impl From<PostgresTable> for TableInfo {
fn from(t: PostgresTable) -> TableInfo {
TableInfo {
name: t.name,
namespace: t.namespace,
rel_id: t.relation_id,
schema: t.columns.into_iter().map(|c| c.into()).collect(),
}
}
}
impl Arbitrary for PostgresColumn {
type Strategy = BoxedStrategy<Self>;
type Parameters = ();
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
(
any::<String>(),
any::<i32>(),
any::<i32>(),
any::<bool>(),
any::<bool>(),
)
.prop_map(
|(name, type_oid, type_mod, nullable, primary_key)| PostgresColumn {
name,
type_oid,
type_mod,
nullable,
primary_key,
},
)
.boxed()
}
}
impl Arbitrary for PostgresTable {
type Strategy = BoxedStrategy<Self>;
type Parameters = ();
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
(
any::<String>(),
any::<String>(),
any::<u32>(),
any::<Vec<PostgresColumn>>(),
)
.prop_map(|(name, namespace, relation_id, columns)| PostgresTable {
name,
namespace,
relation_id,
columns,
})
.boxed()
}
}
impl Arbitrary for PostgresSourceDetails {
type Strategy = BoxedStrategy<Self>;
type Parameters = ();
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
(any::<Vec<PostgresTable>>(), any::<String>())
.prop_map(|(tables, slot)| PostgresSourceDetails { tables, slot })
.boxed()
}
}