-
-
Notifications
You must be signed in to change notification settings - Fork 157
Query staging data #448
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
Merged
Merged
Query staging data #448
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b00761
Add local query
trueleo bb92227
Clippy
trueleo 509bcd5
Banner
trueleo e52c47b
Clippy
trueleo 76154ba
Clippy
trueleo 21851de
Fix filter optimizer
trueleo 8fa7739
Fix empty exec projection
trueleo f1dd539
Fix
trueleo b9f3f5c
Merge branch 'main' into arrow_stream
nitisht db793bd
Use memtable instead of streaming table
trueleo 97c33fc
Fix
trueleo 1ea2bf3
Merge branch 'main' into arrow_stream
nitisht 5bab6c9
Change limit
trueleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Parseable Server (C) 2022 - 2023 Parseable, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| use std::{collections::HashSet, sync::Arc}; | ||
|
|
||
| use arrow_array::RecordBatch; | ||
| use arrow_schema::Schema; | ||
| use arrow_select::concat::concat_batches; | ||
| use itertools::Itertools; | ||
|
|
||
| use crate::utils::arrow::adapt_batch; | ||
|
|
||
| /// Structure to keep recordbatches in memory. | ||
| /// | ||
| /// Any new schema is updated in the schema map. | ||
| /// Recordbatches are pushed to mutable buffer first and then concated together and pushed to read buffer | ||
| #[derive(Debug)] | ||
| pub struct MemWriter<const N: usize> { | ||
| schema: Schema, | ||
| // for checking uniqueness of schema | ||
| schema_map: HashSet<String>, | ||
| read_buffer: Vec<RecordBatch>, | ||
| mutable_buffer: MutableBuffer<N>, | ||
| } | ||
|
|
||
| impl<const N: usize> Default for MemWriter<N> { | ||
| fn default() -> Self { | ||
| Self { | ||
| schema: Schema::empty(), | ||
| schema_map: HashSet::default(), | ||
| read_buffer: Vec::default(), | ||
| mutable_buffer: MutableBuffer::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<const N: usize> MemWriter<N> { | ||
| pub fn push(&mut self, schema_key: &str, rb: RecordBatch) { | ||
| if !self.schema_map.contains(schema_key) { | ||
| self.schema_map.insert(schema_key.to_owned()); | ||
| self.schema = Schema::try_merge([self.schema.clone(), (*rb.schema()).clone()]).unwrap(); | ||
| } | ||
|
|
||
| if let Some(record) = self.mutable_buffer.push(rb) { | ||
| let record = concat_records(&Arc::new(self.schema.clone()), &record); | ||
| self.read_buffer.push(record); | ||
| } | ||
| } | ||
|
|
||
| pub fn recordbatch_cloned(&self, schema: &Arc<Schema>) -> Vec<RecordBatch> { | ||
| let mut read_buffer = self.read_buffer.clone(); | ||
| if self.mutable_buffer.rows > 0 { | ||
| let rb = concat_records(schema, &self.mutable_buffer.inner); | ||
| read_buffer.push(rb) | ||
| } | ||
|
|
||
| read_buffer | ||
| .into_iter() | ||
| .map(|rb| adapt_batch(schema, &rb)) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| fn concat_records(schema: &Arc<Schema>, record: &[RecordBatch]) -> RecordBatch { | ||
| let records = record.iter().map(|x| adapt_batch(schema, x)).collect_vec(); | ||
| let record = concat_batches(schema, records.iter()).unwrap(); | ||
| record | ||
| } | ||
|
|
||
| #[derive(Debug, Default)] | ||
| struct MutableBuffer<const N: usize> { | ||
| pub inner: Vec<RecordBatch>, | ||
| pub rows: usize, | ||
| } | ||
|
|
||
| impl<const N: usize> MutableBuffer<N> { | ||
| fn push(&mut self, rb: RecordBatch) -> Option<Vec<RecordBatch>> { | ||
| if self.rows + rb.num_rows() >= N { | ||
| let left = N - self.rows; | ||
| let right = rb.num_rows() - left; | ||
| let left_slice = rb.slice(0, left); | ||
| let right_slice = if left < rb.num_rows() { | ||
| Some(rb.slice(left, right)) | ||
| } else { | ||
| None | ||
| }; | ||
| self.inner.push(left_slice); | ||
| // take all records | ||
| let src = Vec::with_capacity(self.inner.len()); | ||
| let inner = std::mem::replace(&mut self.inner, src); | ||
| self.rows = 0; | ||
|
|
||
| if let Some(right_slice) = right_slice { | ||
| self.rows = right_slice.num_rows(); | ||
| self.inner.push(right_slice); | ||
| } | ||
|
|
||
| Some(inner) | ||
| } else { | ||
| self.rows += rb.num_rows(); | ||
| self.inner.push(rb); | ||
| None | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.