chore: upgrade some dependencies (#5777)

* chore: upgrade some dependencies

* chore: upgrade some dependencies

* fix: cr

* fix: ci

* fix: test

* fix: cargo fmt
This commit is contained in:
fys
2025-03-27 02:48:44 +00:00
committed by GitHub
parent e107bd5529
commit 2b2ea5bf72
55 changed files with 665 additions and 555 deletions
+4 -3
View File
@@ -16,6 +16,7 @@ use std::collections::HashSet;
use std::marker::PhantomData;
use lazy_static::lazy_static;
use rand::prelude::IndexedRandom;
use rand::seq::{IteratorRandom, SliceRandom};
use rand::Rng;
@@ -33,9 +34,9 @@ lazy_static! {
/// Modified from https://github.com/ucarion/faker_rand/blob/ea70c660e1ecd7320156eddb31d2830a511f8842/src/lib.rs
macro_rules! faker_impl_from_values {
($name: ident, $values: expr) => {
impl rand::distributions::Distribution<$name> for rand::distributions::Standard {
impl rand::distr::Distribution<$name> for rand::distr::StandardUniform {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $name {
$name($values[rng.gen_range(0..$values.len())].clone())
$name($values[rng.random_range(0..$values.len())].clone())
}
}
@@ -68,7 +69,7 @@ pub fn random_capitalize_map<R: Rng + 'static>(rng: &mut R, s: Ident) -> Ident {
let mut v = s.value.chars().collect::<Vec<_>>();
let str_len = s.value.len();
let select = rng.gen_range(0..str_len);
let select = rng.random_range(0..str_len);
for idx in (0..str_len).choose_multiple(rng, select) {
v[idx] = v[idx].to_uppercase().next().unwrap();
}
+24 -24
View File
@@ -40,7 +40,7 @@ fn add_column_options_generator<R: Rng>(
// 0 -> NULL
// 1 -> DEFAULT VALUE
// 2 -> PRIMARY KEY + DEFAULT VALUE
let idx = rng.gen_range(0..3);
let idx = rng.random_range(0..3);
match idx {
0 => vec![ColumnOption::Null],
1 => {
@@ -79,15 +79,15 @@ impl<R: Rng + 'static> Generator<AlterTableExpr, R> for AlterExprAddColumnGenera
type Error = Error;
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
let with_location = self.location && rng.gen::<bool>();
let with_location = self.location && rng.random::<bool>();
let location = if with_location {
let use_first = rng.gen::<bool>();
let use_first = rng.random::<bool>();
let location = if use_first {
AddColumnLocation::First
} else {
AddColumnLocation::After {
column_name: self.table_ctx.columns
[rng.gen_range(0..self.table_ctx.columns.len())]
[rng.random_range(0..self.table_ctx.columns.len())]
.name
.to_string(),
}
@@ -129,7 +129,7 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprDropColumnGenerator<R> {
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
let droppable = droppable_columns(&self.table_ctx.columns);
ensure!(!droppable.is_empty(), error::DroppableColumnsSnafu);
let name = droppable[rng.gen_range(0..droppable.len())].name.clone();
let name = droppable[rng.random_range(0..droppable.len())].name.clone();
Ok(AlterTableExpr {
table_name: self.table_ctx.name.clone(),
alter_kinds: AlterTableOperation::DropColumn { name },
@@ -174,7 +174,7 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprModifyDataTypeGenerator<R
fn generate(&self, rng: &mut R) -> Result<AlterTableExpr> {
let modifiable = modifiable_columns(&self.table_ctx.columns);
let changed = modifiable[rng.gen_range(0..modifiable.len())].clone();
let changed = modifiable[rng.random_range(0..modifiable.len())].clone();
let mut to_type = self.column_type_generator.gen(rng);
while !changed.column_type.can_arrow_type_cast_to(&to_type) {
to_type = self.column_type_generator.gen(rng);
@@ -209,8 +209,8 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
let all_options = AlterTableOption::iter().collect::<Vec<_>>();
// Generate random distinct options
let mut option_templates_idx = vec![];
for _ in 1..rng.gen_range(2..=all_options.len()) {
let option = rng.gen_range(0..all_options.len());
for _ in 1..rng.random_range(2..=all_options.len()) {
let option = rng.random_range(0..all_options.len());
if !option_templates_idx.contains(&option) {
option_templates_idx.push(option);
}
@@ -219,10 +219,10 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
.iter()
.map(|idx| match all_options[*idx] {
AlterTableOption::Ttl(_) => {
let ttl_type = rng.gen_range(0..3);
let ttl_type = rng.random_range(0..3);
match ttl_type {
0 => {
let duration: u32 = rng.gen();
let duration: u32 = rng.random();
AlterTableOption::Ttl(Ttl::Duration((duration as i64).into()))
}
1 => AlterTableOption::Ttl(Ttl::Instant),
@@ -231,27 +231,27 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprSetTableOptionsGenerator<
}
}
AlterTableOption::TwcsTimeWindow(_) => {
let time_window: u32 = rng.gen();
let time_window: u32 = rng.random();
AlterTableOption::TwcsTimeWindow((time_window as i64).into())
}
AlterTableOption::TwcsMaxOutputFileSize(_) => {
let max_output_file_size: u64 = rng.gen();
let max_output_file_size: u64 = rng.random();
AlterTableOption::TwcsMaxOutputFileSize(ReadableSize(max_output_file_size))
}
AlterTableOption::TwcsMaxInactiveWindowRuns(_) => {
let max_inactive_window_runs: u64 = rng.gen();
let max_inactive_window_runs: u64 = rng.random();
AlterTableOption::TwcsMaxInactiveWindowRuns(max_inactive_window_runs)
}
AlterTableOption::TwcsMaxActiveWindowFiles(_) => {
let max_active_window_files: u64 = rng.gen();
let max_active_window_files: u64 = rng.random();
AlterTableOption::TwcsMaxActiveWindowFiles(max_active_window_files)
}
AlterTableOption::TwcsMaxActiveWindowRuns(_) => {
let max_active_window_runs: u64 = rng.gen();
let max_active_window_runs: u64 = rng.random();
AlterTableOption::TwcsMaxActiveWindowRuns(max_active_window_runs)
}
AlterTableOption::TwcsMaxInactiveWindowFiles(_) => {
let max_inactive_window_files: u64 = rng.gen();
let max_inactive_window_files: u64 = rng.random();
AlterTableOption::TwcsMaxInactiveWindowFiles(max_inactive_window_files)
}
})
@@ -279,8 +279,8 @@ impl<R: Rng> Generator<AlterTableExpr, R> for AlterExprUnsetTableOptionsGenerato
let all_options = AlterTableOption::iter().collect::<Vec<_>>();
// Generate random distinct options
let mut option_templates_idx = vec![];
for _ in 1..rng.gen_range(2..=all_options.len()) {
let option = rng.gen_range(0..all_options.len());
for _ in 1..rng.random_range(2..=all_options.len()) {
let option = rng.random_range(0..all_options.len());
if !option_templates_idx.contains(&option) {
option_templates_idx.push(option);
}
@@ -325,7 +325,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"AddColumn":{"column":{"name":{"value":"velit","quote_style":null},"column_type":{"Int32":{}},"options":[{"DefaultValue":{"Int32":1606462472}}]},"location":null}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"AddColumn":{"column":{"name":{"value":"consequatur","quote_style":null},"column_type":{"Float64":{}},"options":[{"DefaultValue":{"Float64":0.48809950435391647}}]},"location":null}}}"#;
assert_eq!(expected, serialized);
let expr = AlterExprRenameGeneratorBuilder::default()
@@ -335,7 +335,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"RenameTable":{"new_table_name":{"value":"nihil","quote_style":null}}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"RenameTable":{"new_table_name":{"value":"voluptates","quote_style":null}}}}"#;
assert_eq!(expected, serialized);
let expr = AlterExprDropColumnGeneratorBuilder::default()
@@ -345,7 +345,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"DropColumn":{"name":{"value":"cUmquE","quote_style":null}}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"DropColumn":{"name":{"value":"ImPEDiT","quote_style":null}}}}"#;
assert_eq!(expected, serialized);
let expr = AlterExprModifyDataTypeGeneratorBuilder::default()
@@ -355,7 +355,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"ModifyDataType":{"column":{"name":{"value":"toTAm","quote_style":null},"column_type":{"Int64":{}},"options":[]}}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"ModifyDataType":{"column":{"name":{"value":"ADIpisci","quote_style":null},"column_type":{"Int64":{}},"options":[]}}}}"#;
assert_eq!(expected, serialized);
let expr = AlterExprSetTableOptionsGeneratorBuilder::default()
@@ -365,7 +365,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"SetTableOptions":{"options":[{"TwcsMaxActiveWindowRuns":14908016120444947142},{"TwcsMaxActiveWindowFiles":5840340123887173415},{"TwcsMaxOutputFileSize":17740311466571102265}]}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"SetTableOptions":{"options":[{"TwcsMaxOutputFileSize":16770910638250818741}]}}}"#;
assert_eq!(expected, serialized);
let expr = AlterExprUnsetTableOptionsGeneratorBuilder::default()
@@ -375,7 +375,7 @@ mod tests {
.generate(&mut rng)
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"alter_kinds":{"UnsetTableOptions":{"keys":["compaction.twcs.max_active_window_runs"]}}}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"alter_kinds":{"UnsetTableOptions":{"keys":["compaction.twcs.max_active_window_runs","compaction.twcs.max_output_file_size","compaction.twcs.time_window","compaction.twcs.max_inactive_window_files","compaction.twcs.max_active_window_files"]}}}"#;
assert_eq!(expected, serialized);
}
}
+6 -6
View File
@@ -399,7 +399,7 @@ mod tests {
#[test]
fn test_create_table_expr_generator() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let expr = CreateTableExprGeneratorBuilder::default()
.columns(10)
@@ -440,13 +440,13 @@ mod tests {
.unwrap();
let serialized = serde_json::to_string(&expr).unwrap();
let expected = r#"{"table_name":{"value":"animI","quote_style":null},"columns":[{"name":{"value":"IMpEdIT","quote_style":null},"column_type":{"Float64":{}},"options":["PrimaryKey","NotNull"]},{"name":{"value":"natuS","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"ADIPisCI","quote_style":null},"column_type":{"Float64":{}},"options":["Null"]},{"name":{"value":"EXpEdita","quote_style":null},"column_type":{"Int16":{}},"options":[{"DefaultValue":{"Int16":4864}}]},{"name":{"value":"cUlpA","quote_style":null},"column_type":{"Int64":{}},"options":["PrimaryKey"]},{"name":{"value":"MOLeStIAs","quote_style":null},"column_type":{"Float64":{}},"options":["NotNull"]},{"name":{"value":"cUmquE","quote_style":null},"column_type":{"Boolean":null},"options":["Null"]},{"name":{"value":"toTAm","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.21569687}}]},{"name":{"value":"deBitIs","quote_style":null},"column_type":{"Float64":{}},"options":["NotNull"]},{"name":{"value":"QUi","quote_style":null},"column_type":{"Float32":{}},"options":["Null"]}],"if_not_exists":true,"partition":{"partition_columns":["IMpEdIT"],"partition_bounds":[{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"Lt","rhs":{"Value":{"Float64":5.992310449541053e307}}}},{"Expr":{"lhs":{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"GtEq","rhs":{"Value":{"Float64":5.992310449541053e307}}}},"op":"And","rhs":{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"Lt","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}}},{"Expr":{"lhs":{"Column":"IMpEdIT"},"op":"GtEq","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}]},"engine":"mito2","options":{},"primary_keys":[0,4]}"#;
let expected = r#"{"table_name":{"value":"quasi","quote_style":null},"columns":[{"name":{"value":"mOLEsTIAs","quote_style":null},"column_type":{"Float64":{}},"options":["PrimaryKey","Null"]},{"name":{"value":"CUMQUe","quote_style":null},"column_type":{"Timestamp":{"Second":null}},"options":["TimeIndex"]},{"name":{"value":"NaTus","quote_style":null},"column_type":{"Int64":{}},"options":[]},{"name":{"value":"EXPeDITA","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"ImPEDiT","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.56425774}}]},{"name":{"value":"ADIpisci","quote_style":null},"column_type":{"Float32":{}},"options":["PrimaryKey"]},{"name":{"value":"deBITIs","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.31315368}}]},{"name":{"value":"toTaM","quote_style":null},"column_type":{"Int32":{}},"options":["NotNull"]},{"name":{"value":"QuI","quote_style":null},"column_type":{"Float32":{}},"options":[{"DefaultValue":{"Float32":0.39941502}}]},{"name":{"value":"INVeNtOre","quote_style":null},"column_type":{"Boolean":null},"options":["PrimaryKey"]}],"if_not_exists":true,"partition":{"partition_columns":["mOLEsTIAs"],"partition_bounds":[{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"Lt","rhs":{"Value":{"Float64":5.992310449541053e307}}}},{"Expr":{"lhs":{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"GtEq","rhs":{"Value":{"Float64":5.992310449541053e307}}}},"op":"And","rhs":{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"Lt","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}}},{"Expr":{"lhs":{"Column":"mOLEsTIAs"},"op":"GtEq","rhs":{"Value":{"Float64":1.1984620899082105e308}}}}]},"engine":"mito2","options":{},"primary_keys":[0,5,9]}"#;
assert_eq!(expected, serialized);
}
#[test]
fn test_create_logical_table_expr_generator() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let physical_table_expr = CreatePhysicalTableExprGeneratorBuilder::default()
.if_not_exists(false)
@@ -529,13 +529,13 @@ mod tests {
.unwrap();
let logical_table_serialized = serde_json::to_string(&logical_table_expr).unwrap();
let logical_table_expected = r#"{"table_name":{"value":"impedit","quote_style":null},"columns":[{"name":{"value":"ts","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"val","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"qui","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"totam","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"molestias","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"natus","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"cumque","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]}],"if_not_exists":false,"partition":null,"engine":"metric","options":{"on_physical_table":{"String":"expedita"}},"primary_keys":[2,5,3,6,4]}"#;
let logical_table_expected = r#"{"table_name":{"value":"impedit","quote_style":null},"columns":[{"name":{"value":"ts","quote_style":null},"column_type":{"Timestamp":{"Millisecond":null}},"options":["TimeIndex"]},{"name":{"value":"val","quote_style":null},"column_type":{"Float64":{}},"options":[]},{"name":{"value":"totam","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"cumque","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"natus","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"molestias","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]},{"name":{"value":"qui","quote_style":null},"column_type":{"String":null},"options":["PrimaryKey"]}],"if_not_exists":false,"partition":null,"engine":"metric","options":{"on_physical_table":{"String":"expedita"}},"primary_keys":[4,2,3,6,5]}"#;
assert_eq!(logical_table_expected, logical_table_serialized);
}
#[test]
fn test_create_database_expr_generator() {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let expr = CreateDatabaseExprGeneratorBuilder::default()
.if_not_exists(true)
@@ -558,7 +558,7 @@ mod tests {
let serialized = serde_json::to_string(&expr).unwrap();
let expected =
r#"{"database_name":{"value":"eXPedITa","quote_style":null},"if_not_exists":true}"#;
r#"{"database_name":{"value":"EXPediTA","quote_style":null},"if_not_exists":true}"#;
assert_eq!(expected, serialized);
}
}
+4 -4
View File
@@ -16,7 +16,7 @@ use std::marker::PhantomData;
use datatypes::value::Value;
use derive_builder::Builder;
use rand::seq::SliceRandom;
use rand::seq::{IndexedRandom, SliceRandom};
use rand::Rng;
use super::TsValueGenerator;
@@ -60,7 +60,7 @@ impl<R: Rng + 'static> Generator<InsertIntoExpr, R> for InsertExprGenerator<R> {
let can_omit = column.is_nullable() || column.has_default_value();
// 50% chance to omit a column if it's not required
if !can_omit || rng.gen_bool(0.5) {
if !can_omit || rng.random_bool(0.5) {
values_columns.push(column.clone());
}
}
@@ -76,12 +76,12 @@ impl<R: Rng + 'static> Generator<InsertIntoExpr, R> for InsertExprGenerator<R> {
for _ in 0..self.rows {
let mut row = Vec::with_capacity(values_columns.len());
for column in &values_columns {
if column.is_nullable() && rng.gen_bool(0.2) {
if column.is_nullable() && rng.random_bool(0.2) {
row.push(RowValue::Value(Value::Null));
continue;
}
if column.has_default_value() && rng.gen_bool(0.2) {
if column.has_default_value() && rng.random_bool(0.2) {
row.push(RowValue::Default);
continue;
}
+5 -5
View File
@@ -15,7 +15,7 @@
use std::marker::PhantomData;
use derive_builder::Builder;
use rand::seq::SliceRandom;
use rand::seq::{IndexedRandom, SliceRandom};
use rand::Rng;
use crate::context::TableContextRef;
@@ -37,7 +37,7 @@ impl<R: Rng + 'static> Generator<SelectExpr, R> for SelectExprGenerator<R> {
type Error = Error;
fn generate(&self, rng: &mut R) -> Result<SelectExpr> {
let selection = rng.gen_range(1..self.table_ctx.columns.len());
let selection = rng.random_range(1..self.table_ctx.columns.len());
let mut selected_columns = self
.table_ctx
.columns
@@ -46,16 +46,16 @@ impl<R: Rng + 'static> Generator<SelectExpr, R> for SelectExprGenerator<R> {
.collect::<Vec<_>>();
selected_columns.shuffle(rng);
let order_by_selection = rng.gen_range(1..selection);
let order_by_selection = rng.random_range(1..selection);
let order_by = selected_columns
.choose_multiple(rng, order_by_selection)
.map(|c| c.name.to_string())
.collect::<Vec<_>>();
let limit = rng.gen_range(1..self.max_limit);
let limit = rng.random_range(1..self.max_limit);
let direction = if rng.gen_bool(1.0 / 2.0) {
let direction = if rng.random_bool(1.0 / 2.0) {
Direction::Asc
} else {
Direction::Desc
+19 -19
View File
@@ -34,7 +34,7 @@ use datatypes::value::Value;
use derive_builder::Builder;
pub use insert_expr::InsertIntoExpr;
use lazy_static::lazy_static;
use rand::seq::SliceRandom;
use rand::seq::{IndexedRandom, SliceRandom};
use rand::Rng;
use serde::{Deserialize, Serialize};
@@ -146,15 +146,15 @@ pub fn generate_random_value<R: Rng>(
random_str: Option<&dyn Random<Ident, R>>,
) -> Value {
match datatype {
&ConcreteDataType::Boolean(_) => Value::from(rng.gen::<bool>()),
ConcreteDataType::Int16(_) => Value::from(rng.gen::<i16>()),
ConcreteDataType::Int32(_) => Value::from(rng.gen::<i32>()),
ConcreteDataType::Int64(_) => Value::from(rng.gen::<i64>()),
ConcreteDataType::Float32(_) => Value::from(rng.gen::<f32>()),
ConcreteDataType::Float64(_) => Value::from(rng.gen::<f64>()),
&ConcreteDataType::Boolean(_) => Value::from(rng.random::<bool>()),
ConcreteDataType::Int16(_) => Value::from(rng.random::<i16>()),
ConcreteDataType::Int32(_) => Value::from(rng.random::<i32>()),
ConcreteDataType::Int64(_) => Value::from(rng.random::<i64>()),
ConcreteDataType::Float32(_) => Value::from(rng.random::<f32>()),
ConcreteDataType::Float64(_) => Value::from(rng.random::<f64>()),
ConcreteDataType::String(_) => match random_str {
Some(random) => Value::from(random.gen(rng).value),
None => Value::from(rng.gen::<char>().to_string()),
None => Value::from(rng.random::<char>().to_string()),
},
ConcreteDataType::Date(_) => generate_random_date(rng),
@@ -188,25 +188,25 @@ pub fn generate_random_timestamp<R: Rng>(rng: &mut R, ts_type: TimestampType) ->
TimestampType::Second(_) => {
let min = i64::from(Timestamp::MIN_SECOND);
let max = i64::from(Timestamp::MAX_SECOND);
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_second(value)
}
TimestampType::Millisecond(_) => {
let min = i64::from(Timestamp::MIN_MILLISECOND);
let max = i64::from(Timestamp::MAX_MILLISECOND);
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_millisecond(value)
}
TimestampType::Microsecond(_) => {
let min = i64::from(Timestamp::MIN_MICROSECOND);
let max = i64::from(Timestamp::MAX_MICROSECOND);
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_microsecond(value)
}
TimestampType::Nanosecond(_) => {
let min = i64::from(Timestamp::MIN_NANOSECOND);
let max = i64::from(Timestamp::MAX_NANOSECOND);
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_nanosecond(value)
}
};
@@ -219,25 +219,25 @@ pub fn generate_random_timestamp_for_mysql<R: Rng>(rng: &mut R, ts_type: Timesta
TimestampType::Second(_) => {
let min = 1;
let max = 2_147_483_647;
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_second(value)
}
TimestampType::Millisecond(_) => {
let min = 1000;
let max = 2_147_483_647_499;
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_millisecond(value)
}
TimestampType::Microsecond(_) => {
let min = 1_000_000;
let max = 2_147_483_647_499_999;
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_microsecond(value)
}
TimestampType::Nanosecond(_) => {
let min = 1_000_000_000;
let max = 2_147_483_647_499_999_000;
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
Timestamp::new_nanosecond(value)
}
};
@@ -247,7 +247,7 @@ pub fn generate_random_timestamp_for_mysql<R: Rng>(rng: &mut R, ts_type: Timesta
fn generate_random_date<R: Rng>(rng: &mut R) -> Value {
let min = i64::from(Timestamp::MIN_MILLISECOND);
let max = i64::from(Timestamp::MAX_MILLISECOND);
let value = rng.gen_range(min..=max);
let value = rng.random_range(min..=max);
let date = Timestamp::new_millisecond(value).to_chrono_date().unwrap();
Value::from(Date::from(date))
}
@@ -411,7 +411,7 @@ pub fn column_options_generator<R: Rng>(
// 2 -> DEFAULT VALUE
// 3 -> PRIMARY KEY
// 4 -> EMPTY
let option_idx = rng.gen_range(0..5);
let option_idx = rng.random_range(0..5);
match option_idx {
0 => vec![ColumnOption::Null],
1 => vec![ColumnOption::NotNull],
@@ -434,7 +434,7 @@ pub fn partible_column_options_generator<R: Rng + 'static>(
// 1 -> NOT NULL
// 2 -> DEFAULT VALUE
// 3 -> PRIMARY KEY
let option_idx = rng.gen_range(0..4);
let option_idx = rng.random_range(0..4);
match option_idx {
0 => vec![ColumnOption::PrimaryKey, ColumnOption::Null],
1 => vec![ColumnOption::PrimaryKey, ColumnOption::NotNull],
+10 -10
View File
@@ -82,7 +82,7 @@ mod tests {
#[test]
fn test_insert_into_translator() {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0);
let omit_column_list = rng.gen_bool(0.2);
let omit_column_list = rng.random_bool(0.2);
let test_ctx = test_utils::new_test_ctx();
let insert_expr_generator = InsertExprGeneratorBuilder::default()
@@ -95,23 +95,23 @@ mod tests {
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
let expected = r#"INSERT INTO test (ts, host, cpu_util) VALUES
('+199601-11-07 21:32:56.695+0000', 'corrupti', 0.051130243193075464),
('+40822-03-25 02:17:34.328+0000', NULL, 0.6552502332327004);"#;
let expected = r#"INSERT INTO test (cpu_util, ts, host) VALUES
(0.494276426950336, '+210328-02-20 15:44:23.848+0000', 'aut'),
(0.5240550121500691, '-78231-02-16 05:32:41.400+0000', 'in');"#;
assert_eq!(output, expected);
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
let expected = r#"INSERT INTO test (ts, memory_util) VALUES
('+22606-05-02 04:44:02.976+0000', 0.7074194466620976),
('+33689-06-12 08:42:11.037+0000', 0.40987428386535585);"#;
let expected = r#"INSERT INTO test (ts, host) VALUES
('+137972-11-29 18:23:19.505+0000', 'repellendus'),
('-237884-01-11 09:44:43.491+0000', 'a');"#;
assert_eq!(output, expected);
let insert_expr = insert_expr_generator.generate(&mut rng).unwrap();
let output = InsertIntoExprTranslator.translate(&insert_expr).unwrap();
let expected = r#"INSERT INTO test (ts, disk_util, cpu_util, host) VALUES
('+200107-10-22 01:36:36.924+0000', 0.9082597320638828, 0.020853190804573818, 'voluptates'),
('+241156-12-16 20:52:15.185+0000', 0.6492772846116915, 0.18078027701087784, 'repellat');"#;
let expected = r#"INSERT INTO test (disk_util, ts) VALUES
(0.399415030703252, '+154545-01-21 09:38:13.768+0000'),
(NULL, '-227688-03-19 14:23:24.582+0000');"#;
assert_eq!(output, expected);
}
}
@@ -69,7 +69,8 @@ mod tests {
let select_expr = select_expr_generator.generate(&mut rng).unwrap();
let output = SelectExprTranslator.translate(&select_expr).unwrap();
let expected = r#"SELECT memory_util, ts, cpu_util, disk_util FROM test ORDER BY cpu_util, disk_util DESC;"#;
let expected =
r#"SELECT ts, memory_util, cpu_util, disk_util FROM test ORDER BY disk_util, ts DESC;"#;
assert_eq!(output, expected);
}
}
+3 -3
View File
@@ -191,9 +191,9 @@ impl UnstableProcessController {
self.running.store(true, Ordering::Relaxed);
let mut rng = ChaChaRng::seed_from_u64(self.seed);
while self.running.load(Ordering::Relaxed) {
let min = rng.gen_range(50..100);
let max = rng.gen_range(300..600);
let ms = rng.gen_range(min..max);
let min = rng.random_range(50..100);
let max = rng.random_range(300..600);
let ms = rng.random_range(min..max);
let pid = self
.start_process_with_retry(3)
.await