Skip to content

Commit 0791e14

Browse files
committed
Refactor for shapes with ids
1 parent 273a665 commit 0791e14

14 files changed

Lines changed: 81 additions & 62 deletions

File tree

.gitconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[url "https://github.com/"]
2+
insteadOf = git@github.com:

Cargo.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ readme = "../README.md"
88
#keywords = TODO
99
#categories = TODO
1010
exclude = [
11-
"**/.git/**",
12-
"**/.github/**",
13-
"**/.travis.yml",
14-
"**/.appveyor.yml",
11+
"**/.git/**",
12+
"**/.github/**",
13+
"**/.travis.yml",
14+
"**/.appveyor.yml",
1515
]
1616
edition = "2021"
1717
version = "0.1.0"
1818

19-
[patch.crates-io]
2019
[workspace]
2120
members = [
2221
"partiql-beamline-cli",
@@ -36,3 +35,14 @@ opt-level = 3
3635
[profile.bench]
3736
debug = true
3837
lto = true
38+
39+
[patch.crates-io]
40+
partiql-parser = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
41+
partiql-ast = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
42+
partiql-types = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
43+
partiql-value = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
44+
partiql-extension-ddl = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
45+
partiql-extension-ion = { git = "https://github.com/partiql/partiql-lang-rust", branch = "feat-type-nodeid" }
46+
47+
[net]
48+
git-fetch-with-cli = true

config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[net]
2+
git-fetch-with-cli = true

partiql-beamline-query/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version.workspace = true
1616
partiql-beamline = { path = "../partiql-beamline-sim", version = "0.1" }
1717

1818
partiql-parser = "0.10"
19-
partiql-ast = "0.10.1"
19+
partiql-ast = "^0.10.1"
2020
partiql-extension-ion = "0.10"
2121
partiql-value = "0.10"
2222
partiql-types = "0.10"

partiql-beamline-query/tests/simple.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use partiql_beamline_query::strategy::query::SelectFromWhereBuilder;
1616
use partiql_beamline_query::strategy::where_clause::{RandomRowFilter, RandomRowPredicateBuilder};
1717
use partiql_beamline_query::strategy::{QueryStrategy, StrategyBoxed};
1818
use partiql_beamline_query::{QueryTextGenerator, QueryTextGeneratorConfigBuilder};
19-
use partiql_types::{BagType, PartiqlShape, StaticType};
19+
use partiql_types::{BagType, PartiqlShape, PartiqlShapeBuilder, StaticType};
2020
use rand::SeedableRng;
2121
use rand_pcg::Pcg64Mcg;
2222
use std::collections::Bound;
@@ -108,27 +108,27 @@ fn simple_ast_gen() -> miette::Result<()> {
108108
let from = FromTable {
109109
name: "Foo".to_string(),
110110
}
111-
.agboxed();
111+
.agboxed();
112112
let five = ConstantLiteral::Int8Lit(5).agboxed();
113113
let eight = ConstantLiteral::Int8Lit(8).agboxed();
114114
let sum = BinOp {
115115
kind: ast::BinOpKind::Add,
116116
lhs: five,
117117
rhs: eight,
118118
}
119-
.agboxed();
119+
.agboxed();
120120
let gt = BinOp {
121121
kind: ast::BinOpKind::Gt,
122122
lhs: sum,
123123
rhs: ConstantLiteral::Int8Lit(7).agboxed(),
124124
}
125-
.agboxed();
125+
.agboxed();
126126
let and = BinOp {
127127
kind: ast::BinOpKind::And,
128128
lhs: gt.clone(),
129129
rhs: gt,
130130
}
131-
.agboxed();
131+
.agboxed();
132132
let where_clause = Some(RowFilter { expr: and }.agboxed());
133133
let sfw = BasicSFW {
134134
project,
@@ -149,9 +149,9 @@ fn simple_strategy() -> miette::Result<()> {
149149
.into_diagnostic()?
150150
.sboxed();
151151

152-
let shape = PartiqlShape::new_bag(BagType::new(Box::new(PartiqlShape::Static(
153-
StaticType::new(partiql_types::Static::Int),
154-
))));
152+
let shape = PartiqlShapeBuilder::init_or_get().new_bag(BagType::new(Box::new(
153+
PartiqlShapeBuilder::init_or_get().new_static(partiql_types::Static::Int),
154+
)));
155155
let dataset = DatasetTypeMapping::from([("Table".to_string(), shape)]);
156156
let gen = strat.build(&dataset, rng).into_diagnostic()?;
157157

partiql-beamline-sim/src/gen/data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::gen::{DataGenerationResult, ValueGenerator};
33

44
use crate::sim::SimContext;
55
use indexmap::IndexMap;
6-
use partiql_types::{PartiqlShape, StructConstraint, StructField, StructType};
6+
use partiql_types::{PartiqlShape, PartiqlShapeBuilder, StructConstraint, StructField, StructType};
77
use partiql_value::{Tuple, Value};
88
use rand::Rng;
99
use std::fmt::{Debug, Formatter};
@@ -109,7 +109,8 @@ where
109109
}
110110
})
111111
.collect();
112-
PartiqlShape::new_struct(StructType::new([StructConstraint::Fields(fields)].into()))
112+
PartiqlShapeBuilder::init_or_get()
113+
.new_struct(StructType::new([StructConstraint::Fields(fields)].into()))
113114
}
114115
}
115116
}

