Skip to content

Commit abaefb0

Browse files
committed
chore(cubestore): New cubestore rebased to master
1 parent d181f49 commit abaefb0

File tree

7 files changed

+100
-111
lines changed

7 files changed

+100
-111
lines changed

rust/cubestore/cubestore/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(async_closure)]
21
#![feature(box_patterns)]
32
#![feature(hash_set_entry)]
43

rust/cubestore/cubestore/src/metastore/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4972,7 +4972,7 @@ mod tests {
49724972

49734973
#[test]
49744974
fn test_structures_size() {
4975-
assert_eq!(std::mem::size_of::<MetaStoreEvent>(), 672);
4975+
assert_eq!(std::mem::size_of::<MetaStoreEvent>(), 640);
49764976
}
49774977

49784978
#[tokio::test]

rust/cubestore/cubestore/src/queryplanner/info_schema/system_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl InfoSchemaTableDef for SystemChunksTableDef {
105105
row.get_row()
106106
.created_at()
107107
.as_ref()
108-
.map(|t| t.timestamp_nanos())
108+
.map(timestamp_nanos_or_panic)
109109
},
110110
)))
111111
}),

rust/cubestore/cubestore/src/queryplanner/info_schema/system_tables.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,23 @@ impl InfoSchemaTableDef for SystemTablesTableDef {
181181
)))
182182
}),
183183
Box::new(|tables| {
184-
Arc::new(StringArray::from_iter_values(
185-
tables
186-
.iter()
187-
.map(|row| {
188-
row.table
189-
.get_row()
190-
.seal_at()
191-
.as_ref()
192-
.map(timestamp_nanos_or_panic)
193-
})
194-
.collect::<Vec<_>>(),
195-
))
184+
Arc::new(TimestampNanosecondArray::from_iter(tables.iter().map(
185+
|row| {
186+
row.table
187+
.get_row()
188+
.seal_at()
189+
.as_ref()
190+
.map(timestamp_nanos_or_panic)
191+
},
192+
)))
196193
}),
197194
Box::new(|tables| {
198-
Arc::new(BooleanArray::from_iter_values(
199-
tables.iter().map(|row| row.table.get_row().sealed()),
195+
Arc::new(BooleanArray::from_iter(
196+
tables.iter().map(|row| Some(row.table.get_row().sealed())),
200197
))
201198
}),
202199
Box::new(|tables| {
203-
Arc::new(StringArray::from_iter_values(tables.iter().map(|row| {
200+
Arc::new(StringArray::from_iter(tables.iter().map(|row| {
204201
row.table
205202
.get_row()
206203
.select_statement()

rust/cubestore/cubestore/src/queryplanner/topk/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ struct ColumnProjection<'a> {
321321

322322
fn extract_projections_and_havings(
323323
p: &Arc<LogicalPlan>,
324-
) -> Result<Option<ColumnProjection>, DataFusionError> {
324+
) -> Result<Option<ColumnProjection<'_>>, DataFusionError> {
325325
// Goal: Deal with arbitrary series of Projection and Filter, where the Projections are column
326326
// projections (or cardinality(column)), on top of an underlying node.
327327
//

rust/cubestore/cubestore/src/queryplanner/udfs.rs

Lines changed: 78 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//TODO rebase use super::udf_xirr::XirrAccumulator;
2-
use crate::queryplanner::coalesce::SUPPORTED_COALESCE_TYPES;
31
use crate::queryplanner::hll::{Hll, HllUnion};
42
use crate::queryplanner::info_schema::timestamp_nanos_or_panic;
53
use crate::queryplanner::udf_xirr::{XirrUDF, XIRR_UDAF_NAME};
@@ -32,6 +30,7 @@ pub fn registerable_scalar_udfs_iter() -> impl Iterator<Item = ScalarUDF> {
3230
ScalarUDF::new_from_impl(DateAddSub::new_sub()),
3331
ScalarUDF::new_from_impl(UnixTimestamp::new()),
3432
ScalarUDF::new_from_impl(ConvertTz::new()),
33+
ScalarUDF::new_from_impl(Now::new()),
3534
]
3635
.into_iter()
3736
}
@@ -72,62 +71,74 @@ pub fn aggregate_kind_by_name(n: &str) -> Option<CubeAggregateUDFKind> {
7271
// TODO: add custom type and use it instead of `Binary` for HLL columns.
7372

7473
#[derive(Debug)]
75-
struct UnixTimestamp {
74+
struct Now {
7675
signature: Signature,
7776
}
7877

79-
struct Now {}
8078
impl Now {
79+
fn new() -> Self {
80+
Now {
81+
signature: Self::signature(),
82+
}
83+
}
84+
8185
fn signature() -> Signature {
82-
Signature::Exact(Vec::new())
86+
Signature::exact(Vec::new(), Volatility::Stable)
8387
}
8488
}
85-
/* TODO rebase - reimplement for new interface
86-
impl CubeScalarUDF for Now {
87-
fn kind(&self) -> CubeScalarUDFKind {
88-
CubeScalarUDFKind::Now
89-
}
9089

90+
impl ScalarUDFImpl for Now {
9191
fn name(&self) -> &str {
9292
"NOW"
9393
}
9494

95-
fn descriptor(&self) -> ScalarUDF {
96-
ScalarUDF {
97-
name: self.name().to_string(),
98-
signature: Self::signature(),
99-
return_type: Arc::new(|inputs| {
100-
assert!(inputs.is_empty());
101-
Ok(Arc::new(DataType::Timestamp(TimeUnit::Nanosecond, None)))
102-
}),
103-
fun: Arc::new(|_| {
104-
let t = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
105-
Ok(t) => t,
106-
Err(e) => {
107-
return Err(DataFusionError::Internal(format!(
108-
"Failed to get current timestamp: {}",
109-
e
110-
)))
111-
}
112-
};
113-
114-
let nanos = match i64::try_from(t.as_nanos()) {
115-
Ok(t) => t,
116-
Err(e) => {
117-
return Err(DataFusionError::Internal(format!(
118-
"Failed to convert timestamp to i64: {}",
119-
e
120-
)))
121-
}
122-
};
95+
fn as_any(&self) -> &dyn Any {
96+
self
97+
}
12398

124-
Ok(ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(
125-
Some(nanos),
99+
fn signature(&self) -> &Signature {
100+
&self.signature
101+
}
102+
103+
fn return_type(&self, _arg_types: &[DataType]) -> datafusion::common::Result<DataType> {
104+
Ok(DataType::Timestamp(TimeUnit::Nanosecond, None))
105+
}
106+
107+
fn invoke_with_args(
108+
&self,
109+
_args: datafusion::logical_expr::ScalarFunctionArgs,
110+
) -> datafusion::error::Result<ColumnarValue> {
111+
let t = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
112+
Ok(t) => t,
113+
Err(e) => {
114+
return Err(DataFusionError::Internal(format!(
115+
"Failed to get current timestamp: {}",
116+
e
126117
)))
127-
}),
128-
}
118+
}
119+
};
120+
121+
let nanos = match i64::try_from(t.as_nanos()) {
122+
Ok(t) => t,
123+
Err(e) => {
124+
return Err(DataFusionError::Internal(format!(
125+
"Failed to convert timestamp to i64: {}",
126+
e
127+
)))
128+
}
129+
};
130+
131+
Ok(ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(
132+
Some(nanos),
133+
None,
134+
)))
129135
}
130-
} */
136+
}
137+
138+
#[derive(Debug)]
139+
struct UnixTimestamp {
140+
signature: Signature,
141+
}
131142

132143
impl UnixTimestamp {
133144
pub fn new() -> Self {
@@ -145,40 +156,6 @@ impl ScalarUDFImpl for UnixTimestamp {
145156
"unix_timestamp"
146157
}
147158

148-
/* TODO rebase - reimplement for new interface
149-
* fn descriptor(&self) -> ScalarUDF {
150-
ScalarUDF {
151-
name: self.name().to_string(),
152-
signature: Self::signature(),
153-
return_type: Arc::new(|inputs| {
154-
assert!(inputs.is_empty());
155-
Ok(Arc::new(DataType::Int64))
156-
}),
157-
fun: Arc::new(|_| {
158-
let t = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
159-
Ok(t) => t,
160-
Err(e) => {
161-
return Err(DataFusionError::Internal(format!(
162-
"Failed to get current timestamp: {}",
163-
e
164-
)))
165-
}
166-
};
167-
168-
let seconds = match i64::try_from(t.as_secs()) {
169-
Ok(t) => t,
170-
Err(e) => {
171-
return Err(DataFusionError::Internal(format!(
172-
"Failed to convert timestamp to i64: {}",
173-
e
174-
)))
175-
}
176-
};
177-
178-
Ok(ColumnarValue::Scalar(ScalarValue::Int64(Some(seconds))))
179-
}),
180-
}
181-
}*/
182159
fn as_any(&self) -> &dyn Any {
183160
self
184161
}
@@ -191,16 +168,31 @@ impl ScalarUDFImpl for UnixTimestamp {
191168
Ok(DataType::Int64)
192169
}
193170

194-
fn invoke(&self, _args: &[ColumnarValue]) -> datafusion::common::Result<ColumnarValue> {
195-
Err(DataFusionError::Internal(
196-
"UNIX_TIMESTAMP() was not optimized away".to_string(),
197-
))
198-
}
171+
fn invoke_with_args(
172+
&self,
173+
_args: datafusion::logical_expr::ScalarFunctionArgs,
174+
) -> datafusion::error::Result<ColumnarValue> {
175+
let t = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
176+
Ok(t) => t,
177+
Err(e) => {
178+
return Err(DataFusionError::Internal(format!(
179+
"Failed to get current timestamp: {}",
180+
e
181+
)))
182+
}
183+
};
199184

200-
fn invoke_no_args(&self, _number_rows: usize) -> datafusion::common::Result<ColumnarValue> {
201-
Err(DataFusionError::Internal(
202-
"UNIX_TIMESTAMP() was not optimized away".to_string(),
203-
))
185+
let seconds = match i64::try_from(t.as_secs()) {
186+
Ok(t) => t,
187+
Err(e) => {
188+
return Err(DataFusionError::Internal(format!(
189+
"Failed to convert timestamp to i64: {}",
190+
e
191+
)))
192+
}
193+
};
194+
195+
Ok(ColumnarValue::Scalar(ScalarValue::Int64(Some(seconds))))
204196
}
205197

206198
fn simplify(

rust/cubestore/cubestore/src/sql/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,13 @@ impl SqlService for SqlServiceImpl {
808808

809809
let disable_quoting = with_options
810810
.iter()
811-
.find(|&opt| opt.name.value == "disable_quoting")
812-
.map_or(Ok(false), |option| match &option.value {
813-
Value::Boolean(value) => Ok(*value),
811+
.filter_map(filter_sql_option_key_value)
812+
.find(|&(name, _)| name.value == "disable_quoting")
813+
.map_or(Ok(false), |(_, value)| match value {
814+
Expr::Value(Value::Boolean(value)) => Ok(*value),
814815
_ => Err(CubeError::user(format!(
815816
"Bad disable_quoting flag (expected boolean) {}",
816-
option.value
817+
value
817818
))),
818819
})?;
819820

@@ -4349,9 +4350,9 @@ mod tests {
43494350
};
43504351
assert_eq!(
43514352
pp_plan,
4352-
"Projection, [information_schema.tables.table_name]\
4353+
"Projection, [information_schema.tables.table_name:table_name]\
43534354
\n Filter\
4354-
\n Scan information_schema.tables, source: InfoSchemaTableProvider, fields: [table_schema, table_name]"
4355+
\n Scan information_schema.tables, source: InfoSchemaTableProvider(table: Tables), fields: [table_schema, table_name]"
43554356
);
43564357
}).await;
43574358
}

0 commit comments

Comments
 (0)