Few utility functions for our mostly data engineering applications.
Few functions to generate consistent hash based external ids.
Rust
pub fn get_external_id_str(name: &str, prefix: &str) -> String {
let mut spooky_hasher = SpookyHasher::new(1337, 7331);
spooky_hasher.write(name.as_bytes());
let hash_uint64 = spooky_hasher.finish();
let hash_hex = format!("{:x}", hash_uint64);
let base32 = base32::encode(Alphabet::RFC4648 { padding: false }, hash_hex.as_bytes());
format!("{}-{}", prefix, base32.to_ascii_lowercase())
}
There are few kinds we have in most of our applications:
```Rust pub fn getdbeid(databasename: &str) -> String { getexternalidstr(database_name, "db") }
pub fn gettableeid(tablename: &str) -> String { getexternalidstr(table_name, "table") }
pub fn getjobeid(jobname: &str) -> String { getexternalidstr(job_name, "job") }
pub fn getqueryeid(queryname: &str) -> String { getexternalidstr(query_name, "query") } ```
There is only one small function in this to get the string version of Utc::now().
Rust
pub fn utc_now() -> String {
let now: DateTime<Utc> = Utc::now();
now.to_rfc3339()
}