Skip to content

Commit 4acf218

Browse files
authored
refactor(cubesql): Finally drop MySQL 💀 (#10022)
1 parent 1729e96 commit 4acf218

File tree

20 files changed

+54
-959
lines changed

20 files changed

+54
-959
lines changed

rust/cubesql/cubesql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.28.0"
44
authors = ["Cube Dev, Inc."]
55
edition = "2018"
66
license = "Apache-2.0"
7-
description = "SQL API for Cube as proxy over MySQL protocol"
7+
description = "SQL API for Cube as proxy over PostgreSQL protocol"
88
documentation = "https://cube.dev/docs"
99
homepage = "https://cube.dev"
1010

rust/cubesql/cubesql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Cube SQL API
1212

13-
Cube SQL API allows querying Cube via MySQL-compatible SQL.
13+
Cube SQL API allows querying Cube via PostgreSQL-compatible SQL.
1414

1515
## License
1616

rust/cubesql/cubesql/src/compile/engine/context_mysql.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

rust/cubesql/cubesql/src/compile/engine/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ pub mod information_schema;
33
pub mod udf;
44

55
mod context;
6-
mod context_mysql;
76
mod context_postgresql;
8-
mod variable_provider;
97

108
// Public API
119
pub use context::*;
12-
pub use variable_provider::*;

rust/cubesql/cubesql/src/compile/engine/udf/common.rs

Lines changed: 5 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use datafusion::{
1212
array::{
1313
new_null_array, Array, ArrayBuilder, ArrayRef, BooleanArray, BooleanBuilder,
1414
Date32Array, Float64Array, Float64Builder, GenericStringArray, Int32Array,
15-
Int32Builder, Int64Array, Int64Builder, IntervalDayTimeBuilder,
16-
IntervalMonthDayNanoArray, ListArray, ListBuilder, PrimitiveArray, PrimitiveBuilder,
17-
StringArray, StringBuilder, StructBuilder, TimestampMicrosecondArray,
18-
TimestampMillisecondArray, TimestampNanosecondArray, TimestampNanosecondBuilder,
19-
TimestampSecondArray, UInt32Builder, UInt64Builder,
15+
Int32Builder, Int64Array, Int64Builder, IntervalMonthDayNanoArray, ListArray,
16+
ListBuilder, PrimitiveArray, PrimitiveBuilder, StringArray, StringBuilder,
17+
StructBuilder, TimestampMicrosecondArray, TimestampMillisecondArray,
18+
TimestampNanosecondArray, TimestampNanosecondBuilder, TimestampSecondArray,
19+
UInt32Builder, UInt64Builder,
2020
},
2121
compute::{cast, concat},
2222
datatypes::{
@@ -101,28 +101,6 @@ pub fn create_db_udf(name: String, state: Arc<SessionState>) -> ScalarUDF {
101101
)
102102
}
103103

104-
// It's the same as current_user UDF, but with another host
105-
pub fn create_user_udf(state: Arc<SessionState>) -> ScalarUDF {
106-
let fun = make_scalar_function(move |_args: &[ArrayRef]| {
107-
let mut builder = StringBuilder::new(1);
108-
if let Some(user) = &state.user() {
109-
builder.append_value(user.clone() + "@127.0.0.1").unwrap();
110-
} else {
111-
builder.append_null()?;
112-
}
113-
114-
Ok(Arc::new(builder.finish()) as ArrayRef)
115-
});
116-
117-
create_udf(
118-
"user",
119-
vec![],
120-
Arc::new(DataType::Utf8),
121-
Volatility::Immutable,
122-
fun,
123-
)
124-
}
125-
126104
pub fn create_current_user_udf(state: Arc<SessionState>, name: &str, with_host: bool) -> ScalarUDF {
127105
let fun = make_scalar_function(move |_args: &[ArrayRef]| {
128106
let mut builder = StringBuilder::new(1);
@@ -776,134 +754,6 @@ pub fn create_greatest_udf() -> ScalarUDF {
776754
)
777755
}
778756

779-
// CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.
780-
pub fn create_convert_tz_udf() -> ScalarUDF {
781-
let fun = make_scalar_function(move |args: &[ArrayRef]| {
782-
assert!(args.len() == 3);
783-
784-
let input_dt = &args[0];
785-
let from_tz = &args[1];
786-
let to_tz = &args[2];
787-
788-
let (_, input_tz) = match input_dt.data_type() {
789-
DataType::Timestamp(unit, tz) => (unit, tz),
790-
_ => {
791-
return Err(DataFusionError::Execution(format!(
792-
"dt argument must be a Timestamp, actual: {}",
793-
from_tz.data_type()
794-
)));
795-
}
796-
};
797-
798-
if from_tz.data_type() == &DataType::UInt8 {
799-
return Err(DataFusionError::Execution(format!(
800-
"from_tz argument must be a Utf8, actual: {}",
801-
from_tz.data_type()
802-
)));
803-
};
804-
805-
if to_tz.data_type() == &DataType::UInt8 {
806-
return Err(DataFusionError::Execution(format!(
807-
"to_tz argument must be a Utf8, actual: {}",
808-
to_tz.data_type()
809-
)));
810-
};
811-
812-
let from_tz = downcast_string_arg!(&from_tz, "from_tz", i32);
813-
let to_tz = downcast_string_arg!(&to_tz, "to_tz", i32);
814-
815-
if from_tz.value(0) != "SYSTEM" || to_tz.value(0) != "+00:00" {
816-
return Err(DataFusionError::NotImplemented(format!(
817-
"convert_tz is not implemented, it's stub"
818-
)));
819-
}
820-
821-
if let Some(tz) = input_tz {
822-
if tz != "UTC" {
823-
return Err(DataFusionError::NotImplemented(format!(
824-
"convert_tz does not non UTC timezone as input, actual {}",
825-
tz
826-
)));
827-
};
828-
};
829-
830-
Ok(input_dt.clone())
831-
});
832-
833-
let return_type: ReturnTypeFunction = Arc::new(move |types| {
834-
assert!(types.len() == 3);
835-
836-
Ok(Arc::new(types[0].clone()))
837-
});
838-
839-
ScalarUDF::new(
840-
"convert_tz",
841-
&Signature::any(3, Volatility::Immutable),
842-
&return_type,
843-
&fun,
844-
)
845-
}
846-
847-
pub fn create_timediff_udf() -> ScalarUDF {
848-
let fun = make_scalar_function(move |args: &[ArrayRef]| {
849-
assert!(args.len() == 2);
850-
851-
let left_dt = &args[0];
852-
let right_dt = &args[1];
853-
854-
let left_date = match left_dt.data_type() {
855-
DataType::Timestamp(TimeUnit::Nanosecond, _) => {
856-
let arr = downcast_primitive_arg!(left_dt, "left_dt", TimestampNanosecondType);
857-
let ts = arr.value(0);
858-
859-
// NaiveDateTime::from_timestamp(ts, 0)
860-
ts
861-
}
862-
_ => {
863-
return Err(DataFusionError::Execution(format!(
864-
"left_dt argument must be a Timestamp, actual: {}",
865-
left_dt.data_type()
866-
)));
867-
}
868-
};
869-
870-
let right_date = match right_dt.data_type() {
871-
DataType::Timestamp(TimeUnit::Nanosecond, _) => {
872-
let arr = downcast_primitive_arg!(right_dt, "right_dt", TimestampNanosecondType);
873-
arr.value(0)
874-
}
875-
_ => {
876-
return Err(DataFusionError::Execution(format!(
877-
"right_dt argument must be a Timestamp, actual: {}",
878-
right_dt.data_type()
879-
)));
880-
}
881-
};
882-
883-
let diff = right_date - left_date;
884-
if diff != 0 {
885-
return Err(DataFusionError::NotImplemented(format!(
886-
"timediff is not implemented, it's stub"
887-
)));
888-
}
889-
890-
let mut interal_arr = IntervalDayTimeBuilder::new(1);
891-
interal_arr.append_value(diff)?;
892-
893-
Ok(Arc::new(interal_arr.finish()) as ArrayRef)
894-
});
895-
896-
let return_type: ReturnTypeFunction =
897-
Arc::new(move |_| Ok(Arc::new(DataType::Interval(IntervalUnit::DayTime))));
898-
899-
ScalarUDF::new(
900-
"timediff",
901-
&Signature::any(2, Volatility::Immutable),
902-
&return_type,
903-
&fun,
904-
)
905-
}
906-
907757
pub fn create_ends_with_udf() -> ScalarUDF {
908758
let fun = make_scalar_function(move |args: &[ArrayRef]| {
909759
assert!(args.len() == 2);

rust/cubesql/cubesql/src/compile/engine/variable_provider.rs

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)