|
17 | 17 | *
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -pub mod format; |
| 20 | +use std::{collections::HashMap, sync::Arc}; |
21 | 21 |
|
22 | 22 | use arrow_array::RecordBatch;
|
23 |
| -use arrow_schema::{Field, Fields, Schema}; |
24 |
| -use itertools::Itertools; |
25 |
| -use std::sync::Arc; |
26 |
| - |
27 |
| -use self::error::EventError; |
28 |
| -use crate::{ |
29 |
| - metadata::update_stats, |
30 |
| - parseable::{StagingError, PARSEABLE}, |
31 |
| - storage::StreamType, |
32 |
| - LOCK_EXPECT, |
33 |
| -}; |
| 23 | +use arrow_schema::Field; |
34 | 24 | use chrono::NaiveDateTime;
|
35 |
| -use std::collections::HashMap; |
| 25 | +use error::EventError; |
| 26 | +use itertools::Itertools; |
| 27 | + |
| 28 | +use crate::{metadata::update_stats, parseable::PARSEABLE, storage::StreamType}; |
| 29 | + |
| 30 | +pub mod format; |
36 | 31 |
|
37 | 32 | pub const DEFAULT_TIMESTAMP_KEY: &str = "p_timestamp";
|
38 | 33 | pub const USER_AGENT_KEY: &str = "p_user_agent";
|
@@ -67,11 +62,12 @@ impl Event {
|
67 | 62 | }
|
68 | 63 | }
|
69 | 64 |
|
| 65 | + let stream = PARSEABLE.get_or_create_stream(&self.stream_name); |
70 | 66 | if self.is_first_event {
|
71 |
| - commit_schema(&self.stream_name, self.rb.schema())?; |
| 67 | + stream.commit_schema(self.rb.schema())?; |
72 | 68 | }
|
73 | 69 |
|
74 |
| - PARSEABLE.get_or_create_stream(&self.stream_name).push( |
| 70 | + stream.push( |
75 | 71 | &key,
|
76 | 72 | &self.rb,
|
77 | 73 | self.parsed_timestamp,
|
@@ -117,32 +113,20 @@ pub fn get_schema_key(fields: &[Arc<Field>]) -> String {
|
117 | 113 | format!("{hash:x}")
|
118 | 114 | }
|
119 | 115 |
|
120 |
| -pub fn commit_schema(stream_name: &str, schema: Arc<Schema>) -> Result<(), StagingError> { |
121 |
| - let mut stream_metadata = PARSEABLE.streams.write().expect("lock poisoned"); |
122 |
| - |
123 |
| - let map = &mut stream_metadata |
124 |
| - .get_mut(stream_name) |
125 |
| - .expect("map has entry for this stream name") |
126 |
| - .metadata |
127 |
| - .write() |
128 |
| - .expect(LOCK_EXPECT) |
129 |
| - .schema; |
130 |
| - let current_schema = Schema::new(map.values().cloned().collect::<Fields>()); |
131 |
| - let schema = Schema::try_merge(vec![current_schema, schema.as_ref().clone()])?; |
132 |
| - map.clear(); |
133 |
| - map.extend(schema.fields.iter().map(|f| (f.name().clone(), f.clone()))); |
134 |
| - Ok(()) |
135 |
| -} |
136 |
| - |
137 | 116 | pub mod error {
|
138 | 117 |
|
139 |
| - use crate::{parseable::StagingError, storage::ObjectStorageError}; |
| 118 | + use crate::{ |
| 119 | + parseable::{StagingError, StreamNotFound}, |
| 120 | + storage::ObjectStorageError, |
| 121 | + }; |
140 | 122 |
|
141 | 123 | #[derive(Debug, thiserror::Error)]
|
142 | 124 | pub enum EventError {
|
143 | 125 | #[error("Staging Failed: {0}")]
|
144 | 126 | Staging(#[from] StagingError),
|
145 | 127 | #[error("ObjectStorage Error: {0}")]
|
146 | 128 | ObjectStorage(#[from] ObjectStorageError),
|
| 129 | + #[error("{0}")] |
| 130 | + NotFound(#[from] StreamNotFound), |
147 | 131 | }
|
148 | 132 | }
|
0 commit comments