partiql-beamline-sim/src/gen/distributions.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::gen::{DataGenerationResult, ValueGenerator};
22
use crate::sim::SimContext;
3-
use partiql_types::PartiqlShape;
3+
use partiql_types::{PartiqlShape, PartiqlShapeBuilder};
44
use partiql_value::Value;
55
use rand::Rng;
66
use rand_distr::Distribution;
@@ -197,7 +197,9 @@ where
197197
if self.density().null.is_some() {
198198
inner_type
199199
} else {
200-
inner_type.as_non_nullable().unwrap_or(inner_type)
200+
PartiqlShapeBuilder::init_or_get()
201+
.as_non_nullable(&inner_type)
202+
.expect("non-nullable")
201203
}
202204
}
203205

partiql-beamline-sim/src/gen/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::primitives::{DataSetId, DataSetName, ProcessId, Sample, Tick};
33
use crate::sim::{ConstantBindingValue, DatasetTypeMapping, SimContext};
44
use indexmap::map::Entry;
55
use indexmap::IndexMap;
6-
use partiql_types::{BagType, PartiqlShape};
6+
use partiql_types::{BagType, PartiqlShape, PartiqlShapeBuilder};
77

88
#[derive(Debug, Clone)]
99
pub struct SimpleProcess {
@@ -99,7 +99,7 @@ impl RandomDataSets {
9999
.map(|(k, v)| {
100100
(
101101
k.to_string(),
102-
PartiqlShape::new_bag(BagType::new(Box::new(v))),
102+
PartiqlShapeBuilder::init_or_get().new_bag(BagType::new(Box::new(v))),
103103
)
104104
})
105105
.collect()

partiql-beamline-sim/src/gen/simple.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::gen::distributions::{Density, InnerValueGenerator, Meta, RandomVariable};
22
use crate::gen::{DataGenerationError, DataGenerationResult, ValueGenerator};
33
use crate::sim::SimContext;
4-
use partiql_types::{ArrayType, PartiqlShape, TYPE_BOOL, TYPE_STRING};
4+
use partiql_types::{type_bool, type_string, ArrayType, PartiqlShape, PartiqlShapeBuilder};
55

66
use partiql_value::{List, Value};
77
use rand::distributions::Distribution;
@@ -35,7 +35,7 @@ where
3535
density: Density,
3636
) -> DataGenerationResult<Self> {
3737
let types: Vec<PartiqlShape> = generators.iter().map(|gen| gen.value_type()).collect();
38-
let types = PartiqlShape::any_of(types);
38+
let types = PartiqlShapeBuilder::init_or_get().any_of(types);
3939
let dist =
4040
statrs::distribution::DiscreteUniform::new(0, (generators.len() - 1) as i64)?.into();
4141
RandomVariable::create(
@@ -90,7 +90,8 @@ where
9090
"Empty choice vector".to_string(),
9191
));
9292
}
93-
let types = PartiqlShape::any_of(choices.iter().map(|v| v.infer_shape()));
93+
let types =
94+
PartiqlShapeBuilder::init_or_get().any_of(choices.iter().map(|v| v.infer_shape()));
9495
RandomVariable::create(rng, meta, density, SimpleChooseImpl { choices, types })
9596
}
9697
}
@@ -137,8 +138,8 @@ where
137138
Err(DataGenerationError::Bounds(min, max))
138139
} else {
139140
let dist = statrs::distribution::DiscreteUniform::new(min, max)?.into();
140-
let types =
141-
PartiqlShape::new_array(ArrayType::new(Box::new(elem_generator.value_type())));
141+
let types = PartiqlShapeBuilder::init_or_get()
142+
.new_array(ArrayType::new(Box::new(elem_generator.value_type())));
142143
RandomVariable::create(
143144
rng,
144145
meta,
@@ -200,7 +201,7 @@ where
200201
}
201202

202203
fn value_type(&self) -> PartiqlShape {
203-
TYPE_BOOL
204+
type_bool!()
204205
}
205206
}
206207

@@ -219,6 +220,6 @@ where
219220
}
220221

221222
fn value_type(&self) -> PartiqlShape {
222-
TYPE_STRING
223+
type_string!()
223224
}
224225
}

