Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql fixes #1574

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/deployment/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn for_each_state(
append_deployment_row(&mut builder, &mut temp, deployment);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -87,6 +87,6 @@ async fn for_each_state(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/idempotency/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn for_each_state(
);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -91,6 +91,6 @@ async fn for_each_state(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/inbox/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn for_each_state(
append_inbox_row(&mut builder, &mut temp, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -84,6 +84,6 @@ async fn for_each_state(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/invocation_state/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async fn for_each_state<'a, I>(
append_state_row(&mut builder, &mut temp, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -90,6 +90,6 @@ async fn for_each_state<'a, I>(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn for_each_status<'a, I>(
append_invocation_status_row(&mut builder, &mut temp, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -81,6 +81,6 @@ async fn for_each_status<'a, I>(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/journal/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn for_each_journal<'a, I>(
append_journal_row(&mut builder, &mut temp, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -81,6 +81,6 @@ async fn for_each_journal<'a, I>(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
77 changes: 76 additions & 1 deletion crates/storage-query-datafusion/src/journal/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use crate::mocks::*;
use crate::row;
use bytes::Bytes;
use datafusion::arrow::array::{LargeStringArray, UInt32Array};
use datafusion::arrow::array::{Int64Array, LargeStringArray, UInt32Array};
use datafusion::arrow::record_batch::RecordBatch;
use futures::StreamExt;
use googletest::all;
Expand Down Expand Up @@ -130,3 +130,78 @@ async fn get_entries() {
)
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn select_count_star() {
let tc = TaskCenterBuilder::default()
.default_runtime_handle(tokio::runtime::Handle::current())
.build()
.expect("task_center builds");
let mut engine = tc
.run_in_scope("mock-query-engine", None, MockQueryEngine::create())
.await;

let mut tx = engine.partition_store().transaction();
let journal_invocation_id = InvocationId::mock_random();
tx.put_journal_entry(
&journal_invocation_id,
0,
JournalEntry::Entry(ProtobufRawEntryCodec::serialize_enriched(Entry::Input(
InputEntry {
value: Default::default(),
},
))),
)
.await;
tx.put_journal_entry(
&journal_invocation_id,
1,
JournalEntry::Entry(EnrichedRawEntry::new(
EnrichedEntryHeader::Call {
is_completed: false,
enrichment_result: Some(CallEnrichmentResult {
invocation_id: InvocationId::mock_random(),
invocation_target: InvocationTarget::mock_virtual_object(),
completion_retention_time: None,
span_context: Default::default(),
}),
},
Bytes::new(),
)),
)
.await;
tx.put_journal_entry(
&journal_invocation_id,
2,
JournalEntry::Entry(EnrichedRawEntry::new(
EnrichedEntryHeader::Run {},
service_protocol::RunEntryMessage {
name: "my-side-effect".to_string(),
result: None,
}
.encode_to_vec()
.into(),
)),
)
.await;
tx.commit().await.unwrap();

let records = engine
.execute("SELECT COUNT(*) AS count FROM sys_journal")
.await
.unwrap()
.collect::<Vec<Result<RecordBatch, _>>>()
.await
.remove(0)
.unwrap();

assert_that!(
records,
all!(row!(
0,
{
"count" => Int64Array: eq(3)
}
),)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn for_each_status<'a, I>(
append_virtual_object_status_row(&mut builder, &mut temp, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -81,6 +81,6 @@ async fn for_each_status<'a, I>(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/promise/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn for_each_state(
append_promise_row(&mut builder, &mut temp, owned_promise_row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -81,6 +81,6 @@ async fn for_each_state(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/service/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn for_each_state(
append_service_row(&mut builder, &mut temp, service);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -86,6 +86,6 @@ async fn for_each_state(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
4 changes: 2 additions & 2 deletions crates/storage-query-datafusion/src/state/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn for_each_state<'a, I>(
append_state_row(&mut builder, row);
if builder.full() {
let batch = builder.finish();
if tx.send(Ok(batch)).await.is_err() {
if tx.send(batch).await.is_err() {
// not sure what to do here?
// the other side has hung up on us.
// we probably don't want to panic, is it will cause the entire process to exit
Expand All @@ -80,6 +80,6 @@ async fn for_each_state<'a, I>(
}
if !builder.empty() {
let result = builder.finish();
let _ = tx.send(Ok(result)).await;
let _ = tx.send(result).await;
}
}
7 changes: 5 additions & 2 deletions crates/storage-query-datafusion/src/table_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,12 @@ macro_rules! define_table {
self.rows_inserted_so_far == 0
}

pub fn finish(self) -> ::datafusion::arrow::record_batch::RecordBatch {
pub fn finish(self) -> ::datafusion::common::Result<::datafusion::arrow::record_batch::RecordBatch> {
let arrays = self.arrays.finish();
::datafusion::arrow::record_batch::RecordBatch::try_new(self.projected_schema, arrays).unwrap()
// We add the row count as it wouldn't otherwise work with queries that
// just run aggregate functions (e.g. COUNT(*)) without selecting fields.
let options = ::datafusion::arrow::record_batch::RecordBatchOptions::new().with_row_count(Some(self.rows_inserted_so_far));
Ok(::datafusion::arrow::record_batch::RecordBatch::try_new_with_options(self.projected_schema, arrays, &options)?)
slinkydeveloper marked this conversation as resolved.
Show resolved Hide resolved
}

}
Expand Down
Loading