Skip to content

Commit

Permalink
Retain order for property maps (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
CapCap authored Jan 14, 2025
1 parent 27d9d66 commit a905292
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
23 changes: 12 additions & 11 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ google-cloud-googleapis = "0.10.0"
google-cloud-pubsub = "0.18.0"
hex = "0.4.3"
itertools = "0.12.1"
indexmap = { version = "2.7.0", features = ["serde"] }
jemallocator = { version = "0.5.0", features = [
"profiling",
"unprefixed_malloc_on_supported_platforms",
Expand Down
1 change: 1 addition & 0 deletions rust/processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ google-cloud-pubsub = { workspace = true }
google-cloud-storage = { workspace = true }
hex = { workspace = true }
hyper = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
kanal = { workspace = true }
lazy_static = { workspace = true }
Expand Down
11 changes: 6 additions & 5 deletions rust/processor/src/db/postgres/models/property_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::utils::util;
use ahash::AHashMap;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_json::{Result, Value};

Expand All @@ -21,14 +22,14 @@ pub fn create_property_value(typ: String, value: String) -> Result<PropertyValue

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PropertyMap {
data: AHashMap<String, PropertyValue>,
data: IndexMap<String, PropertyValue>,
}

impl PropertyMap {
/// Deserializes PropertyValue from bcs encoded json
pub fn from_bcs_encode_str(val: Value) -> Option<Value> {
let mut pm = PropertyMap {
data: AHashMap::new(),
data: IndexMap::new(),
};
let records: &Vec<Value> = val.get("map")?.get("data")?.as_array()?;
for entry in records {
Expand Down Expand Up @@ -71,14 +72,14 @@ pub fn create_token_object_property_value(

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TokenObjectPropertyMap {
data: AHashMap<String, TokenObjectPropertyValue>,
data: IndexMap<String, TokenObjectPropertyValue>,
}

impl TokenObjectPropertyMap {
/// Deserializes PropertyValue from bcs encoded json
pub fn from_bcs_encode_str(val: Value) -> Option<Value> {
let mut pm = TokenObjectPropertyMap {
data: AHashMap::new(),
data: IndexMap::new(),
};
let records: &Vec<Value> = val.get("data")?.as_array()?;
for entry in records {
Expand All @@ -95,7 +96,7 @@ impl TokenObjectPropertyMap {
/// For example: Object {"data": Object {"creation_time_sec": Object {"value": String("1666125588")}}}
/// becomes Object {"creation_time_sec": "1666125588"}
fn to_flat_json_new(val: TokenObjectPropertyMap) -> Value {
let mut map = AHashMap::new();
let mut map = IndexMap::new();
for (k, v) in val.data {
map.insert(k, v.value);
}
Expand Down

0 comments on commit a905292

Please sign in to comment.