partiql-beamline-sim/src/gen/simple_numeric.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::gen::{DataGenerationError, DataGenerationResult};
33
use crate::sim::SimContext;
44

55
use partiql_types::{
6-
PartiqlShape, Static, TYPE_DOUBLE, TYPE_INT16, TYPE_INT32, TYPE_INT64, TYPE_INT8,
6+
type_float64, type_int16, type_int32, type_int64, type_int8, PartiqlShape, PartiqlShapeBuilder,
7+
Static,
78
};
89
use partiql_value::Value;
910
use rand::distributions::Distribution;
@@ -107,36 +108,30 @@ macro_rules! make_rv_ranged_continuous {
107108
};
108109
}
109110

110-
// TODO fix in partiql-type
111-
pub const TYPE_UINT8: PartiqlShape = PartiqlShape::new(Static::Int64);
112-
pub const TYPE_UINT16: PartiqlShape = PartiqlShape::new(Static::Int64);
113-
pub const TYPE_UINT32: PartiqlShape = PartiqlShape::new(Static::Int64);
114-
pub const TYPE_UINT64: PartiqlShape = PartiqlShape::new(Static::Int64);
115-
116111
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
117-
make_rv_ranged_discrete!(SimpleUInt8, SimpleUInt8Impl, u8, TYPE_UINT8, u8::MIN, u8::MAX);
112+
make_rv_ranged_discrete!(SimpleUInt8, SimpleUInt8Impl, u8, type_int8!(), u8::MIN, u8::MAX);
118113
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
119-
make_rv_ranged_discrete!(SimpleUInt16,SimpleUInt16Impl, u16, TYPE_UINT16, u16::MIN, u16::MAX);
114+
make_rv_ranged_discrete!(SimpleUInt16,SimpleUInt16Impl, u16, type_int16!(), u16::MIN, u16::MAX);
120115
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
121-
make_rv_ranged_discrete!(SimpleUInt32,SimpleUInt32Impl, u32, TYPE_UINT32, u32::MIN, u32::MAX);
116+
make_rv_ranged_discrete!(SimpleUInt32,SimpleUInt32Impl, u32, type_int32!(), u32::MIN, u32::MAX);
122117
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
123-
make_rv_ranged_discrete!(SimpleUInt64,SimpleUInt64Impl, u64, TYPE_UINT64, i64, u64::MIN as i64, i64::MAX);
118+
make_rv_ranged_discrete!(SimpleUInt64,SimpleUInt64Impl, u64, type_int64!(), i64, u64::MIN as i64, i64::MAX);
124119
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
125-
make_rv_ranged_discrete!(SimpleInt8, SimpleInt8Impl, i8, TYPE_INT8, i8::MIN, i8::MAX);
120+
make_rv_ranged_discrete!(SimpleInt8, SimpleInt8Impl, i8, type_int8!(), i8::MIN, i8::MAX);
126121
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
127-
make_rv_ranged_discrete!(SimpleInt16, SimpleInt16Impl, i16, TYPE_INT16, i16::MIN, i16::MAX);
122+
make_rv_ranged_discrete!(SimpleInt16, SimpleInt16Impl, i16, type_int16!(), i16::MIN, i16::MAX);
128123
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
129-
make_rv_ranged_discrete!(SimpleInt32, SimpleInt32Impl, i32, TYPE_INT32, i32::MIN, i32::MAX);
124+
make_rv_ranged_discrete!(SimpleInt32, SimpleInt32Impl, i32, type_int32!(), i32::MIN, i32::MAX);
130125
#[rustfmt::skip::macros(make_rv_ranged_discrete)]
131-
make_rv_ranged_discrete!(SimpleInt64, SimpleInt64Impl, i64, TYPE_INT64, i64::MIN, i64::MAX);
126+
make_rv_ranged_discrete!(SimpleInt64, SimpleInt64Impl, i64, type_int64!(), i64::MIN, i64::MAX);
132127

133128
rv_ranged!(SimpleF64Impl, f64, statrs::distribution::Uniform);
134129
rv_typedef!(
135130
#[doc = "Yields values of type f64"]
136131
SimpleF64,
137132
SimpleF64Impl
138133
);
139-
rv_ranged_ivg!(SimpleF64Impl, f64, TYPE_DOUBLE);
134+
rv_ranged_ivg!(SimpleF64Impl, f64, type_float64!());
140135

141136
impl<R> SimpleF64<R>
142137
where
@@ -236,7 +231,7 @@ where
236231
}
237232

238233
fn value_type(&self) -> PartiqlShape {
239-
PartiqlShape::new(Static::DecimalP(
234+
PartiqlShapeBuilder::init_or_get().new_static(Static::DecimalP(
240235
self.precision as usize,
241236
self.scale as usize,
242237
))

0 commit comments

Comments
 (0)